Skip to contentSkip to conversation

drm/amdgpu/userq: check NULL pointer

PATCH In review David (Ming Qiang) Wu 3 participants 7 messages Nov 4, 2025

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

PATCH 1/1 drm/amdgpu/userq: check NULL pointer

bo could be NULL in the vm->done list and the
access of it must be avoided.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1 -1
index cc2f96ed7004..d0ff226c6dc1 100644
@@ -943,7 +943,7 @@ amdgpu_userq_vm_validate(struct amdgpu_userq_mgr *uq_mgr)
 	list_for_each_entry(bo_va, &vm->done, base.vm_status) {
 		bo = bo_va->base.bo;
 
-		if (!amdgpu_ttm_tt_is_userptr(bo->tbo.ttm))
+		if (!bo || !amdgpu_ttm_tt_is_userptr(bo->tbo.ttm))
 			continue;
 
 		range = xa_load(&xa, key);
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/1 drm/amdgpu/userq: need to unref bo

unref bo after amdgpu_bo_unreserve() failure as it has called amdgpu_bo_ref() already

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +1 -0
index 2aeeaa954882..99ae1d19b751 100644
@@ -386,6 +386,7 @@ static int amdgpu_userq_fence_read_wptr(struct amdgpu_usermode_queue *queue,
 	amdgpu_bo_unreserve(queue->vm->root.bo);
 	r = amdgpu_bo_reserve(bo, true);
 	if (r) {
+		amdgpu_bo_unref(&bo);
 		DRM_ERROR("Failed to reserve userqueue wptr bo");
 		return r;
 	}
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH] drm/amdgpu/userq: need to unref bo

Quoted 3 lines · David (Ming Qiang) Wu

unref bo after amdgpu_bo_unreserve() failure as it has called amdgpu_bo_ref() already

The other error paths need to be fixed as well.

Alex

Quoted 21 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +1 -1
index 2aeeaa954882..99ae1d19b751 100644
@@ -386,6 +386,7 @@ static int amdgpu_userq_fence_read_wptr(struct amdgpu_usermode_queue *queue,
        amdgpu_bo_unreserve(queue->vm->root.bo);
        r = amdgpu_bo_reserve(bo, true);
        if (r) {
+               amdgpu_bo_unref(&bo);
                DRM_ERROR("Failed to reserve userqueue wptr bo");
                return r;
        }
--

2.43.0

#3 lore raw

Re: [PATCH] drm/amdgpu/userq: need to unref bo

Quoted 4 lines · Alex Deucher
Quoted 2 lines · David (Ming Qiang) Wu

unref bo after amdgpu_bo_unreserve() failure as it has called amdgpu_bo_ref() already

The other error paths need to be fixed as well.

hmm... do you mean "map_error"? it has the amdgpu_bo_unref() already.

David

Quoted 22 lines

Alex

Quoted 20 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 1 +
  1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +1 -1
index 2aeeaa954882..99ae1d19b751 100644
@@ -386,6 +386,7 @@ static int amdgpu_userq_fence_read_wptr(struct amdgpu_usermode_queue *queue,
         amdgpu_bo_unreserve(queue->vm->root.bo);
         r = amdgpu_bo_reserve(bo, true);
         if (r) {
+               amdgpu_bo_unref(&bo);
                 DRM_ERROR("Failed to reserve userqueue wptr bo");
                 return r;
         }
--

2.43.0

Reviewed-by
#4 lore raw

Re: [PATCH] drm/amdgpu/userq: need to unref bo

Quoted 8 lines · David Wu
Quoted 4 lines · Alex Deucher
Quoted 2 lines · David (Ming Qiang) Wu

unref bo after amdgpu_bo_unreserve() failure as it has called amdgpu_bo_ref() already

The other error paths need to be fixed as well.

hmm... do you mean "map_error"? it has the amdgpu_bo_unref() already.

whoops, yes, sorry.

Quoted 25 lines

David

Quoted 22 lines

Alex

Quoted 20 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 1 +
  1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +1 -1
index 2aeeaa954882..99ae1d19b751 100644
@@ -386,6 +386,7 @@ static int amdgpu_userq_fence_read_wptr(struct amdgpu_usermode_queue *queue,
         amdgpu_bo_unreserve(queue->vm->root.bo);
         r = amdgpu_bo_reserve(bo, true);
         if (r) {
+               amdgpu_bo_unref(&bo);
                 DRM_ERROR("Failed to reserve userqueue wptr bo");
                 return r;
         }
--

2.43.0

#5 lore raw

Re: [PATCH] drm/amdgpu/userq: need to unref bo

no worries - also fix the typo ( amdgpu_bo_unreserve -> amdgpu_bo_reserve). Thanks for review.

David

Quoted 35 lines · Alex Deucher
Quoted 6 lines · David Wu
Quoted 4 lines · Alex Deucher
Quoted 2 lines · David (Ming Qiang) Wu

unref bo after amdgpu_bo_unreserve() failure as it has called amdgpu_bo_ref() already

The other error paths need to be fixed as well.

hmm... do you mean "map_error"? it has the amdgpu_bo_unref() already.

whoops, yes, sorry.

Quoted 24 lines

David

Quoted 22 lines

Alex

Quoted 20 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 1 +
   1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +1 -1
index 2aeeaa954882..99ae1d19b751 100644
@@ -386,6 +386,7 @@ static int amdgpu_userq_fence_read_wptr(struct amdgpu_usermode_queue *queue,
          amdgpu_bo_unreserve(queue->vm->root.bo);
          r = amdgpu_bo_reserve(bo, true);
          if (r) {
+               amdgpu_bo_unref(&bo);
                  DRM_ERROR("Failed to reserve userqueue wptr bo");
                  return r;
          }
--

2.43.0

Reviewed-by Christian König on v1 1/1
#6 lore raw
In reply to David (Ming Qiang) Wu
Quoted 5 lines · David (Ming Qiang) Wu

bo could be NULL in the vm->done list and the
access of it must be avoided.

Sunil already fixed this in:
commit b15e3cc46803daf49625ab3289d103c437310ec3

Author: Sunil Khatri <[email protected]>
Date:   Fri Oct 31 14:10:13 2025 +0530

drm/amdgpu: validate the bo from done list for NULL

Make sure the bo is valid before using it.

Quoted 20 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1 -2
index cc2f96ed7004..d0ff226c6dc1 100644
@@ -943,7 +943,7 @@ amdgpu_userq_vm_validate(struct amdgpu_userq_mgr *uq_mgr)
        list_for_each_entry(bo_va, &vm->done, base.vm_status) {
                bo = bo_va->base.bo;
 
-               if (!amdgpu_ttm_tt_is_userptr(bo->tbo.ttm))
+               if (!bo || !amdgpu_ttm_tt_is_userptr(bo->tbo.ttm))
                        continue;
 
                range = xa_load(&xa, key);
--

2.43.0