From: sashiko-bot@kernel.org
To: "Arunpravin Paneer Selvam" <arunpravin.paneerselvam@amd.com>
Cc: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH v4 2/3] gpu/buddy: add range-restricted contiguous allocation fallback
Date: Fri, 09 Oct 2026 10:23:53 +0000 [thread overview]
Message-ID: <sashiko-outbox-165224@kernel.org> (raw)
In-Reply-To: <20261009100546.1103622-2-arunpravin.paneerselvam@amd.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] mm: gpu/buddy try-harder fails range allocation when free space exceeds range_end
- [High] mm: gpu/buddy try-harder misses higher-order blocks for range allocations
--
commit 3089b8dadc6718a57b0162914961a76a654e9d6b
Author: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Subject: gpu/buddy: add range-restricted contiguous allocation fallback
This commit adds support for range-restricted contiguous allocation
fallback in the GPU buddy allocator. It extends __alloc_contig_try_harder
to confine candidate placements to a specified [range_start, range_end)
window.
> diff --git a/drivers/gpu/buddy.c b/drivers/gpu/buddy.c
> index 6566bad4fef15..1f648bcfce574 100644
> --- a/drivers/gpu/buddy.c
> +++ b/drivers/gpu/buddy.c
> @@ -1682,26 +1682,14 @@ static int __gpu_buddy_alloc_range(struct gpu_buddy *mm,
[ ... ]
> static int __alloc_contig_try_harder(struct gpu_buddy *mm,
> + u64 range_start, u64 range_end,
> u64 size,
> u64 min_block_size,
> unsigned long flags,
> struct list_head *blocks)
> {
[Severity: High]
Does the try-harder fallback miss higher-order blocks for range allocations?
When this function is called as a fallback, it derives an order based on the
unrounded size and searches exclusively in mm->free_tree[order]:
modify_size = rounddown_pow_of_two(size);
pages = modify_size >> ilog2(mm->chunk_size);
order = fls(pages) - 1;
...
root = &mm->free_tree[order];
if (RB_EMPTY_ROOT(root))
return -ENOSPC;
However, for range contiguous allocations, the normal allocation pass rounds up
the requested size. If a higher-order block intersects the range but cannot
fit the rounded-up size within the bounds, it gets skipped and is not split.
If this occurs, the valid contiguous space remains in a higher-order tree.
Since the try-harder fallback only checks the single derived order's tree,
will it fail immediately with -ENOSPC, missing the free space that resides in
the unsplit, higher-order blocks?
> - u64 rhs_offset, lhs_offset, filled;
> + u64 rhs_offset, lhs_offset, filled, aligned;
> struct gpu_buddy_block *block;
> struct rb_root *root;
> struct rb_node *iter;
> @@ -1726,25 +1714,36 @@ static int __alloc_contig_try_harder(struct gpu_buddy *mm,
>
> rhs_offset = gpu_buddy_block_offset(block);
>
> + if (rhs_offset >= range_end) {
> + iter = rb_prev(iter);
> + continue;
> + }
> + if (rhs_offset < range_start)
> + break;
> +
> /* Allocate blocks traversing RHS */
> err = __gpu_buddy_alloc_range(mm, rhs_offset, size,
> flags, &filled, blocks);
> if (err && err != -ENOSPC)
> return err;
> - if (!err && IS_ALIGNED(rhs_offset, min_block_size))
> + if (!err && IS_ALIGNED(rhs_offset, min_block_size) &&
> + rhs_offset >= range_start && rhs_offset + size <= range_end)
> return 0;
> if (!err) {
> /* Allocate the unaligned RHS offset using round_down */
> gpu_buddy_free_list_internal(mm, blocks);
> - err = __alloc_contig_aligned_retry(mm, rhs_offset,
> - size,
> - min_block_size,
> - flags, blocks);
> - if (!err)
> - return 0;
> - if (err != -ENOSPC) {
> - gpu_buddy_free_list_internal(mm, blocks);
> - return err;
> +
> + aligned = round_down(rhs_offset, min_block_size);
> + if (aligned >= range_start &&
> + aligned + size <= range_end) {
> + err = __gpu_buddy_alloc_range(mm, aligned, size,
> + flags, NULL, blocks);
> + if (!err)
> + return 0;
> + if (err != -ENOSPC) {
> + gpu_buddy_free_list_internal(mm, blocks);
> + return err;
> + }
> }
> goto next;
> }
[Severity: High]
Does this bypass the left-shift fallback when free space exceeds range_end?
__alloc_contig_try_harder() attempts to place a contiguous block by calling
__gpu_buddy_alloc_range() without passing range_end.
If the contiguous free space extends beyond range_end, this allocation fully
succeeds and returns err == 0.
Because the allocation succeeded, the condition aligned + size <= range_end
will evaluate to false if the memory exceeds the requested range, and the code
hits goto next:
if (aligned >= range_start &&
aligned + size <= range_end) {
...
}
goto next;
}
This completely skips the lhs_offset fallback path that normally follows:
if (size - filled > rhs_offset)
goto next;
lhs_offset = rhs_offset - (size - filled);
...
Had the allocator been bounded by range_end, it would have returned -ENOSPC
with filled set, triggering the left-shift fallback to perfectly slide the
allocation into the requested range.
Will the presence of extra free memory outside the range cause valid contiguous
allocations to spuriously fail?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261009100546.1103622-1-arunpravin.paneerselvam@amd.com?part=2
next prev parent reply other threads:[~2026-10-09 10:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 10:05 [PATCH v4 1/3] gpu/buddy: restore two-pass clear/dirty guard for range-biased allocation Arunpravin Paneer Selvam
2026-10-09 10:05 ` [PATCH v4 2/3] gpu/buddy: add range-restricted contiguous allocation fallback Arunpravin Paneer Selvam
2026-10-09 10:23 ` sashiko-bot [this message]
2026-10-09 10:05 ` [PATCH v4 3/3] gpu/buddy: search lower orders in contiguous try-harder fallback Arunpravin Paneer Selvam
2026-10-09 10:17 ` [PATCH v4 1/3] gpu/buddy: restore two-pass clear/dirty guard for range-biased allocation sashiko-bot
2026-10-09 12:07 ` ✓ i915.CI.BAT: success for series starting with [v4,1/3] " Patchwork
2026-10-09 14:58 ` ✓ i915.CI.Full: " Patchwork
2026-10-13 14:31 ` [PATCH v4 1/3] " Arunpravin Paneer Selvam
2026-10-13 15:06 ` Matthew Auld
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-165224@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=arunpravin.paneerselvam@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox