From mboxrd@z Thu Jan 1 00:00:00 1970 From: Claude Code Review Bot To: dri-devel-reviews@example.com Subject: Claude review: drm/amdgpu: replace PASID IDR with XArray Date: Wed, 01 Apr 2026 07:43:14 +1000 Message-ID: In-Reply-To: <20260331142127.52796-1-mikhail.v.gavrilov@gmail.com> References: <20260331142127.52796-1-mikhail.v.gavrilov@gmail.com> <20260331142127.52796-1-mikhail.v.gavrilov@gmail.com> X-Mailer: Claude Code Patch Reviewer Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Patch Review **Critical bug =E2=80=94 wrong locking wrappers:** ```c + r =3D xa_alloc_cyclic(&amdgpu_pasid_xa, &pasid, xa_mk_value(0), + XA_LIMIT(1, (1U << bits) - 1), + &amdgpu_pasid_xa_next, GFP_KERNEL); ``` This must be `xa_alloc_cyclic_irq()` to disable interrupts while holding th= e xa_lock. The plain `xa_alloc_cyclic()` uses `xa_lock()`/`xa_unlock()` (se= e `include/linux/xarray.h:976-987`), which does not disable IRQs. ```c + xa_erase(&amdgpu_pasid_xa, pasid); ``` This must be `xa_erase_irq()`. The plain `xa_erase()` uses `xa_lock()`/`xa_= unlock()` (see `lib/xarray.c:1665-1674`), which does not disable IRQs. Sinc= e `amdgpu_pasid_free()` can be called from hardirq context (via the fence s= ignal path documented in the commit message), and `xa_alloc_cyclic()` in pr= ocess context takes the same lock without disabling IRQs, the exact same de= adlock scenario described in the commit message still applies. **The fix:** Replace `xa_alloc_cyclic()` with `xa_alloc_cyclic_irq()` and `= xa_erase()` with `xa_erase_irq()`. Alternatively, use explicit `xa_lock_irq= save()`/`__xa_erase()`/`xa_unlock_irqrestore()` in `amdgpu_pasid_free()` (s= ince it's called from hardirq, `_irqsave` is the safest choice there), and = `xa_alloc_cyclic_irq()` for the allocation path. **Note:** The v5 changelog mentions that the author previously used explici= t `xa_lock_irqsave`/`__xa_erase` for this exact reason, but was told to use= the convenience wrappers in v6. The v6/v7 approach unfortunately reintrodu= ces the problem. **Minor nits (non-blocking):** - The `XA_FLAGS_LOCK_IRQ` flag in `DEFINE_XARRAY_FLAGS` is not harmful, but= it also isn't doing what the author thinks. It sets the lock class for loc= kdep =E2=80=94 it doesn't make convenience wrappers use IRQ-safe locking. I= t's still correct to set it (it tells lockdep the lock is used in IRQ conte= xt), but the actual API calls must be the `_irq` variants. - The `xa_mk_value(0)` store is fine =E2=80=94 it stores a non-NULL value s= o the slot is occupied, preventing double-allocation of the same PASID. - The `XA_FLAGS_ALLOC1` usage is correct (zero is not a valid PASID), thoug= h the `XA_LIMIT(1, ...)` already enforces the minimum of 1. - The cleanup function change to `xa_destroy()` is correct and straightforw= ard. --- Generated by Claude Code Patch Reviewer