[PATCH] lib: sbi: Preserve vl and vtype during domain switches
Anup Patel
anup at brainfault.org
Thu Oct 22 23:10:17 PDT 2026
On Fri, Oct 23, 2026 at 5:11 AM whensun
<theodoruswensanfebruanto025 at gmail.com> wrote:
>
> Save vl and vtype as part of the Vector domain context.
>
> Restore both CSRs using vsetvl after restoring the Vector register
> file. Restore vstart after vsetvl because Vector configuration
> instructions reset vstart.
>
> Link: https://github.com/riscv-software-src/opensbi/issues/434
> Signed-off-by: whensun <theodoruswensanfebruanto025 at gmail.com>
Expand your other series "Preserve more S/HS architectural state
across domain switches" to include this patch as well.
Better to call that series "Preserve more architectural state across
domain switches".
> ---
> include/sbi/sbi_vector.h | 2 ++
> lib/sbi/sbi_vector.c | 11 +++++++++++
> 2 files changed, 13 insertions(+)
>
> diff --git a/include/sbi/sbi_vector.h b/include/sbi/sbi_vector.h
> index c14f3174..480f9ac3 100644
> --- a/include/sbi/sbi_vector.h
> +++ b/include/sbi/sbi_vector.h
> @@ -15,6 +15,8 @@
> struct sbi_vector_context {
> unsigned long vcsr;
> unsigned long vstart;
> + unsigned long vl;
> + unsigned long vtype;
>
> /* size depends on VLEN */
> uint8_t vregs[];
> diff --git a/lib/sbi/sbi_vector.c b/lib/sbi/sbi_vector.c
> index 1f9e01cf..53c2e5a7 100644
> --- a/lib/sbi/sbi_vector.c
> +++ b/lib/sbi/sbi_vector.c
> @@ -33,6 +33,8 @@ void sbi_vector_save(struct sbi_vector_context *dst)
> /* Step 2: Save CSRs */
> dst->vcsr = csr_read(vcsr);
> dst->vstart = csr_read(vstart);
> + dst->vl = csr_read(vl);
> + dst->vtype = csr_read(vtype);
>
> /* Step 3: Save vector registers */
> #define SAVE_VREG(i) \
> @@ -86,6 +88,15 @@ void sbi_vector_restore(const struct sbi_vector_context *src)
>
> /* Step 3: Restore CSR's last */
> /* Restore CSRs first */
> + asm volatile(
> + ".option push\n\t"
> + ".option arch, +v\n\t"
> + "vsetvl zero, %0, %1\n\t"
> + ".option pop\n\t"
> + :
> + : "r"(src->vl), "r"(src->vtype)
> + : "memory");
> +
> csr_write(vcsr, src->vcsr);
> csr_write(vstart, src->vstart);
>
> --
> 2.43.0
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
Regards,
Anup
More information about the opensbi
mailing list