public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: lib: test_hmm: evict device pages on file close to avoid use-after-free
Date: Tue, 31 Mar 2026 16:41:09 +1000	[thread overview]
Message-ID: <review-patch1-20260331063445.3551404-2-apopple@nvidia.com> (raw)
In-Reply-To: <20260331063445.3551404-2-apopple@nvidia.com>

Patch Review

**Correctness concern — evicts ALL device chunks, not just this dmirror's pages:**

The release handler iterates over all `mdevice->devmem_chunks` and calls `dmirror_device_evict_chunk()` on each:

```c
if (mdevice->devmem_chunks) {
    for (i = 0; i < mdevice->devmem_count; i++) {
        struct dmirror_chunk *devmem =
            mdevice->devmem_chunks[i];
        dmirror_device_evict_chunk(devmem);
    }
}
```

This evicts **all** device private pages from the entire device, not just pages belonging to the closing dmirror instance. If multiple file descriptors (and thus multiple `dmirror` structs) are open on the same device simultaneously, closing one will evict pages that belong to other active dmirror instances. The `migrate_device_range()` call operates on physical PFN ranges and doesn't filter by owner.

In practice this is probably fine for a test driver (tests are sequential), but it's worth noting in the commit message or as a comment. The proper fix would filter pages by checking `zone_device_data` against the closing `dmirror`, but that's significantly more complex and probably overkill for a test module.

**Missing locking:** The `dmirror_device_remove_chunks()` function takes `mdevice->devmem_lock` and `mdevice->lock` when doing eviction, but the eviction in `dmirror_fops_release()` holds neither lock. `migrate_device_range()` likely handles its own synchronization, but the lack of `devmem_lock` around the `mdevice->devmem_chunks` / `mdevice->devmem_count` access is a potential TOCTOU issue if chunks could be added/removed concurrently.

**No NULL check on folio_alloc for compound pages:**

```c
if (src_pfns[i] & MIGRATE_PFN_COMPOUND) {
    dpage = folio_page(folio_alloc(GFP_HIGHUSER_MOVABLE,
                  order), 0);
}
```

If `folio_alloc()` returns NULL, `folio_page(NULL, 0)` will crash. The non-compound path uses `__GFP_NOFAIL` but the compound path doesn't. This is a pre-existing issue (the function was just moved), not introduced by this patch.

**Overall:** The fix is correct for the reported problem. The function move is clean — the code is identical.

---
Generated by Claude Code Patch Reviewer

  reply	other threads:[~2026-03-31  6:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-31  6:34 [PATCH 0/3] Minor hmm_test fixes and cleanups Alistair Popple
2026-03-31  6:34 ` [PATCH 1/3] lib: test_hmm: evict device pages on file close to avoid use-after-free Alistair Popple
2026-03-31  6:41   ` Claude Code Review Bot [this message]
2026-03-31  6:34 ` [PATCH 2/3] selftests/mm: hmm-tests: don't hardcode THP size to 2MB Alistair Popple
2026-03-31  6:41   ` Claude review: " Claude Code Review Bot
2026-03-31  6:34 ` [PATCH 3/3] lib: test_hmm: Implement a device release method Alistair Popple
2026-03-31  6:41   ` Claude review: " Claude Code Review Bot
2026-03-31  6:41 ` Claude review: Minor hmm_test fixes and cleanups Claude Code Review Bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=review-patch1-20260331063445.3551404-2-apopple@nvidia.com \
    --to=claude-review@example.com \
    --cc=dri-devel-reviews@example.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox