Skip to contentSkip to conversation

drm/amdgpu: add missing NULL check

PATCH In review Christian König 3 participants 4 messages Oct 6, 2023 – Oct 9, 2023

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

PATCH 1/1 drm/amdgpu: add missing NULL check

bo->tbo.resource can easily be NULL here.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -1
index f3ee83cdf97e..d28e21baef16 100644
@@ -252,7 +252,7 @@ static inline bool amdgpu_bo_in_cpu_visible_vram(struct amdgpu_bo *bo)
 	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
 	struct amdgpu_res_cursor cursor;
 
-	if (bo->tbo.resource->mem_type != TTM_PL_VRAM)
+	if (!bo->tbo.resource || bo->tbo.resource->mem_type != TTM_PL_VRAM)
 		return false;
 
 	amdgpu_res_first(bo->tbo.resource, 0, amdgpu_bo_size(bo), &cursor);
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Christian König

bo->tbo.resource can easily be NULL here.

Add a link to the bug report? With that:

Quoted 20 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -2
index f3ee83cdf97e..d28e21baef16 100644
@@ -252,7 +252,7 @@ static inline bool amdgpu_bo_in_cpu_visible_vram(struct amdgpu_bo *bo)
        struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
        struct amdgpu_res_cursor cursor;
 
-       if (bo->tbo.resource->mem_type != TTM_PL_VRAM)
+       if (!bo->tbo.resource || bo->tbo.resource->mem_type != TTM_PL_VRAM)
                return false;
 
        amdgpu_res_first(bo->tbo.resource, 0, amdgpu_bo_size(bo), &cursor);
--

2.34.1

#2 lore raw

Am 06.10.23 um 16:41 schrieb Alex Deucher:

Quoted 6 lines
Quoted 3 lines · Christian König

bo->tbo.resource can easily be NULL here.

Add a link to the bug report?

Ah, crap. Forgotten to add the link before pushing that. But I've added a CC stable.

Apart from that I suspect that this doesn't fix the real issue here, it just mitigates the problem.

For some reason we can't allocate OA resources, but also doesn't fail and instead keep working with an empty BO.

Regards,
Christian.

Quoted 23 lines

With that:

Quoted 20 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -2
index f3ee83cdf97e..d28e21baef16 100644
@@ -252,7 +252,7 @@ static inline bool amdgpu_bo_in_cpu_visible_vram(struct amdgpu_bo *bo)
         struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
         struct amdgpu_res_cursor cursor;
 
-       if (bo->tbo.resource->mem_type != TTM_PL_VRAM)
+       if (!bo->tbo.resource || bo->tbo.resource->mem_type != TTM_PL_VRAM)
                 return false;
 
         amdgpu_res_first(bo->tbo.resource, 0, amdgpu_bo_size(bo), &cursor);
--

2.34.1

#3 lore raw
In reply to Christian König

I can confirm this patch fixes the kernel crash I reported.

But as discussed with Christian, we should find the root cause.

Quoted 20 lines · Christian König

bo->tbo.resource can easily be NULL here.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -1
index f3ee83cdf97e..d28e21baef16 100644
@@ -252,7 +252,7 @@ static inline bool amdgpu_bo_in_cpu_visible_vram(struct amdgpu_bo *bo)
  	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
  	struct amdgpu_res_cursor cursor;
 
-	if (bo->tbo.resource->mem_type != TTM_PL_VRAM)
+	if (!bo->tbo.resource || bo->tbo.resource->mem_type != TTM_PL_VRAM)
  		return false;
 
  	amdgpu_res_first(bo->tbo.resource, 0, amdgpu_bo_size(bo), &cursor);