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/Resource_Sharing.adoc
+13-13Lines changed: 13 additions & 13 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 similar architecture of PMP and SPMP registers, including their shared address-matching logic, makes hardware reuse a practical approach for resource conservation.
5
5
This chapter introduces the `Smpmpdeleg` extension, a mechanism that allows hardware resources to be dynamically allocated between PMP and SPMP.
6
6
7
-
*This extension is mandatory for implementations that support Sspmp (<<S-level_Physical_Memory_Protection>>) in conjunction with M-mode (i.e., `Sm1p13`).*
7
+
*This extension is mandatory for implementations that support Sspmp in conjunction with M-mode (i.e., `Sm1p13`).*
8
8
To streamline the specification and reduce optional features, the `Smpmpdeleg` extension implements 64 PMP entries, but fewer can be writable; any non-writable entries behave as read-only zero.
9
9
10
10
@@ -40,12 +40,17 @@ Both PMP and SPMP entries are indexed starting from zero.
40
40
For example, in an implementation with 64 total entries where `pmpnum` is configured to 16:
41
41
42
42
. PMP entries 0 through 15 act as PMP (i.e., `PMP[0..15]`) and are accessible via standard PMP CSRs (i.e., `pmpcfg[0..3]` and `pmpaddr[0..15]` for RV32; `pmpcfg[0,2]` and `pmpaddr[0..15]` for RV64).
43
-
. The remaining 48 entries are delegated as SPMP (i.e., `SPMP[0..47]`) and are indirectly accessed via `xiselect` (see <<m_mode_indirect_access>> and <<access_method>>).
43
+
. The remaining 48 entries are delegated as SPMP (i.e., `SPMP[0..47]`) and are indirectly accessed via `xiselect` (see <<access_method>> and <<m_mode_indirect_access>>).
44
44
. Accesses to out-of-range indices, such as reading `PMP[16]` or writing to `SPMP[48]` in this scenario, are handled as follows: reads return zero, and writes are ignored.
45
45
46
46
47
+
*Configuration registers:*
47
48
48
-
*Reconfiguration:*
49
+
The configuration register `spmpcfg[i]` of an SPMP entry is SXLEN-bit.
50
+
Its lower 8 bits are an alias for the 8-bit field in the corresponding M-mode PMP configuration register.
51
+
52
+
53
+
*Reconfiguration of delegated entries:*
49
54
50
55
. M-mode software can dynamically adjust the allocation between PMP and SPMP by writing to the `mpmpdeleg` CSR.
51
56
. The `pmpnum` value cannot be set to an index that is less than or equal to that of any locked PMP entry.
@@ -60,9 +65,9 @@ PMP entries are accessed directly through their dedicated CSRs (i.e., `pmpcfg` a
60
65
Delegated SPMP entries, however, are accessed indirectly using the `xiselect` CSR (i.e., `siselect` and `miselect`).
61
66
62
67
For these indirect accesses, `miselect` selects the target SPMP entry, `mireg` accesses its `spmpaddr` register, and `mireg2` accesses its `spmpcfg` register.
63
-
The `mireg3` through `mireg6` are read-only 0.
68
+
The `mireg3` through `mireg6` are reserved as WPRI.
64
69
65
-
The lock bit (`spmpcfg[i].L`) of an SPMP entry can only be cleared by the execution environment (M-mode in this case) through an indirect access using `miselect`.
70
+
The lock bit (`spmpcfg[i].L`) of an SPMP entry can only be cleared by M-mode through an indirect access using `miselect`.
66
71
67
72
The view provided by `miselect` is identical to that of `siselect` (see <<access_method>>).
68
73
For instance, if 48 out of 64 entries are delegated, both S-mode (via `siselect` indices 0-47) and M-mode (via `siselect` or `miselect` indices 0-47) can access `SPMP[0..47]`.
@@ -79,12 +84,7 @@ Any access attempt by either mode to an index outside this range (i.e., `i >= 48
79
84
|===
80
85
81
86
82
-
Indirect accesses to SPMP CSRs are not ordered with respect to each other or with subsequent memory accesses.
83
-
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.
84
-
87
+
*Memory access in M-mode:*
88
+
If the effective privilege mode of the memory access is M, the access is `allowed` regardless of the SPMP permissions.
85
89
86
-
[NOTE]
87
-
====
88
-
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.
89
-
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.
90
-
====
90
+
If the Hypervisor Extension is implemented in conjunction with `Sspmp`, then when V = 1 and hgatp.MODE = Bare, the Hypervisor Virtual Machine Load and Store instructions (HLV, HLVX, HSV) executed from M-mode are subject to SPMP checks.
Copy file name to clipboardExpand all lines: sspmp/spmp_spec.adoc
+59-73Lines changed: 59 additions & 73 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,29 +12,8 @@ Consequently, if a memory access violates both SPMP and PMP/PMA rules, only the
12
12
SPMP checks are enforced on all memory accesses with effective privilege modes less privileged than M-mode.
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
-
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 the execution environment, HS-mode, or U-mode (when hstatus.HU = 1), are also subject to SPMP checks under the V = 1 condition.
17
-
18
-
19
-
[[spmp-and-paging]]
20
-
=== SPMP and Paging
21
-
SPMP and paged virtual memory are mutually exclusive.
22
-
// and cannot be enabled concurrently for two primary reasons:
23
-
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.
27
-
28
-
The following table dictates which isolation mechanism is active based on the satp configuration.
29
-
30
-
31
-
[cols="^1,^1", stripes=even, options="header"]
32
-
|===
33
-
|satp|Isolation mechanism
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
37
-
|===
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 the HS-mode, or U-mode (when hstatus.HU = 1), are also subject to SPMP checks under the V = 1 condition.
38
17
39
18
40
19
=== Extension Dependencies
@@ -45,8 +24,7 @@ The following table dictates which isolation mechanism is active based on the sa
45
24
+
46
25
. 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`.
47
26
+
48
-
. If the Hypervisor Extension is implemented in conjunction with Sspmp, the only mandatory translation mode in both hgatp and satp is Bare.
49
-
27
+
. If the Hypervisor Extension is implemented in conjunction with `Sspmp`, the only mandatory translation mode in both hgatp and satp is Bare.
50
28
51
29
52
30
[NOTE]
@@ -73,10 +51,10 @@ An SPMP rule is defined by the contents of an `spmpcfg` register and its corresp
73
51
These registers collectively define a protected physical memory region and its access constraints.
74
52
====
75
53
76
-
The SPMP address registers, named `spmpaddr0` through `spmpaddr63`, share the same layout as the machine-mode PMP architecture.
54
+
The SPMP address registers, named `spmpaddr0` through `spmpaddr63`, share the same layout as the M-mode PMP architecture.
77
55
On RV32 systems, each `spmpaddr` register encodes a 34-bit physical address from bit 33 down to bit 2, as illustrated in <<spmpaddr-rv32>>.
78
56
On RV64 systems, each `spmpaddr` register encodes a 56-bit physical address from bit 55 down to bit 2, as shown in <<spmpaddr-rv64>>.
79
-
An implementation may support fewer address bits, particularly on systems with a smaller physical address space.
57
+
An implementation may support fewer address bits on systems with a smaller physical address space.
80
58
All writable SPMP entries should implement the same number of address bits.
81
59
Since not all physical address bits must be implemented, the SPMP address registers are considered WARL, with exceptions defined by granularity rules.
82
60
Refer to the {privspec}, Section 3.7: Physical Memory Protection, Address Matching.
Every SPMP entry contains an SXLEN-bit configuration register, `spmpcfg[i]`.
94
-
// Its lower 8 bits are an alias for the 8-bit field of the corresponding PMP configuration register.
95
72
<<spmpcfg>> illustrates the layout of `spmpcfg[i]`.
96
73
Permission rules and their encodings are detailed in <<encoding>>.
97
74
@@ -118,9 +95,45 @@ M-mode can leverage the L bit to create a sandbox for S-mode software.
118
95
This is achieved by setting and locking high-priority SPMP entries where `spmpcfg[i].U` is 1.
119
96
This mechanism effectively thwarts privilege escalation attacks that might try to reconfigure SPMP entries to bypass S-mode restrictions.
120
97
While PMP/ePMP entries could offer a similar function, the resulting configuration is not identical because PMP does not distinguish between S-mode and U-mode.
121
-
Moreover, if resource sharing is statically defined (e.g., `mpmpdeleg.pmpnum` is hardwired, see <<PMP_Entry_Sharing>>), there might not be enough PMP/ePMP entries to enforce the intended isolation policy.
98
+
Moreover, if resource sharing is statically defined (see <<PMP_Entry_Sharing>>), there might not be enough PMP/ePMP entries to enforce the intended isolation policy.
99
+
====
100
+
101
+
102
+
[[address_matching]]
103
+
=== Address Matching
104
+
105
+
The A field within an SPMP entry's configuration register determines the address-matching mode for its associated spmpaddr register.
106
+
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
-
====
193
-
This encoding is consistent with the PMP/ePMP.
194
-
For comprehensive details, refer to the "Address Matching" subsection for PMP in the {privspec}.
195
-
====
196
-
197
-
198
-
199
-
[NOTE]
200
-
====
201
-
Software can probe the minimum SPMP granularity.
202
-
This is done by clearing `spmpcfg[i]`, writing all ones to `spmpaddr[i]`, and then reading back the resulting `spmpaddr[i]` value.
203
-
If asciimath:[G] is the index of the least-significant bit set in the result, the granularity is asciimath:[2^{G+2}] bytes.
204
-
205
-
Software can also determine the implemented physical address bits in `spmpaddr`.
206
-
This involves setting `spmpcfg[i].A` to `0b11`, writing all ones to `spmpaddr[i]`, and reading back the result.
207
-
(Consult the "NAPOT range encoding in PMP address and configuration registers" table in the {privspec} for interpretation.)
208
-
209
-
Because the `spmpcfg[i].A` field is WARL, an implementation is free to hardwire a specific address-matching mode.
210
-
====
211
-
212
-
213
184
=== Matching Logic
214
-
215
-
216
185
. SPMP entries are statically prioritized.
217
186
+
218
187
. The lowest-numbered SPMP entry that matches any byte of an access (indicated by an address and the accessed length) determines whether that access is allowed or denied.
@@ -241,6 +210,23 @@ S-mode software can subsequently constrain these permissions by refining the SPM
241
210
====
242
211
243
212
213
+
[[spmp-and-paging]]
214
+
=== SPMP and Paging
215
+
SPMP and paged virtual memory are mutually exclusive.
216
+
217
+
The following table dictates which isolation mechanism is active based on the satp configuration.
218
+
219
+
220
+
[cols="^1,^1", stripes=even, options="header"]
221
+
|===
222
+
|satp|Isolation mechanism
223
+
|satp.mode == Bare with Sspmp |SPMP only
224
+
|satp.mode == Bare without Sspmp|no S-mode protection checks
225
+
|satp.mode != Bare |Paged Virtual Memory only
226
+
|===
227
+
228
+
229
+
244
230
[[access_method]]
245
231
=== The Access Method for SPMP CSRs in S-mode
246
232
Each value of `siselect` maps to a corresponding set of SPMP CSRs.
0 commit comments