[PATCH v3 3/3] lib: sbi: domain FP/Vector context support for context switch
Radim Krčmář
radim.krcmar at oss.qualcomm.com
Thu Apr 2 06:54:18 PDT 2026
2026-03-31T06:58:57+01:00, <dave.patel at riscstar.com>:
> From: Dave Patel <dave.patel at riscstar.com>
>
> This patch adds proper support for per-domain floating-point (FP) and
> vector (V) contexts in the domain context switch logic. Each domain
> now maintains its own FP and vector state, which is saved and restored
> during domain switches.
>
> Changes include:
>
> - Added `fp_ctx` and `vec_ctx` members to `struct sbi_domain`.
> - Introduced `sbi_vector_domain_init` for vlen check
> to allocate and free per-domain FP and vector context.
> - Modified `sbi_domain_register()` to initialize FP/Vector context per domain.
> - Updated `switch_to_next_domain_context()` to save/restore FP and vector
> contexts safely:
> - Ensures FS/VS fields in `mstatus` are enabled (set to Initial) only if Off.
> - Restores original FS/VS bits after context switch.
> - Adds NULL checks to handle domains without FP or Vector extensions.
> - Updated domain context deinit to free FP and vector contexts per domain.
> - Added runtime checks for FP and vector extensions where needed.
> - Corrected handling of MSTATUS FS/VS bits to avoid unsafe full-bit writes.
>
> This improves support for multi-domain systems with FP and Vector
> extensions, and prevents corruption of FP/Vector state during domain
> switches.
>
> Signed-off-by: Dave Patel <dave.patel at riscstar.com>
> ---
> diff --git a/include/sbi/sbi_fp.h b/include/sbi/sbi_fp.h
> @@ -8,13 +8,8 @@
> #ifndef __SBI_FP_H__
> #define __SBI_FP_H__
>
> -#include <sbi/riscv_encoding.h>
> #include <sbi/sbi_types.h>
>
> -#if defined(__riscv_f) || defined(__riscv_d)
> -
> -#include <stdint.h>
> -
> struct sbi_fp_context {
> #if __riscv_d
> uint64_t f[32];
> @@ -22,13 +17,7 @@ struct sbi_fp_context {
> uint32_t f[32];
> #endif
> uint32_t fcsr;
> -} __aligned(16);
> -
> -#else /* No FP (e.g., Zve32x) */
> -
> -struct sbi_fp_context { };
> -
> -#endif //defined(__riscv_f) || defined(__riscv_d)
> +};
Similar comment as to [2/3]: these should have been introduced earlier.
(There is a lot of other random artifacts in the patch.)
> diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c
> @@ -143,6 +146,15 @@ static int switch_to_next_domain_context(struct hart_context *ctx,
> + /* Make sure FS and VS is on before context switch */
> + csr_set(CSR_MSTATUS, MSTATUS_FS | MSTATUS_VS);
Where is the ctx->sstatus restored to CSR_SSTATUS?
Thanks.
More information about the opensbi
mailing list