]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
perf: Have get_perf_callchain() return NULL if crosstask and user are set
authorJosh Poimboeuf <jpoimboe@kernel.org>
Wed, 20 Aug 2025 18:03:40 +0000 (14:03 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 2 Nov 2025 13:15:20 +0000 (22:15 +0900)
[ Upstream commit 153f9e74dec230f2e070e16fa061bc7adfd2c450 ]

get_perf_callchain() doesn't support cross-task unwinding for user space
stacks, have it return NULL if both the crosstask and user arguments are
set.

Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20250820180428.426423415@kernel.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/events/callchain.c

index d1a09e6f514c98cfb7f3b11d08362b8a4ee957a9..49d87e6db553f0f5c31bf480caeb82fd7201efeb 100644 (file)
@@ -223,6 +223,10 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
        struct perf_callchain_entry_ctx ctx;
        int rctx, start_entry_idx;
 
+       /* crosstask is not supported for user stacks */
+       if (crosstask && user && !kernel)
+               return NULL;
+
        entry = get_callchain_entry(&rctx);
        if (!entry)
                return NULL;
@@ -239,7 +243,7 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
                perf_callchain_kernel(&ctx, regs);
        }
 
-       if (user) {
+       if (user && !crosstask) {
                if (!user_mode(regs)) {
                        if (current->flags & (PF_KTHREAD | PF_USER_WORKER))
                                regs = NULL;
@@ -248,9 +252,6 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
                }
 
                if (regs) {
-                       if (crosstask)
-                               goto exit_put;
-
                        if (add_mark)
                                perf_callchain_store_context(&ctx, PERF_CONTEXT_USER);
 
@@ -260,7 +261,6 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
                }
        }
 
-exit_put:
        put_callchain_entry(rctx);
 
        return entry;