Skip to contentSkip to conversation

drm/ttm: fix missing NULL check in ttm_device_swapout

PATCH In review Christian König 2 participants 5 messages Jun 3, 2022 – Jun 6, 2022

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

PATCH 1/1 drm/ttm: fix missing NULL check in ttm_device_swapout

Resources about to be destructed are not tied to BOs any more.

---
 drivers/gpu/drm/ttm/ttm_device.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_device.c +5 -1
index a0562ab386f5..e7147e304637 100644
@@ -156,8 +156,12 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
 
 		ttm_resource_manager_for_each_res(man, &cursor, res) {
 			struct ttm_buffer_object *bo = res->bo;
-			uint32_t num_pages = PFN_UP(bo->base.size);
+			uint32_t num_pages;
 
+			if (!bo)
+				continue;
+
+			num_pages = PFN_UP(bo->base.size);
 			ret = ttm_bo_swapout(bo, ctx, gfp_flags);
 			/* ttm_bo_swapout has dropped the lru_lock */
 			if (!ret)
Signature · 1 line
2.25.1
#1 lore raw
Quoted 1 line · Christian König

Resources about to be destructed are not tied to BOs any more.

I've been seeing a backtrace in that area with a patch series I'm working on, but didn't have enough time to track it down yet. I'll try if this patch fixes it.

Regards,
  Felix

Quoted 24 lines
---
  drivers/gpu/drm/ttm/ttm_device.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_device.c +5 -1
index a0562ab386f5..e7147e304637 100644
@@ -156,8 +156,12 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
 
  		ttm_resource_manager_for_each_res(man, &cursor, res) {
  			struct ttm_buffer_object *bo = res->bo;
-			uint32_t num_pages = PFN_UP(bo->base.size);
+			uint32_t num_pages;
 
+			if (!bo)
+				continue;
+
+			num_pages = PFN_UP(bo->base.size);
  			ret = ttm_bo_swapout(bo, ctx, gfp_flags);
  			/* ttm_bo_swapout has dropped the lru_lock */
  			if (!ret)
#2 lore raw

[+amd-gfx]

Quoted 4 lines · Felix Kuehling
Quoted 1 line · Christian König

Resources about to be destructed are not tied to BOs any more.

I've been seeing a backtrace in that area with a patch series I'm working on, but didn't have enough time to track it down yet. I'll try if this patch fixes it.

The patch doesn't apply on amd-staging-drm-next. I made the following change instead, which fixes my problem (and I do see the pr_err being triggered):

drivers/gpu/drm/ttm/ttm_device.c +4 -0
@@ -157,6 +157,10 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
                        list_for_each_entry(bo, &man->lru[j], lru) {
                                uint32_t num_pages = PFN_UP(bo->base.size);
 
+                               if (!bo->resource) {
+                                       pr_err("### bo->resource is NULL\n");
+                                       continue;
+                               }
                                ret = ttm_bo_swapout(bo, ctx, gfp_flags);
                                /* ttm_bo_swapout has dropped the lru_lock */
                                if (!ret)
Quoted 28 lines

Regards,
  Felix

Quoted 23 lines

---
  drivers/gpu/drm/ttm/ttm_device.c | 6 +++++-

  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_device.c +4 -1
index a0562ab386f5..e7147e304637 100644
@@ -156,8 +156,12 @@ int ttm_device_swapout(struct ttm_device *bdev, 
 struct ttm_operation_ctx *ctx,
             ttm_resource_manager_for_each_res(man, &cursor, res) {
               struct ttm_buffer_object *bo = res->bo;
-            uint32_t num_pages = PFN_UP(bo->base.size);
+            uint32_t num_pages;
   +            if (!bo)
+                continue;
+
+            num_pages = PFN_UP(bo->base.size);
               ret = ttm_bo_swapout(bo, ctx, gfp_flags);
               /* ttm_bo_swapout has dropped the lru_lock */
               if (!ret)
#3 lore raw

Am 04.06.22 um 00:44 schrieb Felix Kuehling:

Quoted 14 lines

[+amd-gfx]

Quoted 4 lines · Felix Kuehling
Quoted 1 line · Christian König

Resources about to be destructed are not tied to BOs any more.

I've been seeing a backtrace in that area with a patch series I'm working on, but didn't have enough time to track it down yet. I'll try if this patch fixes it.

The patch doesn't apply on amd-staging-drm-next. I made the following change instead, which fixes my problem (and I do see the pr_err being triggered):

drivers/gpu/drm/ttm/ttm_device.c int ttm_device_swapout(struct ttm_device *bdev, · line 165

Quoted 9 lines
drivers/gpu/drm/ttm/ttm_device.c +4 -0
@@ -157,6 +157,10 @@ int ttm_device_swapout(struct ttm_device *bdev, 
 struct ttm_operation_ctx *ctx,
                         list_for_each_entry(bo, &man->lru[j], lru) {
                                 uint32_t num_pages = PFN_UP(bo->base.size);
 
+                               if (!bo->resource) {
+                                       pr_err("### bo->resource is 
 NULL\n");
+                                       continue;
+                               }

Yeah, that should be functional identical.

Can I get an rb for that? Going to provide backports to older kernels as well then.

Regards,
Christian.

Quoted 32 lines
drivers/gpu/drm/ttm/ttm_device.c +0 -0
 ret = ttm_bo_swapout(bo, ctx, gfp_flags);

                                /* ttm_bo_swapout has dropped the lru_lock */ if (!ret)

Quoted 28 lines

Regards,
  Felix

Quoted 23 lines

---
  drivers/gpu/drm/ttm/ttm_device.c | 6 +++++-

  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_device.c +4 -1
index a0562ab386f5..e7147e304637 100644
@@ -156,8 +156,12 @@ int ttm_device_swapout(struct ttm_device *bdev, 
 struct ttm_operation_ctx *ctx,
             ttm_resource_manager_for_each_res(man, &cursor, res) {
               struct ttm_buffer_object *bo = res->bo;
-            uint32_t num_pages = PFN_UP(bo->base.size);
+            uint32_t num_pages;
   +            if (!bo)
+                continue;
+
+            num_pages = PFN_UP(bo->base.size);
               ret = ttm_bo_swapout(bo, ctx, gfp_flags);
               /* ttm_bo_swapout has dropped the lru_lock */
               if (!ret)
Reviewed-by on v1 1/1
#4 lore raw
In reply to Christian König

Am 2022-06-03 um 06:46 schrieb Christian König:

Quoted 3 lines

Resources about to be destructed are not tied to BOs any more.

Quoted 22 lines
---
  drivers/gpu/drm/ttm/ttm_device.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_device.c +5 -1
index a0562ab386f5..e7147e304637 100644
@@ -156,8 +156,12 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
 
  		ttm_resource_manager_for_each_res(man, &cursor, res) {
  			struct ttm_buffer_object *bo = res->bo;
-			uint32_t num_pages = PFN_UP(bo->base.size);
+			uint32_t num_pages;
 
+			if (!bo)
+				continue;
+
+			num_pages = PFN_UP(bo->base.size);
  			ret = ttm_bo_swapout(bo, ctx, gfp_flags);
  			/* ttm_bo_swapout has dropped the lru_lock */
  			if (!ret)