From: David Laight <david.laight.linux@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
Josh Poimboeuf <jpoimboe@kernel.org>, Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH] unwind deferred: Annotate struct unwind_cache with __counted_by
Date: Fri, 14 Nov 2025 15:02:09 +0000 [thread overview]
Message-ID: <20251114150209.27354ddd@pumpkin> (raw)
In-Reply-To: <20251114085332.396aff85@gandalf.local.home>
On Fri, 14 Nov 2025 08:53:32 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:
> On Fri, 14 Nov 2025 08:43:46 -0500
> Steven Rostedt <rostedt@goodmis.org> wrote:
>
> > I need to add a comment here that entries is not bound by nr_entries.
> >
> > https://lore.kernel.org/all/20250730093249.4833be14@gandalf.local.home/
> >
> > Maybe this?:
>
> Or better yet, if this compiles (I haven't tried):
>
> diff --git a/include/linux/unwind_deferred_types.h b/include/linux/unwind_deferred_types.h
> index 33b62ac25c86..253a69b21e76 100644
> --- a/include/linux/unwind_deferred_types.h
> +++ b/include/linux/unwind_deferred_types.h
> @@ -2,10 +2,14 @@
> #ifndef _LINUX_UNWIND_USER_DEFERRED_TYPES_H
> #define _LINUX_UNWIND_USER_DEFERRED_TYPES_H
>
> +/* Make the cache fit in a 4K page */
> +#define UNWIND_MAX_ENTRIES \
> + ((SZ_4K - offset_of(struct unwind_cache, entries)) / sizeof(long))
> +
> struct unwind_cache {
> unsigned long unwind_completed;
> unsigned int nr_entries;
> - unsigned long entries[];
> + unsigned long entries[UNWIND_MAX_ENTRIES];
That won't compile - I tried it.
You could add __aligned(4096) to force the structure to be padded to 4k,
and then define UNWIND_MAX_ENTRIES in terms of the structure size.
David
> };
>
> /*
> diff --git a/kernel/unwind/deferred.c b/kernel/unwind/deferred.c
> index dc6040aae3ee..5dfd0ac264d1 100644
> --- a/kernel/unwind/deferred.c
> +++ b/kernel/unwind/deferred.c
> @@ -37,10 +37,6 @@ static inline bool try_assign_cnt(struct unwind_task_info *info, u32 cnt)
> }
> #endif
>
> -/* Make the cache fit in a 4K page */
> -#define UNWIND_MAX_ENTRIES \
> - ((SZ_4K - sizeof(struct unwind_cache)) / sizeof(long))
> -
> /* Guards adding to or removing from the list of callbacks */
> static DEFINE_MUTEX(callback_mutex);
> static LIST_HEAD(callbacks);
> @@ -118,8 +114,7 @@ int unwind_user_faultable(struct unwind_stacktrace *trace)
> return -EINVAL;
>
> if (!info->cache) {
> - info->cache = kzalloc(struct_size(cache, entries, UNWIND_MAX_ENTRIES),
> - GFP_KERNEL);
> + info->cache = kzalloc(sizeof(*cache), GFP_KERNEL);
> if (!info->cache)
> return -ENOMEM;
> }
>
> -- Steve
>
next prev parent reply other threads:[~2025-11-14 15:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 12:27 [PATCH] unwind deferred: Annotate struct unwind_cache with __counted_by Thorsten Blum
2025-11-14 13:43 ` Steven Rostedt
2025-11-14 13:53 ` Steven Rostedt
2025-11-14 14:57 ` Steven Rostedt
2025-11-14 15:02 ` David Laight [this message]
2025-11-14 15:48 ` Steven Rostedt
2025-11-14 14:31 ` David Laight
2025-11-14 14:56 ` Steven Rostedt
2025-11-14 15:49 ` Steven Rostedt
2025-11-14 15:53 ` Steven Rostedt
2025-11-14 16:15 ` Thorsten Blum
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=20251114150209.27354ddd@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=gustavoars@kernel.org \
--cc=jpoimboe@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=thorsten.blum@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.