Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "William Palacek" <William.Palacek@amd.com>,
	dri-devel@lists.freedesktop.org
Cc: intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v3 1/2] gpu/buddy: find range-biased blocks in the free trees
Date: Mon, 16 Nov 2026 16:23:32 +0000	[thread overview]
Message-ID: <sashiko-outbox-217356@kernel.org> (raw)
In-Reply-To: <17f2a6366ba845edc799dbeb712c12f8d060afad.1794845083.git.William.Palacek@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] gpu/buddy: u64 underflow on inverted range in
  __alloc_range_bias()
--

commit 84539d9e7a89604b1f5d66dfb390e667e4fccb69
Author: William Palacek <William.Palacek@amd.com>

gpu/buddy: find range-biased blocks in the free trees

This commit replaces the root-to-leaf block tree walk in
__alloc_range_bias() with augmented RB-tree lookups in the per-order
free trees, adding a subtree_has_dirty augment to skip all-clear
subtrees on dirty requests.

> diff --git a/drivers/gpu/buddy.c b/drivers/gpu/buddy.c
> index e7d2212bcec95..baf17700ffba5 100644
> --- a/drivers/gpu/buddy.c
> +++ b/drivers/gpu/buddy.c

[ ... ]

> @@ -1247,96 +1262,155 @@ static bool block_incompatible(struct gpu_buddy_block *block, unsigned int flags
>  			     gpu_buddy_block_is_clear(block);
>  }
>  
> -static struct gpu_buddy_block *
> -__alloc_range_bias(struct gpu_buddy *mm,
> -		   u64 start, u64 end,
> -		   unsigned int order,
> -		   unsigned long flags,
> -		   bool fallback)

[ ... ]

> +static struct gpu_buddy_block *
> +__alloc_range_bias(struct gpu_buddy *mm,
> +		   u64 start, u64 end,
> +		   unsigned int order,
> +		   unsigned long flags,
> +		   bool fallback)
> +{
> +	u64 req_size = mm->chunk_size << order;
> +	struct gpu_buddy_block *block = NULL;
> +	u64 best = 0;
> +	unsigned int i;
> +	int err;
>  
> +	for (i = order; i <= mm->max_order; i++) {
> +		struct rb_root *root = &mm->free_tree[i];
> +		u64 size = mm->chunk_size << i;
> +		struct gpu_buddy_block *found;
> +		u64 offset = 0;
>  
> +		if (!fallback) {
> +			if (end - start < size)
> +				break;
>  
> +			found = rbtree_last_range_block(root, end - size + 1,
> +							flags, false);
> +			if (!found || gpu_buddy_block_offset(found) < start)
> +				continue;

[Severity: Medium]
Can end - start and end - size + 1 underflow when start > end, causing
__alloc_range_bias() to allocate a block outside [start, end)?

gpu_buddy_alloc_blocks() checks end <= mm->size and
range_overflows(start, size, mm->size), which only checks start + size
<= mm->size, so an inverted range (for example, when
AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED clamps lpfn to visible_pfn below a
memory partition's fpfn in amdgpu_bo_placement_from_domain()) reaches
__alloc_range_bias() with start > end.  Previously, the adjusted_end vs
adjusted_start check rejected inverted ranges with -ENOSPC.  In the new
strict pass, end - start wraps in u64 arithmetic past the size check,
and when size > end, end - size + 1 wraps to near U64_MAX, so
rbtree_last_range_block() matches and returns a block at offset >= start
> end.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/17f2a6366ba845edc799dbeb712c12f8d060afad.1794845083.git.William.Palacek@amd.com?part=1

           reply	other threads:[~2026-11-16 16:23 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <17f2a6366ba845edc799dbeb712c12f8d060afad.1794845083.git.William.Palacek@amd.com>]

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-217356@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=William.Palacek@amd.com \
    --cc=dri-devel@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