[PATCH] lib: Fix MSTATUS_FS bit usage in sbi_fp_save()
Huamao Wu
huamao.wu at spacemit.com
Mon Aug 10 20:17:27 PDT 2026
The sbi_fp_save() function incorrectly uses MSTATUS_VS (0x600, Vector
extension state) instead of MSTATUS_FS (0x6000, Floating-Point extension
state) when enabling floating-point instructions before saving FP registers.
This causes an illegal instruction exception when executing the first fsd/fsw
instruction, because the FP unit remains disabled (MSTATUS.FS=0) while the
code attempts to access FP registers.
The bug was introduced in commit 718e1d194f5a ("lib: Add FP context save/restore
support", 2026-05-18) and affects OpenSBI v1.9 and later versions.
Symptom observed on a development platform with dual 40-hart RVA23 CPUs and OP-TEE:
- Domain context switch triggers sbi_fp_save()
- First fsd instruction at PC 0x23ce4 raises illegal instruction trap
- System fails to enter OP-TEE trusted domain
The sbi_fp_restore() function in the same file correctly uses MSTATUS_FS
(line 112), confirming this is a copy-paste error.
Fix: Change MSTATUS_VS to MSTATUS_FS in sbi_fp_save().
Signed-off-by: Huamao Wu <huamao.wu at spacemit.com>
---
lib/sbi/sbi_fp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/sbi/sbi_fp.c b/lib/sbi/sbi_fp.c
index c8941252..38fb7a01 100644
--- a/lib/sbi/sbi_fp.c
+++ b/lib/sbi/sbi_fp.c
@@ -20,7 +20,7 @@ void sbi_fp_save(struct sbi_fp_context *dst)
if (!dst)
return;
- mstatus_orig = csr_read_set(CSR_MSTATUS, MSTATUS_VS);
+ mstatus_orig = csr_read_set(CSR_MSTATUS, MSTATUS_FS);
asm volatile(
#if defined(__riscv_d)
--
2.43.0
This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking.
本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。
More information about the opensbi
mailing list