mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paul Walmsley <pjw@kernel.org>
To: Rui Qi <qirui.001@bytedance.com>
Cc: Paul Walmsley <pjw@kernel.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	 Albert Ou <aou@eecs.berkeley.edu>,
	Alexandre Ghiti <alex@ghiti.fr>,
	 linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 1/2] riscv: stacktrace: Remove bogus -0x4 offset in non-FP walk_stackframe
Date: Thu, 4 Jun 2026 17:41:10 -0600 (MDT)	[thread overview]
Message-ID: <f04aa9b7-9118-d9f6-6431-75234dc2a207@kernel.org> (raw)
In-Reply-To: <20260603115329.791603-2-qirui.001@bytedance.com>

On Wed, 3 Jun 2026, Rui Qi wrote:

> In the non-frame-pointer version of walk_stackframe, each value read
> from the stack is treated as a potential return address and has 0x4
> subtracted before being used as the program counter. This was intended
> to convert the return address (the instruction after a call) back to
> the call site, but it is incorrect:
> 
> 1. RISC-V has variable-length instructions due to the RVC (compressed
>    instruction) extension. A call instruction can be either 4 bytes
>    (regular) or 2 bytes (compressed, e.g. c.jal). Subtracting a fixed
>    0x4 assumes all call instructions are 4 bytes, which is wrong for
>    compressed instructions.
> 
> 2. Stack traces conventionally report return addresses, not call sites.
>    Other architectures (ARM64, x86, ARM) do not subtract instruction
>    size from return addresses in their stack unwinding code.
> 
> 3. The frame-pointer version of walk_stackframe already dropped the
>    -0x4 offset. Commit b785ec129bd9 ("riscv/ftrace: Add
>    HAVE_FUNCTION_GRAPH_RET_ADDR_PTR support") replaced "pc =
>    frame->ra - 0x4" with ftrace_graph_ret_addr(), and the commit
>    message explicitly noted that "the original calculation, pc =
>    frame->ra - 4, is buggy when the instruction at the return address
>    happened to be a compressed inst." The non-FP version was simply
>    overlooked.
> 
> Remove the bogus -0x4 offset to match the FP version and the
> conventions used by other architectures.

Thanks for the very clear commit message and for the fix.  Queued for 
v7.1-rc.


- Paul

  reply	other threads:[~2026-06-04 23:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03 11:53 [PATCH v1 0/2] riscv: stacktrace: Fix return address handling in non-FP unwinder Rui Qi
2026-06-03 11:53 ` [PATCH v1 1/2] riscv: stacktrace: Remove bogus -0x4 offset in non-FP walk_stackframe Rui Qi
2026-06-04 23:41   ` Paul Walmsley [this message]
2026-06-03 11:53 ` [PATCH v1 2/2] riscv: stacktrace: Use %pB for backtrace display Rui Qi
2026-06-05  0:33   ` Paul Walmsley
2026-06-05  8:12     ` Rui Qi
2026-06-05  8:20 ` [PATCH v2 0/2] riscv: stacktrace: Fix return address handling in non-FP unwinder Rui Qi
2026-06-05  8:20   ` [PATCH v2 1/2] riscv: stacktrace: Remove bogus -0x4 offset in non-FP walk_stackframe Rui Qi
2026-06-05  8:20   ` [PATCH v2 2/2] riscv: stacktrace: Use %pB for return addresses and %pS for exact IPs Rui Qi
2026-06-07  5:10   ` [PATCH v2 0/2] riscv: stacktrace: Fix return address handling in non-FP unwinder 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=f04aa9b7-9118-d9f6-6431-75234dc2a207@kernel.org \
    --to=pjw@kernel.org \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=qirui.001@bytedance.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®