[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z8gW1rihV0aIp8Oo@gmail.com>
Date: Wed, 5 Mar 2025 10:18:14 +0100
From: Ingo Molnar <mingo@...nel.org>
To: linux-kernel@...r.kernel.org
Cc: linux-tip-commits@...r.kernel.org,
Thorsten Blum <thorsten.blum@...ux.dev>,
Peter Zijlstra <peterz@...radead.org>, x86@...nel.org
Subject: Re: [tip: perf/core] perf/x86: Annotate struct bts_buffer with
__counted_by()
* tip-bot2 for Thorsten Blum <tip-bot2@...utronix.de> wrote:
> The following commit has been merged into the perf/core branch of tip:
>
> Commit-ID: 077dcef270361089c322a969b792438b33cfb479
> Gitweb: https://git.kernel.org/tip/077dcef270361089c322a969b792438b33cfb479
> Author: Thorsten Blum <thorsten.blum@...ux.dev>
> AuthorDate: Tue, 04 Mar 2025 19:30:57 +01:00
> Committer: Ingo Molnar <mingo@...nel.org>
> CommitterDate: Tue, 04 Mar 2025 19:58:01 +01:00
>
> perf/x86: Annotate struct bts_buffer with __counted_by()
>
> Add the __counted_by() compiler attribute to the flexible array member
> buf to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
> CONFIG_FORTIFY_SOURCE.
>
> Use struct_size() to calculate the number of bytes to allocate for a new
> bts_buffer. Compared to offsetof(), struct_size() has additional
> compile-time checks (e.g., __must_be_array()).
>
> No functional changes intended.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@...ux.dev>
> Signed-off-by: Ingo Molnar <mingo@...nel.org>
> Cc: Peter Zijlstra <peterz@...radead.org>
> Link: https://lore.kernel.org/r/20250304183056.78920-2-thorsten.blum@linux.dev
> ---
> arch/x86/events/intel/bts.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/events/intel/bts.c b/arch/x86/events/intel/bts.c
> index 8e09319..debfc18 100644
> --- a/arch/x86/events/intel/bts.c
> +++ b/arch/x86/events/intel/bts.c
> @@ -58,7 +58,7 @@ struct bts_buffer {
> local_t head;
> unsigned long end;
> void **data_pages;
> - struct bts_phys buf[];
> + struct bts_phys buf[] __counted_by(nr_bufs);
> };
>
> static struct pmu bts_pmu;
> @@ -101,7 +101,7 @@ bts_buffer_setup_aux(struct perf_event *event, void **pages,
> if (overwrite && nbuf > 1)
> return NULL;
Actually, on a second thought:
> - buf = kzalloc_node(offsetof(struct bts_buffer, buf[nbuf]), GFP_KERNEL, node);
> + buf = kzalloc_node(struct_size(buf, buf, nbuf), GFP_KERNEL, node);
Firstly, in what world is 'buf, buf' more readable? One is a member of
a structure, the other is the name of the structure - and they match,
which shows that this function's naming conventions are a mess.
Which should be fixed first ...
I'm also not sure the code is correct ...
So I zapped this commit from tip:perf/core.
Thanks,
Ingo
Powered by blists - more mailing lists