Skip to content

Commit 66ef79b

Browse files
committed
polish Sspmp
1 parent 9c3b399 commit 66ef79b

File tree

1 file changed

+54
-32
lines changed

1 file changed

+54
-32
lines changed

sspmp/spmp_spec.adoc

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
The RISC-V S-level Physical Memory Protection (SPMP) mechanism provides per-hart control registers in supervisor mode.
55
These registers define physical memory access privileges—read, write, and execute—for discrete physical memory regions.
66

7-
A memory access is successful only when permission checks for both PMP/ePMP and SPMP pass.
7+
A memory access is successful only when permission checks for both S-mode execution environment and SPMP pass.
88
SPMP checks can be performed by the hardware in parallel with PMA and PMP checks.
99
SPMP exceptions take priority over PMP or PMA exceptions.
1010
Consequently, if a memory access violates both SPMP and PMP/PMA rules, only the SPMP exception is reported.
@@ -13,47 +13,56 @@ SPMP checks are enforced on all memory accesses with effective privilege modes l
1313
SPMP can be configured to grant permissions to U-mode, which has none by default, and to revoke permissions from S-mode.
1414

1515
If the Hypervisor Extension is implemented in conjunction with Sspmp, when V = 1 and hgatp.MODE = Bare, SPMP enforces access checks on all memory accesses from VS and VU-modes, effectively applying SPMP protections to guest execution contexts.
16-
Additionally, the Hypervisor Virtual Machine Load and Store instructions (HLV, HLVX, HSV), when executed from M-mode, HS-mode, or U-mode (when hstatus.HU = 1), are also subject to SPMP checks under the V = 1 condition.
16+
Additionally, the Hypervisor Virtual Machine Load and Store instructions (HLV, HLVX, HSV), when executed from the execution environment, HS-mode, or U-mode (when hstatus.HU = 1), are also subject to SPMP checks under the V = 1 condition.
1717

1818

1919
[[spmp-and-paging]]
2020
=== SPMP and Paging
21-
SPMP and paged virtual memory are mutually exclusive and cannot be enabled concurrently for two primary reasons:
21+
SPMP and paged virtual memory are mutually exclusive.
22+
// and cannot be enabled concurrently for two primary reasons:
2223

23-
. Enabling both introduces a redundant layer of permission checks for each memory access.
24-
+
25-
. Paged virtual memory, by itself, offers a sufficient level of protection.
24+
// . Enabling both introduces a redundant layer of permission checks for each memory access.
25+
// +
26+
// . Paged virtual memory, by itself, offers a sufficient level of protection.
2627

27-
The following table dictates which isolation mechanism is active based on the satp configuration, assuming the hardware implements both.
28+
The following table dictates which isolation mechanism is active based on the satp configuration.
2829

2930

3031
[cols="^1,^1", stripes=even, options="header"]
3132
|===
3233
|satp|Isolation mechanism
33-
|satp.mode == Bare|SPMP only
34-
|satp.mode != Bare|Paged Virtual Memory only
34+
|satp.mode == Bare with Sspmp |SPMP only
35+
|satp.mode == Bare without Sspmp|no S-mode protection checks
36+
|satp.mode != Bare |Paged Virtual Memory only
3537
|===
3638

3739

3840
=== Extension Dependencies
3941

4042
. The `Sscsrind` extension for indirect CSR access must be implemented.
4143
+
42-
. The `sstatus.SUM` (permit Supervisor User Memory access) bit must be *writable*, deviating from the Privileged Architecture (i.e., `Svbare`). In SPMP, this writability is essential because the bit alters how S-mode load and store operations access user memory.
44+
. The `sstatus.SUM` (permit Supervisor User Memory access) bit must be *writable*. In SPMP, this writability is essential because the bit alters how S-mode load and store operations access user memory.
4345
+
44-
. The `sstatus.MXR` (Make eXecutable Readable) bit must be *writable*, deviating from the Privileged Architecture (i.e., `Svbare`). This writability supports M-mode emulation handlers that require reading instructions with `MXR=1 and MPRV=1`.
46+
. The `sstatus.MXR` (Make eXecutable Readable) bit must be *writable*. This writability supports M-mode emulation handlers that require reading instructions with `MXR=1 and MPRV=1`.
4547
+
46-
. The Sspmp extension can be virtualized. If the Hypervisor Extension is implemented in conjunction with Sspmp, the only mandatory translation mode in both hgatp and satp is Bare.
48+
. If the Hypervisor Extension is implemented in conjunction with Sspmp, the only mandatory translation mode in both hgatp and satp is Bare.
49+
50+
51+
52+
[NOTE]
53+
====
54+
The `Sspmp` extension does not provide ISA support to accelerate virtualization of the SPMP functionality.
55+
====
4756

4857

4958
[[spmp_csrs]]
5059
=== S-level Physical Memory Protection CSRs
5160

52-
// Each SPMP entry is composed of a 16-bit configuration field within an SXLEN-bit configuration register and an associated SXLEN-bit address register.
5361
Each SPMP entry is composed of an SXLEN-bit configuration register and an associated SXLEN-bit address register.
54-
From S-mode, the SPMP registers are accessible only via the indirect access mechanism (see <<access_method>>).
62+
The SPMP registers are accessible only via the indirect access mechanism.
63+
For details on CSR numbers and how to access them, see <<access_method>>.
5564
In TOR mode, an entry also uses the address register of the preceding entry to define its range (see <<address_matching>>).
56-
Implementations support up to 64 SPMP entries.
65+
Implementations support from 1 to 64 SPMP entries.
5766

5867

5968
[NOTE]
@@ -62,17 +71,13 @@ An SPMP entry refers to the register pair `spmpcfg[i]` and `spmpaddr[i]`.
6271
6372
An SPMP rule is defined by the contents of an `spmpcfg` register and its corresponding `spmpaddr` register(s).
6473
These registers collectively define a protected physical memory region and its access constraints.
65-
66-
For a rule to be valid, its `spmpcfg[i].A` field must not be OFF.
67-
Furthermore, if `spmpcfg[i].A` is set to TOR, the condition `spmpaddr[i-1] < spmpaddr[i]` must hold.
68-
Particularly, if `spmpcfg[0].A` is set to TOR, zero is used for the lower bound.
6974
====
7075

71-
The SPMP address registers, named `spmpaddr0` through `spmpaddr63`, share the same layout as PMP architecture.
76+
The SPMP address registers, named `spmpaddr0` through `spmpaddr63`, share the same layout as the machine-mode PMP architecture.
7277
On RV32 systems, each `spmpaddr` register encodes a 34-bit physical address from bit 33 down to bit 2, as illustrated in <<spmpaddr-rv32>>.
7378
On RV64 systems, each `spmpaddr` register encodes a 56-bit physical address from bit 55 down to bit 2, as shown in <<spmpaddr-rv64>>.
7479
An implementation may support fewer address bits, particularly on systems with a smaller physical address space.
75-
All writable SPMP entries should implement a consistent number of address bits.
80+
All writable SPMP entries should implement the same number of address bits.
7681
Since not all physical address bits must be implemented, the SPMP address registers are considered WARL, with exceptions defined by granularity rules.
7782
Refer to the {privspec}, Section 3.7: Physical Memory Protection, Address Matching.
7883

@@ -85,9 +90,8 @@ include::images/bytefield/spmpaddr-rv32.adoc[]
8590
.SPMP address register format, RV64.
8691
include::images/bytefield/spmpaddr-rv64.adoc[]
8792

88-
// Every SPMP entry contains a 16-bit configuration field, `spmpcfg[i]`.
8993
Every SPMP entry contains an SXLEN-bit configuration register, `spmpcfg[i]`.
90-
Its lower 8 bits are an alias for the 8-bit field of the corresponding PMP configuration register.
94+
// Its lower 8 bits are an alias for the 8-bit field of the corresponding PMP configuration register.
9195
<<spmpcfg>> illustrates the layout of `spmpcfg[i]`.
9296
Permission rules and their encodings are detailed in <<encoding>>.
9397

@@ -96,7 +100,7 @@ Permission rules and their encodings are detailed in <<encoding>>.
96100
. Bits 5 and 6 are reserved for future standard use.
97101
. The L (lock) bit designates an entry as locked.
98102
Setting the L bit locks the SPMP entry, regardless of the A field's setting (even OFF).
99-
Attempts to write to locked `spmpcfg[i]` and `spmpaddr[i]` registers using the `siselect` CSR are ignored, irrespective of privilege level.
103+
Attempts to write to locked `spmpcfg[i]` and `spmpaddr[i]` registers using the `siselect` CSR are ignored.
100104
If a locked entry has `spmpcfg[i].A` set to TOR, writes to the preceding `spmpaddr[i-1]` via `siselect` are also ignored.
101105
. If locking is not a required feature, an implementation can hardwire the L bit to 0.
102106
. For any rule not designated as a `Shared-Region`, the U bit determines if it is `U-mode` (when set) or `S-mode-only` (when clear), as explained in <<encoding>>.
@@ -125,7 +129,7 @@ Moreover, if resource sharing is statically defined (e.g., `mpmpdeleg.pmpnum` is
125129

126130
SPMP supports three distinct rule types: *S-mode-only*, *U-mode* and *Shared-Region*.
127131

128-
. An *S-mode-only* rule is *enforced* for accesses from Supervisor mode and *denied* for accesses from User mode.
132+
. An *S-mode-only* rule *enforces* accesses for Supervisor mode and *denies* accesses for User mode.
129133
+
130134
. A *U-mode* rule is always enforced for User mode accesses. Its behavior for Supervisor mode accesses depends on the `sstatus.SUM` bit.
131135
+
@@ -157,7 +161,11 @@ image::SPMP_Encoding_Table_v12.svg[title="SPMP Encoding Table"]
157161
*Reserved*: This encoding is reserved for future standard use.
158162

159163
*SUM bit*: The SPMP mechanism uses the `sstatus.SUM` (permit Supervisor User Memory access) bit to alter the privilege of S-mode load and store operations on physical memory.
164+
165+
[NOTE]
166+
====
160167
The semantics of `sstatus.SUM` within SPMP are consistent with its definition in the Machine-Level ISA (for details, refer to the "Memory Privilege in mstatus Register" subsection of the {privspec}).
168+
====
161169

162170

163171
[[address_matching]]
@@ -175,8 +183,17 @@ The following table details the A field's encoding.
175183
|3|NAPOT|Naturally aligned power-of-two region, ≥8 bytes
176184
|===
177185

186+
For a rule to be valid, its `spmpcfg[i].A` field must not be OFF.
187+
Furthermore, if `spmpcfg[i].A` is set to TOR, the condition `spmpaddr[i-1] < spmpaddr[i]` must hold.
188+
Particularly, if `spmpcfg[0].A` is set to TOR, zero is used for the lower bound.
189+
190+
191+
[NOTE]
192+
====
178193
This encoding is consistent with the PMP/ePMP.
179194
For comprehensive details, refer to the "Address Matching" subsection for PMP in the {privspec}.
195+
====
196+
180197

181198

182199
[NOTE]
@@ -204,8 +221,6 @@ Because the `spmpcfg[i].A` field is WARL, an implementation is free to hardwire
204221
+
205222
. This matching is done irrespective of the SHARED, U, R, W, and X bits.
206223
+
207-
. If the effective privilege mode of the access is M, the access is `allowed`.
208-
+
209224
. If the effective privilege mode of the access is S/U and no SPMP entry matches, but at least one SPMP entry is implemented, the access is `denied`.
210225
+
211226
. Otherwise, each access is checked according to the permission bits in the matching SPMP entry. That access is allowed if it satisfies the permission checking with the encoding corresponding to the access type.
@@ -230,7 +245,7 @@ S-mode software can subsequently constrain these permissions by refining the SPM
230245
=== The Access Method for SPMP CSRs in S-mode
231246
Each value of `siselect` maps to a corresponding set of SPMP CSRs.
232247
`sireg` is used to access the `spmpaddr` register, while `sireg2` is used for the `spmpcfg` register.
233-
The registers `sireg3` through `sireg6` are read-only 0.
248+
The registers `sireg3` through `sireg6` are reserved as WPRI.
234249

235250
SPMP entries are indexed starting from zero.
236251
In a system with 48 SPMP entries, S-mode can address `SPMP[0..47]` using `siselect#0..47`.
@@ -249,17 +264,24 @@ An access to an out-of-bounds index via `siselect` will return zero on read and
249264

250265
[NOTE]
251266
====
252-
The rationale for disallowing `siselect` writes to clear a lock bit is to isolate this capability within the `miselect` CSR space, rather than merely differentiating by privilege mode.
253-
254267
The design choice to map only one SPMP entry per `siselect` value is motivated by performance.
255268
Mapping multiple entries would necessitate a jump table or extra logic to select the correct target `sireg` register, adding overhead.
256269
257-
When `spmpcfg1` is written to via `siselect` and `sireg2`, the full SXLEN-bit value is written right-justified, even though the hardware may store the upper bits and lower 8 bits in separate register arrays.
258-
259270
For further details on indirect CSR access, refer to the `Sscsrind` extension specification in the {privspec}.
260271
====
261272

262273

274+
Indirect accesses to SPMP CSRs are not ordered with respect to each other or with subsequent memory accesses.
275+
To enforce ordering, software must execute an `SFENCE.VMA` instruction with `rs1=x0` and `rs2=x0`, which synchronizes subsequent memory accesses with all preceding SPMP CSR writes.
276+
277+
278+
[NOTE]
279+
====
280+
Allowing indirect accesses to SPMP CSRs to be not ordered with respect to each other or to subsequent memory accesses enables fast context switching of SPMP registers.
281+
While `SFENCE.VMA` instructions normally order preceding stores and subsequent implicit accesses to memory management structures, SPMP entries are also effectively regarded as memory management structures.
282+
====
283+
284+
263285
[[exceptions]]
264286
=== Exceptions
265287
A failed SPMP check triggers an exception whose type corresponds to the memory operation (load, store/AMO, or instruction fetch).

0 commit comments

Comments
 (0)