Skip to content

Commit b2b8d22

Browse files
authored
Merge pull request #72 from ybc-alkaid/main
Polish the specification.
2 parents e099adb + 9ac622a commit b2b8d22

File tree

6 files changed

+39
-39
lines changed

6 files changed

+39
-39
lines changed

rv-spmp-spec.pdf

3.92 KB
Binary file not shown.

sspmp/Resource_Sharing.adoc

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
The similar architecture of PMP and SPMP registers, including their shared address-matching logic, makes hardware reuse a practical approach for resource conservation.
55
This chapter introduces the `Smpmpdeleg` extension, a mechanism that allows hardware resources to be dynamically allocated between PMP and SPMP.
66

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`).*
88
To streamline the specification and reduce optional features, the `Smpmpdeleg` extension mandates a total of 64 PMP entries.
99
However, an implementation retains the flexibility to provide fewer physical entries; any unimplemented entries behave as read-only zero.
1010

@@ -21,7 +21,7 @@ All PMP entries with an index equal to or greater than `pmpnum` are delegated as
2121
. 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.
2222
. Setting `pmpnum` to zero delegates all PMP entries to SPMP, while setting it to the total number of entries delegates none.
2323
. 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.
2525

2626

2727
[[mpmpdeleg_format_rv64]]
@@ -40,17 +40,18 @@ The `mpmpdeleg.pmpnum` field is a WARL field, which allows an implementation to
4040
Both PMP and SPMP entries are indexed starting from zero.
4141
For example, in an implementation with 64 total entries where `pmpnum` is configured to 16:
4242

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).
4444
. 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>>).
4545
. 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.
4646

4747

4848

49-
*Re-configuration:*
49+
*Reconfiguration:*
5050

5151
. M-mode software can dynamically adjust the allocation between PMP and SPMP by writing to the `mpmpdeleg` CSR.
5252
. The `pmpnum` value cannot be set to an index that is less than or equal to that of any locked PMP entry.
5353
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`.
5455

5556

5657
[[m_mode_indirect_access]]
@@ -62,9 +63,6 @@ Delegated SPMP entries, however, are accessed indirectly using the `xiselect` CS
6263
For these indirect accesses, `miselect` selects the target SPMP entry, `mireg` accesses its `spmpaddr` register, and `mireg2` accesses its `spmpcfg` register.
6364
The `mireg3` through `mireg6` are read-only 0.
6465

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-
6866
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`.
6967

7068
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
7472

7573
[cols="^1,^2",stripes=even, options="header"]
7674
|===
77-
|`miselect` number| indirect CSR access of `mireg`
78-
|`miselect#0`|`mireg` -> `spmpaddr[0]`, `mireg2` -> `spmpcfg[0]`
79-
|`miselect#1`|`mireg` -> `spmpaddr[1]`, `mireg2` -> `spmpcfg[1]`
75+
|`miselect` value| indirect CSR access of `mireg`
76+
|`0x100`|`mireg` -> `spmpaddr[0]`, `mireg2` -> `spmpcfg[0]`
77+
|`0x101`|`mireg` -> `spmpaddr[1]`, `mireg2` -> `spmpcfg[1]`
8078
| ... | ...
81-
|`miselect#63`|`mireg` -> `spmpaddr[63]`, `mireg2` -> `spmpcfg[63]`
79+
|`0x13F`|`mireg` -> `spmpaddr[63]`, `mireg2` -> `spmpcfg[63]`
8280
|===
8381

82+
83+
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.
91+
====

sspmp/guidelines.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ For each relevant `spmpcfg[i]` field:
5959
[NOTE]
6060
====
6161
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.
6363
Keeping supervisor entries persistent minimizes reconfiguration overhead and guarantees the consistent enforcement of supervisor memory protection.
6464
====
6565

66-
=== Entry Configuration Recomendations
66+
=== Entry Configuration Recommendations
6767

6868
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>>).
6969

@@ -90,7 +90,7 @@ This strategy, which corresponds to an ascending order of priority, permits the
9090
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.
9191

9292

93-
=== Re-configuration Non-preemption and Synchronization
93+
=== Reconfiguration Non-preemption and Synchronization
9494

9595
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.
9696
This is necessary because the process involves modifications to multiple CSRs, and any interruption could leave the system in an inconsistent or insecure state.

sspmp/header.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[[header]]
22
:description: RISC-V S-level Physical Memory Protection (Sspmp)
33
:company: RISC-V.org
4-
:revdate: 10/2025
5-
:revnumber: 1.0.0-rc4
4+
:revdate: 11/2025
5+
:revnumber: 1.0.0-rc5
66
:revremark: This document is in development. Assume everything can change. See http://riscv.org/spec-state for details.
77
:url-riscv: http://riscv.org
88
:doctype: book
@@ -70,7 +70,7 @@ include::spmpswitch.adoc[]
7070
// include::Summary_of_Hardware_Changes.adoc[]
7171
include::guidelines.adoc[]
7272
// include::Interaction_with_hypervisor_extension.adoc[]
73-
include::Interaction_with_other_proposals.adoc[]
73+
// include::Interaction_with_other_proposals.adoc[]
7474
//the index must precede the bibliography
7575
// include::index.adoc[]
7676
// include::bibliography.adoc[]

sspmp/spmp_spec.adoc

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ 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.
1111

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.
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

@@ -34,10 +34,6 @@ The following table dictates which isolation mechanism is active based on the sa
3434

3535
=== Extension Dependencies
3636

37-
. The SPMP is dependent on `Ss1p13`.
38-
+
39-
. The `Smpmpdeleg` extension is mandatory if M-mode (i.e., `Sm1p13`) is implemented.
40-
+
4137
. The `Sscsrind` extension for indirect CSR access must be implemented.
4238
+
4339
. 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.
@@ -83,7 +79,7 @@ include::images/bytefield/spmpaddr-rv64.adoc[]
8379

8480
Every SPMP entry contains a 16-bit configuration field, `spmpcfg[i]`.
8581
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]`.
8783
Permission rules and their encodings are detailed in <<encoding>>.
8884

8985
. 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
9591
Attempts to write to locked `spmpcfg[i]` and `spmpaddr[i]` registers using the `siselect` CSR are ignored, irrespective of privilege level.
9692
If a locked entry has `spmpcfg[i].A` set to TOR, writes to the preceding `spmpaddr[i-1]` via `siselect` are also ignored.
9793
. 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>>.
9995
. The SHARED bit identifies a rule as a `Shared-Region` rule.
10096

10197

@@ -119,15 +115,15 @@ Moreover, if resource sharing is statically defined (e.g., `mpmpdeleg.pmpnum` is
119115
=== Encoding of Permissions
120116

121117

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*.
123119

124120
. An *S-mode-only* rule is *enforced* for accesses from Supervisor mode and *denied* for accesses from User mode.
125121
+
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.
127123
+
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.
129125
+
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.
131127
+
132128
. 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.
133129
+
@@ -227,28 +223,24 @@ Each value of `siselect` maps to a corresponding set of SPMP CSRs.
227223
`sireg` is used to access the `spmpaddr` register, while `sireg2` is used for the `spmpcfg` register.
228224
The registers `sireg3` through `sireg6` are read-only 0.
229225

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-
234226
SPMP entries are indexed starting from zero.
235227
In a system with 48 SPMP entries, S-mode can address `SPMP[0..47]` using `siselect#0..47`.
236228
An access to an out-of-bounds index via `siselect` will return zero on read and be ignored on write.
237229

238230

239-
231+
<<<
240232
[cols="^1,^2",stripes=even, options="header"]
241233
|===
242-
|`siselect` number| indirect CSR access of `sireg`
243-
|`siselect#0`|`sireg` -> `spmpaddr[0]`, `sireg2` -> `spmpcfg[0]`
244-
|`siselect#1`|`sireg` -> `spmpaddr[1]`, `sireg2` -> `spmpcfg[1]`
234+
|`siselect` value| indirect CSR access of `sireg`
235+
|`0x100`|`sireg` -> `spmpaddr[0]`, `sireg2` -> `spmpcfg[0]`
236+
|`0x101`|`sireg` -> `spmpaddr[1]`, `sireg2` -> `spmpcfg[1]`
245237
| ... | ...
246-
|`siselect#63`|`sireg` -> `spmpaddr[63]`, `sireg2` -> `spmpcfg[63]`
238+
|`0x13F`|`sireg` -> `spmpaddr[63]`, `sireg2` -> `spmpcfg[63]`
247239
|===
248240

249241
[NOTE]
250242
====
251-
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.
252244
253245
The design choice to map only one SPMP entry per `siselect` value is motivated by performance.
254246
Mapping multiple entries would necessitate a jump table or extra logic to select the correct target `sireg` register, adding overhead.

sspmp/spmpswitch.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[[Sspmpsw_extension]]
22
== "Sspmpsw" Extension for Optimizing Context Switching of SPMP Entries
33

4-
In RV64, a context switch for the SPMP mechanism involves updating as many as 64 address registers and 8 configuration registers.
4+
In RV64, a context switch for the SPMP mechanism involves updating as many as 64 address registers and configuration registers.
55
The `Sspmpsw` extension, introduced in this chapter, is an optional feature designed to enhance the performance of SPMP context switches.
66

77
* For RV64 architectures, it introduces a 64-bit WARL CSR, `sspmpswitch`.

0 commit comments

Comments
 (0)