Skip to contentSkip to conversation

drm/amdkfd: Unreserve bo if queue update failed

PATCH In review Philip Yang 4 participants 6 messages Dec 9, 2025 – Dec 10, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdkfd: Unreserve bo if queue update failed

Error handling path should unreserve bo then return failed.

Fixes 305cd109b761 ("drm/amdkfd: Validate user queue update")
---
 drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +1 -0
index 232103742712..6babdf025359 100644
@@ -592,6 +592,7 @@ int pqm_update_queue_properties(struct process_queue_manager *pqm,
 					 p->queue_size)) {
 			pr_debug("ring buf 0x%llx size 0x%llx not mapped on GPU\n",
 				 p->queue_address, p->queue_size);
+			amdgpu_bo_unreserve(vm->root.bo);
 			return -EFAULT;
 		}
 
Signature · 1 line
2.50.1
Reviewed-by on v1 1/1
#1 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 33 lines

-----Original Message-----
From: Yang, Philip <[email protected]>
Sent: Tuesday, December 9, 2025 2:37 PM
To: [email protected]
Cc: Sierra Guiza, Alejandro (Alex) <[email protected]>; Kuehling, Felix <[email protected]>; Yang, Philip <[email protected]>
Subject: [PATCH] drm/amdkfd: Unreserve bo if queue update failed

Error handling path should unreserve bo then return failed.

Fixes 305cd109b761 ("drm/amdkfd: Validate user queue update")
---
 drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +1 -0
index 232103742712..6babdf025359 100644
@@ -592,6 +592,7 @@ int pqm_update_queue_properties(struct
 process_queue_manager *pqm,
                                       p->queue_size)) {
                      pr_debug("ring buf 0x%llx size 0x%llx not mapped on
 GPU\n",
                               p->queue_address, p->queue_size);
+                     amdgpu_bo_unreserve(vm->root.bo);
                      return -EFAULT;
              }

--
2.50.1

#2 lore raw
In reply to Philip Yang
Quoted 13 lines · Philip Yang

Error handling path should unreserve bo then return failed.

Fixes 305cd109b761 ("drm/amdkfd: Validate user queue update")
---
  drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c | 1 +
  1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +0 -0
index 232103742712..6babdf025359 100644

drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c int pqm_update_queue_properties(struct process_queue_manager *pqm, · line 595

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +1 -0
@@ -592,6 +592,7 @@ int pqm_update_queue_properties(struct process_queue_manager *pqm,
  					 p->queue_size)) {
  			pr_debug("ring buf 0x%llx size 0x%llx not mapped on GPU\n",
  				 p->queue_address, p->queue_size);
+			amdgpu_bo_unreserve(vm->root.bo);

but why need have amdgpu_bo_reserve before call kfd_queue_buffer_get? kfd_queue_buffer_get just check if mapping at addr exist, it adds bo_ref and mapping->bo_va->queue_refcount. Then after immediately call kfd_queue_unref_bo_va and kfd_queue_buffer_put.

Regards

Xiaogang

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +0 -0
  			return -EFAULT;
  		}
 
#3 lore raw
Quoted 10 lines · Xiaogang
Quoted 8 lines · Philip Yang

Error handling path should unreserve bo then return failed.

Fixes 305cd109b761 ("drm/amdkfd: Validate user queue update")

---
  drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c | 1 +

  1 file changed, 1 insertion(+)
Quoted 12 lines

drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c int pqm_update_queue_properties(struct · line 596

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +1 -0
index 232103742712..6babdf025359 100644
@@ -592,6 +592,7 @@ int pqm_update_queue_properties(struct 
 process_queue_manager *pqm,
                        p->queue_size)) {
               pr_debug("ring buf 0x%llx size 0x%llx not mapped on GPU\n",
                    p->queue_address, p->queue_size);
+            amdgpu_bo_unreserve(vm->root.bo);

but why need have amdgpu_bo_reserve before call kfd_queue_buffer_get? kfd_queue_buffer_get just check if mapping at addr exist, it adds bo_ref and mapping->bo_va->queue_refcount. Then after immediately call kfd_queue_unref_bo_va and kfd_queue_buffer_put.

amdgpu_vm_bo_lookup_mapping access vm->va interval tree, this requires to take vm lock.

Regards,
Philip

Quoted 8 lines

Regards

Xiaogang

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +0 -0
               return -EFAULT;
           }
#4 lore raw
Quoted 25 lines · Philip Yang
Quoted 10 lines · Xiaogang
Quoted 8 lines · Philip Yang

Error handling path should unreserve bo then return failed.

Fixes 305cd109b761 ("drm/amdkfd: Validate user queue update")

---
  drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c | 1 +

  1 file changed, 1 insertion(+)
Quoted 12 lines

drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c int pqm_update_queue_properties(struct · line 596

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +1 -0
index 232103742712..6babdf025359 100644
@@ -592,6 +592,7 @@ int pqm_update_queue_properties(struct 
 process_queue_manager *pqm,
                        p->queue_size)) {
               pr_debug("ring buf 0x%llx size 0x%llx not mapped on GPU\n",
                    p->queue_address, p->queue_size);
+            amdgpu_bo_unreserve(vm->root.bo);

but why need have amdgpu_bo_reserve before call kfd_queue_buffer_get? kfd_queue_buffer_get just check if mapping at addr exist, it adds bo_ref and mapping->bo_va->queue_refcount. Then after immediately call kfd_queue_unref_bo_va and kfd_queue_buffer_put.

Quoted 1 line

amdgpu_vm_bo_lookup_mapping access vm->va interval tree, this requires to take vm lock.

ok, it locks a vm->root.bo. I sought it locks a general bo.  I think the lock/unlock can be inside kfd_queue_buffer_get before and after amdgpu_vm_bo_lookup_mapping because that is what need be protected, then do not have to care unlock after this function call as current case.

For such lock can we use drm_exec_init/amdgpu_vm_lock_pd instead, as it is a more general way?

Regards

Xiaogang

Quoted 12 lines

Regards,
Philip

Quoted 8 lines

Regards

Xiaogang

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +0 -0
               return -EFAULT;
           }
#5 lore raw
Quoted 27 lines · Xiaogang
Quoted 25 lines · Philip Yang
Quoted 22 lines · Xiaogang
Quoted 13 lines · Philip Yang

Error handling path should unreserve bo then return failed.

Fixes 305cd109b761 ("drm/amdkfd: Validate user queue update")

---
  drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c | 1 +

  1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +0 -0
index 232103742712..6babdf025359 100644

drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c int pqm_update_queue_properties(struct · line 596

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +1 -0
@@ -592,6 +592,7 @@ int pqm_update_queue_properties(struct 
 process_queue_manager *pqm,
                        p->queue_size)) {
               pr_debug("ring buf 0x%llx size 0x%llx not mapped on GPU\n",
                    p->queue_address, p->queue_size);
+            amdgpu_bo_unreserve(vm->root.bo);

but why need have amdgpu_bo_reserve before call kfd_queue_buffer_get? kfd_queue_buffer_get just check if mapping at addr exist, it adds bo_ref and mapping->bo_va->queue_refcount. Then after immediately call kfd_queue_unref_bo_va and kfd_queue_buffer_put.

Quoted 4 lines
Quoted 1 line

amdgpu_vm_bo_lookup_mapping access vm->va interval tree, this requires to take vm lock.

ok, it locks a vm->root.bo. I sought it locks a general bo.  I think the lock/unlock can be inside kfd_queue_buffer_get before and after amdgpu_vm_bo_lookup_mapping because that is what need be protected, then do not have to care unlock after this function call as current case.

create queue path will call kfd_queue_buffer_get many times to validate ring buffer, wptr, rptr, eop, cwsr BOs, so it is better to take the vm lock outside kfd_queue_buffer_get.

Quoted 1 line

For such lock can we use drm_exec_init/amdgpu_vm_lock_pd instead, as it is a more general way?

This is used to take root BO lock and multiple BOs lock to avoid circular lock / deadlock, we only take vm lock here.

Regards,
Philip

Quoted 17 lines

Regards

Xiaogang

Quoted 12 lines

Regards,
Philip

Quoted 8 lines

Regards

Xiaogang

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +0 -0
               return -EFAULT;
           }