From: Alexandre Ghiti <alex@ghiti.fr>
To: "Clément Léger" <cleger@rivosinc.com>,
"Paul Walmsley" <paul.walmsley@sifive.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"open list:RISC-V ARCHITECTURE" <linux-riscv@lists.infradead.org>,
"open list" <linux-kernel@vger.kernel.org>
Cc: Anton Blanchard <antonb@tenstorrent.com>
Subject: Re: [PATCH] riscv: stacktrace: fix backtracing through exceptions
Date: Mon, 6 Jan 2025 12:15:21 +0100 [thread overview]
Message-ID: <8264591a-68ad-4d11-ab78-2ebd73c8cb02@ghiti.fr> (raw)
In-Reply-To: <20241209155714.1239665-1-cleger@rivosinc.com>
Hi Clément,
On 09/12/2024 16:57, Clément Léger wrote:
> Prior to commit 5d5fc33ce58e ("riscv: Improve exception and system call
> latency"), backtrace through exception worked since ra was filled with
> ret_from_exception symbol address and the stacktrace code checked 'pc' to
> be equal to that symbol. Now that handle_exception uses regular 'call'
> instructions, this isn't working anymore and backtrace stops at
> handle_exception(). Since there are multiple call site to C code in the
> exception handling path, rather than checking multiple potential return
> addresses, add a new symbol at the end of exception handling and check pc
> to be in that range.
>
> Fixes: 5d5fc33ce58e ("riscv: Improve exception and system call latency")
> Signed-off-by: Clément Léger <cleger@rivosinc.com>
>
> ---
> arch/riscv/kernel/entry.S | 1 +
> arch/riscv/kernel/stacktrace.c | 4 +++-
> 2 files changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
> index 216581835eb0..33a5a9f2a0d4 100644
> --- a/arch/riscv/kernel/entry.S
> +++ b/arch/riscv/kernel/entry.S
> @@ -278,6 +278,7 @@ SYM_CODE_START_NOALIGN(ret_from_exception)
> #else
> sret
> #endif
> +SYM_INNER_LABEL(ret_from_exception_end, SYM_L_GLOBAL)
> SYM_CODE_END(ret_from_exception)
> ASM_NOKPROBE(ret_from_exception)
>
> diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c
> index 153a2db4c5fa..d4355c770c36 100644
> --- a/arch/riscv/kernel/stacktrace.c
> +++ b/arch/riscv/kernel/stacktrace.c
> @@ -17,6 +17,7 @@
> #ifdef CONFIG_FRAME_POINTER
>
> extern asmlinkage void handle_exception(void);
> +extern unsigned long ret_from_exception_end;
>
> static inline int fp_is_valid(unsigned long fp, unsigned long sp)
> {
> @@ -71,7 +72,8 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
> fp = frame->fp;
> pc = ftrace_graph_ret_addr(current, &graph_idx, frame->ra,
> &frame->ra);
> - if (pc == (unsigned long)handle_exception) {
> + if (pc >= (unsigned long)handle_exception &&
> + pc < (unsigned long)&ret_from_exception_end) {
> if (unlikely(!__kernel_text_address(pc) || !fn(arg, pc)))
> break;
>
You can add:
Tested-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Thanks,
Alex
next prev parent reply other threads:[~2025-01-06 11:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-09 15:57 Clément Léger
2025-01-06 11:15 ` Alexandre Ghiti [this message]
2025-01-09 16:16 ` patchwork-bot+linux-riscv
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=8264591a-68ad-4d11-ab78-2ebd73c8cb02@ghiti.fr \
--to=alex@ghiti.fr \
--cc=antonb@tenstorrent.com \
--cc=cleger@rivosinc.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®