[PATCH v5 4/9] tracing: Do not bother getting user space stacktraces for kernel threads

Steven Rostedt
2025-04-24T19:24:17Z

From: Steven Rostedt <rostedt@goodmis.org>

If a user space stacktrace is requested when running a kernel thread, just
return, as there's no point trying to get the user space stacktrace as
there is no user space.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
kernel/trace/trace.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 8ddf6b17215c..523e98cd121d 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -3087,6 +3087,10 @@ ftrace_trace_userstack(struct trace_array *tr,
if (!(tr->trace_flags & TRACE_ITER_USERSTACKTRACE))
return;

+ /* No point doing user space stacktraces on kernel threads */
+ if (current->flags & PF_KTHREAD)
+ return;
+
/*
* NMIs can not handle page faults, even with fix ups.
* The save user stack can (and often does) fault.
--
2.47.2