Skip to contentSkip to conversation

drm/ttm: fix missing NULL check in ttm_device_swapout

PATCH In review Felix Kuehling 2 participants 2 messages Jul 14, 2022 – Jul 15, 2022

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

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

Backport of Christian's patch 81b0d0e4f811 to amd-staging-drm-next. This branch may be nearly obsolete, but this patch may still be worth applying as it can serve as a template for backports to some release branches. It fixes intermittent kernel oopses when memory is severely overcommitted.

---
 drivers/gpu/drm/ttm/ttm_device.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/ttm/ttm_device.c +3 -0
index be24bb6cefd0..165a6cbb45d5 100644
@@ -157,6 +157,9 @@ 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)
+					continue;
+
 				ret = ttm_bo_swapout(bo, ctx, gfp_flags);
 				/* ttm_bo_swapout has dropped the lru_lock */
 				if (!ret)
Signature · 1 line
2.32.0
#1 lore raw

Am 14.07.22 um 23:58 schrieb Felix Kuehling:

Quoted 7 lines

Backport of Christian's patch 81b0d0e4f811 to amd-staging-drm-next. This branch may be nearly obsolete, but this patch may still be worth applying as it can serve as a template for backports to some release branches. It fixes intermittent kernel oopses when memory is severely overcommitted.

I was hoping that Alex rebase would land before anybody notices this problem.

Anyway patch is Reviewed-by: Christian König <[email protected]>.

Regards,
Christian.

Quoted 18 lines
---
  drivers/gpu/drm/ttm/ttm_device.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/gpu/drm/ttm/ttm_device.c +3 -0
index be24bb6cefd0..165a6cbb45d5 100644
@@ -157,6 +157,9 @@ 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)
+					continue;
+
  				ret = ttm_bo_swapout(bo, ctx, gfp_flags);
  				/* ttm_bo_swapout has dropped the lru_lock */
  				if (!ret)