Skip to contentSkip to conversation

drm/amdgpu: Add entity's check when alloc sdma jobs

PATCH In review Bingxi Guo 2 participants 2 messages Dec 22, 2025 – Dec 23, 2025

Subsystems (2)
lore
Share & tools
lore

Bingxi Guo

author
#0 lore raw

PATCH 1/1 drm/amdgpu: Add entity's check when alloc sdma jobs

issue:When one of multiple processes sharing the same amdgpu device fd is killed, amdgpu_flush runs but amdgpu_drm_release does not, so the vm's entitys have been stopped but bos still alive. Later, when the KFD fd is closed, the driver unmaps BOs from the GPU VM, clears the freed BO list, and normally submits SDMA jobs plus an amdgpu_tlb_fence_work to wait on the job's finished fences which will not be signaled.

add check if entity is NULL or has been stopped, if so, don't submit sdma jobs and create amdgpu_tlb_fence_work

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +7 -0
index 36805dcfa159..e57d496a06e1 100644
@@ -49,6 +49,13 @@ static int amdgpu_vm_sdma_alloc_job(struct amdgpu_vm_update_params *p,
 	unsigned int ndw;
 	int r;
 
+	spin_lock(&entity->lock);
+	if (entity->stopped) {
+		spin_unlock(&entity->lock);
+		return -EINVAL;
+	}
+	spin_unlock(&entity->lock);
+
 	/* estimate how many dw we need */
 	ndw = AMDGPU_VM_SDMA_MIN_NUM_DW;
 	if (p->pages_addr)
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 1 line · Bingxi Guo

issue:When one of multiple processes sharing the same amdgpu device

That is illegal to begin with. Multiple processes shouldn't share the same device fd.

Quoted 6 lines

fd is killed, amdgpu_flush runs but amdgpu_drm_release does not, so the vm's entitys have been stopped but bos still alive. Later, when the KFD fd is closed, the driver unmaps BOs from the GPU VM, clears the freed BO list, and normally submits SDMA jobs plus an amdgpu_tlb_fence_work to wait on the job's finished fences which will not be signaled.

The problem is the KFD code and not the SDMA backend, this check here is especially racy since the entity status can change as soon as you drop the lock.

So clear NAK to that.

Regards,
Christian.

Quoted 27 lines

add check if entity is NULL or has been stopped, if so, don't submit sdma jobs and create amdgpu_tlb_fence_work

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +7 -0
index 36805dcfa159..e57d496a06e1 100644
@@ -49,6 +49,13 @@ static int amdgpu_vm_sdma_alloc_job(struct amdgpu_vm_update_params *p,
 	unsigned int ndw;
 	int r;
 
+	spin_lock(&entity->lock);
+	if (entity->stopped) {
+		spin_unlock(&entity->lock);
+		return -EINVAL;
+	}
+	spin_unlock(&entity->lock);
+
 	/* estimate how many dw we need */
 	ndw = AMDGPU_VM_SDMA_MIN_NUM_DW;
 	if (p->pages_addr)