Skip to content

Commit f41900e

Browse files
matt-auldChristianKoenigAMD
authored andcommitted
drm/buddy: fix range bias
There is a corner case here where start/end is after/before the block range we are currently checking. If so we need to be sure that splitting the block will eventually give use the block size we need. To do that we should adjust the block range to account for the start/end, and only continue with the split if the size/alignment will fit the requested size. Not doing so can result in leaving split blocks unmerged when it eventually fails. Fixes: afea229 ("drm: improve drm_buddy_alloc function") Signed-off-by: Matthew Auld <matthew.auld@intel.com> Cc: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com> Cc: Christian König <christian.koenig@amd.com> Cc: <stable@vger.kernel.org> # v5.18+ Reviewed-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com> Link: https://patchwork.freedesktop.org/patch/msgid/20240219121851.25774-4-matthew.auld@intel.com Signed-off-by: Christian König <christian.koenig@amd.com>
1 parent 00d6a28 commit f41900e

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

drivers/gpu/drm/drm_buddy.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ alloc_range_bias(struct drm_buddy *mm,
332332
u64 start, u64 end,
333333
unsigned int order)
334334
{
335+
u64 req_size = mm->chunk_size << order;
335336
struct drm_buddy_block *block;
336337
struct drm_buddy_block *buddy;
337338
LIST_HEAD(dfs);
@@ -367,6 +368,15 @@ alloc_range_bias(struct drm_buddy *mm,
367368
if (drm_buddy_block_is_allocated(block))
368369
continue;
369370

371+
if (block_start < start || block_end > end) {
372+
u64 adjusted_start = max(block_start, start);
373+
u64 adjusted_end = min(block_end, end);
374+
375+
if (round_down(adjusted_end + 1, req_size) <=
376+
round_up(adjusted_start, req_size))
377+
continue;
378+
}
379+
370380
if (contains(start, end, block_start, block_end) &&
371381
order == drm_buddy_block_order(block)) {
372382
/*

0 commit comments

Comments
 (0)