* [PATCH] riscv: misaligned: Make enabling delegation depend on BROKEN
@ 2026-03-30 6:47 Vivian Wang
2026-03-30 12:59 ` Conor Dooley
0 siblings, 1 reply; 3+ messages in thread
From: Vivian Wang @ 2026-03-30 6:47 UTC (permalink / raw)
To: Clément Léger, Paul Walmsley, Palmer Dabbelt, Alexandre Ghiti
Cc: linux-riscv, linux-kernel, stable, Songsong Zhang, Vivian Wang
The unaligned access emulation code in Linux has various deficiencies.
For example, it doesn't emulate vector instructions [1], and doesn't
emulate KVM guest accesses. Therefore, requesting misaligned exception
delegation with SBI FWFT actually regresses userspace and KVM guest
behavior. Until Linux can handle it properly, guard these sbi_fwft_set()
calls behind RISCV_SBI_FWFT_DELEGATE_MISALIGNED, which in turn depends
on BROKEN.
The rest of the existing code proceeds as before, except as if
SBI_FWFT_MISALIGNED_EXC_DELEG is not available, to handle any remaining
address misaligned exceptions on a best-effort basis. The KVM SBI FWFT
implementation is also not touched, but it is disabled if the firmware
emulates unaligned accesses.
Cc: stable@vger.kernel.org
Fixes: cf5a8abc6560 ("riscv: misaligned: request misaligned exception from SBI")
Reported-by: Songsong Zhang <U2FsdGVkX1@gmail.com> # KVM
Link: https://lore.kernel.org/linux-riscv/38ce44c1-08cf-4e3f-8ade-20da224f529c@iscas.ac.cn/ [1]
Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
---
Clément: Sorry to call what you did broken, but it really is breaking
on real hardware out there. I think this is the right way for now.
---
arch/riscv/Kconfig | 14 ++++++++++++++
arch/riscv/kernel/traps_misaligned.c | 2 +-
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 90c531e6abf5..8ad1f13c170e 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -941,6 +941,20 @@ config RISCV_VECTOR_MISALIGNED
help
Enable detecting support for vector misaligned loads and stores.
+config RISCV_SBI_FWFT_DELEGATE_MISALIGNED
+ bool "Request firmware delegation of unaligned access exceptions"
+ depends on RISCV_SBI
+ depends on BROKEN
+ help
+ Use SBI FWFT to request delegation of load address misaligned and
+ store address misaligned exceptions, if possible, and prefer Linux
+ kernel emulation of these accesses to firmware emulation.
+
+ Since the Linux kernel's emulation is incomplete, enabling this may
+ cause unexpected userspace and KVM guest crashes.
+
+ If you don't know what to do here, say N.
+
choice
prompt "Unaligned Accesses Support"
default RISCV_PROBE_UNALIGNED_ACCESS
diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/traps_misaligned.c
index 2a27d3ff4ac6..81b7682e6c6d 100644
--- a/arch/riscv/kernel/traps_misaligned.c
+++ b/arch/riscv/kernel/traps_misaligned.c
@@ -584,7 +584,7 @@ static int cpu_online_check_unaligned_access_emulated(unsigned int cpu)
static bool misaligned_traps_delegated;
-#ifdef CONFIG_RISCV_SBI
+#if defined(CONFIG_RISCV_SBI_FWFT_DELEGATE_MISALIGNED)
static int cpu_online_sbi_unaligned_setup(unsigned int cpu)
{
---
base-commit: f338e77383789c0cae23ca3d48adcc5e9e137e3c
change-id: 20260330-riscv-misaligned-dont-delegate-3cf98c76ee08
Best regards,
--
Vivian "dramforever" Wang
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] riscv: misaligned: Make enabling delegation depend on BROKEN
2026-03-30 6:47 [PATCH] riscv: misaligned: Make enabling delegation depend on BROKEN Vivian Wang
@ 2026-03-30 12:59 ` Conor Dooley
2026-03-31 3:19 ` Vivian Wang
0 siblings, 1 reply; 3+ messages in thread
From: Conor Dooley @ 2026-03-30 12:59 UTC (permalink / raw)
To: Vivian Wang
Cc: Clément Léger, Paul Walmsley, Palmer Dabbelt,
Alexandre Ghiti, linux-riscv, linux-kernel, stable,
Songsong Zhang
[-- Attachment #1: Type: text/plain, Size: 3656 bytes --]
On Mon, Mar 30, 2026 at 02:47:15PM +0800, Vivian Wang wrote:
> The unaligned access emulation code in Linux has various deficiencies.
> For example, it doesn't emulate vector instructions [1], and doesn't
> emulate KVM guest accesses. Therefore, requesting misaligned exception
> delegation with SBI FWFT actually regresses userspace and KVM guest
> behavior. Until Linux can handle it properly, guard these sbi_fwft_set()
> calls behind RISCV_SBI_FWFT_DELEGATE_MISALIGNED, which in turn depends
> on BROKEN.
>
> The rest of the existing code proceeds as before, except as if
> SBI_FWFT_MISALIGNED_EXC_DELEG is not available, to handle any remaining
> address misaligned exceptions on a best-effort basis. The KVM SBI FWFT
> implementation is also not touched, but it is disabled if the firmware
> emulates unaligned accesses.
>
> Cc: stable@vger.kernel.org
> Fixes: cf5a8abc6560 ("riscv: misaligned: request misaligned exception from SBI")
> Reported-by: Songsong Zhang <U2FsdGVkX1@gmail.com> # KVM
> Link: https://lore.kernel.org/linux-riscv/38ce44c1-08cf-4e3f-8ade-20da224f529c@iscas.ac.cn/ [1]
> Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
> ---
> Clément: Sorry to call what you did broken, but it really is breaking
> on real hardware out there. I think this is the right way for now.
> ---
> arch/riscv/Kconfig | 14 ++++++++++++++
> arch/riscv/kernel/traps_misaligned.c | 2 +-
> 2 files changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index 90c531e6abf5..8ad1f13c170e 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -941,6 +941,20 @@ config RISCV_VECTOR_MISALIGNED
> help
> Enable detecting support for vector misaligned loads and stores.
>
> +config RISCV_SBI_FWFT_DELEGATE_MISALIGNED
> + bool "Request firmware delegation of unaligned access exceptions"
> + depends on RISCV_SBI
> + depends on BROKEN
Making it hard to enable I think makes a lot of sense, given the issues
you're reporting but I tacking on BROKEN will remove effectively all
build coverage of it* and will definitely stop almost anyone using it.
Should it be just made NONPORTABLE with the text about being incomplete
expanded a wee bit to say what is broken so that people can make a
decision?
Cheers,
Conor.
*it's like 10 lines, probably an irrelevant concern.
> + help
> + Use SBI FWFT to request delegation of load address misaligned and
> + store address misaligned exceptions, if possible, and prefer Linux
> + kernel emulation of these accesses to firmware emulation.
> +
> + Since the Linux kernel's emulation is incomplete, enabling this may
> + cause unexpected userspace and KVM guest crashes.
> +
> + If you don't know what to do here, say N.
> +
> choice
> prompt "Unaligned Accesses Support"
> default RISCV_PROBE_UNALIGNED_ACCESS
> diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/traps_misaligned.c
> index 2a27d3ff4ac6..81b7682e6c6d 100644
> --- a/arch/riscv/kernel/traps_misaligned.c
> +++ b/arch/riscv/kernel/traps_misaligned.c
> @@ -584,7 +584,7 @@ static int cpu_online_check_unaligned_access_emulated(unsigned int cpu)
>
> static bool misaligned_traps_delegated;
>
> -#ifdef CONFIG_RISCV_SBI
> +#if defined(CONFIG_RISCV_SBI_FWFT_DELEGATE_MISALIGNED)
>
> static int cpu_online_sbi_unaligned_setup(unsigned int cpu)
> {
>
> ---
> base-commit: f338e77383789c0cae23ca3d48adcc5e9e137e3c
> change-id: 20260330-riscv-misaligned-dont-delegate-3cf98c76ee08
>
> Best regards,
> --
> Vivian "dramforever" Wang
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] riscv: misaligned: Make enabling delegation depend on BROKEN
2026-03-30 12:59 ` Conor Dooley
@ 2026-03-31 3:19 ` Vivian Wang
0 siblings, 0 replies; 3+ messages in thread
From: Vivian Wang @ 2026-03-31 3:19 UTC (permalink / raw)
To: Conor Dooley
Cc: Clément Léger, Paul Walmsley, Palmer Dabbelt,
Alexandre Ghiti, linux-riscv, linux-kernel, stable,
Songsong Zhang
On 3/30/26 20:59, Conor Dooley wrote:
> On Mon, Mar 30, 2026 at 02:47:15PM +0800, Vivian Wang wrote:
>> The unaligned access emulation code in Linux has various deficiencies.
>> For example, it doesn't emulate vector instructions [1], and doesn't
>> emulate KVM guest accesses. Therefore, requesting misaligned exception
>> delegation with SBI FWFT actually regresses userspace and KVM guest
>> behavior. Until Linux can handle it properly, guard these sbi_fwft_set()
>> calls behind RISCV_SBI_FWFT_DELEGATE_MISALIGNED, which in turn depends
>> on BROKEN.
>>
>> The rest of the existing code proceeds as before, except as if
>> SBI_FWFT_MISALIGNED_EXC_DELEG is not available, to handle any remaining
>> address misaligned exceptions on a best-effort basis. The KVM SBI FWFT
>> implementation is also not touched, but it is disabled if the firmware
>> emulates unaligned accesses.
>>
>> Cc: stable@vger.kernel.org
>> Fixes: cf5a8abc6560 ("riscv: misaligned: request misaligned exception from SBI")
>> Reported-by: Songsong Zhang <U2FsdGVkX1@gmail.com> # KVM
>> Link: https://lore.kernel.org/linux-riscv/38ce44c1-08cf-4e3f-8ade-20da224f529c@iscas.ac.cn/ [1]
>> Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
>> ---
>> Clément: Sorry to call what you did broken, but it really is breaking
>> on real hardware out there. I think this is the right way for now.
>> ---
>> arch/riscv/Kconfig | 14 ++++++++++++++
>> arch/riscv/kernel/traps_misaligned.c | 2 +-
>> 2 files changed, 15 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
>> index 90c531e6abf5..8ad1f13c170e 100644
>> --- a/arch/riscv/Kconfig
>> +++ b/arch/riscv/Kconfig
>> @@ -941,6 +941,20 @@ config RISCV_VECTOR_MISALIGNED
>> help
>> Enable detecting support for vector misaligned loads and stores.
>>
>> +config RISCV_SBI_FWFT_DELEGATE_MISALIGNED
>> + bool "Request firmware delegation of unaligned access exceptions"
>> + depends on RISCV_SBI
>> + depends on BROKEN
> Making it hard to enable I think makes a lot of sense, given the issues
> you're reporting but I tacking on BROKEN will remove effectively all
> build coverage of it* and will definitely stop almost anyone using it.
> Should it be just made NONPORTABLE with the text about being incomplete
> expanded a wee bit to say what is broken so that people can make a
> decision?
Having thought about it more, I think NONPORTABLE does make sense. There
is still a noticible amount of older non-H and non-RVV hardware out
there that remain quite popular, and on these machines this will work
fine, any further bugs notwithstanding.
I'll change it to NONPORTABLE in v2, and, as you said, expand on known
issues.
Thanks,
Vivian "dramforever" Wang
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-31 3:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-30 6:47 [PATCH] riscv: misaligned: Make enabling delegation depend on BROKEN Vivian Wang
2026-03-30 12:59 ` Conor Dooley
2026-03-31 3:19 ` Vivian Wang
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®