All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Andrii Nakryiko" <andrii@kernel.org>, <bpf@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>
Cc: <catalin.marinas@arm.com>, <will@kernel.org>,
	<mark.rutland@arm.com>, <linux-perf-users@vger.kernel.org>,
	<peterz@infradead.org>, <jolsa@kernel.org>, <rostedt@goodmis.org>
Subject: Re: [PATCH bpf-next v2 1/3] arm64: perf: Don't report the caller twice in caller-regs callchains
Date: Thu, 19 Nov 2026 01:38:22 +0000	[thread overview]
Message-ID: <DMYSXNCMOF26.38XGLPOW4K29X@gmail.com> (raw)
In-Reply-To: <20261119000112.2377949-2-andrii@kernel.org>

On Wed, Nov 18, 2026 at 04:01 PM Andrii Nakryiko <andrii@kernel.org> wrote:
> Do the same on arm64. Set pstate to PSR_MODE_EL1t, which exceptions
> taken from the kernel never have (the kernel runs in EL1h, or EL2h
> with VHE), and skip the leaf regs->pc in perf_callchain_kernel() for
> regs with that mode. The unwind still starts from regs, with the frame
> record at x29 walked by the unwinder.

my bot thinks the following will be a more accurate fix...

diff --git a/arch/arm64/include/asm/perf_event.h b/arch/arm64/include/asm/perf_event.h
index ee45b4e..7c5ab65 100644
--- a/arch/arm64/include/asm/perf_event.h
+++ b/arch/arm64/include/asm/perf_event.h
@@ -13,11 +13,12 @@
 #define perf_arch_bpf_user_pt_regs(regs) &regs->user_regs
 #endif
 
+/* PSR_MODE_EL1t marks these regs for kunwind_stack_walk() */
 #define perf_arch_fetch_caller_regs(regs, __ip) { \
 	(regs)->pc = (__ip);    \
 	(regs)->regs[29] = (unsigned long) __builtin_frame_address(0); \
 	(regs)->sp = current_stack_pointer; \
-	(regs)->pstate = PSR_MODE_EL1h;	\
+	(regs)->pstate = PSR_MODE_EL1t;	\
 }
 
 #endif
diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
index 3ebcf8c..de394ff 100644
--- a/arch/arm64/kernel/stacktrace.c
+++ b/arch/arm64/kernel/stacktrace.c
@@ -357,6 +357,13 @@ kunwind_stack_walk(kunwind_consume_fn consume_state,
 		if (task != current)
 			return -EINVAL;
 		kunwind_init_from_regs(&state, regs);
+		/*
+		 * With perf_arch_fetch_caller_regs() the PC is a copy of the
+		 * LR in the frame record at FP. Start from that record.
+		 */
+		if (processor_mode(regs) == PSR_MODE_EL1t &&
+		    kunwind_next(&state))
+			return -EINVAL;
 	} else if (task == current) {
 		kunwind_init_from_caller(&state);
 	} else {


  parent reply	other threads:[~2026-11-19  1:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  0:01 [PATCH bpf-next v2 0/3] Fix duplicate caller frame in arm64 stack traces Andrii Nakryiko
2026-11-19  0:01 ` [PATCH bpf-next v2 1/3] arm64: perf: Don't report the caller twice in caller-regs callchains Andrii Nakryiko
2026-11-19  0:22   ` sashiko-bot
2026-11-19  1:38   ` Alexei Starovoitov [this message]
2026-11-19  4:45     ` Andrii Nakryiko
2026-11-19  0:01 ` [PATCH bpf-next v2 2/3] selftests/bpf: Add stacktrace_ips test for tracepoint Andrii Nakryiko
2026-11-19  0:07   ` sashiko-bot
2026-11-19  0:01 ` [PATCH bpf-next v2 3/3] selftests/bpf: Run stacktrace_ips raw_tp, tp and fentry tests on arm64 Andrii Nakryiko
2026-11-19  0:05   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DMYSXNCMOF26.38XGLPOW4K29X@gmail.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=jolsa@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.