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: setup device page migration in HMM pagewalk
Date: Mon, 25 May 2026 16:46:28 +1000	[thread overview]
Message-ID: <review-patch4-20260525050830.100254-5-mpenttil@redhat.com> (raw)
In-Reply-To: <20260525050830.100254-5-mpenttil@redhat.com>

Patch Review

**Most substantive patch; several issues.**

1. **`migrate_vma_setup()` now returns errors where it previously returned 0.** The original `migrate_vma_setup()` always returned 0 (or negative for invalid args). Now it returns `hmm_range_fault()`'s return value, and when that's non-zero, it calls `migrate_vma_pages()` + `migrate_vma_finalize()` to clean up:
   ```c
   ret = hmm_range_fault(&range);
   migrate_hmm_range_setup(&range);
   /* Remove migration PTEs */
   if (ret) {
       migrate_vma_pages(args);
       migrate_vma_finalize(args);
   }
   ...
   return ret;
   ```
   This changes the API contract. Callers of `migrate_vma_setup()` previously never checked for non-argument errors. Any existing driver calling `migrate_vma_setup()` that doesn't handle `-EBUSY` etc. will now break. This is a **significant behavioral change** that needs careful audit of all callers.

2. **`hmm_vma_handle_migrate_prepare()` uses `pfn` for device private pages but doesn't initialize it in the present-pte path before `flush_cache_page()`:**
   ```c
   if (!pte_present(pte)) {
       ...
       pfn = page_to_pfn(page);
       ...
   } else {
       pfn = pte_pfn(pte);
       ...
       page = vm_normal_page(walk->vma, addr, pte);
       ...
   }
   ...
   flush_cache_page(walk->vma, addr, pfn);
   ```
   In the present-pte path, `pfn` is set to `pte_pfn(pte)`, but later `page` may be NULL (from `vm_normal_page()`), and the code reaches the `!page || !page->mapping` check and goes to `out`. This is fine. But if `page` exists and we reach `flush_cache_page()`, `pfn` is correct. OK on closer inspection.

3. **`hmm_vma_walk_split()` folio locking inconsistency.** When the `fault_folio == folio` case is hit:
   ```c
   if (folio != fault_folio) {
       if (unlikely(!folio_trylock(folio))) {
           folio_put(folio);
           ret = -EBUSY;
           goto out;
       }
   }  else
       folio_put(folio);
   
   ret = split_folio(folio);
   if (fault_folio != folio) {
       folio_unlock(folio);
       folio_put(folio);
   }
   ```
   When `folio == fault_folio`: the `else` branch does `folio_put(folio)` (dropping the ref taken by `folio_get` a few lines above), then calls `split_folio(folio)` on a folio that may now have been freed. This is a potential **use-after-free**. The `folio_put()` should be deferred until after `split_folio()`.

4. **`migrate_vma_split_folio()` in hmm.c** takes an additional `hmm_vma_walk` + `ptep` parameter compared to the original in `migrate_device.c`, and does `pte_unmap_unlock(ptep, hmm_vma_walk->ptl)`. The original version didn't hold pte locks (it was called after `pte_unmap_unlock`). This is correct for the new call site but the function name is now misleading since it does pte unlock as a side effect.

5. **Kernel coding style**: Multiple `} else` without braces when the `if` has braces, and C++-style comments (`//`).

6. **Missing `lazy_mmu_mode_enable/disable`**: The original `migrate_vma_collect_pmd()` used `lazy_mmu_mode_enable()` before the PTE loop and `lazy_mmu_mode_disable()` after. The new `hmm_vma_walk_pmd()` does not call these, which may have performance implications on architectures that support lazy TLB mode (e.g., paravirtualized).

---

---
Generated by Claude Code Patch Reviewer

  reply	other threads:[~2026-05-25  6:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-25  5:08 [PATCH v11 0/5] Migrate on fault for device pages mpenttil
2026-05-25  5:08 ` [PATCH v11 1/5] mm/Kconfig: changes for migrate " mpenttil
2026-05-25  6:46   ` Claude review: " Claude Code Review Bot
2026-05-25  5:08 ` [PATCH v11 2/5] mm: Add helper to convert HMM pfn to migrate pfn mpenttil
2026-05-25  6:46   ` Claude review: " Claude Code Review Bot
2026-05-25  5:08 ` [PATCH v11 3/5] mm/hmm: do the plumbing for HMM to participate in migration mpenttil
2026-05-25  6:46   ` Claude review: " Claude Code Review Bot
2026-05-25  5:08 ` [PATCH v11 4/5] mm: setup device page migration in HMM pagewalk mpenttil
2026-05-25  6:46   ` Claude Code Review Bot [this message]
2026-05-25  5:08 ` [PATCH v11 5/5] lib/test_hmm: add a new testcase for the migrate on fault mpenttil
2026-05-25  6:46   ` Claude review: " Claude Code Review Bot
2026-05-25  6:46 ` Claude review: Migrate on fault for device pages Claude Code Review Bot
  -- strict thread matches above, loose matches on Subject: below --
2026-05-25  8:45 [PATCH v12 0/5] " mpenttil
2026-05-25  8:45 ` [PATCH v12 4/5] mm: setup device page migration in HMM pagewalk mpenttil
2026-05-25 21:29   ` Claude review: " 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-patch4-20260525050830.100254-5-mpenttil@redhat.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