From: Steven Rostedt <rost...@goodmis.org> Add the function unwind_user_get_cookie() API that allows a subsystem to retrieve the current context cookie. This can be used by perf to attach a cookie to its task deferred unwinding code that doesn't use the deferred unwind logic.
Signed-off-by: Steven Rostedt (Google) <rost...@goodmis.org> --- include/linux/unwind_deferred.h | 5 +++++ kernel/unwind/deferred.c | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/linux/unwind_deferred.h b/include/linux/unwind_deferred.h index 26122d00708a..ce507495972c 100644 --- a/include/linux/unwind_deferred.h +++ b/include/linux/unwind_deferred.h @@ -41,6 +41,8 @@ void unwind_deferred_cancel(struct unwind_work *work); void unwind_deferred_task_exit(struct task_struct *task); +u64 unwind_user_get_cookie(void); + static __always_inline void unwind_reset_info(void) { struct unwind_task_info *info = ¤t->unwind_info; @@ -76,6 +78,9 @@ static inline void unwind_deferred_cancel(struct unwind_work *work) {} static inline void unwind_deferred_task_exit(struct task_struct *task) {} static inline void unwind_reset_info(void) {} +/* Must be non-zero */ +static inline u64 unwind_user_get_cookie(void) { return (u64)-1; } + #endif /* !CONFIG_UNWIND_USER */ #endif /* _LINUX_UNWIND_USER_DEFERRED_H */ diff --git a/kernel/unwind/deferred.c b/kernel/unwind/deferred.c index dc6040aae3ee..90f90e30000a 100644 --- a/kernel/unwind/deferred.c +++ b/kernel/unwind/deferred.c @@ -94,6 +94,27 @@ static u64 get_cookie(struct unwind_task_info *info) return info->id.id; } +/** + * unwind_user_get_cookie - Get the current user context cookie + * + * This is used to get a unique context cookie for the current task. + * Every time a task enters the kernel it has a new context. If + * a subsystem needs to have a unique identifier for that context for + * the current task, it can call this function to retrieve a unique + * cookie for that task context. + * + * Returns: A unque identifier for the current task user context. + */ +u64 unwind_user_get_cookie(void) +{ + struct unwind_task_info *info = ¤t->unwind_info; + + guard(irqsave)(); + /* Make sure to clear the info->id.id when exiting the kernel */ + set_bit(UNWIND_USED_BIT, &info->unwind_mask); + return get_cookie(info); +} + /** * unwind_user_faultable - Produce a user stacktrace in faultable context * @trace: The descriptor that will store the user stacktrace -- 2.50.1