[PATCH v6 12/18] perf: Simplify get_perf_callchain() user logic

Steven Rostedt
2025-04-25T14:56:15Z

Simplify the get_perf_callchain() user logic a bit. task_pt_regs()
should never be NULL.

Acked-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
Changes since v5: https://lore.kernel.org/20250424162633.048002581@goodmis.org

- Use (current->flags & PF_KTHREAD) instead of current->mm == NULL to
determine if a task is a kernel thread or not (Peter Zijlstra)

kernel/events/callchain.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/kernel/events/callchain.c b/kernel/events/callchain.c
index cda145dc11bd..2798c0c9f782 100644
--- a/kernel/events/callchain.c
+++ b/kernel/events/callchain.c
@@ -247,21 +247,19 @@ get_perf_callchain(struct pt_regs *regs, bool kernel, bool user,
if (user) {
if (!user_mode(regs)) {
if (current->flags & PF_KTHREAD)
- regs = NULL;
- else
- regs = task_pt_regs(current);
+ goto exit_put;
+ regs = task_pt_regs(current);
}

- if (regs) {
- if (add_mark)
- perf_callchain_store_context(&ctx, PERF_CONTEXT_USER);
+ if (add_mark)
+ perf_callchain_store_context(&ctx, PERF_CONTEXT_USER);

- start_entry_idx = entry->nr;
- perf_callchain_user(&ctx, regs);
- fixup_uretprobe_trampoline_entries(entry, start_entry_idx);
- }
+ start_entry_idx = entry->nr;
+ perf_callchain_user(&ctx, regs);
+ fixup_uretprobe_trampoline_entries(entry, start_entry_idx);
}

+exit_put:
put_callchain_entry(rctx);

return entry;
--
2.47.2