[RFC PATCH 0/5] Preserve more S/HS architectural state across domain switches
whensun
theodoruswensanfebruanto025 at gmail.com
Thu Oct 22 19:43:40 PDT 2026
From: Theodorus Wensan Februanto <theodoruswensanfebruanto025 at gmail.com>
This RFC series is a partial implementation for the missing S/HS
architectural state reported in OpenSBI issue #433:
https://github.com/riscv-software-src/opensbi/issues/433
An earlier patch for hcounteren and htimedelta was submitted separately.
This series intentionally does not repeat that patch.
The five patches add per-domain preservation of 18 CSR names:
* stimecmp
* hstatus, hedeleg, hideleg, hie, hgeie, henvcfg, htval,
htinst, hvip, and hgatp
* hvien and hstateen0 through hstateen3
* scountinhibit
* siselect (selector only)
These patches do NOT fully fix the following 10 CSR names:
* hip: pending bits include aliases and hardware-derived state.
The preservation of hvip/hgeie/hstatus addresses some underlying
software-controlled inputs, but hip should not be blindly swapped.
* sireg, sireg2 through sireg6: these are indirect windows. The
backing registers depend on siselect and the implemented extension.
The series does not save or restore that backing state.
* sctrctl, sctrdepth, and sctrstatus: complete CTR isolation also
requires preservation of CTR record entries accessed via sireg,
sireg2, and sireg3 with selectors 0x200..0x2ff. The status write
pointer, depth, and recording state require coordinated handling.
In particular, scountinhibit is a masked alias of mcountinhibit for
counters delegated to S-mode. Its swap is limited to the configuration
and does not virtualize the underlying physical counter values.
Could maintainers review whether these CSR families belong to the
sbi_domain_context_enter()/exit() preservation contract, and whether
extension-specific helpers would be appropriate for indirect CSR
backing state and the shared CTR buffer?
The patches were prepared against OpenSBI master commit
6ad246a1494807ee91e36ffcf60e4c30bb309d45.
The series was subsequently applied with git am to a local OpenSBI
worktree based on 337c23dd, and git diff --check passed. The generic
platform build with riscv64-linux-gnu-gcc completed successfully,
producing fw_dynamic.elf, fw_jump.elf, and fw_payload.elf.
The new CSR accesses were visible in the compiled sbi_domain_context.o.
Runtime regression testing of A -> B -> A domain transitions has NOT
been completed. The earlier hcounteren/htimedelta patch was submitted
separately and is not included in this 5-patch series. Please treat
this series as an RFC, not a confirmed fix for all 28 CSR names.
Theodorus Wensan Februanto (5):
lib: sbi: Preserve stimecmp across domain switches
lib: sbi: Save core hypervisor state across domain switches
lib: sbi: Save optional H-extension context
lib: sbi: Preserve supervisor count inhibit configuration
lib: sbi: Preserve the supervisor indirect CSR selector
lib/sbi/sbi_domain_context.c | 68 ++++++++++++++++++++++++++++++++++++
1 file changed, 68 insertions(+)
--
2.47.3
More information about the opensbi
mailing list