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: mm/memory: Fix spurious warning when unmapping device-private/exclusive pages
Date: Tue, 05 May 2026 09:37:51 +1000	[thread overview]
Message-ID: <review-patch1-20260501065116.2057242-1-apopple@nvidia.com> (raw)
In-Reply-To: <20260501065116.2057242-1-apopple@nvidia.com>

Patch Review

**Kernel fix (mm/memory.c):**

The one-line change is correct and well-placed:

```c
-		WARN_ON_ONCE(!vma_is_anonymous(vma));
+		WARN_ON_ONCE(!folio_test_anon(folio));
```

The `folio` variable is already in scope (declared at the top of the device-private/exclusive block), so this is safe. The fix aligns the unmap-path assertion with what `__migrate_device_pages()` actually enforces at migration time (see `mm/migrate_device.c:1203`):

```c
if (!folio_test_anon(folio) ||
    !folio_free_swap(folio)) {
    src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
    goto next;
}
```

The surrounding comment ("Both device private/exclusive mappings should only work with anonymous page") remains accurate — the invariant is about the folio being anonymous, not the VMA. The uffd-wp reasoning still holds since uffd-wp markers for anonymous folios are tracked via swap entries, independent of VMA type.

The Fixes tag (`999dad824c39e`) and `Cc: stable` are appropriate.

**Selftest (hmm-tests.c):**

The new `migrate_file_private` test correctly exercises the bug:
1. Creates a temp file via `hmm_create_file()`
2. Maps it `MAP_PRIVATE` (file-backed VMA, `vma_is_anonymous()` = false)
3. Writes to it (triggers CoW, `folio_test_anon()` becomes true)
4. Migrates to device private memory (succeeds because `folio_test_anon()` is checked)
5. `hmm_buffer_free()` calls `munmap()`, triggering `zap_nonpresent_ptes()` — where the old assertion would fire

The test follows the existing patterns (`file_read`, `migrate`) well.

**Minor nit:** The test leaks the file descriptor from `hmm_create_file()`. Since the file is `O_TMPFILE`, the data is cleaned up on process exit, but `close(fd)` should be called for correctness, especially in a long-running test harness. This is technically a pre-existing issue (the `file_read` test at line 847 has the same leak), but since this is new code, it's worth adding a `close(buffer->fd)` or `close(fd)` before `hmm_buffer_free()`. Alternatively, `hmm_buffer_free()` could be extended to close `buffer->fd` when it's not `-1`.

No other issues found.

---
Generated by Claude Code Patch Reviewer

      parent reply	other threads:[~2026-05-04 23:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-01  6:51 [PATCH] mm/memory: Fix spurious warning when unmapping device-private/exclusive pages Alistair Popple
2026-05-02  1:14 ` Balbir Singh
2026-05-04 23:37 ` Claude review: " Claude Code Review Bot
2026-05-04 23:37 ` Claude Code Review Bot [this message]

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-20260501065116.2057242-1-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