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
+19-11Lines changed: 19 additions & 11 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 (<<S-level_Physical_Memory_Protection>>) in conjunction with M-mode (i.e., `Sm1p13`).*
8
8
To streamline the specification and reduce optional features, the `Smpmpdeleg` extension mandates a total of 64 PMP entries.
9
9
However, an implementation retains the flexibility to provide fewer physical entries; any unimplemented entries behave as read-only zero.
10
10
@@ -21,7 +21,7 @@ All PMP entries with an index equal to or greater than `pmpnum` are delegated as
21
21
. If a write to `pmpnum` specifies a value exceeding the number of physically implemented PMP entries, the field subsequently reads back the total count of implemented entries.
22
22
. Setting `pmpnum` to zero delegates all PMP entries to SPMP, while setting it to the total number of entries delegates none.
23
23
. By default, unless hardwired, `pmpnum` resets to the total number of implemented PMP entries.
24
-
. If no entries are delegated to SPMP, the `Sspmp` extension is effectively disabled, and any attempt to access SPMP-related registers results in an illegal instruction exception.
24
+
. If no entries are delegated to SPMP, the `Sspmp` extension is effectively disabled, and any attempt to access SPMP-related registers results in reads returning zero, and writes being ignored.
25
25
26
26
27
27
[[mpmpdeleg_format_rv64]]
@@ -40,17 +40,18 @@ The `mpmpdeleg.pmpnum` field is a WARL field, which allows an implementation to
40
40
Both PMP and SPMP entries are indexed starting from zero.
41
41
For example, in an implementation with 64 total entries where `pmpnum` is configured to 16:
42
42
43
-
. PMP entries 0 through 15 acts 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
+
. 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).
44
44
. 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>>).
45
45
. 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.
46
46
47
47
48
48
49
-
*Re-configuration:*
49
+
*Reconfiguration:*
50
50
51
51
. M-mode software can dynamically adjust the allocation between PMP and SPMP by writing to the `mpmpdeleg` CSR.
52
52
. The `pmpnum` value cannot be set to an index that is less than or equal to that of any locked PMP entry.
53
53
For instance, if `PMP[7]` is locked, any attempt to write a value less than 8 to `pmpnum` is ignored, and the field retains its prior value.
54
+
. The `pmpnum` value can be set to override locked SPMP entries. For example, if `SPMP[0]` is locked, M-mode software can still increment `pmpnum`.
54
55
55
56
56
57
[[m_mode_indirect_access]]
@@ -62,9 +63,6 @@ Delegated SPMP entries, however, are accessed indirectly using the `xiselect` CS
62
63
For these indirect accesses, `miselect` selects the target SPMP entry, `mireg` accesses its `spmpaddr` register, and `mireg2` accesses its `spmpcfg` register.
63
64
The `mireg3` through `mireg6` are read-only 0.
64
65
65
-
The architecture does not guarantee ordering between consecutive indirect writes to SPMP CSRs.
66
-
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.
67
-
68
66
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`.
69
67
70
68
The view provided by `miselect` is identical to that of `siselect` (see <<access_method>>).
@@ -74,10 +72,20 @@ Any access attempt by either mode to an index outside this range (i.e., `i >= 48
74
72
75
73
[cols="^1,^2",stripes=even, options="header"]
76
74
|===
77
-
|`miselect` number| indirect CSR access of `mireg`
Indirect accesses to SPMP CSRs are not ordered with respect to each other or with subsequent memory accesses.
84
+
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.
85
+
86
+
87
+
[NOTE]
88
+
====
89
+
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.
90
+
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.
Copy file name to clipboardExpand all lines: sspmp/guidelines.adoc
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,11 +59,11 @@ For each relevant `spmpcfg[i]` field:
59
59
[NOTE]
60
60
====
61
61
SPMP entries configured to protect the supervisor, which are identified by `spmpcfg[i].U == 0`, should be treated as resident.
62
-
It is highly recommended not to reprogram these entries during the context switch procedure.
62
+
It is highly recommended that these entries not be reprogrammed during the context switch procedure.
63
63
Keeping supervisor entries persistent minimizes reconfiguration overhead and guarantees the consistent enforcement of supervisor memory protection.
64
64
====
65
65
66
-
=== Entry Configuration Recomendations
66
+
=== Entry Configuration Recommendations
67
67
68
68
Programming SPMP entries involves a trade-off between the Naturally Aligned Power-of-Two (NAPOT) and Top-of-Range (TOR) address-matching modes (see <<address_matching>>).
69
69
@@ -90,7 +90,7 @@ This strategy, which corresponds to an ascending order of priority, permits the
90
90
Adhering to this structured approach with TOR-mode entries fosters clearer isolation boundaries, minimizes the risk of configuration errors, and enhances the runtime flexibility of the memory protection scheme.
91
91
92
92
93
-
=== Re-configuration Non-preemption and Synchronization
93
+
=== Reconfiguration Non-preemption and Synchronization
94
94
95
95
To maintain the integrity of the SPMP configuration, the entire reconfiguration sequence during a context switch must execute atomically as a non-preemptible critical section.
96
96
This is necessary because the process involves modifications to multiple CSRs, and any interruption could leave the system in an inconsistent or insecure state.
Copy file name to clipboardExpand all lines: sspmp/spmp_spec.adoc
+13-21Lines changed: 13 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ 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.
11
11
12
-
SPMP checks are enforced on all memory accesses originating from effective privilege modes less privileged than M-mode.
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
15
@@ -34,10 +34,6 @@ The following table dictates which isolation mechanism is active based on the sa
34
34
35
35
=== Extension Dependencies
36
36
37
-
. The SPMP is dependent on `Ss1p13`.
38
-
+
39
-
. The `Smpmpdeleg` extension is mandatory if M-mode (i.e., `Sm1p13`) is implemented.
40
-
+
41
37
. The `Sscsrind` extension for indirect CSR access must be implemented.
42
38
+
43
39
. 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.
Every SPMP entry contains a 16-bit configuration field, `spmpcfg[i]`.
85
81
Its lower 8 bits are an alias for the 8-bit field of the corresponding PMP configuration register.
86
-
Figure <<spmpcfg>> illustrates the layout of `spmpcfg[i]`.
82
+
<<spmpcfg>> illustrates the layout of `spmpcfg[i]`.
87
83
Permission rules and their encodings are detailed in <<encoding>>.
88
84
89
85
. The R, W, and X bits govern permissions for read, write, and instruction execution, respectively.
@@ -95,7 +91,7 @@ Modifications to locked `spmpcfg[i]` and `spmpaddr[i]` registers are only permit
95
91
Attempts to write to locked `spmpcfg[i]` and `spmpaddr[i]` registers using the `siselect` CSR are ignored, irrespective of privilege level.
96
92
If a locked entry has `spmpcfg[i].A` set to TOR, writes to the preceding `spmpaddr[i-1]` via `siselect` are also ignored.
97
93
. If locking is not a required feature, an implementation can hardwire the L bit to 0.
98
-
. For any rule not designated as a `Shared-Region`, the U bit determines if it is `U-mode-only` (when set) or `S-mode-only` (when clear), as explained in <<encoding>>.
94
+
. 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>>.
99
95
. The SHARED bit identifies a rule as a `Shared-Region` rule.
100
96
101
97
@@ -119,15 +115,15 @@ Moreover, if resource sharing is statically defined (e.g., `mpmpdeleg.pmpnum` is
119
115
=== Encoding of Permissions
120
116
121
117
122
-
SPMP supports three distinct rule types: *S-mode-only*, *U-mode-only* and *Shared-Region*.
118
+
SPMP supports three distinct rule types: *S-mode-only*, *U-mode* and *Shared-Region*.
123
119
124
120
. An *S-mode-only* rule is *enforced* for accesses from Supervisor mode and *denied* for accesses from User mode.
125
121
+
126
-
. A *U-mode-only* rule is always enforced for User mode accesses. Its behavior for Supervisor mode accesses depends on the `sstatus.SUM` bit.
122
+
. A *U-mode* rule is always enforced for User mode accesses. Its behavior for Supervisor mode accesses depends on the `sstatus.SUM` bit.
127
123
+
128
-
* With `sstatus.SUM` set, the rule is enforced for Supervisor mode data accesses, but execution permission is denied (termed *EnforceNoX* in <<spmpencode>>). This behavior provides a Supervisor Memory Execution Prevention (SMEP) guarantee.
124
+
* With `sstatus.SUM` set, the rule is enforced for Supervisor mode data accesses, but execution permission is denied (termed *EnforceNoX* in <<spmpencode>>). This prevents the OS from executing the memory of an unprivileged process at all times.
129
125
+
130
-
* With `sstatus.SUM` clear, the rule is denied for any Supervisor mode access. This provides a Supervisor Memory Access Prevention (SMAP) guarantee.
126
+
* With `sstatus.SUM` clear, the rule is denied for any Supervisor mode access. This prevents the OS from accessing the memory of an unprivileged process unless a specific code path is followed.
131
127
+
132
128
. The encoding `spmpcfg.SHARED == 1 and spmpcfg.U == 1` defines a *Shared-Region* rule. For shared regions, the state of the `sstatus.SUM` bit is irrelevant.
133
129
+
@@ -227,28 +223,24 @@ Each value of `siselect` maps to a corresponding set of SPMP CSRs.
227
223
`sireg` is used to access the `spmpaddr` register, while `sireg2` is used for the `spmpcfg` register.
228
224
The registers `sireg3` through `sireg6` are read-only 0.
229
225
230
-
S-mode software can lock an SPMP entry by setting its `spmpcfg[i].L` bit.
231
-
Once `spmpcfg[i].L` is set, any attempt to write to that SPMP entry via `siselect` is ignored, regardless of the privilege mode.
232
-
The lock bit `spmpcfg[i].L` can only be cleared by an execution environment access using `miselect` (see <<m_mode_indirect_access>>).
233
-
234
226
SPMP entries are indexed starting from zero.
235
227
In a system with 48 SPMP entries, S-mode can address `SPMP[0..47]` using `siselect#0..47`.
236
228
An access to an out-of-bounds index via `siselect` will return zero on read and be ignored on write.
237
229
238
230
239
-
231
+
<<<
240
232
[cols="^1,^2",stripes=even, options="header"]
241
233
|===
242
-
|`siselect` number| indirect CSR access of `sireg`
The rationale for disallowing `siselect` writes to clear a lock bit is to isolate this capability within the `miselect` CSR space, rather than differentiating it merely by privilege mode.
243
+
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.
252
244
253
245
The design choice to map only one SPMP entry per `siselect` value is motivated by performance.
254
246
Mapping multiple entries would necessitate a jump table or extra logic to select the correct target `sireg` register, adding overhead.
0 commit comments