riscv-software-src / riscv-software-src/opensbi
lib: sbi_fp_save enables VS instead of FS before saving floating-point state
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 1.5k
- Forks
- 712
- PR merge metrics
- No merged PRs in 30d
Description
Summary
lib/sbi/sbi_fp.c:sbi_fp_save() enables the Vector state (mstatus.VS) instead of the Floating-Point state (mstatus.FS) before executing floating-point store instructions.
The issue is present in OpenSBI v1.9 and current master.
Affected code
In sbi_fp_save():
mstatus_orig = csr_read_set(CSR_MSTATUS, MSTATUS_VS);
The function subsequently executes fsd/fsw instructions to save f0-f31.
In contrast, sbi_fp_restore() correctly uses:
mstatus_orig = csr_read_set(CSR_MSTATUS, MSTATUS_FS);
Expected behavior
Before accessing the floating-point registers, sbi_fp_save() should enable floating-point state through mstatus.FS.
Actual behavior
sbi_fp_save() sets mstatus.VS, which controls vector state rather than floating-point state.
If mstatus.FS is Off when sbi_fp_save() is called, the subsequent floating-point save instructions cannot execute normally, causing the domain context switch to fail instead of saving the FP context.
Impact
This is a functional/reliability issue in the floating-point domain context-switching support.
A domain switch on a hart with the F or D extension can fail when the outgoing context has mstatus.FS=Off.
Proposed fix
- mstatus_orig = csr_read_set(CSR_MSTATUS, MSTATUS_VS);
+ mstatus_orig = csr_read_set(CSR_MSTATUS, MSTATUS_FS);
This also makes the save path consistent with sbi_fp_restore(), which already uses MSTATUS_FS.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib/sbi/sbi_fp.c at sbi_fp_save() and compare its mstatus handling with sbi_fp_restore(). Done means the save path enables floating-point state through mstatus.FS before executing the f0-f31 save instructions, while preserving the existing restore behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100