mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matthew Auld <matthew.auld@intel.com>
To: Bill Wendling <morbo@google.com>,
	Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Joel Fernandes <joelagnelf@nvidia.com>,
	Kees Cook <kees@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org,
	codemender-patching+linux@google.com
Subject: Re: [PATCH] gpu/buddy: add __counted_by_ptr attribute to roots
Date: Mon, 28 Sep 2026 13:20:51 +0100	[thread overview]
Message-ID: <605221ed-a1b5-4179-be8d-b206c79487d7@intel.com> (raw)
In-Reply-To: <20260925204423.80661-1-morbo@google.com>

On 25/09/2026 21:44, Bill Wendling wrote:
> In 'struct gpu_buddy', the 'roots' field points to an array of pointers
> to 'struct gpu_buddy_block'. The number of allocated roots is tracked
> by the 'n_roots' field.
> 
> Annotate the 'roots' pointer with the '__counted_by_ptr' attribute
> referencing 'n_roots' to enable compile-time and runtime bounds-checking
> via KASAN and '__builtin_dynamic_object_size'.
> 
> In 'gpu_buddy_init', 'mm->n_roots' is initialized first, and 'mm->roots' is
> subsequently allocated with 'kmalloc_objs(struct gpu_buddy_block *,
> mm->n_roots)'.
> 
> Since the bounds associated with 'roots' ('n_roots') are fully set prior
> to any array allocation or access and remain invariant, this annotation
> will not cause runtime panics or false-positive bounds checks.
> 
> Cc: codemender-patching+linux@google.com
> Assisted-by: LLM
> Signed-off-by: Bill Wendling <morbo@google.com>

Reviewed-by: Matthew Auld <matthew.auld@intel.com>

Would it make sense to also do this for *_scoreboard and free_tree, if 
we add a new field n_orders?

> ---
>   include/linux/gpu_buddy.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/gpu_buddy.h b/include/linux/gpu_buddy.h
> index 2c36124bb696..d7249e500ab6 100644
> --- a/include/linux/gpu_buddy.h
> +++ b/include/linux/gpu_buddy.h
> @@ -172,7 +172,7 @@ struct gpu_buddy {
>   	 * a power of two, with each root being the largest power-of-two
>   	 * that fits in the remaining space.
>   	 */
> -	struct gpu_buddy_block **roots;
> +	struct gpu_buddy_block **roots __counted_by_ptr(n_roots);
>   	/*
>   	 * Per-order free block scoreboard: free_scoreboard[order] holds the
>   	 * number of blocks of that order currently in the free state.


  reply	other threads:[~2026-09-28 12:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-25 20:44 Bill Wendling
2026-09-28 12:20 ` Matthew Auld [this message]
2026-09-28 18:44   ` Bill Wendling
2026-09-29  8:36     ` 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=605221ed-a1b5-4179-be8d-b206c79487d7@intel.com \
    --to=matthew.auld@intel.com \
    --cc=arunpravin.paneerselvam@amd.com \
    --cc=codemender-patching+linux@google.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gustavoars@kernel.org \
    --cc=joelagnelf@nvidia.com \
    --cc=kees@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=morbo@google.com \
    /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

all inboxes | Powered by JetHome®