All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Arunpravin Paneer Selvam" <arunpravin.paneerselvam@amd.com>
Cc: intel-xe@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v4 1/3] gpu/buddy: restore two-pass clear/dirty guard for range-biased allocation
Date: Fri, 09 Oct 2026 10:17:36 +0000	[thread overview]
Message-ID: <sashiko-outbox-165221@kernel.org> (raw)
In-Reply-To: <20261009100546.1103622-1-arunpravin.paneerselvam@amd.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] gpu/buddy: block_incompatible() incorrectly rejects mixed subtrees during CLEAR allocations
- [High] gpu/buddy: range allocator strict pass skips valid subtrees due to stale split block clear bits
--

commit 19316e455db24fbfaa4dda04f7d988cae7073da7
Author: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>

gpu/buddy: restore two-pass clear/dirty guard for range-biased allocation

This commit introduces a two-pass range search in the buddy allocator's
range-biased allocation path. The strict pass uses block_incompatible() to
reject opposite-class blocks, while the fallback pass relaxes this constraint
when opposite-class space is the only option remaining.

> diff --git a/drivers/gpu/buddy.c b/drivers/gpu/buddy.c
> index 2f2aaadafe351..6566bad4fef15 100644
> --- a/drivers/gpu/buddy.c
> +++ b/drivers/gpu/buddy.c
> @@ -1240,11 +1240,19 @@ static void __gpu_buddy_undo_splits(struct gpu_buddy *mm,
>  	}
>  }
>  
> +static bool block_incompatible(struct gpu_buddy_block *block, unsigned int flags)
> +{
> +	bool needs_clear = flags & GPU_BUDDY_CLEAR_ALLOCATION;
> +
> +	return needs_clear != gpu_buddy_block_is_clear(block);
> +}

[Severity: High]
Does this evaluation correctly handle intermediate SPLIT blocks?

A SPLIT block's GPU_BUDDY_HEADER_CLEAR bit retains the value from when it
was last FREE and is not updated after splitting. If a root or intermediate
block was dirty when split, its clear bit remains 0 even if it now contains
free clear children.

For a CLEAR allocation, will this cause the strict pass to read a stale 0 bit
and incorrectly skip the entire valid subtree?

Additionally, are mixed subtrees inadvertently rejected during CLEAR
allocations here?

Since mixed subtrees contain both clear and dirty pages, their is_clear
state evaluates to false. Consequently, block_incompatible() will evaluate
mixed subtrees as incompatible, causing the strict pass to skip them entirely
unless the entire root block is fully clear.

>  static struct gpu_buddy_block *
>  __alloc_range_bias(struct gpu_buddy *mm,
>  		   u64 start, u64 end,
>  		   unsigned int order,
> -		   unsigned long flags)
> +		   unsigned long flags,
> +		   bool fallback)
>  {

[ ... ]

> @@ -1315,38 +1324,8 @@ __alloc_range_bias(struct gpu_buddy *mm,
>  				goto err_undo;
>  		}
>  
> -		/*
> -		 * Top-down is a strict address-placement policy, so when it is
> -		 * requested we ignore clear steering and simply descend the
> -		 * right (higher-address) child first. Only a non-top-down clear
> -		 * request biases the descent towards clear/has_clear subtrees.
> -		 */
> -		if ((flags & GPU_BUDDY_CLEAR_ALLOCATION) &&
> -		    !(flags & GPU_BUDDY_TOPDOWN_ALLOCATION)) {
> -			struct gpu_buddy_block *prefer;
> -
> -			if (gpu_buddy_block_is_clear(block->right))
> -				prefer = block->right;
> -			else if (gpu_buddy_block_is_clear(block->left))
> -				prefer = block->left;
> -			else if (block->right->has_clear)
> -				prefer = block->right;
> -			else if (block->left->has_clear)
> -				prefer = block->left;
> -			else
> -				prefer = block->right;
> -
> -			if (prefer == block->right) {
> -				list_add(&block->left->tmp_link, &dfs);
> -				list_add(&block->right->tmp_link, &dfs);
> -			} else {
> -				list_add(&block->right->tmp_link, &dfs);
> -				list_add(&block->left->tmp_link, &dfs);
> -			}
> -		} else {
> -			list_add(&block->left->tmp_link, &dfs);
> -			list_add(&block->right->tmp_link, &dfs);
> -		}
> +		list_add(&block->left->tmp_link, &dfs);
> +		list_add(&block->right->tmp_link, &dfs);
>  	} while (1);

[Severity: High]
Without the has_clear steering logic, how does the fallback pass handle
CLEAR allocations when descending?

If the strict pass fails (as described above for mixed subtrees), the
allocator executes the fallback pass which ignores class preferences.
Because the fallback pass now blindly traverses top-down (right child first)
after the removal of the has_clear steering logic, could a CLEAR range
allocation incorrectly allocate and return dirty blocks if they happen to
be right-most?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261009100546.1103622-1-arunpravin.paneerselvam@amd.com?part=1

  parent reply	other threads:[~2026-10-09 10:17 UTC|newest]

Thread overview: 12+ 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
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:15 ` ✓ CI.KUnit: success for series starting with [v4,1/3] gpu/buddy: restore two-pass clear/dirty guard for range-biased allocation Patchwork
2026-10-09 10:17 ` sashiko-bot [this message]
2026-10-09 11:13 ` ✓ Xe.CI.BAT: " Patchwork
2026-10-09 12:07 ` ✓ i915.CI.BAT: " Patchwork
2026-10-09 13:35 ` ✓ Xe.CI.FULL: " 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-165221@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.