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: drm/xe/userptr: Convert invalidation to two-pass MMU notifier
Date: Wed, 04 Mar 2026 07:09:16 +1000	[thread overview]
Message-ID: <review-patch2-20260303133409.11609-3-thomas.hellstrom@linux.intel.com> (raw)
In-Reply-To: <20260303133409.11609-3-thomas.hellstrom@linux.intel.com>

Patch Review

This converts the xe userptr notifier from a single `invalidate` callback to the new `invalidate_start`/`invalidate_finish` two-pass model.

**BUG — static local variable in `xe_vma_userptr_force_invalidate`:**

```c
void xe_vma_userptr_force_invalidate(struct xe_userptr_vma *uvma)
{
	static struct mmu_interval_notifier_finish *finish;
```

This declares `finish` as `static`, meaning it's shared across all calls to this function. This is almost certainly wrong — it should be a plain local variable. Using `static` here would cause data races if this function were ever called concurrently (even though it's under `CONFIG_DRM_XE_USERPTR_INVAL_INJECT` and may currently be single-threaded in testing paths, `static` is still incorrect). Should be:

```c
	struct mmu_interval_notifier_finish *finish;
```

**Design observation — `finish_inuse` flag:**

The `finish_inuse` bool is used to prevent two concurrent invalidations from both trying to use the embedded `struct mmu_interval_notifier_finish`. When `finish_inuse` is set, the second caller falls back to the synchronous single-pass path. This is a pragmatic approach that avoids dynamic allocation.

However, the lock protection for `finish_inuse` should be reviewed carefully. It's documented as:
```
Protected by struct xe_vm::svm.gpusvm.notifier_lock in write mode
alternatively by the same lock in read mode *and* the vm resv held.
```

In `xe_vma_userptr_invalidate_start`, the notifier_lock is held in write mode when `xe_vma_userptr_invalidate_pass1` reads and sets `finish_inuse`, so that's correct. In `xe_vma_userptr_invalidate_finish`, the notifier_lock is also taken in write mode, so clearing `finish_inuse` via `xe_vma_userptr_do_inval(vm, uvma, true)` is also correct.

**Locking assertion `xe_userptr_assert_in_notifier`:**

```c
static void xe_userptr_assert_in_notifier(struct xe_vm *vm)
{
	lockdep_assert(lockdep_is_held_type(&vm->svm.gpusvm.notifier_lock, 0) ||
		       (lockdep_is_held(&vm->lock) &&
			lockdep_is_held_type(&vm->svm.gpusvm.notifier_lock, 1) &&
			dma_resv_held(xe_vm_resv(vm))));
}
```

This asserts either: notifier_lock in write mode, OR (vm->lock held AND notifier_lock in read mode AND resv held). This matches the documented locking for the state members and looks correct.

**Minor nit:** The `xe_vma_userptr_do_inval` function unconditionally does `dma_resv_wait_timeout` with `MAX_SCHEDULE_TIMEOUT` and a non-blockable `false` parameter. This was inherited from the original code but it means this path always sleeps. The `mmu_notifier_range_blockable` check happens earlier in `xe_vma_userptr_invalidate_start`, which returns `false` if non-blockable. So this is fine.

Overall: **One bug (static variable), otherwise looks correct.**

---

---
Generated by Claude Code Patch Reviewer

  parent reply	other threads:[~2026-03-03 21:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-03 13:34 [PATCH v3 0/4] Two-pass MMU interval notifiers Thomas Hellström
2026-03-03 13:34 ` [PATCH v3 1/4] mm/mmu_notifier: Allow two-pass struct mmu_interval_notifiers Thomas Hellström
2026-03-03 21:09   ` Claude review: " Claude Code Review Bot
2026-03-03 13:34 ` [PATCH v3 2/4] drm/xe/userptr: Convert invalidation to two-pass MMU notifier Thomas Hellström
2026-03-03 18:10   ` Matthew Brost
2026-03-03 21:09   ` Claude Code Review Bot [this message]
2026-03-03 13:34 ` [PATCH v3 3/4] drm/xe: Split TLB invalidation into submit and wait steps Thomas Hellström
2026-03-03 18:13   ` Matthew Brost
2026-03-03 21:09   ` Claude review: " Claude Code Review Bot
2026-03-03 13:34 ` [PATCH v3 4/4] drm/xe/userptr: Defer Waiting for TLB invalidation to the second pass if possible Thomas Hellström
2026-03-03 21:09   ` Claude review: " Claude Code Review Bot
2026-03-03 21:09 ` Claude review: Two-pass MMU interval notifiers Claude Code Review Bot
  -- strict thread matches above, loose matches on Subject: below --
2026-03-02 16:32 [PATCH v2 0/4] " Thomas Hellström
2026-03-02 16:32 ` [PATCH v2 2/4] drm/xe/userptr: Convert invalidation to two-pass MMU notifier Thomas Hellström
2026-03-03  3:05   ` 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-patch2-20260303133409.11609-3-thomas.hellstrom@linux.intel.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