[PATCH v6 12/12] drm/xe/bo: Skip zero-refcount BOs in shrinker

Arvind Yadav
2026-03-03T15:21:05Z

Zero-refcount BOs are being destroyed. Skip them in the shrinker
to avoid racing with cleanup by returning -EBUSY.

Ghost BOs from ttm_bo_pipeline_gutting() still hold reclaimable
pages, so continue processing them via xe_bo_shrink_purge().

Fixes: 00c8efc3180f ("drm/xe: Add a shrinker for xe bos")

v6:
- Split from patch 0010 (Thomas)

Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Arvind Yadav <arvind.yadav@intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 598d4463baf3..07acce383cb1 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -1295,9 +1295,13 @@ long xe_bo_shrink(struct ttm_operation_ctx *ctx, struct ttm_buffer_object *bo,
if (!xe_bo_eviction_valuable(bo, &place))
return -EBUSY;

- if (!xe_bo_is_xe_bo(bo) || !xe_bo_get_unless_zero(xe_bo))
+ /* Ghost BOs still hold reclaimable pages, try to shrink them. */
+ if (!xe_bo_is_xe_bo(bo))
return xe_bo_shrink_purge(ctx, bo, scanned);

+ if (!xe_bo_get_unless_zero(xe_bo))
+ return -EBUSY;
+
if (xe_tt->purgeable) {
if (bo->resource->mem_type != XE_PL_SYSTEM)
lret = xe_bo_move_notify(xe_bo, ctx);
--
2.43.0