i-RISCV Hypervisor Support
The i-RISCV core implements the RISC-V H (Hypervisor) extension. The following mechanisms are supported.
Virtualization Modes and CSRs
- A virtualization-mode bit
Vlayering VS-mode and VU-mode on top of HS-mode/U-mode; SRET is the only way a hart enters a guest (hstatus.SPV/sstatus.SPP) - The full hypervisor CSR set (
hstatus,hedeleg/hideleg,hie/hvip/hip,hgeip/hgeie,henvcfg,hcounteren,htimedelta,htval/htinst,hgatp) and the VS-mode shadow CSRs (vsstatus,vsie/vsip,vstvec,vsscratch,vsepc,vscause,vstval,vsatp,vstimecmp) - Transparent CSR substitution while
V=1: supervisor CSRs redirect to their VS counterparts, includingsatp/vsatpandstimecmp/vstimecmp henvcfgmirrorsmenvcfg’s own enable fields (STCE,PBMTE,ADUE,FIOM,CBZE/CBCFE/CBIE,LPE/SSE/DTE) for VS-stage and genuinely gates VS-mode independently ofmenvcfg– Svpbmt/Zicbom/Zicboz access in VS-mode is gated byhenvcfg’s own bit alone; onlySTCEandADUEstack both levels (the guest’s effective enable is the AND), withSSE/DTEspec-forced to 0 whenever theirmenvcfgcounterpart clears
Trap Delegation and Virtual Instructions
- Three-way M/HS/VS trap routing via
medeleg/midelegplus the guest-levelhedeleg/hideleg; VS interrupts (VSSIP/VSTIP/VSEIP) and SGEIP are always delegated at least to HS-level, and SGEIP can never be delegated further down - Interrupt-cause renumbering when delegated into VS-mode, so a guest sees ordinary supervisor numbering
- Virtual-instruction exceptions for HS-qualified instructions blocked by
V=1, covering both spec groups (VTVM/VTSR-gated and unconditional, incl. WFI under VTW)
Two-Stage Address Translation
- Separate VS-stage and G-stage walkers/TLBs in
Sv39x4/Sv48x4/Sv57x4, mirroring the single-stage modes - “Walk of a walk”: every VS-stage page-table read – root pointer and each PTE – is itself G-stage translated before reaching memory
- Guest-page-fault causes (20/21/23) distinct from ordinary page faults, always attributed to the original access kind – including when a VS-stage PTE fetch (checked as an implicit read) fails in G-stage
- HS-level
mstatus.MXRoverrides both stages while guestvsstatus.MXRoverrides only the VS stage; HS-level SUM is ignored for two-stage accesses - G-stage’s own permission quirks per spec: the U bit is always checked as though in U-mode, and a cached final result is re-checked whenever the access kind or the active VMID changes
Nested Virtualization
- A single hardware VS/G-stage context supports nested (“L2+”) virtualization through software trap-and-emulate: a guest hypervisor runs at ordinary VS-mode, and its privileged operations (e.g.
hgatpwrites, HFENCE.GVMA) virtual-instruction-trap to the outer hypervisor for emulation - Shadow G-stage page-table merging enforces the inner hypervisor’s intended permissions on top of the outer hosting mapping; arbitrarily deep nesting by recursively re-applying the same technique, with no additional hardware
Hypervisor Instructions and Guest Interrupts
- HLV/HSV/HLVX explicit guest-memory access that always acts as though
V=1athstatus.SPVP, overriding MPRV – including execute-for-read substitution in both stages - HFENCE.VVMA / HFENCE.GVMA TLB invalidation for the VS-stage and G-stage respectively, reusing
SFENCE.VMA’s 4-case selective predicate –rs2selects an ASID for VVMA, a single VMID for GVMA (see Tagged TLB) - Guest interrupt injection via
hvip, real per-guest-file MSI delivery through two IMSIC guest files (GEILEN=2) selected byhstatus.VGEIN– each with its own physical MSI region, so migrating a guest between files never moves the device’s write target – and SGEIP/SGEIE pending/enable plumbing - VS-mode virtual timer: a real
vstimecmpcomparator (Sstc) OR’d withhvip.VSTIP, gated by the guest’s ownhenvcfg.STCE; accessingvstimecmpitself requires that gate stacked on top of HS-level’smenvcfg.STCE;htimedeltaoffsets the guest’s view oftime
Disclosed Simplifications
Spec-legal, not silent:
htval/mtval2always read 0 – software recovers the faulting address viastval(the guest virtual address) alone- G-stage checks R rather than X permission for a guest instruction fetch’s final address (the shared walker instance also serves the always-a-read PTE-fetch case); VS-stage’s own X check is unaffected and correctly enforced
- A hypervisor must still set
hvip.VSEIP=1once per guest-file assignment: the guest file’s real delivery signal is not independently OR’d intohip.VSEIP(the pre-AIA software-injection path remains required)