From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: drm/amdgpu: replace PASID IDR with XArray
Date: Wed, 01 Apr 2026 07:48:28 +1000 [thread overview]
Message-ID: <review-patch1-20260331111808.16578-1-mikhail.v.gavrilov@gmail.com> (raw)
In-Reply-To: <20260331111808.16578-1-mikhail.v.gavrilov@gmail.com>
Patch Review
**Critical bug — hardirq deadlock not fixed:**
The core issue is that `amdgpu_pasid_free()` is called from hardirq context (via `amdgpu_pasid_free_cb` → fence signal path), and `amdgpu_pasid_alloc()` is called from process context. Both must use IRQ-disabling locking to prevent deadlock.
```c
xa_erase(&amdgpu_pasid_xa, pasid);
```
`xa_erase()` is defined in `lib/xarray.c` as:
```c
void *xa_erase(struct xarray *xa, unsigned long index)
{
xa_lock(xa); /* = spin_lock() -- IRQs NOT disabled */
entry = __xa_erase(xa, index);
xa_unlock(xa); /* = spin_unlock() */
return entry;
}
```
Similarly, `xa_alloc_cyclic()` in `include/linux/xarray.h`:
```c
static inline int xa_alloc_cyclic(...)
{
xa_lock(xa); /* = spin_lock() -- IRQs NOT disabled */
err = __xa_alloc_cyclic(...);
xa_unlock(xa);
return err < 0 ? err : 0;
}
```
The `XA_FLAGS_LOCK_IRQ` flag only affects `xas_lock_type()`/`xas_unlock_type()` used internally by `__xas_nomem()` when the XArray needs to drop the lock for memory allocation. It has **no effect** on the outer locking in `xa_erase()` or `xa_alloc_cyclic()`.
The XArray API provides dedicated IRQ-safe wrappers for exactly this situation:
- `xa_erase_irq()` — uses `xa_lock_irq()`/`xa_unlock_irq()`
- `xa_alloc_cyclic_irq()` — uses `xa_lock_irq()`/`xa_unlock_irq()`
**However**, `xa_erase_irq()` uses `spin_unlock_irq()` which unconditionally re-enables interrupts. Calling this from hardirq context would re-enable interrupts inside the hardirq handler, which is also wrong.
**The correct fix for `amdgpu_pasid_free()`** (callable from any context) should use `xa_lock_irqsave`/`xa_unlock_irqrestore` as v5 proposed:
```c
void amdgpu_pasid_free(u32 pasid)
{
unsigned long flags;
trace_amdgpu_pasid_freed(pasid);
xa_lock_irqsave(&amdgpu_pasid_xa, flags);
__xa_erase(&amdgpu_pasid_xa, pasid);
xa_unlock_irqrestore(&amdgpu_pasid_xa, flags);
}
```
For `amdgpu_pasid_alloc()` (process context only), `xa_alloc_cyclic_irq()` would work correctly, or alternatively the same `irqsave` pattern.
**Other observations (minor, all correct):**
- `DEFINE_XARRAY_FLAGS(amdgpu_pasid_xa, XA_FLAGS_LOCK_IRQ | XA_FLAGS_ALLOC1)` — using `XA_FLAGS_ALLOC1` to prevent PASID 0 allocation is appropriate, and makes the explicit `XA_LIMIT(1, ...)` minimum redundant but harmless.
- The return value handling is correct: `xa_alloc_cyclic()` returns 0 on success (squashing the wrap indicator), stores the ID in `&pasid`, and the code correctly checks `r >= 0` then returns `pasid`.
- Storing `xa_mk_value(0)` as the entry is fine — XArray needs a non-NULL entry for the slot to be considered allocated, and `xa_mk_value(0)` serves this purpose since the original IDR code stored `NULL` via `idr_alloc_cyclic(..., NULL, ...)`.
- The `xa_destroy()` call in `amdgpu_pasid_mgr_cleanup()` is correct and does not need external locking.
- Dropping `Cc: stable` is correct since the regression (commit 8f1de51f49be) hasn't reached a stable kernel.
**Recommendation: NAK in current form.** The patch must use IRQ-safe locking wrappers. The simplest correct approach would be to use `xa_alloc_cyclic_irq()` for allocation and `xa_lock_irqsave`/`__xa_erase`/`xa_unlock_irqrestore` for free, as the v5 approach partially identified.
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-03-31 21:48 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 11:17 [PATCH v6] drm/amdgpu: replace PASID IDR with XArray Mikhail Gavrilov
2026-03-31 12:28 ` Christian König
2026-03-31 14:30 ` Mikhail Gavrilov
2026-03-31 21:48 ` Claude Code Review Bot [this message]
2026-03-31 21:48 ` Claude review: " Claude Code Review Bot
-- strict thread matches above, loose matches on Subject: below --
2026-03-31 14:21 [PATCH v7] " Mikhail Gavrilov
2026-03-31 21:43 ` Claude review: " Claude Code Review Bot
2026-03-31 21:43 ` Claude Code Review Bot
2026-03-30 19:11 [PATCH v5] " Mikhail Gavrilov
2026-03-31 6:57 ` Claude review: " Claude Code Review Bot
2026-03-31 6:57 ` Claude Code Review Bot
2026-03-30 14:50 [PATCH v4] " Mikhail Gavrilov
2026-03-31 7:08 ` Claude review: " Claude Code Review Bot
2026-03-31 7:08 ` Claude Code Review Bot
2026-03-30 11:35 [PATCH v3] " Mikhail Gavrilov
2026-03-31 7:18 ` Claude review: " Claude Code Review Bot
2026-03-31 7:18 ` 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-patch1-20260331111808.16578-1-mikhail.v.gavrilov@gmail.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