Re: [PATCH v16 03/10] unwind_user/deferred: Add unwind cache
From: Steven Rostedt
Date: Wed Jul 30 2025 - 09:32:53 EST
On Tue, 29 Jul 2025 21:55:39 -0700
Indu Bhagat <indu.bhagat@xxxxxxxxxx> wrote:
> > diff --git a/include/linux/unwind_deferred.h b/include/linux/unwind_deferred.h
> > index a5f6e8f8a1a2..baacf4a1eb4c 100644
> > --- a/include/linux/unwind_deferred.h
> > +++ b/include/linux/unwind_deferred.h
> > @@ -12,6 +12,12 @@ void unwind_task_free(struct task_struct *task);
> >
> > int unwind_user_faultable(struct unwind_stacktrace *trace);
> >
> > +static __always_inline void unwind_reset_info(void)
> > +{
> > + if (unlikely(current->unwind_info.cache))
> > + current->unwind_info.cache->nr_entries = 0;
> > +}
>
> Should the entries[] items upto nr_entries (stack trace info from the
> previous request) also be reset to 0 here ?
This is in a critical path, there's no reason to reset to zero. The data will
just be stale. Nothing should care about anything over nr_entries.
> > diff --git a/include/linux/unwind_deferred_types.h b/include/linux/unwind_deferred_types.h
> > index aa32db574e43..db5b54b18828 100644
> > --- a/include/linux/unwind_deferred_types.h
> > +++ b/include/linux/unwind_deferred_types.h
> > @@ -2,8 +2,13 @@
> > #ifndef _LINUX_UNWIND_USER_DEFERRED_TYPES_H
> > #define _LINUX_UNWIND_USER_DEFERRED_TYPES_H
> >
> > +struct unwind_cache {
> > + unsigned int nr_entries;
> > + unsigned long entries[];
> > +};
> > +
>
> Should we use __counted_by ?
The size of entries[] is not determined by nr_entries. It is allocated on
the first use, and not freed until the task exits. It's a fixed size
defined by:
/* Make the cache fit in a 4K page */
#define UNWIND_MAX_ENTRIES \
((SZ_4K - sizeof(struct unwind_cache)) / sizeof(long))
-- Steve