[PATCH v7 0/3] Add eager FP and RISC-V vector context switching support

Anup Patel anup at brainfault.org
Mon May 18 01:31:19 PDT 2026


On Mon, May 18, 2026 at 11:12 AM <dave.patel at riscstar.com> wrote:
>
> From: Dave Patel <dave.patel at riscstar.com>
>
> This patch series 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.
>
> Conditionalize FP and Vector save/restore based on extensions, unconditional
> save and restore of floating-point (FP) and Vector registers fails on
> generic platform firmware. This firmware must run on multiple platforms
> that may lack these extensions.
>
> Address this by conditionally executing FP save/restore only if the underlying
> hart supports the F or D extensions. Similarly, perform Vector save/restore
> only if the hart supports the Vector extension.
>
> Changes include:
>
> - Add Vector save and restore functionality
> - Add Floating Point save and restore functioanlity
> - Added `fp_ctx` and `vec_ctx` members to `struct hart_context`.
> - Introduced dynamic vector struct allocation for vlenb in 'struct hart_context'
>   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.
> - Added runtime checks for FP and vector extensions where needed.
> - Added SBI_HART_EXT_F, SBI_HART_EXT_D, SBI_HART_EXT_V to enum
>   sbi_hart_extensions and the sbi_hart_ext[] array. Use sbi_hart_has_extension()
>   to check for these capabilities before performing the context switches
>
> This improves support for multi-domain systems with FP and Vector
> extensions, and prevents corruption of FP/Vector state during domain
> switches.
>
> Dave Patel (3):
>   lib: sbi: Add RISC-V vector context save/restore support
>   lib: sbi: Add floating-point context save/restore support.
>   lib: sbi: domain FP/Vector context support for context switch
>
>  include/sbi/sbi_fp.h         |  26 +++++
>  include/sbi/sbi_hart.h       |   6 +
>  include/sbi/sbi_vector.h     |  28 +++++
>  lib/sbi/objects.mk           |   2 +
>  lib/sbi/sbi_domain_context.c |  36 ++++++
>  lib/sbi/sbi_fp.c             | 207 +++++++++++++++++++++++++++++++++++
>  lib/sbi/sbi_hart.c           |   3 +
>  lib/sbi/sbi_vector.c         | 118 ++++++++++++++++++++
>  8 files changed, 426 insertions(+)
>  create mode 100644 include/sbi/sbi_fp.h
>  create mode 100644 include/sbi/sbi_vector.h
>  create mode 100644 lib/sbi/sbi_fp.c
>  create mode 100644 lib/sbi/sbi_vector.c
>
> --
> 2.43.0
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi

I have send-out v8 to address my own comments.

Regards,
Anup



More information about the opensbi mailing list