mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-08-27 06:50:37 +00:00

On do_exit() when a task is exiting, if a unwind is requested and the deferred user stacktrace is deferred via the task_work, the task_work callback is called after exit_mm() is called in do_exit(). This means that the user stack trace will not be retrieved and an empty stack is created. Instead, add a function unwind_deferred_task_exit() and call it just before exit_mm() so that the unwinder can call the requested callbacks with the user space stack. Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Josh Poimboeuf <jpoimboe@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Andrii Nakryiko <andrii@kernel.org> Cc: Indu Bhagat <indu.bhagat@oracle.com> Cc: "Jose E. Marchesi" <jemarch@gnu.org> Cc: Beau Belgrave <beaub@linux.microsoft.com> Cc: Jens Remus <jremus@linux.ibm.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Jens Axboe <axboe@kernel.dk> Cc: Florian Weimer <fweimer@redhat.com> Cc: Sam James <sam@gentoo.org> Link: https://lore.kernel.org/20250729182406.504259474@kernel.org Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
82 lines
2.3 KiB
C
82 lines
2.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _LINUX_UNWIND_USER_DEFERRED_H
|
|
#define _LINUX_UNWIND_USER_DEFERRED_H
|
|
|
|
#include <linux/task_work.h>
|
|
#include <linux/unwind_user.h>
|
|
#include <linux/unwind_deferred_types.h>
|
|
|
|
struct unwind_work;
|
|
|
|
typedef void (*unwind_callback_t)(struct unwind_work *work, struct unwind_stacktrace *trace, u64 cookie);
|
|
|
|
struct unwind_work {
|
|
struct list_head list;
|
|
unwind_callback_t func;
|
|
int bit;
|
|
};
|
|
|
|
#ifdef CONFIG_UNWIND_USER
|
|
|
|
enum {
|
|
UNWIND_PENDING_BIT = 0,
|
|
UNWIND_USED_BIT,
|
|
};
|
|
|
|
enum {
|
|
UNWIND_PENDING = BIT(UNWIND_PENDING_BIT),
|
|
|
|
/* Set if the unwinding was used (directly or deferred) */
|
|
UNWIND_USED = BIT(UNWIND_USED_BIT)
|
|
};
|
|
|
|
void unwind_task_init(struct task_struct *task);
|
|
void unwind_task_free(struct task_struct *task);
|
|
|
|
int unwind_user_faultable(struct unwind_stacktrace *trace);
|
|
|
|
int unwind_deferred_init(struct unwind_work *work, unwind_callback_t func);
|
|
int unwind_deferred_request(struct unwind_work *work, u64 *cookie);
|
|
void unwind_deferred_cancel(struct unwind_work *work);
|
|
|
|
void unwind_deferred_task_exit(struct task_struct *task);
|
|
|
|
static __always_inline void unwind_reset_info(void)
|
|
{
|
|
struct unwind_task_info *info = ¤t->unwind_info;
|
|
unsigned long bits;
|
|
|
|
/* Was there any unwinding? */
|
|
if (unlikely(info->unwind_mask)) {
|
|
bits = info->unwind_mask;
|
|
do {
|
|
/* Is a task_work going to run again before going back */
|
|
if (bits & UNWIND_PENDING)
|
|
return;
|
|
} while (!try_cmpxchg(&info->unwind_mask, &bits, 0UL));
|
|
current->unwind_info.id.id = 0;
|
|
|
|
if (unlikely(info->cache)) {
|
|
info->cache->nr_entries = 0;
|
|
info->cache->unwind_completed = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
#else /* !CONFIG_UNWIND_USER */
|
|
|
|
static inline void unwind_task_init(struct task_struct *task) {}
|
|
static inline void unwind_task_free(struct task_struct *task) {}
|
|
|
|
static inline int unwind_user_faultable(struct unwind_stacktrace *trace) { return -ENOSYS; }
|
|
static inline int unwind_deferred_init(struct unwind_work *work, unwind_callback_t func) { return -ENOSYS; }
|
|
static inline int unwind_deferred_request(struct unwind_work *work, u64 *timestamp) { return -ENOSYS; }
|
|
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) {}
|
|
|
|
#endif /* !CONFIG_UNWIND_USER */
|
|
|
|
#endif /* _LINUX_UNWIND_USER_DEFERRED_H */
|