From: Eric Biggers <ebiggers@kernel.org>
To: Vivian Wang <wangruikang@iscas.ac.cn>
Cc: Jerry Shih <jerry.shih@sifive.com>,
"Jason A. Donenfeld" <Jason@zx2c4.com>,
Ard Biesheuvel <ardb@kernel.org>, Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
linux-crypto@vger.kernel.org, linux-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lib/crypto: riscv/chacha: Maintain a frame pointer
Date: Sun, 30 Nov 2025 10:29:14 -0800 [thread overview]
Message-ID: <20251130182914.GA1395@sol> (raw)
In-Reply-To: <20251130-riscv-chacha_zvkb-fp-v1-1-68ef7a6d477a@iscas.ac.cn>
On Sun, Nov 30, 2025 at 06:23:50PM +0800, Vivian Wang wrote:
> crypto_zvkb doesn't maintain a frame pointer and also uses s0, which
> means that if it crashes we don't get a stack trace. Modify prologue and
> epilogue to maintain a frame pointer as -fno-omit-frame-pointer would.
> Also reallocate registers to match.
>
> Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
> ---
> Found while diagnosing a crypto_zvkb "load address misaligned" crash [1]
>
> [1]: https://lore.kernel.org/r/b3cfcdac-0337-4db0-a611-258f2868855f@iscas.ac.cn/
> ---
> lib/crypto/riscv/chacha-riscv64-zvkb.S | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
Do I understand correctly that the problem isn't so much that
crypto_zvkb() doesn't set up its own frame pointer, but rather it reuses
the frame pointer register (s0 i.e. fp) for other data?
That's what we've seen on other architectures, like x86_64 with %rbp.
Assembly functions need to set their own frame pointer only if they call
other functions. Otherwise, they can just run with their parent's frame
pointer. However, in either case, they must not store other data in the
frame pointer register.
Is that the case on RISC-V too? If so, the appropriate fix is to just
stop using s0 for other data; we don't actually need to set up a frame
pointer. (Note that none of the RISC-V crypto assembly code sets up
frame pointers. So if that was an issue, it would affect every file.)
- Eric
WARNING: multiple messages have this Message-ID (diff)
From: Eric Biggers <ebiggers@kernel.org>
To: Vivian Wang <wangruikang@iscas.ac.cn>
Cc: Jerry Shih <jerry.shih@sifive.com>,
"Jason A. Donenfeld" <Jason@zx2c4.com>,
Ard Biesheuvel <ardb@kernel.org>, Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
linux-crypto@vger.kernel.org, linux-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lib/crypto: riscv/chacha: Maintain a frame pointer
Date: Sun, 30 Nov 2025 10:29:14 -0800 [thread overview]
Message-ID: <20251130182914.GA1395@sol> (raw)
In-Reply-To: <20251130-riscv-chacha_zvkb-fp-v1-1-68ef7a6d477a@iscas.ac.cn>
On Sun, Nov 30, 2025 at 06:23:50PM +0800, Vivian Wang wrote:
> crypto_zvkb doesn't maintain a frame pointer and also uses s0, which
> means that if it crashes we don't get a stack trace. Modify prologue and
> epilogue to maintain a frame pointer as -fno-omit-frame-pointer would.
> Also reallocate registers to match.
>
> Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
> ---
> Found while diagnosing a crypto_zvkb "load address misaligned" crash [1]
>
> [1]: https://lore.kernel.org/r/b3cfcdac-0337-4db0-a611-258f2868855f@iscas.ac.cn/
> ---
> lib/crypto/riscv/chacha-riscv64-zvkb.S | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
Do I understand correctly that the problem isn't so much that
crypto_zvkb() doesn't set up its own frame pointer, but rather it reuses
the frame pointer register (s0 i.e. fp) for other data?
That's what we've seen on other architectures, like x86_64 with %rbp.
Assembly functions need to set their own frame pointer only if they call
other functions. Otherwise, they can just run with their parent's frame
pointer. However, in either case, they must not store other data in the
frame pointer register.
Is that the case on RISC-V too? If so, the appropriate fix is to just
stop using s0 for other data; we don't actually need to set up a frame
pointer. (Note that none of the RISC-V crypto assembly code sets up
frame pointers. So if that was an issue, it would affect every file.)
- Eric
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2025-11-30 18:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-30 10:23 [PATCH] lib/crypto: riscv/chacha: Maintain a frame pointer Vivian Wang
2025-11-30 10:23 ` Vivian Wang
2025-11-30 18:29 ` Eric Biggers [this message]
2025-11-30 18:29 ` Eric Biggers
2025-12-01 1:50 ` Vivian Wang
2025-12-01 1:50 ` Vivian Wang
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=20251130182914.GA1395@sol \
--to=ebiggers@kernel.org \
--cc=Jason@zx2c4.com \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=ardb@kernel.org \
--cc=jerry.shih@sifive.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=wangruikang@iscas.ac.cn \
/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.