From: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
To: Alex Deucher <alexander.deucher@amd.com>,
Christian König <christian.koenig@amd.com>
Cc: Eric Huang <jinhuieric.huang@amd.com>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
stable@vger.kernel.org,
Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Subject: [PATCH v2 2/2] drm/amdgpu: use spin_lock_irqsave for PASID IDR lock
Date: Mon, 30 Mar 2026 10:30:25 +0500 [thread overview]
Message-ID: <20260330053025.19203-3-mikhail.v.gavrilov@gmail.com> (raw)
In-Reply-To: <20260330053025.19203-1-mikhail.v.gavrilov@gmail.com>
amdgpu_pasid_free() can be called from hardirq context via the fence
signal path:
sdma_v6_0_process_trap_irq
-> amdgpu_fence_process
-> dma_fence_signal
-> drm_sched_job_done
-> dma_fence_signal
-> amdgpu_pasid_free_cb
-> amdgpu_pasid_free
-> spin_lock(&amdgpu_pasid_idr_lock) <- hardirq context
But the lock was originally taken with plain spin_lock() in process
context (amdgpu_pasid_alloc), creating an inconsistent
{HARDIRQ-ON-W} -> {IN-HARDIRQ-W} lock state that can deadlock if an
interrupt arrives while the lock is held on the same CPU.
Use spin_lock_irqsave/spin_unlock_irqrestore for all call sites of
amdgpu_pasid_idr_lock to prevent the deadlock.
This patch applies on top of "drm/amdgpu: fix sleeping allocation
under spinlock in PASID IDR".
Fixes: 8f1de51f49be ("drm/amdgpu: prevent immediate PASID reuse case")
Cc: stable@vger.kernel.org
Signed-off-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
index 515775eab2ef..762ceb3c708a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
@@ -62,16 +62,17 @@ struct amdgpu_pasid_cb {
*/
int amdgpu_pasid_alloc(unsigned int bits)
{
+ unsigned long flags;
int pasid;
if (bits == 0)
return -EINVAL;
idr_preload(GFP_KERNEL);
- spin_lock(&amdgpu_pasid_idr_lock);
+ spin_lock_irqsave(&amdgpu_pasid_idr_lock, flags);
pasid = idr_alloc_cyclic(&amdgpu_pasid_idr, NULL, 1,
1U << bits, GFP_NOWAIT);
- spin_unlock(&amdgpu_pasid_idr_lock);
+ spin_unlock_irqrestore(&amdgpu_pasid_idr_lock, flags);
idr_preload_end();
if (pasid >= 0)
@@ -86,11 +87,12 @@ int amdgpu_pasid_alloc(unsigned int bits)
*/
void amdgpu_pasid_free(u32 pasid)
{
+ unsigned long flags;
trace_amdgpu_pasid_freed(pasid);
- spin_lock(&amdgpu_pasid_idr_lock);
+ spin_lock_irqsave(&amdgpu_pasid_idr_lock, flags);
idr_remove(&amdgpu_pasid_idr, pasid);
- spin_unlock(&amdgpu_pasid_idr_lock);
+ spin_unlock_irqrestore(&amdgpu_pasid_idr_lock, flags);
}
static void amdgpu_pasid_free_cb(struct dma_fence *fence,
@@ -633,7 +635,9 @@ void amdgpu_vmid_mgr_fini(struct amdgpu_device *adev)
*/
void amdgpu_pasid_mgr_cleanup(void)
{
- spin_lock(&amdgpu_pasid_idr_lock);
+ unsigned long flags;
+
+ spin_lock_irqsave(&amdgpu_pasid_idr_lock, flags);
idr_destroy(&amdgpu_pasid_idr);
- spin_unlock(&amdgpu_pasid_idr_lock);
+ spin_unlock_irqrestore(&amdgpu_pasid_idr_lock, flags);
}
--
2.53.0
next prev parent reply other threads:[~2026-03-30 5:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-30 5:30 [PATCH v2 0/2] drm/amdgpu: fix locking issues in PASID IDR management Mikhail Gavrilov
2026-03-30 5:30 ` [PATCH v2 1/2] drm/amdgpu: fix sleeping allocation under spinlock in PASID IDR Mikhail Gavrilov
2026-03-31 7:36 ` Claude review: " Claude Code Review Bot
2026-03-30 5:30 ` Mikhail Gavrilov [this message]
2026-03-31 7:36 ` Claude review: drm/amdgpu: use spin_lock_irqsave for PASID IDR lock Claude Code Review Bot
2026-03-31 7:36 ` Claude review: drm/amdgpu: fix locking issues in PASID IDR management 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=20260330053025.19203-3-mikhail.v.gavrilov@gmail.com \
--to=mikhail.v.gavrilov@gmail.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jinhuieric.huang@amd.com \
--cc=simona@ffwll.ch \
--cc=stable@vger.kernel.org \
/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