Implement Smstateen and Ssstateen - #1881
davidharrishmc wants to merge 2 commits into
Conversation
|
The buildroot boot finished: Linux boots clean with Smstateen enabled. It reaches This was the check worth doing, because enabling Smstateen genuinely changes supervisor behavior: with so firmware detects The boot tracks the pre-change trajectory almost cycle for cycle, which is what you want from a change that should be invisible once firmware cooperates:
Userspace does real work before the prompt: creates and moves a file, runs a script and a symlink to it, reports disk usage, and lists processes with Caveat worth keeping in view: this is simulation with OpenSBI as the firmware. Any bare-metal or alternative-firmware supervisor software that writes |
2fe8c63 to
9cf8a1a
Compare
Adds the machine- and supervisor-level state enable CSRs. Each bit of a stateen register controls access from less-privileged modes to the state the bit names; machine mode is never restricted. mstateen0 is 64 bits wide even on RV32, following the menvcfg pattern, with the bit assignments from the privileged spec: SE0 (63) controls access to sstateen0 and ENVCFG (62) controls access to senvcfg, both writable. The remaining defined bits are read-only zero unless the state they control is implemented: CSRIND (60) gated by Sscsrind, AIA (59) and IMSIC (58) by Ssaia, CONTEXT (57) by Sdtrig, P1P13 (56) by the new SMP1P13_SUPPORTED, SRMCFG (55) by Ssqosid, JVT (2) by Zcmt, and FCSR (1) by Zfinx. CTR (54) is read-only zero because Smctr is not supported, and C (0) is read-only zero because Wally has no custom state. ENVCFG needs no gate because Wally is Sm1p12 compatible, so senvcfg always exists. mstateen1-3 are read-only zero, which the spec permits because the hypervisor extension is not implemented and sstateen1-3 are read-only zero; on RV32 the mstateen*h CSRs give access to the upper halves. sstateen0-3 are added to csrs. Every defined sstateen0 bit (C, FCSR, JVT) is read-only zero in Wally, but the register is built with the write mask and read masking against mstateen0 that the spec requires, so it stays correct if Zcmt or Zfinx is ever enabled. Enforcement matches the spec as well as the register contents: with mstateen0.SE0 clear, a supervisor-mode access to sstateen0 raises an illegal instruction, and with mstateen0.ENVCFG clear the same is true for senvcfg. Both reads and write enables are gated, following the existing pattern for satp under mstatus.TVM. sstateen1-3 are reachable only from machine mode because bit 63 of mstateen1-3 is read-only zero. Smstateen and Ssstateen are enabled on rv32gc and rv64gc; every new parameter is zero in all other configs. Assertions require Smstateen to have Zicsr and U, and Ssstateen to have Smstateen and S. Verified with the Smstateen-00 and Ssstateen-00 tests from ACT4, which pass on both cvw-rv32gc and cvw-rv64gc. lint-wally is clean and regression-wally shows no new failures. OpenSBI now detects the extension and reports smstateen in the boot hart ISA string. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Bit 54 of mstateen0 controls access to the control transfer records added by Smctr. It was hardwired to zero; gate it like the other state bits so it becomes writable if Smctr is ever implemented. SMCTR_SUPPORTED is zero in every config. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
9cf8a1a to
19ab24e
Compare
Implements the Smstateen and Ssstateen extensions: the machine- and supervisor-level state enable CSRs. Each bit of a
stateenregister controls access from less-privileged modes to the state that bit names; machine mode is never restricted by them.Registers
mstateen0follows themenvcfgpattern incsrm.svand is 64 bits wide even on RV32. Bit assignments are taken from the figure in the privileged spec chapter:sstateen0senvcfgSSCSRIND_SUPPORTEDSSAIA_SUPPORTEDSDTRIG_SUPPORTEDSMP1P13_SUPPORTEDSSQOSID_SUPPORTEDZCMT_SUPPORTEDZFINX_SUPPORTEDENVCFG needs no gate: Wally is Sm1p12 compatible, so
senvcfgalways exists. FCSR is additionally required to be read-only zero whenmisa.F= 1, which holds here because F and Zfinx are mutually exclusive.mstateen1-3are read-only zero. The spec permits that only when the hypervisor extension is absent and the matchingsstateenis all read-only zeros, both of which hold. On RV32 themstateen*hCSRs give access to the upper halves.sstateen0-3are added tocsrs.sv. Every definedsstateen0bit (C, FCSR, JVT) is read-only zero in Wally, but the register is built with the write mask and the read masking againstmstateen0that the spec requires, so it stays correct if Zcmt or Zfinx is ever enabled.Enforcement
The registers are only half the extension; the access control is the other half. With
mstateen0.SE0clear, a supervisor-mode access tosstateen0raises an illegal instruction, and withmstateen0.ENVCFGclear the same applies tosenvcfg. Reads and write enables are both gated, following the existing pattern forsatpundermstatus.TVM.sstateen1-3are reachable only from machine mode, because bit 63 ofmstateen1-3is read-only zero.Configuration
Nine new parameters. Smstateen and Ssstateen are 1 on rv32gc and rv64gc; every other new parameter is 0 in every config. Assertions require Smstateen to have Zicsr and U, and Ssstateen to have Smstateen and S.
Verification
Smstateen-00,Ssstateen-00on cvw-rv64gcSmstateen-00,Ssstateen-00on cvw-rv32gclint-wally, 7 configsregression-wallyThe ACT4 runs need the companion config change in riscv/riscv-arch-test (linked below); without it the reference model does not implement
sstateen0, traps on the test's first machine-mode access, and every expected trap signature shifts.imperas.icfor rv32gc and rv64gc now overrideSmstateenandSsstateenso nightly lockstep agrees.The three regression failures present are all pre-existing on
mainand unrelated: rv32i, rv64i and rv32e hit theMinstretprobe bug that #1878 fixes;arch64vm_sv57has no test vectors in my environment; andwally64privfailsWALLY-trap-01result 12 byte-identically to pristinemain.Note for reviewers
This changes observable behavior for supervisor software: with
mstateen0reset to zero, an S-mode access tosenvcfgnow traps until machine-mode firmware sets the ENVCFG bit. That is what the spec requires, and OpenSBI already detects the extension, now reportingsmstateenfirst in the boot hart ISA string where previously it was absent. A full buildroot Linux boot is running to confirm the kernel'ssenvcfguse is unaffected; I will report the result here.🤖 Generated with Claude Code