Skip to content

riscv: keep mstatus.MPP=M after mret on harts without U-mode - #2396

Open
carlosqwqqwq wants to merge 1 commit into
unicorn-engine:masterfrom
carlosqwqqwq:fix/riscv-mret-mpp-no-u
Open

riscv: keep mstatus.MPP=M after mret on harts without U-mode#2396
carlosqwqqwq wants to merge 1 commit into
unicorn-engine:masterfrom
carlosqwqqwq:fix/riscv-mret-mpp-no-u

Conversation

@carlosqwqqwq

@carlosqwqqwq carlosqwqqwq commented Aug 12, 2026

Copy link
Copy Markdown

riscv: keep mstatus.MPP=M after mret on harts without U-mode

Fixes #2391

Problem

helper_mret unconditionally writes mstatus.MPP = PRV_U. On a hart whose MISA does not include U, the least-privileged supported mode is M, so after mret the MPP field must read 3, not 0. The reproducer runs on a locally built no-U model library (default riscv_any with RVU cleared; stock E51/U54 keep U as the control).

Change

qemu/target/riscv/op_helper.c helper_mret writes MSTATUS_MPP = PRV_U unconditionally. The fix selects PRV_U only when riscv_has_ext(env, RVU), otherwise PRV_M, mirroring upstream QEMU's mret implementation. The proposed change is source-only and contains no test-framework or repository-local changes.

Regression scope

The regression must verify the CSR field reads back its legal value after a write of a reserved/illegal value (and that the legal encodings still read back unchanged), and that a U-enabled control model keeps the previous behavior. Existing CSR tests must remain unchanged.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RISC-V: mret sets mstatus.MPP=U on harts without U-mode

1 participant