drm/amdgpu: fix the idr allocation flags
Subsystems (2)
PATCH 1/1 drm/amdgpu: fix the idr allocation flags
Fix the IDR allocation flags by using atomic GFP flags in non‑sleepable contexts to avoid the __might_sleep() complaint.
268.290239] [drm] Initialized amdgpu 3.64.0 for 0000:03:00.0 on minor 0
[ 268.294900] BUG: sleeping function called from invalid context at ./include/linux/sched/mm.h:323
[ 268.295355] in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 1744, name: modprobe
[ 268.295705] preempt_count: 1, expected: 0
[ 268.295886] RCU nest depth: 0, expected: 0
[ 268.296072] 2 locks held by modprobe/1744:
[ 268.296077] #0: ffff8c3a44abd1b8 (&dev->mutex){....}-{4:4}, at: __driver_attach+0xe4/0x210
[ 268.296100] #1: ffffffffc1a6ea78 (amdgpu_pasid_idr_lock){+.+.}-{3:3}, at: amdgpu_pasid_alloc+0x26/0xe0 [amdgpu]
[ 268.296494] CPU: 12 UID: 0 PID: 1744 Comm: modprobe Tainted: G U OE 6.19.0-custom #16 PREEMPT(voluntary)
[ 268.296498] Tainted: [U]=USER, [O]=OOT_MODULE, [E]=UNSIGNED_MODULE
[ 268.296499] Hardware name: AMD Majolica-RN/Majolica-RN, BIOS RMJ1009A 06/13/2021
[ 268.296501] Call Trace:--- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +1 -1
@@ -69,7 +69,7 @@ int amdgpu_pasid_alloc(unsigned int bits)spin_lock (&amdgpu_pasid_idr_lock); pasid =idr_alloc_cyclic (&amdgpu_pasid_idr,NULL ,1 , -1U << bits,GFP_KERNEL ); +1U << bits,GFP_ATOMIC );spin_unlock (&amdgpu_pasid_idr_lock);if (pasid >=0 )
Signature · 1 line
2.34.1
Christian König
maintainerQuoted 28 lines · Prike Liang
Fix the IDR allocation flags by using atomic GFP flags in non‑sleepable contexts to avoid the
__might_sleep()complaint.268.290239] [drm] Initialized amdgpu 3.64.0 for 0000:03:00.0 on minor 0
[ 268.294900] BUG: sleeping function called from invalid context at ./include/linux/sched/mm.h:323 [ 268.295355] in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 1744, name: modprobe [ 268.295705] preempt_count: 1, expected: 0 [ 268.295886] RCU nest depth: 0, expected: 0 [ 268.296072] 2 locks held by modprobe/1744: [ 268.296077] #0: ffff8c3a44abd1b8 (&dev->mutex){....}-{4:4}, at: __driver_attach+0xe4/0x210 [ 268.296100] #1: ffffffffc1a6ea78 (amdgpu_pasid_idr_lock){+.+.}-{3:3}, at: amdgpu_pasid_alloc+0x26/0xe0 [amdgpu] [ 268.296494] CPU: 12 UID: 0 PID: 1744 Comm: modprobe Tainted: G U OE 6.19.0-custom #16 PREEMPT(voluntary) [ 268.296498] Tainted: [U]=USER, [O]=OOT_MODULE, [E]=UNSIGNED_MODULE [ 268.296499] Hardware name: AMD Majolica-RN/Majolica-RN, BIOS RMJ1009A 06/13/2021 [ 268.296501] Call Trace:Fixes e6d765de3d6b ("drm/amdgpu: prevent immediate PASID reuse case")Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c int amdgpu_pasid_alloc(unsigned int bits) · line 72
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +1
-1@@ -69,7 +69,7 @@ int amdgpu_pasid_alloc(unsigned int bits)spin_lock (&amdgpu_pasid_idr_lock); pasid =idr_alloc_cyclic (&amdgpu_pasid_idr,NULL ,1 , -1U << bits,GFP_KERNEL ); +1U << bits,GFP_ATOMIC );
We should avoid using GFP_ATOMIC here and rather replace the spinlock with a mutex.
Regards,
Christian.
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +0
-0spin_unlock (&amdgpu_pasid_idr_lock);if (pasid >=0 )
[Public]
Regards,
Prike
Quoted 43 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Monday, March 23, 2026 5:54 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Huang, JinHuiEric <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix the idr allocation flagsQuoted 11 lines · Prike Liang
Fix the IDR allocation flags by using atomic GFP flags in non‑sleepable contexts to avoid the
__might_sleep()complaint.268.290239] [drm] Initialized amdgpu 3.64.0 for 0000:03:00.0 on
minor 0 [ 268.294900] BUG: sleeping function called from invalid context at./include/linux/sched/mm.h:323[ 268.295355]in_atomic():
1,irqs_disabled(): 0,non_block: 0, pid: 1744, name: modprobe [ 268.295705]preempt_count: 1, expected: 0 [ 268.295886] RCU nest
depth: 0, expected: 0 [ 268.296072] 2 locks held by modprobe/1744:[ 268.296077] #0: ffff8c3a44abd1b8 (&dev->mutex){....}-{4:4}, at:
__driver_attach+0xe4/0x210[ 268.296100] #1:ffffffffc1a6ea78(amdgpu_pasid_idr_lock){+.+.}-{3:3}, at:
amdgpu_pasid_alloc+0x26/0xe0[amdgpu]Quoted 1 line
[ 268.296494] CPU: 12 UID: 0 PID: 1744 Comm: modprobe Tainted: G U OE6.19.0-custom #16 PREEMPT(voluntary)
Quoted 1 line
[ 268.296498] Tainted: [U]=USER, [O]=OOT_MODULE,[E]=UNSIGNED_MODULE
Quoted 16 lines
[ 268.296499] Hardware name: AMD Majolica-RN/Majolica-RN, BIOSRMJ1009A 06/13/2021 [ 268.296501] Call Trace:
Fixes e6d765de3d6b ("drm/amdgpu: prevent immediate PASID reuse case")Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +0
-0@@ -69,7 +69,7 @@ int amdgpu_pasid_alloc(unsigned int bits)
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c int amdgpu_pasid_alloc(unsigned int bits) · line 72
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +1
-1spin_lock (&amdgpu_pasid_idr_lock); pasid =idr_alloc_cyclic (&amdgpu_pasid_idr,NULL ,1 , -1U << bits,GFP_KERNEL ); +1U << bits,GFP_ATOMIC );We should avoid using
GFP_ATOMIChere and rather replace the spinlock with a mutex.
OK, I will check that whether can use a mutex for the idr allocation in other places.
Quoted 6 lines
Regards,
Christian.Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +0
-0spin_unlock (&amdgpu_pasid_idr_lock);if (pasid >=0 )
[Public]
Regards,
Prike
Quoted 59 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Liang, Prike
Sent: Monday, March 23, 2026 8:14 PM
To: Koenig, Christian <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Huang, JinHuiEric <[email protected]>
Subject: RE: [PATCH] drm/amdgpu: fix the idr allocation flags[Public]
Regards,
PrikeQuoted 22 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Monday, March 23, 2026 5:54 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Huang, JinHuiEric <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix the idr allocation flagsQuoted 11 lines · Prike Liang
Fix the IDR allocation flags by using atomic GFP flags in non‑sleepable contexts to avoid the
__might_sleep()complaint.268.290239] [drm] Initialized amdgpu 3.64.0 for 0000:03:00.0 on
minor 0 [ 268.294900] BUG: sleeping function called from invalid context at./include/linux/sched/mm.h:323[ 268.295355]in_atomic():
1,irqs_disabled(): 0,non_block: 0, pid: 1744, name: modprobe [ 268.295705]preempt_count: 1, expected: 0 [ 268.295886] RCU nest
depth: 0, expected: 0 [ 268.296072] 2 locks held by modprobe/1744:[ 268.296077] #0: ffff8c3a44abd1b8 (&dev->mutex){....}-{4:4}, at:
__driver_attach+0xe4/0x210[ 268.296100] #1:ffffffffc1a6ea78Quoted 3 lines
(amdgpu_pasid_idr_lock){+.+.}-{3:3}, at:
amdgpu_pasid_alloc+0x26/0xe0[amdgpu]Quoted 1 line
[ 268.296494] CPU: 12 UID: 0 PID: 1744 Comm: modprobe Tainted: G UOE
Quoted 20 lines
6.19.0-custom #16 PREEMPT(voluntary)
Quoted 1 line
[ 268.296498] Tainted: [U]=USER, [O]=OOT_MODULE,[E]=UNSIGNED_MODULE
Quoted 17 lines
[ 268.296499] Hardware name: AMD Majolica-RN/Majolica-RN, BIOSRMJ1009A 06/13/2021 [ 268.296501] Call Trace:
Fixes e6d765de3d6b ("drm/amdgpu: prevent immediate PASID reusecase")
Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +0
-0@@ -69,7 +69,7 @@ int amdgpu_pasid_alloc(unsigned int bits)
Quoted 8 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c int amdgpu_pasid_alloc(unsigned int bits) · line 72
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +1
-1spin_lock (&amdgpu_pasid_idr_lock); pasid =idr_alloc_cyclic (&amdgpu_pasid_idr,NULL ,1 , -1U << bits,GFP_KERNEL ); +1U << bits,GFP_ATOMIC );We should avoid using
GFP_ATOMIChere and rather replace the spinlock with a mutex.OK, I will check that whether can use a mutex for the idr allocation in other places.
We may can't replace the spinlock with mutex here, since the lock need to be used in the DMA fence callback within the amdgpu_pasid_free_delayed().
Quoted 6 lines
Quoted 6 lines
Regards,
Christian.Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +0
-0spin_unlock (&amdgpu_pasid_idr_lock);if (pasid >=0 )
Christian König
maintainerQuoted 71 lines · Prike
[Public]
Regards,
PrikeQuoted 66 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Liang, Prike
Sent: Monday, March 23, 2026 8:14 PM
To: Koenig, Christian <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Huang, JinHuiEric <[email protected]>
Subject: RE: [PATCH] drm/amdgpu: fix the idr allocation flags[Public]
Regards,
PrikeQuoted 22 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Monday, March 23, 2026 5:54 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Huang, JinHuiEric <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix the idr allocation flagsQuoted 11 lines · Prike Liang
Fix the IDR allocation flags by using atomic GFP flags in non‑sleepable contexts to avoid the
__might_sleep()complaint.268.290239] [drm] Initialized amdgpu 3.64.0 for 0000:03:00.0 on
minor 0 [ 268.294900] BUG: sleeping function called from invalid context at./include/linux/sched/mm.h:323[ 268.295355]in_atomic():
1,irqs_disabled(): 0,non_block: 0, pid: 1744, name: modprobe [ 268.295705]preempt_count: 1, expected: 0 [ 268.295886] RCU nest
depth: 0, expected: 0 [ 268.296072] 2 locks held by modprobe/1744:[ 268.296077] #0: ffff8c3a44abd1b8 (&dev->mutex){....}-{4:4}, at:
__driver_attach+0xe4/0x210[ 268.296100] #1:ffffffffc1a6ea78Quoted 3 lines
(amdgpu_pasid_idr_lock){+.+.}-{3:3}, at:
amdgpu_pasid_alloc+0x26/0xe0[amdgpu]Quoted 1 line
[ 268.296494] CPU: 12 UID: 0 PID: 1744 Comm: modprobe Tainted: G UOE
Quoted 27 lines
6.19.0-custom #16 PREEMPT(voluntary)
Quoted 1 line
[ 268.296498] Tainted: [U]=USER, [O]=OOT_MODULE,[E]=UNSIGNED_MODULE
Quoted 16 lines
[ 268.296499] Hardware name: AMD Majolica-RN/Majolica-RN, BIOSRMJ1009A 06/13/2021 [ 268.296501] Call Trace:
Fixes e6d765de3d6b ("drm/amdgpu: prevent immediate PASID reusecase")
Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c int amdgpu_pasid_alloc(unsigned int bits) · line 72
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +1
-1@@ -69,7 +69,7 @@ int amdgpu_pasid_alloc(unsigned int bits)spin_lock (&amdgpu_pasid_idr_lock); pasid =idr_alloc_cyclic (&amdgpu_pasid_idr,NULL ,1 , -1U << bits,GFP_KERNEL ); +1U << bits,GFP_ATOMIC );We should avoid using
GFP_ATOMIChere and rather replace the spinlock with a mutex.
Quoted 2 lines
Quoted 1 line
OK, I will check that whether can use a mutex for the idr allocation in other places.
We may can't replace the spinlock with mutex here, since the lock need to be used in the DMA fence callback within the
amdgpu_pasid_free_delayed().
Good point. In that case please add a TODO comment that we need to replace the idr with an xarray at some point and push the patch with my rb.
Thanks,
Christian.
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Regards,
Christian.Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +0
-0spin_unlock (&amdgpu_pasid_idr_lock);if (pasid >=0 )