Skip to content

Add eager FP and RISC-V vector context switching support

[email protected] opensbi 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4lib: sbi: domain: ensure boot_hartid is assignedlib/sbi/sbi_domain.c+24 -00 replies
2/4lib: sbi: Add RISC-V vector context save/restore support (eager switching)include/sbi/sbi_vector.h lib/sbi/objects.mk lib/sbi/sbi_vector.c+167 -00 replies
3/4lib: sbi: Add floating-point context save/restore support.include/sbi/sbi_fp.h lib/sbi/objects.mk lib/sbi/sbi_fp.c+140 -00 replies
4/4include: sbi: scratch: Add per-hart FP and vector context pointers in scratchinclude/sbi/sbi_scratch.h+5 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH v1 0/4] Add eager FP and RISC-V vector context switching support

Hi,

This patch series adds support for eager floating-point and RISC-V vector context save/restore in OpenSBI.

The goal is to ensure that machine-mode trap handling preserves the full architectural state of lower privilege software (e.g., S-mode), providing correct isolation across trap boundaries.

### Overview

This series introduces:

* Per-hart FP and vector context pointers in sbi_scratch
* FP context save/restore implementation
* RISC-V vector context save/restore implementation
* Integration into the OpenSBI trap handler

### Design

The implementation follows an eager context switching model:

* FP and vector state is saved on every trap entry
* FP and vector state is restored before returning from traps

This ensures correctness and avoids the need for lazy switching or trap-on-first-use mechanisms.

### Context Storage

* FP context:

* f0–f31 registers
* fcsr

* Vector context:

* v0–v31 registers
* vl, vtype, vcsr

Stored per-hart via sbi_scratch.

### Notes / Assumptions

* Assumes FP and vector units are enabled when used (mstatus.FS/VS)
* Assumes RV64 for floating-point implementation (fsd/fld)
* Vector maximum size is bounded by SBI_MAX_VLENB
* Context pointers must be initialized before use

### Performance

This approach introduces additional overhead on every trap due to full state save and restore, especially for vector state, but provides a simple and deterministic model.

### Patch Breakdown

* Patch 1: Add FP context save/restore support
* Patch 2: Add vector context save/restore support
* Patch 3: Extend sbi_scratch with FP/vector context pointers
* Patch 4: Integrate into trap handler

Feedback is welcome, especially regarding:

* CSR restore ordering (vtype/vl/vcsr)
* Trap performance implications

Thanks,
Dave Patel

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi