Skip to content

Commit 4548d0e

Browse files
authored
Move Smmpm and Smnpm to machine and Ssnpm to machine/supervisor/hypervisor chapter (#2494)
* Move Smnpm to machine chapter * Move Smmpm to Machine chapter * Move Ssnpm to supervisor chapter * Move Ssnpm additions to H to hypervisor chapter * Clean up the movement of extension details
1 parent 107e9d3 commit 4548d0e

File tree

4 files changed

+148
-88
lines changed

4 files changed

+148
-88
lines changed

src/hypervisor.adoc

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,24 @@ greater protection against software bugs, while still retaining access
262262
to a virtual machine’s memory.
263263
====
264264

265+
When Ssnpm extension is implemented, the `HUPMM` field enables or disables
266+
pointer masking (see <<Zpm>>) for `HLV.\*` and `HSV.*` instructions in U-mode,
267+
according to the values in <<henvcfg-pmm-values>>, when their explicit memory
268+
access is performed as though in VU-mode. In HS- and M-modes, pointer masking
269+
for these instructions is enabled or disabled by `senvcfg.PMM`, when their
270+
explicit memory access is performed as though in VU-mode. Setting `henvcfg.PMM`
271+
enables or disables pointer masking for `HLV.\*` and `HSV.*` when their
272+
explicit memory access is performed as though in VS-mode. When the Ssnpm
273+
extension is not implemented, the `HUPMM` field is read-only zero. The `HUPMM`
274+
field is read-only zero for RV32.
275+
276+
[NOTE]
277+
====
278+
The hypervisor should copy the value written to `senvcfg.PMM` by the guest to
279+
the `hstatus.HUPMM` field prior to invoking `HLV.\*` or `HSV.*` instructions in
280+
U-mode.
281+
====
282+
265283
The SPV bit (Supervisor Previous Virtualization mode) is written by the
266284
implementation whenever a trap is taken into HS-mode. Just as the SPP
267285
bit in `sstatus` is set to the (nominal) privilege mode at the time of
@@ -689,7 +707,22 @@ The definition of the CBZE field is furnished by the Zicboz extension.
689707

690708
The definitions of the CBCFE and CBIE fields are furnished by the Zicbom extension.
691709

692-
The definition of the PMM field is furnished by the Ssnpm extension.
710+
If the Ssnpm extension is implemented, the `PMM` field enables or disables
711+
pointer masking (see <<Zpm>>) for VS-mode, according to the values in
712+
<<henvcfg-pmm-values>>. When the Ssnpm extension is not implemented, the `PMM`
713+
field is read-only zero. The `PMM` field is read-only zero for RV32.
714+
715+
[[henvcfg-pmm-values]]
716+
717+
[%header, cols="25%,75%", options="header"]
718+
.Legal values of `PMM` WARL field
719+
|===
720+
|Value|Description
721+
|00|Pointer masking is disabled (PMLEN = 0)
722+
|01|Reserved
723+
|10|Pointer masking is enabled with PMLEN = XLEN - 57 (PMLEN = 7 on RV64)
724+
|11|Pointer masking is enabled with PMLEN = XLEN - 48 (PMLEN = 16 on RV64)
725+
|===
693726

694727
The Zicfilp extension adds the `LPE` field in `henvcfg`. When the `LPE` field
695728
is set to 1, the Zicfilp extension is enabled in VS-mode. When the `LPE` field
@@ -1307,6 +1340,17 @@ HLVX.WU is valid for RV32, even though LWU and HLV.WU are not. (For
13071340
RV32, HLVX.WU can be considered a variant of HLV.W, as sign extension is
13081341
irrelevant for 32-bit values.)
13091342

1343+
The memory accesses performed by the `HLVX.*` instructions are not subject to
1344+
pointer masking (see <<Zpm>>).
1345+
1346+
[NOTE]
1347+
====
1348+
`HLVX.*` instructions, designed for emulating implicit access to fetch
1349+
instructions from guest memory, perform memory accesses that are exempt from
1350+
pointer masking to facilitate this emulation. For the same reason, pointer
1351+
masking does not apply when MXR is set.
1352+
====
1353+
13101354
Attempts to execute a virtual-machine load/store instruction (HLV, HLVX,
13111355
or HSV) when V=1 cause a virtual-instruction exception. Attempts to execute
13121356
one of these same instructions from U-mode when `hstatus`.HU=0 cause an
@@ -1863,6 +1907,42 @@ code should zero `vsatp`, then swap `hgatp`, then finally write the new
18631907
should be switched after zeroing `vsatp` but before writing the new `vsatp`
18641908
value, obviating the need to execute an HFENCE.VVMA instruction.
18651909

1910+
[[pm-two-stage]]
1911+
==== Interaction with Pointer Masking
1912+
1913+
Guest physical addresses (GPAs) are 2 bits wider than the corresponding virtual
1914+
address translation modes, resulting in additional address translation schemes
1915+
Sv32x4, Sv39x4, Sv48x4, and Sv57x4 for translating guest physical addresses to
1916+
supervisor physical addresses. When running with virtualization in VS/VU mode
1917+
with `vsatp.MODE` = Bare, this means that those two bits may be subject to
1918+
pointer masking, depending on `hgatp.MODE` and `senvcfg.PMM`/`henvcfg.PMM` (for
1919+
VU/VS mode). If `vsatp.MODE` != BARE, this issue does *not* apply.
1920+
1921+
[NOTE]
1922+
====
1923+
An implementation could mask those two bits on the TLB access path, but this can
1924+
have a significant timing impact. Alternatively, an implementation may choose to
1925+
"waste" TLB capacity by having up to 4 duplicate entries for each page. In this
1926+
case, the pointer masking operation can be applied on the TLB refill path, where
1927+
it is unlikely to affect timing. To support this approach, some TLB entries need
1928+
to be flushed when PMLEN changes in a way that may affect these duplicate
1929+
entries.
1930+
====
1931+
1932+
To support implementations where (XLEN-PMLEN) can be less than the GPA width
1933+
supported by `hgatp.MODE`, hypervisors should execute an `HFENCE.GVMA` with
1934+
_rs1_=`x0` if the `henvcfg.PMM` is changed from or to a value where (XLEN-PMLEN)
1935+
is less than GPA width supported by the `hgatp` translation mode of that guest.
1936+
Specifically, these cases are:
1937+
1938+
* `PMLEN=7` and `hgatp.MODE=sv57x4`
1939+
* `PMLEN=16` and `hgatp.MODE=sv57x4`
1940+
* `PMLEN=16` and `hgatp.MODE=sv48x4`
1941+
1942+
Implementation of an address-specific `HFENCE.GVMA` should either ignore the
1943+
address argument, or should ignore the top masked GPA bits of entries when
1944+
comparing for an address match.
1945+
18661946
=== Traps
18671947

18681948
[[sec:hcauses]]

src/machine.adoc

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,7 +2224,23 @@ The definition of the CBZE field is furnished by the Zicboz extension.
22242224

22252225
The definitions of the CBCFE and CBIE fields are furnished by the Zicbom extension.
22262226

2227-
The definition of the PMM field is furnished by the Smnpm extension.
2227+
If the Smnpm extension is implemented, the `PMM` field enables or disables
2228+
pointer masking (see <<Zpm>>) for the next-lower privilege mode (S-/HS-mode if
2229+
S-mode is implemented, or U-mode otherwise), according to the values in
2230+
<<menvcfg-pmm-values>>. If Smnpm is not implemented, `PMM` is read-only zero.
2231+
The `PMM` field is read-only zero for RV32.
2232+
2233+
[[menvcfg-pmm-values]]
2234+
2235+
[%header, cols="25%,75%", options="header"]
2236+
.Legal values of `PMM` WARL field
2237+
|===
2238+
|Value|Description
2239+
|00|Pointer masking is disabled (PMLEN = 0)
2240+
|01|Reserved
2241+
|10|Pointer masking is enabled with PMLEN = XLEN - 57 (PMLEN = 7 on RV64)
2242+
|11|Pointer masking is enabled with PMLEN = XLEN - 48 (PMLEN = 16 on RV64)
2243+
|===
22282244

22292245
The Zicfilp extension adds the `LPE` field in `menvcfg`. When the `LPE` field is
22302246
set to 1 and S-mode is implemented, the Zicfilp extension is enabled in S-mode.
@@ -2260,6 +2276,7 @@ The `menvcfgh` register does not exist when XLEN=64.
22602276
If U-mode is not supported, then registers `menvcfg` and `menvcfgh` do
22612277
not exist.
22622278

2279+
[[sec:mseccfg]]
22632280
==== Machine Security Configuration (`mseccfg`) Register
22642281

22652282
`mseccfg` is an optional 64-bit read/write register, formatted as
@@ -2275,7 +2292,29 @@ entropy-source extension, Zkr.
22752292
The definitions of the RLB, MMWP, and MML fields are furnished by the
22762293
PMP-enhancement extension, Smepmp.
22772294

2278-
The definition of the PMM field is furnished by the Smmpm extension.
2295+
If the Smmpm extension is implemented, the `PMM` field enables or disables
2296+
pointer masking (see <<Zpm>>) for M-mode according to the values in
2297+
<<mseccfg-pmm-values>>. If Smmpm is not implemented, `PMM` is read-only zero.
2298+
The `PMM` field is read-only zero for RV32.
2299+
2300+
[[mseccfg-pmm-values]]
2301+
2302+
[%header, cols="25%,75%", options="header"]
2303+
.Legal values of `PMM` WARL field
2304+
|===
2305+
|Value|Description
2306+
|00|Pointer masking is disabled (PMLEN = 0)
2307+
|01|Reserved
2308+
|10|Pointer masking is enabled with PMLEN = XLEN - 57 (PMLEN = 7 on RV64)
2309+
|11|Pointer masking is enabled with PMLEN = XLEN - 48 (PMLEN = 16 on RV64)
2310+
|===
2311+
2312+
[NOTE]
2313+
====
2314+
`Smmpm` implementations need to satisfy max(largest supported virtual address
2315+
size, largest supported supervisor physical address size) <= (XLEN - PMLEN)
2316+
bits to avoid any masking logic on the TLB access path.
2317+
====
22792318

22802319
The Zicfilp extension adds the `MLPE` field in `mseccfg`. When `MLPE` field is
22812320
1, Zicfilp extension is enabled in M-mode. When the `MLPE` field is 0, the

src/supervisor.adoc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,23 @@ The definition of the CBZE field is furnished by the Zicboz extension.
834834
The definitions of the CBCFE and CBIE fields are furnished by the Zicbom
835835
extension.
836836

837-
The definition of the PMM field is furnished by the Ssnpm extension.
837+
If the Ssnpm extension is implemented, the `PMM` field enables or disables
838+
pointer masking (see <<Zpm>>) for the next-lower privilege mode (U/VU),
839+
according to the values in <<senvcfg-pmm-values>>. If Ssnpm is not
840+
implemented, `PMM` is read-only zero. The `PMM` field is read-only zero for
841+
RV32.
842+
843+
[[senvcfg-pmm-values]]
844+
845+
[%header, cols="25%,75%", options="header"]
846+
.Legal values of `PMM` WARL field
847+
|===
848+
|Value|Description
849+
|00|Pointer masking is disabled (PMLEN = 0)
850+
|01|Reserved
851+
|10|Pointer masking is enabled with PMLEN = XLEN - 57 (PMLEN = 7 on RV64)
852+
|11|Pointer masking is enabled with PMLEN = XLEN - 48 (PMLEN = 16 on RV64)
853+
|===
838854

839855
The Zicfilp extension adds the `LPE` field in `senvcfg`. When the `LPE` field is
840856
set to 1, the Zicfilp extension is enabled in VU/U-mode. When the `LPE` field is
@@ -1260,6 +1276,10 @@ For implementations that make `satp`.MODE read-only zero (always Bare),
12601276
attempts to execute an SFENCE.VMA instruction might raise an
12611277
illegal-instruction exception.
12621278

1279+
No SFENCE.VMA is required after enabling or disabling pointer masking
1280+
(see <<Zpm>>), as pointer masking applies to the effective address only and
1281+
does not affect any memory-management data structures.
1282+
12631283
[[sv32]]
12641284
=== Sv32: Page-Based 32-bit Virtual-Memory Systems
12651285

src/zpm.adoc

Lines changed: 5 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Pointer masking applies to all explicit memory accesses. Currently, in the Base
131131
* **Atomics**: All instructions in RV32A and RV64A.
132132
* **Floating Point**: FLW, FLD, FLQ, FSW, FSD, FSQ.
133133
* **Compressed**: All instructions mapping to any of the above, and C.LWSP, C.LDSP, C.FLWSP, C.FLDSP, C.SWSP, C.SDSP, C.FSWSP, C.FSDSP.
134-
* **Hypervisor Extension**: HLV.\*, HSV.* (in some cases; see <<_ssnpm>>).
134+
* **Hypervisor Extension**: HLV.\*, HSV.* (in some cases; see <<sec:hstatus>>).
135135
* **Cache Management Operations**: All instructions in Zicbom, Zicbop and Zicboz.
136136
* **Vector Extension**: All vector load and store instructions in the ratified RVV 1.0 spec.
137137
* **Zicfiss Extension**: SSPUSH, C.SSPUSH, SSPOPCHK, C.SSPOPCHK, SSAMOSWAP.W/D.
@@ -190,11 +190,9 @@ Pointer masking refers to a number of separate extensions, all of which are priv
190190

191191
**Extensions**:
192192

193-
* **Ssnpm**: A supervisor-level extension that provides pointer masking for the next lower privilege mode (U-mode), and for VS- and VU-modes if the H extension is present.
194-
* **Smnpm**: A machine-level extension that provides pointer masking for the next lower privilege mode (S/HS if S-mode is implemented, or U-mode otherwise).
195-
* **Smmpm**: A machine-level extension that provides pointer masking for M-mode.
196-
197-
See <<_isa_extensions>> for details on how each of these extensions is configured.
193+
* **Ssnpm**: A supervisor-level extension that provides pointer masking for the next lower privilege mode (U-mode), and for VS- and VU-modes if the H extension is present. See <<sec:senvcfg>>, <<sec:henvcfg>>, <<sec:hstatus>>, and <<pm-two-stage>>.
194+
* **Smnpm**: A machine-level extension that provides pointer masking for the next lower privilege mode (S/HS if S-mode is implemented, or U-mode otherwise). See <<sec:menvcfg>>.
195+
* **Smmpm**: A machine-level extension that provides pointer masking for M-mode. See <<sec:mseccfg>>.
198196

199197
In addition, the pointer masking standard defines two extensions that describe an execution environment but have no bearing on hardware implementations. These extensions are intended to be used in profile specifications where a User profile or a Supervisor profile can only reference User level or Supervisor level pointer masking functionality, and not the associated CSR controls that exist at a higher privilege level (i.e., in the execution environment).
200198

@@ -203,95 +201,18 @@ In addition, the pointer masking standard defines two extensions that describe a
203201

204202
The precise nature of these facilities is left to the respective execution environment.
205203

206-
Pointer masking only applies to RV64. In RV32, trying to enable pointer masking will result in an illegal WARL write and not update the pointer masking configuration bits (see <<_isa_extensions>> for details). The same is the case on RV64 or larger systems when UXL/SXL/MXL is set to 1 for the corresponding privilege mode. Note that in RV32, the CSR bits introduced by pointer masking are still present, for compatibility between RV32 and larger systems with UXL/SXL/MXL set to 1. Setting UXL/SXL/MXL to 1 will clear the corresponding pointer masking configuration bits.
204+
Pointer masking only applies to RV64. In RV32, trying to enable pointer masking will result in an illegal WARL write and not update the pointer masking configuration bits (see <<sec:mseccfg>>, <<sec:menvcfg>>, <<sec:henvcfg>>, and <<sec:senvcfg>> for details). The same is the case on RV64 or larger systems when UXL/SXL/MXL is set to 1 for the corresponding privilege mode. Note that in RV32, the CSR bits introduced by pointer masking are still present, for compatibility between RV32 and larger systems with UXL/SXL/MXL set to 1. Setting UXL/SXL/MXL to 1 will clear the corresponding pointer masking configuration bits.
207205

208206
[NOTE]
209207
====
210208
Note that setting UXL/SXL/MXL to 1 and back to 0 does not preserve the previous values of the PMM bits. This includes the case of entering an RV32 virtual machine from an RV64 hypervisor and returning.
211209
====
212210

213-
=== ISA Extensions
214-
215-
This section describes the pointer masking extensions `Smmpm`, `Smnpm` and `Ssnpm`. All of these extensions are privileged ISA extensions and do not add any new CSRs. For the definitions of `Sspm` and `Supm`, see <<_pointer_masking_extensions>>.
216-
217211
[NOTE]
218212
====
219213
Future extensions may introduce additional CSRs to allow different privilege modes to modify their own pointer masking settings. This may be required for future use cases in managed runtime systems that are not currently addressed as part of this extension.
220214
====
221215

222-
Each extension introduces a 2-bit WARL field (`PMM`) that may take on the following values to set the pointer masking settings for a particular privilege mode.
223-
224-
[[pmm-values]]
225-
226-
[%header, cols="25%,75%", options="header"]
227-
.Possible values of `PMM` WARL field.
228-
|===
229-
|Value|Description
230-
|00|Pointer masking is disabled (PMLEN=0)
231-
|01|Reserved
232-
|10|Pointer masking is enabled with PMLEN=XLEN-57 (PMLEN=7 on RV64)
233-
|11|Pointer masking is enabled with PMLEN=XLEN-48 (PMLEN=16 on RV64)
234-
|===
235-
236-
All of these fields are read-only 0 on RV32 systems.
237-
238-
==== Ssnpm
239-
240-
`Ssnpm` adds a new 2-bit WARL field (`PMM`) to bits 33:32 of `senvcfg`. Setting `PMM` enables or disables pointer masking for the next lower privilege mode (U/VU mode), according to the values in <<pmm-values>>.
241-
242-
In systems where the H Extension is present, `Ssnpm` also adds a new 2-bit WARL field (`PMM`) to bits 33:32 of `henvcfg`. Setting `PMM` enables or disables pointer masking for VS-mode, according to the values in <<pmm-values>>. Further, a 2-bit WARL field (`HUPMM`) is added to bits 49:48 of `hstatus`. Setting `hstatus.HUPMM` enables or disables pointer masking for `HLV.\*` and `HSV.*` instructions in U-mode, according to the values in <<pmm-values>>, when their explicit memory access is performed as though in VU-mode. In HS- and M-modes, pointer masking for these instructions is enabled or disabled by `senvcfg.PMM`, when their explicit memory access is performed as though in VU-mode. Setting `henvcfg.PMM` enables or disables pointer masking for `HLV.\*` and `HSV.*` when their explicit memory access is performed as though in VS-mode.
243-
244-
[NOTE]
245-
====
246-
The hypervisor should copy the value written to `senvcfg.PMM` by the guest to the `hstatus.HUPMM` field prior to invoking `HLV.\*` or `HSV.*` instructions in U-mode.
247-
====
248-
249-
The memory accesses performed by the `HLVX.*` instructions are not subject to pointer masking.
250-
251-
[NOTE]
252-
====
253-
`HLVX.*` instructions, designed for emulating implicit access to fetch instructions from guest memory, perform memory accesses that are exempt from pointer masking to facilitate this emulation. For the same reason, pointer masking does not apply when MXR is set.
254-
====
255-
256-
==== Smnpm
257-
258-
`Smnpm` adds a new 2-bit WARL field (`PMM`) to bits 33:32 of `menvcfg`. Setting `PMM` enables or disables pointer masking for the next lower privilege mode (S-/HS-mode if S-mode is implemented, or U-mode otherwise), according to the values in <<pmm-values>>.
259-
260-
[NOTE]
261-
====
262-
The type of address determines which type of pointer masking is applied. For example, when running with virtualization in VS/VU mode with `vsatp.MODE` = Bare, physical address pointer masking (zero extension) applies.
263-
====
264-
265-
==== Smmpm
266-
267-
`Smmpm` adds a new 2-bit WARL field (`PMM`) to bits 33:32 of `mseccfg`. The presence of `Smmpm` implies the presence of the `mseccfg` register, even if it would not otherwise be present. Setting `PMM` enables or disables pointer masking for M mode, according to the values in <<pmm-values>>.
268-
269-
==== Interaction with SFENCE.VMA
270-
271-
Since pointer masking applies to the effective address only and does not affect any memory-management data structures, no SFENCE.VMA is required after enabling/disabling pointer masking.
272-
273-
==== Interaction with Two-Stage Address Translation
274-
275-
Guest physical addresses (GPAs) are 2 bits wider than the corresponding virtual address translation modes, resulting in additional address translation schemes Sv32x4, Sv39x4, Sv48x4, and Sv57x4 for translating guest physical addresses to supervisor physical addresses. When running with virtualization in VS/VU mode with `vsatp.MODE` = Bare, this means that those two bits may be subject to pointer masking, depending on `hgatp.MODE` and `senvcfg.PMM`/`henvcfg.PMM` (for VU/VS mode). If `vsatp.MODE` != BARE, this issue does *not* apply.
276-
277-
[NOTE]
278-
====
279-
An implementation could mask those two bits on the TLB access path, but this can have a significant timing impact. Alternatively, an implementation may choose to "waste" TLB capacity by having up to 4 duplicate entries for each page. In this case, the pointer masking operation can be applied on the TLB refill path, where it is unlikely to affect timing. To support this approach, some TLB entries need to be flushed when PMLEN changes in a way that may affect these duplicate entries.
280-
====
281-
282-
To support implementations where (XLEN-PMLEN) can be less than the GPA width supported by `hgatp.MODE`, hypervisors should execute an `HFENCE.GVMA` with _rs1_=`x0` if the `henvcfg.PMM` is changed from or to a value where (XLEN-PMLEN) is less than GPA width supported by the `hgatp` translation mode of that guest. Specifically, these cases are:
283-
284-
* `PMLEN=7` and `hgatp.MODE=sv57x4`
285-
* `PMLEN=16` and `hgatp.MODE=sv57x4`
286-
* `PMLEN=16` and `hgatp.MODE=sv48x4`
287-
288-
[NOTE]
289-
====
290-
`Smmpm` implementations need to satisfy max(largest supported virtual address size, largest supported supervisor physical address size) <= (XLEN - PMLEN) bits to avoid any masking logic on the TLB access path.
291-
====
292-
293-
Implementation of an address-specific `HFENCE.GVMA` should either ignore the address argument, or should ignore the top masked GPA bits of entries when comparing for an address match.
294-
295216
==== Number of Masked Bits
296217

297218
As described in <<_determining_the_value_of_pmlen>>, the supported values of PMLEN may depend on the effective privilege mode. The current standard only defines PMLEN=XLEN-48 and PMLEN=XLEN-57, but this assumption may be relaxed in future extensions and profiles. Trying to enable pointer masking in an unsupported scenario represents an illegal write to the corresponding pointer masking enable bit and follows WARL semantics. Future profiles may choose to define certain combinations of privilege modes and supported values of PMLEN as mandatory.

0 commit comments

Comments
 (0)