From mboxrd@z Thu Jan 1 00:00:00 1970 From: Claude Code Review Bot 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 Message-ID: In-Reply-To: <20260525050830.100254-5-mpenttil@redhat.com> References: <20260525050830.100254-1-mpenttil@redhat.com> <20260525050830.100254-5-mpenttil@redhat.com> X-Mailer: Claude Code Patch Reviewer Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit MIME-Version: 1.0 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