The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Michael Ellerman <mpe@kernel.org>
To: Vivian Wang <wangruikang@iscas.ac.cn>,
	Anirudh Srinivasan <asrinivasan@oss.tenstorrent.com>,
	Paul Walmsley <pjw@kernel.org>
Cc: "Clément Léger" <cleger@rivosinc.com>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Alexandre Ghiti" <alex@ghiti.fr>,
	"Andrew Jones" <ajones@ventanamicro.com>,
	"Conor Dooley" <conor@kernel.org>,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, "Songsong Zhang" <U2FsdGVkX1@gmail.com>,
	"Drew Fustini" <fustini@kernel.org>
Subject: Re: [PATCH v2] riscv: misaligned: Make enabling delegation depend on NONPORTABLE
Date: Thu, 21 May 2026 21:49:32 +1000	[thread overview]
Message-ID: <a2a5621f-4be1-4e39-8434-9a6009c8f762@kernel.org> (raw)
In-Reply-To: <cec3dd9c-37d8-4859-bfe0-a42ee3efdc97@iscas.ac.cn>

On 21/5/2026 10:27, Vivian Wang wrote:
> 
> On 5/20/26 23:47, Anirudh Srinivasan wrote:
>> Hi Vivian, Paul
>>
>> On Wed, Apr 01, 2026 at 09:53:17AM +0800, Vivian Wang wrote:
>>> The unaligned access emulation code in Linux has various deficiencies.
>>> For example, it doesn't emulate vector instructions [1] [2], and doesn't
>>> emulate KVM guest accesses. Therefore, requesting misaligned exception
>>> delegation with SBI FWFT actually regresses vector instructions' and KVM
>>> guests' behavior.
>>>
>>> Until Linux can handle it properly, guard these sbi_fwft_set() calls
>>> behind RISCV_SBI_FWFT_DELEGATE_MISALIGNED, which in turn depends on
>>> NONPORTABLE. Those who are sure that this wouldn't be a problem can
>>> enable this option, perhaps getting better performance.
>>>
>>> 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.
>> On a Tenstorrent Blackhole with SiFive x280 cores, with OpenSBI 1.7 and
>> defconfig kernel, I'm seeing a bunch of hangs/opensbi prints at boot time.
>> Without this patch, the boot prints this and continues on.
>>
>> [    0.226339] SBI misaligned access exception delegation ok
> 
> Your OpenSBI looks very broken (more on what I mean later), and in a way
> that might only manifest if it's trying to emulate vector misaligned
> instructions? An interesting thing I can think of is maybe your SiFive
> x280 has a very long VLEN (512? 1024? I forgot) which may have exposed
> some stuff...

It's 512.

> I have two ideas:
> 
> Firstly, try bumping this in include/sbi/sbi_platform.h up to 65536 or
> something like that. If that works you can also start trying to lower it
> to 16384 or something similar.
> 
> #define SBI_PLATFORM_DEFAULT_HART_STACK_SIZE    8192

Yep, bumping that to 16384 fixes it for me.

The culprit is in lib/sbi/sbi_trap_v_ldst.c:

#define VLEN_MAX 65536
...

int sbi_misaligned_v_ld_emulator(int rlen, union sbi_ldst_data *out_val,
                                  struct sbi_trap_context *tcntx)
{
         const struct sbi_trap_info *orig_trap = &tcntx->trap;
...
         uint8_t mask[VLEN_MAX / 8];


ie. 8KB on stack buffer.

Shrinking VLEN_MAX to 4096 also gets it booting. But I guess that's not 
viable because in theory someone might build a chip with VLEN 65536 one day?

Would a heap allocation at boot be better?

Or just force the stack to be bigger when vector is enabled, eg:

diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h
index fe382b56..52ed48af 100644
--- a/include/sbi/sbi_platform.h
+++ b/include/sbi/sbi_platform.h
@@ -160,7 +160,11 @@ struct sbi_platform_operations {
  };

  /** Platform default per-HART stack size for exception/interrupt 
handling */
+#ifdef OPENSBI_CC_SUPPORT_VECTOR
+#define SBI_PLATFORM_DEFAULT_HART_STACK_SIZE   16384
+#else
  #define SBI_PLATFORM_DEFAULT_HART_STACK_SIZE   8192
+#endif

  /** Platform default heap size */
  #define SBI_PLATFORM_DEFAULT_HEAP_SIZE(__num_hart)     \

cheers


  reply	other threads:[~2026-05-21 11:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-01  1:53 [PATCH v2] riscv: misaligned: Make enabling delegation depend on NONPORTABLE Vivian Wang
2026-04-01  8:57 ` Conor Dooley
2026-05-14  4:30 ` Paul Walmsley
2026-05-20 15:47 ` Anirudh Srinivasan
2026-05-21  0:27   ` Vivian Wang
2026-05-21 11:49     ` Michael Ellerman [this message]
2026-05-21 12:18       ` 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=a2a5621f-4be1-4e39-8434-9a6009c8f762@kernel.org \
    --to=mpe@kernel.org \
    --cc=U2FsdGVkX1@gmail.com \
    --cc=ajones@ventanamicro.com \
    --cc=alex@ghiti.fr \
    --cc=asrinivasan@oss.tenstorrent.com \
    --cc=cleger@rivosinc.com \
    --cc=conor@kernel.org \
    --cc=fustini@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=stable@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox