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.
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():The function subsequently executes
fsd/fswinstructions to savef0-f31.In contrast,
sbi_fp_restore()correctly uses:Expected behavior
Before accessing the floating-point registers,
sbi_fp_save()should enable floating-point state throughmstatus.FS.Actual behavior
sbi_fp_save()setsmstatus.VS, which controls vector state rather than floating-point state.If
mstatus.FSis Off whensbi_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
This also makes the save path consistent with
sbi_fp_restore(), which already usesMSTATUS_FS.