[PATCH v3 3/3] lib: sbi: ISA extension emulation (Zvbb).
Vivian Wang
wangruikang at iscas.ac.cn
Thu Jun 25 20:17:25 PDT 2026
Hi Benedikt,
We discovered another subtle problem while testing Zvbb emulation:
On 12/27/25 20:18, Benedikt Freisen wrote:
> Add trap-based emulation code for the ISA extension Zvbb based on RVV 1.0 and Zbb.
>
> Signed-off-by: Benedikt Freisen <b.freisen at gmx.net>
> ---
>
> [...]
>
> diff --git a/lib/sbi/sbi_insn_emu_v.c b/lib/sbi/sbi_insn_emu_v.c
> new file mode 100644
> index 00000000..483b0ee6
> --- /dev/null
> +++ b/lib/sbi/sbi_insn_emu_v.c
>
> [...]
>
> +
> +int sbi_insn_emu_op_v(ulong insn, struct sbi_trap_regs *regs)
> +{
>
>
> [...]
>
> +
> + regs->mepc += 4;
> +
> + return 0;
> +}
> +
sbi_insn_emu_op_v does not set xstatus.VS to dirty, which has a chance
to break context switching and cause vector register state to be broken.
Something like SET_VS_DIRTY from [1] is needed before returning:
#define SET_VS_DIRTY(regs) do { \
if (sbi_regs_from_virt(regs)) \
csr_set(CSR_VSSTATUS, MSTATUS_VS); \
regs->mstatus |= MSTATUS_VS; \
} while(0)
It seems unlikely that upstream OpenSBI would accept these emulation
patches, but I'm reporting this for the sake of anyone potentially
running into this.
Thanks,
Vivian "dramforever" Wang
[1]: https://lore.kernel.org/opensbi/20260609060024.706-5-ganboing@gmail.com/
More information about the opensbi
mailing list