[PATCH v8 0/3] Add eager FP and Vector context switching support

Dave Patel dave.patel at riscstar.com
Mon May 18 01:40:08 PDT 2026


On 5/18/26 09:33, Anup Patel wrote:
> On Mon, May 18, 2026 at 2:00 PM Anup Patel <anup.patel at oss.qualcomm.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 since v7:
>> - Rebased on latest OpenSBI master
>> - Addressed all my comments on v7 series
>>
>> 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         |  35 +++++++
>>  include/sbi/sbi_hart.h       |   6 ++
>>  include/sbi/sbi_vector.h     |  40 ++++++++
>>  lib/sbi/objects.mk           |   2 +
>>  lib/sbi/sbi_domain_context.c |  33 ++++++
>>  lib/sbi/sbi_fp.c             | 192 +++++++++++++++++++++++++++++++++++
>>  lib/sbi/sbi_hart.c           |   3 +
>>  lib/sbi/sbi_vector.c         |  94 +++++++++++++++++
>>  8 files changed, 405 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
>>
> 
> Applied this series to the riscv/opensbi repo.
> 
> Regards,
> Anup

Many thanks Anup!

Kind Regards,
Dave



More information about the opensbi mailing list