Skip to content

lib: sbi_fp_save enables VS instead of FS before saving floating-point state #424

Description

@whensun

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions