Skip to content

First proposal for H-extension support for RISC-V Worlds.#19

Open
ruuddw wants to merge 1 commit intoriscv:mainfrom
ruuddw:h_extension
Open

First proposal for H-extension support for RISC-V Worlds.#19
ruuddw wants to merge 1 commit intoriscv:mainfrom
ruuddw:h_extension

Conversation

@ruuddw
Copy link

@ruuddw ruuddw commented Feb 26, 2026

First proposal for the newly proposed Fast-Track to add support for virtualization (H-extension).
The Shwdeleg/Svswid extensions add another delegation level to match the additional level of privilege hierarchy that the H extension introduces. Two HS-mode registers (that are not visible to VS) are added, called hlwid and hwiddeleg. Another HS-mode register called vslwid is added, which is also accessed via the slwid CSR addres in VS-mode.

Signed-off-by: Ruud Derwig <Ruud.Derwig@synopsys.com>
Copy link

@andrewdellow andrewdellow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering why you added hlwid and vslwid - I was expecting just the addition of hlwid, such that

S (no H extension) or HS (with H extension) transactions are tagged with mlwid,

When H is supported and V = 1, VS transactions tagged with hlwid

U/VU transactions tagged with slwid

I then suppose that when H is enabled, mwiddeleg then applies to hlwid, instead of slwid, and we need another CSR set from HS :– hwiddeleg that applies to slwid ?

@ruuddw
Copy link
Author

ruuddw commented Mar 2, 2026

Right, the vslwid is a bit special. It's like other "vs" registers introduced by the H extension:

Furthermore, several virtual supervisor CSRs (VS CSRs) are replicas of the normal supervisor CSRs. For example, vsstatus is the VS CSR that duplicates the usual sstatus CSR.
When V=1, the VS CSRs substitute for the corresponding supervisor CSRs, taking over all functions of the usual supervisor CSRs except as specified otherwise. Instructions that normally read or modify a supervisor CSR shall instead access the corresponding VS CSR. When V=1, an attempt to read or write a VS CSR directly by its own separate CSR address causes a virtual-instruction exception. (Attempts from U-mode cause an illegal-instruction exception as usual.) The VS CSRs can be accessed as themselves only from M-mode or HS-mode.

Rationale for it is in the PoW, probably a note should be added in this spec to explain as well. This is the relevant PoW rationale bullet:

  • For hypervisor VM load/store instructions (hstatus.HU=1) there is no option for software to reprogram slwid before the HLV.x instruction.

If the hypervisor could always reprogram the WID to be used for VU (also when the hypervisor itself needs to access the VU memory with the VU WID, not the S or U WID) we could do without vslwid (with some extra WID switching software). But for hstatus.HU=1, it needs to be done by the hardware.
This was discussed about a year ago: https://lists.riscv.org/g/security/message/1159

* The *Shwdeleg/Svswid* extensions add another delegation level to match the additional
level of privilege hierarchy that the H extension introduces. Two HS-mode
registers (that are not visible to VS) are added, called `hlwid` and `hwiddeleg`.
Another HS-mode register called `vslwid` is added, which is also accessed
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vslwid is the replica CSR of the S-mode slwid CSR ?

And behavior similar to what is described in Priv spec, section 21.2:

When V=1, the VS CSRs substitute for the corresponding supervisor CSRs, taking over all functions of the usual supervisor CSRs except as specified otherwise. Instructions that normally read or modify a supervisor CSR shall instead access the corresponding VS CSR. When V=1, an attempt to read or write a VS CSR directly by its own separate CSR address causes a virtual-instruction exception. (Attempts from U-mode cause an illegal-instruction exception as usual.) The VS CSRs can be accessed as themselves only from M-mode or HS-mode.

| `XLEN` | `hlwid` | WARL for HS | `???` | WID value used for lower privilege
modes than HS-mode with the optional Svswid extension (i.e., VS/VU-mode).
`Ceil(Log~2~NWorlds)` LSBs are used, others are zero.
| `XLEN` | `vslwid` | WARL for HS | `???` | With the Svswid extension, this CSR
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARL for HS and VS ?

modes than HS-mode with the optional Svswid extension (i.e., VS/VU-mode).
`Ceil(Log~2~NWorlds)` LSBs are used, others are zero.
| `XLEN` | `vslwid` | WARL for HS | `???` | With the Svswid extension, this CSR
is the virtualization shadow register of the slwid register. In HS-mode this
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the replica register of the slwid register

modes than HS-mode with the optional Svswid extension (i.e., VS/VU-mode).
`Ceil(Log~2~NWorlds)` LSBs are used, others are zero.
| `XLEN` | `vslwid` | WARL for HS | `???` | With the Svswid extension, this CSR
is the virtualization shadow register of the slwid register. In HS-mode this
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in HS and in VS modes, this ...

VS-mode on a hart is platform-specific.

`hwiddeleg` is always a subset of `mwiddeleg`. Attempts to authorize a WID in
`mwiddeleg` that is not authorized in `mwiddeleg` will fail - the
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: in hwiddeleg

will be implicitly de-authorized in `hwiddeleg` also.

If `hwiddeleg` is zero (which may happen even if non-zero values are written to
it, see the previous paragraph), the Svswid extension is disabled, in which case
Copy link

@yloisel yloisel Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why Svswid extension is disabled if hwiddeleg is empty, as Svswid extension is claimed to add the hlwid CSR.
It should be possible anyway to assign a WID to VS and VU (the same one) using the hlwid CSR, as it is written 2 lines after.

to determine the actual configuration retained by the implementation.

The Svswid extension adds the HS-mode read-write `hlwid` CSR, which
sets the WID used for VS-mode and if not further delegated for VU-mode. The `hlwid`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So Svswid extension is used to have a VS and VU WID (set by hlwid) distinct from the HS WID (set by mlwid), whether hwiddeleg is empty/enabled or not

`hwiddeleg` register represents a set of WIDs as a bit vector with
WID _i_ represented by bit _i_ of the register. The `hwiddeleg` CSR
is a WARL register where each bit that can be set indicates a WID that
is delegated to VS-mode. The set of worlds that can be delegated to
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indicates a WID that can be set for VU mode by VS mode

sets the WID used for VS-mode and if not further delegated for VU-mode. The `hlwid`
field is WARL that can contain Ceil(Log~2~NWorlds)-1:0 writable bits.

If an unauthorized WID (per the `hwiddeleg` list) is written to `hlwid`, then
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hwiddeleg constrains the values in vslwid, not in hlwid (these ones are constrained by mwiddeleg)

To allow for a hypervisor to set or context switch the VS-mode `slwid` CSR,
the `vslwid` shadow register is defined. In HS-mode this register can be
programmed to set the effective WID of VU mode. In VS-mode it is accessed via
the `slwid` CSR address.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this paragraph is redundant with description made above

@yloisel
Copy link

yloisel commented Mar 5, 2026

Seems to be some confusion about the Svswid extension which is claimed to add the hlwid CSR but which is also blocked if there's no delegation to VS mode. So looks like Svswid should be about adding vslwid CSR

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.

3 participants