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:devfrom
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:devfrom
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 always writes mstatus.MPP = PRV_U. On a hart whose MISA omits U, M is the least-privileged supported mode, so the post-mret MPP state must remain M.

Change

Update qemu/target/riscv/op_helper.c:helper_mret() to select PRV_U when RVU is present and PRV_M otherwise, matching the supported privilege modes of the hart.

Validation

  • Rebased onto dev and built the RISC-V targets.
  • The full test_riscv suite passes.
  • A targeted public-API reproducer using a U-clear riscv_any configuration leaves the post-mret privilege state at M; the U-enabled control remains unchanged.
  • The public CPU model list has no U-clear preset, so the U-clear case is documented as a manual API reproducer rather than adding a test-only CPU model.

@carlosqwqqwq
carlosqwqqwq force-pushed the fix/riscv-mret-mpp-no-u branch from 893ccf9 to d7dd352 Compare August 29, 2026 07:25
@carlosqwqqwq
carlosqwqqwq changed the base branch from master to dev August 29, 2026 07:27
@carlosqwqqwq

Copy link
Copy Markdown
Author

Thank you very much for taking the time to review this PR. We have rebased it onto dev and updated the mret MPP handling for harts without U-mode, with focused validation of the affected behavior. Could you please let us know what further code, test, or PR changes you would recommend? We will gladly adjust the patch to match the project guidelines.

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