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/hmm: do the plumbing for HMM to participate in migration
Date: Mon, 25 May 2026 16:46:28 +1000	[thread overview]
Message-ID: <review-patch3-20260525050830.100254-4-mpenttil@redhat.com> (raw)
In-Reply-To: <20260525050830.100254-4-mpenttil@redhat.com>

Patch Review

**Several issues.**

1. **Duplicate `hmm_select_migrate()` definitions will cause build errors.** Patch 3 adds two definitions of `hmm_select_migrate()` in `include/linux/migrate.h`:
   - One at line ~880 inside `#ifdef CONFIG_MIGRATION` / `#else`:
     ```c
     static inline enum migrate_vma_info hmm_select_migrate(struct hmm_range *range)
     {
         return MIGRATE_VMA_SELECT_NONE;
     }
     ```
   - One at line ~902 inside the `CONFIG_DEVICE_MIGRATION` section:
     ```c
     // TODO: enable migration
     static inline enum migrate_vma_info hmm_select_migrate(struct hmm_range *range)
     {
         return 0;
     }
     ```
   When `CONFIG_DEVICE_MIGRATION` is enabled, both definitions are visible, producing a redefinition error. The first one (returning `MIGRATE_VMA_SELECT_NONE`) is only needed as a stub when `CONFIG_DEVICE_MIGRATION` is off. The second has a `// TODO` comment that should not be present in submitted code (and is a C++-style comment).

2. **`migrate_vma_direction` renamed to `migrate_vma_info` in two places** — this is the actual rename, but the `MIGRATE_VMA_SELECT_NONE` / `MIGRATE_VMA_SELECT_COMPOUND` definitions are questionable:
   ```c
   enum migrate_vma_info {
       MIGRATE_VMA_SELECT_NONE = 0,
       MIGRATE_VMA_SELECT_COMPOUND = MIGRATE_VMA_SELECT_NONE,
   };
   ```
   Setting `MIGRATE_VMA_SELECT_COMPOUND = MIGRATE_VMA_SELECT_NONE = 0` means the compound check `(minfo & MIGRATE_VMA_SELECT_COMPOUND)` in `hmm_pfns_fill()` will always be false. This is intentional for the non-migration stub, but confusing because the real `MIGRATE_VMA_SELECT_COMPOUND` (defined elsewhere as `1 << 3`) has a different value.

3. **C++-style comments** throughout (`//` instead of `/* */`). Linux kernel coding style requires C-style comments.

4. **`hmm_vma_walk_pmd()` rewrite is complex and hard to verify.** The function grows from ~50 lines to ~130+ lines with interleaved lock management via booleans. Key concern — after the `pmd_trans_huge()` block processes the PMD:
   ```c
   if (pmd_trans_huge(pmd)) {
       ...
       r = hmm_vma_handle_pmd(walk, addr, end, hmm_pfns, pmd);
       // If not migrating we are done
       if (r || !minfo) {
           if (hmm_vma_walk->pmdlocked) {
               spin_unlock(hmm_vma_walk->ptl);
               hmm_vma_walk->pmdlocked = false;
           }
           return r;
       }
   }
   r = hmm_vma_handle_migrate_prepare_pmd(walk, pmdp, start, end, hmm_pfns);
   ```
   If `hmm_vma_handle_pmd()` returns 0 and `minfo` is set, execution falls through to `hmm_vma_handle_migrate_prepare_pmd()` with the PMD lock still held. This is correct but the flow is non-obvious — the comment "If not migrating we are done" only makes sense if you understand the full state machine.

5. **`hmm_vma_capture_migrate_range()` issues:**
   ```c
   if (!hmm_vma_walk->mmu_range.owner) {
       mmu_notifier_range_init_owner(&hmm_vma_walk->mmu_range, ...);
       mmu_notifier_invalidate_range_start(&hmm_vma_walk->mmu_range);
   }
   ```
   The `mmu_notifier_invalidate_range_start()` is called but the corresponding `_end()` is done later in `hmm_range_fault()` only when `hmm_select_migrate(range) && range->migrate && hmm_vma_walk.mmu_range.owner`. If `hmm_range_fault()` returns early (e.g., `-EBUSY` from `mmu_interval_check_retry()`), the break at line 1530 jumps past the retry loop but still reaches the `#ifdef CONFIG_DEVICE_MIGRATION` cleanup. This appears correct but is fragile.

6. **`hmm_vma_handle_pte()` has an `if/else` without braces mismatch:**
   ```c
   if (!hmm_select_migrate(range)) {
       ...
       return -EBUSY;
   } else
       goto out;
   ```
   Kernel coding style requires braces on the `else` when the `if` has them.

---

---
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 Code Review Bot [this message]
2026-05-25  5:08 ` [PATCH v11 4/5] mm: setup device page migration in HMM pagewalk mpenttil
2026-05-25  6:46   ` Claude review: " Claude Code Review Bot
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 3/5] mm/hmm: do the plumbing for HMM to participate in migration 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-patch3-20260525050830.100254-4-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