On Fri, 14 Nov 2025 08:53:32 -0500
Steven Rostedt <[email protected]> wrote:

> On Fri, 14 Nov 2025 08:43:46 -0500
> Steven Rostedt <[email protected]> wrote:
> 
> > I need to add a comment here that entries is not bound by nr_entries.
> > 
> >    https://lore.kernel.org/all/[email protected]/
> > 
> > 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
> 


Reply via email to