Thank you for your contribution! Sashiko AI review found 1 potential issue(s) 
to consider:
- [Medium] Negative defrag budget values are incorrectly treated as unlimited 
instead of exhausted.
--

--- Patch [8]: [PATCH v3 08/33] drm/ttm: Bound page (re)allocation per 
defragmentation move ---
commit 933e390472c0331c941d5caa6b241841ec7bb236
Author: Matthew Brost <[email protected]>

drm/ttm: Bound page (re)allocation per defragmentation move

This commit introduces a per-move byte budget to bound the reallocation
size during TTM object defragmentation. It updates the pool allocator to
track upgraded pages against this budget, stopping the upgrade process and
harvesting the remaining old pages once the budget is exhausted.

> diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
> index 52f5e64f05ddc..1673e81b8df81 100644
> --- a/drivers/gpu/drm/ttm/ttm_pool.c
> +++ b/drivers/gpu/drm/ttm/ttm_pool.c

[ ... ]

> @@ -1121,10 +1187,23 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, 
> struct ttm_tt *tt,
>               gfp_flags |= GFP_HIGHUSER;
>  
>       it.gfp_flags = gfp_flags;
> +     it.defrag_capped = it.defrag_old_tt && alloc->defrag_bytes_remaining > 
> 0;

[Severity: Medium]
Does this initialization correctly handle negative budget values?

If a caller uses the same ttm_operation_ctx for multiple defragmentation
moves, the first move that overshoots the budget can leave
defrag_bytes_remaining as a negative value.

When this negative value is passed to the next __ttm_pool_alloc() call,
the alloc->defrag_bytes_remaining > 0 check evaluates to false.

Will this disable the cap entirely (defrag_capped = false) and cause the
allocator to perform an unlimited upgrade, potentially reintroducing the
unbounded stall this budget was designed to prevent? Should this condition
be != 0 instead to properly enforce negative or exhausted budgets?

>       for (it.order = ttm_pool_alloc_find_order(MAX_PAGE_ORDER, alloc);
>            alloc->remaining_pages;
>            it.order = ttm_pool_alloc_find_order(it.order, alloc)) {

[ ... ]

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=8

Reply via email to