[PATCH 04/10] drm/ttm: grab BO reference before locking it

From: Natalie Vock

Date: Fri Jul 03 2026 - 12:35:53 EST


From: Christian König <christian.koenig@xxxxxxx>

Previously we always grabbed the BO reference after taking the lock, but
that isn't necessary any more.

So avoid doing that and cleanup the handling here.

Signed-off-by: Christian König <christian.koenig@xxxxxxx>
Signed-off-by: Natalie Vock <natalie.vock@xxxxxx>
---
drivers/gpu/drm/ttm/ttm_bo_util.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index 29f068944a972..a53b25e8c2967 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -1010,14 +1010,17 @@ __ttm_bo_lru_cursor_next(struct ttm_bo_lru_cursor *curs)
break;

bo = res->bo;
- if (ttm_lru_walk_trylock(curs, bo))
- bo_locked = true;
- else if (!arg->ticket || arg->ctx->no_wait_gpu || arg->trylock_only)
+ if (!ttm_bo_get_unless_zero(bo))
continue;

- if (!ttm_bo_get_unless_zero(bo)) {
- if (curs->needs_unlock)
- dma_resv_unlock(bo->base.resv);
+ if (ttm_lru_walk_trylock(curs, bo)) {
+ bo_locked = true;
+
+ } else if (!arg->ticket || arg->ctx->no_wait_gpu ||
+ arg->trylock_only) {
+ spin_unlock(lru_lock);
+ ttm_bo_put(bo);
+ spin_lock(lru_lock);
continue;
}


--
2.55.0