Skip to contentSkip to conversation

drm/amdgpu: use IRQ-safe xarray API for PASID management

PATCH Superseded Mikhail Gavrilov 2 participants 2 messages Apr 1

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: use IRQ-safe xarray API for PASID management

xa_alloc_cyclic() and xa_erase() use plain xa_lock()/xa_unlock() regardless of XA_FLAGS_LOCK_IRQ — the flag only affects lockdep annotations, not runtime locking.

Switch to xa_alloc_cyclic_irq() and xa_erase_irq() which use xa_lock_irq/xa_unlock_irq internally, fixing the IRQ safety issue for amdgpu_pasid_free() called from hardirq via fence callbacks.

Fixes a3c0ee978e16 ("drm/amdgpu: replace PASID IDR with XArray")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +2 -2
index a6ac3b4ce0df..64d0da28441f 100644
@@ -68,7 +68,7 @@ int amdgpu_pasid_alloc(unsigned int bits)
 	if (bits == 0)
 		return -EINVAL;
 
-	r = xa_alloc_cyclic(&amdgpu_pasid_xa, &pasid, xa_mk_value(0),
+	r = xa_alloc_cyclic_irq(&amdgpu_pasid_xa, &pasid, xa_mk_value(0),
 			    XA_LIMIT(1, (1U << bits) - 1),
 			    &amdgpu_pasid_xa_next, GFP_KERNEL);
 	if (r < 0)
@@ -85,7 +85,7 @@ int amdgpu_pasid_alloc(unsigned int bits)
 void amdgpu_pasid_free(u32 pasid)
 {
 	trace_amdgpu_pasid_freed(pasid);
-	xa_erase(&amdgpu_pasid_xa, pasid);
+	xa_erase_irq(&amdgpu_pasid_xa, pasid);
 }
 
 static void amdgpu_pasid_free_cb(struct dma_fence *fence,
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 28 lines · Mikhail Gavrilov

xa_alloc_cyclic() and xa_erase() use plain xa_lock()/xa_unlock() regardless of XA_FLAGS_LOCK_IRQ — the flag only affects lockdep annotations, not runtime locking.

Switch to xa_alloc_cyclic_irq() and xa_erase_irq() which use xa_lock_irq/xa_unlock_irq internally, fixing the IRQ safety issue for amdgpu_pasid_free() called from hardirq via fence callbacks.

Fixes a3c0ee978e16 ("drm/amdgpu: replace PASID IDR with XArray")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +1 -1
index a6ac3b4ce0df..64d0da28441f 100644
@@ -68,7 +68,7 @@ int amdgpu_pasid_alloc(unsigned int bits)
 	if (bits == 0)
 		return -EINVAL;
 
-	r = xa_alloc_cyclic(&amdgpu_pasid_xa, &pasid, xa_mk_value(0),
+	r = xa_alloc_cyclic_irq(&amdgpu_pasid_xa, &pasid, xa_mk_value(0),
 			    XA_LIMIT(1, (1U << bits) - 1),
 			    &amdgpu_pasid_xa_next, GFP_KERNEL);
 	if (r < 0)

drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c int amdgpu_pasid_alloc(unsigned int bits) · line 88

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +1 -1
@@ -85,7 +85,7 @@ int amdgpu_pasid_alloc(unsigned int bits)
 void amdgpu_pasid_free(u32 pasid)
 {
 	trace_amdgpu_pasid_freed(pasid);
-	xa_erase(&amdgpu_pasid_xa, pasid);
+	xa_erase_irq(&amdgpu_pasid_xa, pasid);

This one needs to use:

xa_lock_irqsave(xa, flags);
__xa_eras(...);
xa_unlock_irqrestore(xa, flags);

Since it is actually used in IRQ context and not process context.

Apart from that looks good to me.

Regards,
Christian.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +0 -0
 }
 
 static void amdgpu_pasid_free_cb(struct dma_fence *fence,