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: Tue, 31 Mar 2026 16:57:38 +1000 Message-ID: In-Reply-To: <20260330191120.105065-1-mikhail.v.gavrilov@gmail.com> References: <20260330191120.105065-1-mikhail.v.gavrilov@gmail.com> <20260330191120.105065-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 **Commit message**: Excellent. The bug description is thorough, with clear = lockdep-style annotation and a concrete reproduction scenario (RX 7900 XTX,= Vulkan game under Proton). The changelog across v1-v5 is well documented. **Bug =E2=80=94 xa_alloc_cyclic() is not IRQ-safe** (line 70-72 of patched = file): ```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); ``` `xa_alloc_cyclic()` uses plain `xa_lock()` (see `include/linux/xarray.h:982= `): ```c xa_lock(xa); err =3D __xa_alloc_cyclic(xa, id, entry, limit, next, gfp); xa_unlock(xa); ``` Since `amdgpu_pasid_free()` can be called from hardirq context (the entire = reason for this patch), an IRQ arriving while this lock is held will deadlo= ck. This must be `xa_alloc_cyclic_irq()` which disables IRQs around the loc= k (`include/linux/xarray.h:1054`). **Return value change** (lines 74-79): The original `idr_alloc_cyclic()` re= turned the allocated ID on success (positive) or negative errno. `xa_alloc_= cyclic()` returns 0 on success and writes the ID to `*pasid`. The patch cor= rectly handles this =E2=80=94 checking `r >=3D 0` and returning `pasid` rat= her than `r`. Note that `xa_alloc_cyclic()` actually swallows the wrap-arou= nd indicator (returns 0 even on wrap), but `__xa_alloc_cyclic()` returns 1 = on wrap. Since this code doesn't care about wrap notification, this is fine. **Return value for -EBUSY** (line 79): The original IDR code returned `-ENO= SPC` on exhaustion (per IDR semantics), while `xa_alloc_cyclic()` returns `= -EBUSY`. The docstring at line 59 still says "Returns %-ENOSPC if no PASID = was available" =E2=80=94 this should be updated to `-EBUSY` to match realit= y. Minor documentation nit. **amdgpu_pasid_free() locking** (lines 92-94): Correct. Using `xa_lock_irqs= ave()`/`__xa_erase()`/`xa_unlock_irqrestore()` is the right approach for ha= rdirq context. **xa_mk_value(0) as stored entry** (line 70): Storing `xa_mk_value(0)` work= s =E2=80=94 XArray treats NULL as "empty", so an explicit non-NULL value is= needed to mark the slot as occupied. `xa_mk_value(0)` is the lightest-weig= ht way to do this. Fine. **Cleanup** (line 261): `xa_destroy()` without locking is correct =E2=80=94= this is called at module teardown when no concurrent access is possible. **Recommendation**: NAK as-is due to the `xa_alloc_cyclic()` deadlock. The = one-line fix is to change it to `xa_alloc_cyclic_irq()`. With that change, = the patch would be correct and ready. --- Generated by Claude Code Patch Reviewer