llvm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Bill Wendling <morbo@google.com>
To: Kees Cook <kees@kernel.org>
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nick Desaulniers" <nick.desaulniers+lkml@gmail.com>,
	"Justin Stitt" <justinstitt@google.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Heiko Carstens" <hca@linux.ibm.com>,
	"Marc Herbert" <Marc.Herbert@linux.intel.com>,
	"Uros Bizjak" <ubizjak@gmail.com>, "Tejun Heo" <tj@kernel.org>,
	"Jeff Xu" <jeffxu@chromium.org>,
	"Michal Koutný" <mkoutny@suse.com>,
	"Shakeel Butt" <shakeel.butt@linux.dev>,
	"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
	"John Stultz" <jstultz@google.com>,
	"Christian Brauner" <brauner@kernel.org>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Brian Gerst" <brgerst@gmail.com>,
	"Masahiro Yamada" <masahiroy@kernel.org>,
	"Mike Rapoport" <rppt@kernel.org>,
	linux-mm@kvack.org, linux-hardening@vger.kernel.org,
	llvm@lists.linux.dev
Subject: Re: [PATCH 2/2] memblock: annotate struct memblock_type with __counted_by_ptr
Date: Mon, 24 Nov 2025 12:15:54 -0800	[thread overview]
Message-ID: <CAGG=3QVwhA8yca4hQD1q7c6TgPL0dT5RODpdpBHSw2yuh1x7oQ@mail.gmail.com> (raw)
In-Reply-To: <202511241117.CBE8ADC2@keescook>

On Mon, Nov 24, 2025 at 11:19 AM Kees Cook <kees@kernel.org> wrote:
>
> On Sat, Nov 22, 2025 at 02:16:14PM -0800, Andrew Morton wrote:
> > On Fri, 21 Nov 2025 16:30:43 -0800 Kees Cook <kees@kernel.org> wrote:
> >
> > > On Fri, Nov 21, 2025 at 07:39:44PM +0000, Bill Wendling wrote:
> > > > Add the '__counted_by_ptr' attribute to the 'regions' field of 'struct
> > > > memblock_type'. The 'regions' field is an array of 'struct
> > > > memblock_region' and its size is tracked by the 'max' field, which
> > > > represents the total number of allocated regions.
> > >
> > > As part of any counted_by annotation patch, there needs to be discussion
> > > in the commit log about how it's been shown to be a safe annotation
> > > to make. e.g. in this case, if all allocations of "regions" have a
> > > corresponding "max" assignment, etc. If just "git grep" can't find them
> > > all, using something like Coccinelle or CodeQL to search for struct
> > > memblock_type::regions assignments can work.
> >
> > How is anyone to know these things?  I can't find anything about this
> > in include/ or Documentation/ or in the relevant commits.
> >
> > There should be a comment at the __counted_by() definition site, please.
> >
> > And possibly write a Documentation/ file then change checkpatch to
> > direct people to that file if they add a counted_by?
>
> This is a fair point, yes. The documentation and discussions around
> counted_by are very big in my mind (and for Bill), so it was mostly a
> consolidation/reminder and some extra detail on prior solutions, but
> for anyone new to that annotation, we should have collected common
> guidance. I will write something up.
>
Good point. I'll add documentation for these attributes both in
Documentation/ and at the macro site. The frustrating thing is that
we're likely to have at least one other macro flavor (something like
"__counted_by_expr"), though that's the only foreseeable one. All of
these macros are wrappers around the same attribute because of
compiler skew.

-bw

  reply	other threads:[~2025-11-24 20:16 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-21 19:39 [PATCH 0/2] Add __counted_by_ptr macro Bill Wendling
2025-11-21 19:39 ` [PATCH 1/2] Compiler Attributes: " Bill Wendling
2025-11-21 19:46   ` Bill Wendling
2025-11-21 19:54   ` [PATCH v2 " Bill Wendling
2025-11-21 21:47     ` Miguel Ojeda
2025-11-24 20:01       ` Bill Wendling
2025-11-21 19:39 ` [PATCH 2/2] memblock: annotate struct memblock_type with __counted_by_ptr Bill Wendling
2025-11-22  0:30   ` Kees Cook
2025-11-22 22:16     ` Andrew Morton
2025-11-24 19:19       ` Kees Cook
2025-11-24 20:15         ` Bill Wendling [this message]
2025-11-25 12:08   ` Mike Rapoport
2025-11-21 23:25 ` [PATCH 0/2] Add __counted_by_ptr macro Kees Cook
2025-11-24 20:05   ` Bill Wendling

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='CAGG=3QVwhA8yca4hQD1q7c6TgPL0dT5RODpdpBHSw2yuh1x7oQ@mail.gmail.com' \
    --to=morbo@google.com \
    --cc=Marc.Herbert@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=brgerst@gmail.com \
    --cc=gustavoars@kernel.org \
    --cc=hca@linux.ibm.com \
    --cc=jeffxu@chromium.org \
    --cc=jstultz@google.com \
    --cc=justinstitt@google.com \
    --cc=kees@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=llvm@lists.linux.dev \
    --cc=masahiroy@kernel.org \
    --cc=mkoutny@suse.com \
    --cc=nathan@kernel.org \
    --cc=nick.desaulniers+lkml@gmail.com \
    --cc=ojeda@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rdunlap@infradead.org \
    --cc=rppt@kernel.org \
    --cc=shakeel.butt@linux.dev \
    --cc=thomas.weissschuh@linutronix.de \
    --cc=tj@kernel.org \
    --cc=ubizjak@gmail.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;
as well as URLs for NNTP newsgroup(s).