On Fri, 2026-07-03 at 18:31 +0200, Natalie Vock wrote: > From: Christian König <[email protected]> > > Use the for_each loop to evict all BOs of an resource manager as > well. > > Greately simplifying the handling and finally allows us to > remove ttm_bo_evict_first(). > > Signed-off-by: Christian König <[email protected]> > Signed-off-by: Natalie Vock <[email protected]>
Reviewed-by: Thomas Hellström <[email protected]> > --- > drivers/gpu/drm/ttm/ttm_bo.c | 51 +--------------------------- > ---------- > drivers/gpu/drm/ttm/ttm_resource.c | 22 ++++++++++------ > include/drm/ttm/ttm_bo.h | 1 + > 3 files changed, 17 insertions(+), 57 deletions(-) > > diff --git a/drivers/gpu/drm/ttm/ttm_bo.c > b/drivers/gpu/drm/ttm/ttm_bo.c > index 54f01611ec823..80933ba6aada9 100644 > --- a/drivers/gpu/drm/ttm/ttm_bo.c > +++ b/drivers/gpu/drm/ttm/ttm_bo.c > @@ -351,8 +351,7 @@ static int ttm_bo_bounce_temp_buffer(struct > ttm_buffer_object *bo, > return 0; > } > > -static int ttm_bo_evict(struct ttm_buffer_object *bo, > - struct ttm_operation_ctx *ctx) > +int ttm_bo_evict(struct ttm_buffer_object *bo, struct > ttm_operation_ctx *ctx) > { > struct ttm_resource *evict_mem; > struct ttm_placement placement; > @@ -437,54 +436,6 @@ bool ttm_bo_eviction_valuable(struct > ttm_buffer_object *bo, > } > EXPORT_SYMBOL(ttm_bo_eviction_valuable); > > -/** > - * ttm_bo_evict_first() - Evict the first bo on the manager's LRU > list. > - * @bdev: The ttm device. > - * @man: The manager whose bo to evict. > - * @ctx: The TTM operation ctx governing the eviction. > - * > - * Return: 0 if successful or the resource disappeared. Negative > error code on error. > - */ > -int ttm_bo_evict_first(struct ttm_device *bdev, struct > ttm_resource_manager *man, > - struct ttm_operation_ctx *ctx) > -{ > - struct ttm_resource_cursor cursor; > - struct ttm_buffer_object *bo; > - struct ttm_resource *res; > - unsigned int mem_type; > - int ret = 0; > - > - spin_lock(&bdev->lru_lock); > - ttm_resource_cursor_init(&cursor, man); > - res = ttm_resource_manager_first(&cursor); > - ttm_resource_cursor_fini(&cursor); > - if (!res) { > - ret = -ENOENT; > - goto out_no_ref; > - } > - bo = res->bo; > - if (!ttm_bo_get_unless_zero(bo)) > - goto out_no_ref; > - mem_type = res->mem_type; > - spin_unlock(&bdev->lru_lock); > - ret = ttm_bo_reserve(bo, ctx->interruptible, ctx- > >no_wait_gpu, NULL); > - if (ret) > - goto out_no_lock; > - if (!bo->resource || bo->resource->mem_type != mem_type) > - goto out_bo_moved; > - > - ret = ttm_bo_evict(bo, ctx); > -out_bo_moved: > - dma_resv_unlock(bo->base.resv); > -out_no_lock: > - ttm_bo_put(bo); > - return ret; > - > -out_no_ref: > - spin_unlock(&bdev->lru_lock); > - return ret; > -} > - > /** > * struct ttm_bo_evict_walk - Parameters for the evict walk. > */ > diff --git a/drivers/gpu/drm/ttm/ttm_resource.c > b/drivers/gpu/drm/ttm/ttm_resource.c > index 154d6739256f8..cf3fc3a594388 100644 > --- a/drivers/gpu/drm/ttm/ttm_resource.c > +++ b/drivers/gpu/drm/ttm/ttm_resource.c > @@ -561,17 +561,25 @@ EXPORT_SYMBOL(ttm_resource_manager_init); > int ttm_resource_manager_evict_all(struct ttm_device *bdev, > struct ttm_resource_manager *man) > { > - struct ttm_operation_ctx ctx = { }; > + struct ttm_bo_lru_cursor cursor; > + struct ttm_buffer_object *bo; > + struct ttm_operation_ctx ctx = { > + .interruptible = false, > + .no_wait_gpu = false, > + }; > + struct ttm_lru_walk_arg arg = { > + .ctx = &ctx, > + .trylock_only = true > + }; > struct dma_fence *fence; > int ret, i; > > - do { > - ret = ttm_bo_evict_first(bdev, man, &ctx); > + ttm_bo_lru_for_each_reserved_guarded(&cursor, man, &arg, bo) > { > + ret = ttm_bo_evict(bo, &ctx); > + if (ret) > + return ret; > cond_resched(); > - } while (!ret); > - > - if (ret && ret != -ENOENT) > - return ret; > + } > > ret = 0; > > diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h > index bbed63064c9a9..a4060e44d23d0 100644 > --- a/include/drm/ttm/ttm_bo.h > +++ b/include/drm/ttm/ttm_bo.h > @@ -389,6 +389,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, > void ttm_bo_fini(struct ttm_buffer_object *bo); > void ttm_bo_set_bulk_move(struct ttm_buffer_object *bo, > struct ttm_lru_bulk_move *bulk); > +int ttm_bo_evict(struct ttm_buffer_object *bo, struct > ttm_operation_ctx *ctx); > bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, > const struct ttm_place *place); > int ttm_bo_init_reserved(struct ttm_device *bdev, struct > ttm_buffer_object *bo,
