You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sspmp/spmp_spec.adoc
+54-32Lines changed: 54 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
The RISC-V S-level Physical Memory Protection (SPMP) mechanism provides per-hart control registers in supervisor mode.
5
5
These registers define physical memory access privileges—read, write, and execute—for discrete physical memory regions.
6
6
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.
8
8
SPMP checks can be performed by the hardware in parallel with PMA and PMP checks.
9
9
SPMP exceptions take priority over PMP or PMA exceptions.
10
10
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
13
13
SPMP can be configured to grant permissions to U-mode, which has none by default, and to revoke permissions from S-mode.
14
14
15
15
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.
17
17
18
18
19
19
[[spmp-and-paging]]
20
20
=== 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:
22
23
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.
26
27
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.
28
29
29
30
30
31
[cols="^1,^1", stripes=even, options="header"]
31
32
|===
32
33
|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
35
37
|===
36
38
37
39
38
40
=== Extension Dependencies
39
41
40
42
. The `Sscsrind` extension for indirect CSR access must be implemented.
41
43
+
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.
43
45
+
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`.
45
47
+
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
+
====
47
56
48
57
49
58
[[spmp_csrs]]
50
59
=== S-level Physical Memory Protection CSRs
51
60
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.
53
61
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>>.
55
64
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.
57
66
58
67
59
68
[NOTE]
@@ -62,17 +71,13 @@ An SPMP entry refers to the register pair `spmpcfg[i]` and `spmpaddr[i]`.
62
71
63
72
An SPMP rule is defined by the contents of an `spmpcfg` register and its corresponding `spmpaddr` register(s).
64
73
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.
69
74
====
70
75
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.
72
77
On RV32 systems, each `spmpaddr` register encodes a 34-bit physical address from bit 33 down to bit 2, as illustrated in <<spmpaddr-rv32>>.
73
78
On RV64 systems, each `spmpaddr` register encodes a 56-bit physical address from bit 55 down to bit 2, as shown in <<spmpaddr-rv64>>.
74
79
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.
76
81
Since not all physical address bits must be implemented, the SPMP address registers are considered WARL, with exceptions defined by granularity rules.
77
82
Refer to the {privspec}, Section 3.7: Physical Memory Protection, Address Matching.
// Every SPMP entry contains a 16-bit configuration field, `spmpcfg[i]`.
89
93
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.
91
95
<<spmpcfg>> illustrates the layout of `spmpcfg[i]`.
92
96
Permission rules and their encodings are detailed in <<encoding>>.
93
97
@@ -96,7 +100,7 @@ Permission rules and their encodings are detailed in <<encoding>>.
96
100
. Bits 5 and 6 are reserved for future standard use.
97
101
. The L (lock) bit designates an entry as locked.
98
102
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.
100
104
If a locked entry has `spmpcfg[i].A` set to TOR, writes to the preceding `spmpaddr[i-1]` via `siselect` are also ignored.
101
105
. If locking is not a required feature, an implementation can hardwire the L bit to 0.
102
106
. 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
125
129
126
130
SPMP supports three distinct rule types: *S-mode-only*, *U-mode* and *Shared-Region*.
127
131
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.
129
133
+
130
134
. A *U-mode* rule is always enforced for User mode accesses. Its behavior for Supervisor mode accesses depends on the `sstatus.SUM` bit.
*Reserved*: This encoding is reserved for future standard use.
158
162
159
163
*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
+
====
160
167
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
+
====
161
169
162
170
163
171
[[address_matching]]
@@ -175,8 +183,17 @@ The following table details the A field's encoding.
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
+
====
178
193
This encoding is consistent with the PMP/ePMP.
179
194
For comprehensive details, refer to the "Address Matching" subsection for PMP in the {privspec}.
195
+
====
196
+
180
197
181
198
182
199
[NOTE]
@@ -204,8 +221,6 @@ Because the `spmpcfg[i].A` field is WARL, an implementation is free to hardwire
204
221
+
205
222
. This matching is done irrespective of the SHARED, U, R, W, and X bits.
206
223
+
207
-
. If the effective privilege mode of the access is M, the access is `allowed`.
208
-
+
209
224
. 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`.
210
225
+
211
226
. 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
230
245
=== The Access Method for SPMP CSRs in S-mode
231
246
Each value of `siselect` maps to a corresponding set of SPMP CSRs.
232
247
`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.
234
249
235
250
SPMP entries are indexed starting from zero.
236
251
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
249
264
250
265
[NOTE]
251
266
====
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
-
254
267
The design choice to map only one SPMP entry per `siselect` value is motivated by performance.
255
268
Mapping multiple entries would necessitate a jump table or extra logic to select the correct target `sireg` register, adding overhead.
256
269
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
-
259
270
For further details on indirect CSR access, refer to the `Sscsrind` extension specification in the {privspec}.
260
271
====
261
272
262
273
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
+
263
285
[[exceptions]]
264
286
=== Exceptions
265
287
A failed SPMP check triggers an exception whose type corresponds to the memory operation (load, store/AMO, or instruction fetch).
0 commit comments