From: Clement Leger <clement.leger@linux.dev>
To: Zihui Guo <youzih27@gmail.com>, Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexandre Ghiti <alex@ghiti.fr>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] riscv: misaligned: Do not decode cm.push as c.fsdsp without Zcd
Date: Thu, 3 Dec 2026 19:39:06 +0100 [thread overview]
Message-ID: <8e9e1b6e-239d-43f4-a6dd-8834acc60788@linux.dev> (raw)
In-Reply-To: <20261203053317.24927-1-youzih27@gmail.com>
On 12/3/26 06:33, Zihui Guo wrote:
> The misaligned store emulation decodes the c.fsdsp encoding without
> checking for Zcd. Zcmp and Zcmt reuse that encoding for cm.push,
> cm.pop, cm.popret, cm.popretz, cm.mvsa01, cm.mva01s, cm.jt and
> cm.jalt, and both extensions are incompatible with Zcd. On a hart
> with Zcmp, a cm.push with a misaligned sp traps and is emulated as
> c.fsdsp: eight bytes of a floating-point register are stored instead
> of the register list, sp is not adjusted, and the task continues with
> the wrong stack contents.
>
> Only accept the c.fsdsp encoding when Zcd is present. Otherwise the
> store is not emulated and the task gets SIGBUS, as for any other store
> the emulator does not handle.
>
> Fixes: 7c586a555a48 ("riscv: add floating point insn support to misaligned access emulation")
> Signed-off-by: Zihui Guo <youzih27@gmail.com>
> ---
> Tested on Spike (rv64imafd_zicsr_zifencei_zicntr_zihpm_zca_zcmp, no C
> or Zcd) with OpenSBI master, and Linux built with RISCV_ISA_C=n and
> RISCV_SBI_FWFT_DELEGATE_MISALIGNED=y, so that misaligned stores are
> emulated by the kernel ("SBI misaligned access exception delegation
> ok"). A user process executes cm.push {ra}, -16 (0xb842) with
> sp = 4 mod 8.
>
> Before: the store is emulated as c.fsdsp. sp is unchanged, the value of
> f16 is written at sp-8, and the process continues without a signal.
> After: the process gets SIGBUS (BUS_ADRALN).
> With an aligned sp, cm.push behaves correctly on both kernels.
>
> Not tested on hardware; the test program is available on request.
Hi Zihui,
Could you add the reproducer as a selftest if possible ?
>
> Assisted-by: Claude:claude-opus-5-5
I think the consensus is that this line can now be omitted.
>
> arch/riscv/kernel/traps_misaligned.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/traps_misaligned.c
> index 6e8ae6c66322..4e5d1d09a71e 100644
> --- a/arch/riscv/kernel/traps_misaligned.c
> +++ b/arch/riscv/kernel/traps_misaligned.c
> @@ -387,7 +387,9 @@ static int handle_scalar_misaligned_store(struct pt_regs *regs)
> fp = 1;
> len = 8;
> val.data_u64 = GET_F64_RS2S(insn, regs);
> - } else if ((insn & INSN_MASK_C_FSDSP) == INSN_MATCH_C_FSDSP) {
> + } else if ((insn & INSN_MASK_C_FSDSP) == INSN_MATCH_C_FSDSP &&
> + riscv_has_extension_unlikely(RISCV_ISA_EXT_ZCD)) {
> + /* Without Zcd, this encoding is cm.push, cm.jt and the like */
I wouldn't bother with the comment.
Otherwise, looks good to me (with a test added in selftests).
Thanks,
Clément
> fp = 1;
> len = 8;
> val.data_u64 = GET_F64_RS2C(insn, regs);
>
> base-commit: 19cc08c1a6a650f8e54c0461ff198be6448f425d
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
WARNING: multiple messages have this Message-ID (diff)
From: Clement Leger <clement.leger@linux.dev>
To: Zihui Guo <youzih27@gmail.com>, Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexandre Ghiti <alex@ghiti.fr>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] riscv: misaligned: Do not decode cm.push as c.fsdsp without Zcd
Date: Thu, 3 Dec 2026 19:39:06 +0100 [thread overview]
Message-ID: <8e9e1b6e-239d-43f4-a6dd-8834acc60788@linux.dev> (raw)
In-Reply-To: <20261203053317.24927-1-youzih27@gmail.com>
On 12/3/26 06:33, Zihui Guo wrote:
> The misaligned store emulation decodes the c.fsdsp encoding without
> checking for Zcd. Zcmp and Zcmt reuse that encoding for cm.push,
> cm.pop, cm.popret, cm.popretz, cm.mvsa01, cm.mva01s, cm.jt and
> cm.jalt, and both extensions are incompatible with Zcd. On a hart
> with Zcmp, a cm.push with a misaligned sp traps and is emulated as
> c.fsdsp: eight bytes of a floating-point register are stored instead
> of the register list, sp is not adjusted, and the task continues with
> the wrong stack contents.
>
> Only accept the c.fsdsp encoding when Zcd is present. Otherwise the
> store is not emulated and the task gets SIGBUS, as for any other store
> the emulator does not handle.
>
> Fixes: 7c586a555a48 ("riscv: add floating point insn support to misaligned access emulation")
> Signed-off-by: Zihui Guo <youzih27@gmail.com>
> ---
> Tested on Spike (rv64imafd_zicsr_zifencei_zicntr_zihpm_zca_zcmp, no C
> or Zcd) with OpenSBI master, and Linux built with RISCV_ISA_C=n and
> RISCV_SBI_FWFT_DELEGATE_MISALIGNED=y, so that misaligned stores are
> emulated by the kernel ("SBI misaligned access exception delegation
> ok"). A user process executes cm.push {ra}, -16 (0xb842) with
> sp = 4 mod 8.
>
> Before: the store is emulated as c.fsdsp. sp is unchanged, the value of
> f16 is written at sp-8, and the process continues without a signal.
> After: the process gets SIGBUS (BUS_ADRALN).
> With an aligned sp, cm.push behaves correctly on both kernels.
>
> Not tested on hardware; the test program is available on request.
Hi Zihui,
Could you add the reproducer as a selftest if possible ?
>
> Assisted-by: Claude:claude-opus-5-5
I think the consensus is that this line can now be omitted.
>
> arch/riscv/kernel/traps_misaligned.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/traps_misaligned.c
> index 6e8ae6c66322..4e5d1d09a71e 100644
> --- a/arch/riscv/kernel/traps_misaligned.c
> +++ b/arch/riscv/kernel/traps_misaligned.c
> @@ -387,7 +387,9 @@ static int handle_scalar_misaligned_store(struct pt_regs *regs)
> fp = 1;
> len = 8;
> val.data_u64 = GET_F64_RS2S(insn, regs);
> - } else if ((insn & INSN_MASK_C_FSDSP) == INSN_MATCH_C_FSDSP) {
> + } else if ((insn & INSN_MASK_C_FSDSP) == INSN_MATCH_C_FSDSP &&
> + riscv_has_extension_unlikely(RISCV_ISA_EXT_ZCD)) {
> + /* Without Zcd, this encoding is cm.push, cm.jt and the like */
I wouldn't bother with the comment.
Otherwise, looks good to me (with a test added in selftests).
Thanks,
Clément
> fp = 1;
> len = 8;
> val.data_u64 = GET_F64_RS2C(insn, regs);
>
> base-commit: 19cc08c1a6a650f8e54c0461ff198be6448f425d
next prev parent reply other threads:[~2026-12-03 18:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 5:33 [PATCH] riscv: misaligned: Do not decode cm.push as c.fsdsp without Zcd Zihui Guo
2026-12-03 5:33 ` Zihui Guo
2026-12-03 18:39 ` Clement Leger [this message]
2026-12-03 18:39 ` Clement Leger
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=8e9e1b6e-239d-43f4-a6dd-8834acc60788@linux.dev \
--to=clement.leger@linux.dev \
--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=pjw@kernel.org \
--cc=youzih27@gmail.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 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.