@@ -2304,34 +2304,163 @@ \section{Physical Memory Protection}
23042304\label {sec:pmp }
23052305
23062306To support secure processing and contain faults, it is desirable to
2307- limit the physical addresses accessible by a lower-privilege context
2308- running on a hart. A physical memory protection (PMP) unit can be
2307+ limit the physical addresses accessible by software running on a hart.
2308+ A physical memory protection (PMP) unit can be
23092309provided, with per-hart machine-mode control registers to allow
23102310physical memory access privileges (read, write, execute) to be
23112311specified for each physical memory region. The PMP values are checked
23122312in parallel with the PMA checks described in Section~\ref {sec:pma }.
23132313
2314- The granularity and encoding of the PMP access control settings are
2315- platform-specific, and there might be different granularities and
2316- encodings of permissions for different physical memory regions on a
2317- single platform. Certain regions' privileges can be hardwired---for
2318- example, some regions might only ever be visible in machine mode but
2319- no lower-privilege layers.
2314+ The granularity of PMP access control settings are platform-specific and
2315+ within a platform may vary by physical memory region, but the standard PMP
2316+ encoding supports regions as small as four bytes. Certain regions' privileges
2317+ can be hardwired---for example, some regions might only ever be visible in
2318+ machine mode but no lower-privilege layers.
23202319
23212320\begin {commentary }
23222321Platforms vary widely in demands for physical memory protection, and
2323- so we defer detailed design of PMP structures to each platform. Some
2324- PMP designs might just employ a few CSRs to protect a small number of
2325- physical memory segments, while others might employ memory-resident
2326- protection tables with a protection-table cache indexed by a
2327- protection-table base register to protect large physical memory spaces
2328- with fine granularity. Systems with a protection-table base register
2329- will usually also provide a physical protection domain ID (PDID)
2330- register to denote the current physical protection domain.
2322+ some platforms may provide other PMP structures in addition to or
2323+ instead of the scheme described in this section.
23312324\end {commentary }
23322325
2333- PMP checks are applied to all accesses when the hart is running in H,
2334- S, or U modes, and for loads and stores when the MPRV bit is set in
2326+ PMP checks are applied to all accesses when the hart is running in
2327+ S or U modes, and for loads and stores when the MPRV bit is set in
23352328the {\tt mstatus} register and the MPP field in the {\tt mstatus}
2336- register contains H, S, or U. PMP violations will always be trapped
2337- precisely at the processor.
2329+ register contains S or U. Optionally, PMP checks may additionally
2330+ apply to all M-mode accesses, and the PMP registers themselves may
2331+ be locked so that M-mode software cannot change them without a system
2332+ reset. PMP violations are always trapped precisely at the processor.
2333+
2334+ \subsection {Physical Memory Protection CSRs }
2335+
2336+ PMP configurations are described by an 8-bit configuratoin register and one
2337+ XLEN-bit address register. Some PMP settings additionally use the address
2338+ register associated with the next-lowest numbered PMP entry. Up to 16 PMP
2339+ entries are supported.
2340+
2341+ Figure~\ref {pmpaddr } shows the layout of one of the PMP address registers
2342+ {\tt pmpaddr0}--{\tt pmpaddr15}. A PMP address register encodes
2343+ bits 33--2 of a 34-bit physical address for RV32, and bits 55--2 of a 56-bit
2344+ physical address for RV64.
2345+
2346+ \begin {commentary }
2347+ The Sv32 page-based virtual-memory scheme described in Section~\ref {sec:sv32 }
2348+ supports 34-bit physical addresses for RV32, so the PMP scheme must support
2349+ addresses wider than XLEN for RV32.
2350+ \end {commentary }
2351+
2352+ \begin {figure }[h!]
2353+ {\footnotesize
2354+ \begin {center }
2355+ \begin {tabular }{@{}I@{}I@{}W@{}I@{}I@{}I@{}I@{}I}
2356+ \instbit {7} &
2357+ \instbit {6} &
2358+ \instbitrange {5}{4} &
2359+ \instbit {3} &
2360+ \instbit {2} &
2361+ \instbit {1} &
2362+ \instbit {0} \\
2363+ \hline
2364+ \multicolumn {1}{|c|}{L} &
2365+ \multicolumn {1}{c|}{E} &
2366+ \multicolumn {1}{c|}{A} &
2367+ \multicolumn {1}{c|}{M} &
2368+ \multicolumn {1}{c|}{X} &
2369+ \multicolumn {1}{c|}{W} &
2370+ \multicolumn {1}{c|}{R}
2371+ \\
2372+ \hline
2373+ 1 & 1 & 2 & 1 & 1 & 1 & 1 \\
2374+ \end {tabular }
2375+ \end {center }
2376+ }
2377+ \vspace {-0.1in}
2378+ \caption {PMP configuration register format.}
2379+ \label {pmpcfg }
2380+ \end {figure }
2381+
2382+ Figure~\ref {pmpcfg } shows the layout of a PMP configuration register. The E
2383+ bit indicates this PMP entry is enabled. If E=0, this entry will never match
2384+ an address.
2385+
2386+ The R, W, and X bits, when set, indicate that the PMP entry permits read,
2387+ write, and instruction execution, respectively. When one of these bits is
2388+ clear, the corresponding access type is denied.
2389+
2390+ The M bit indicates whether the PMP entry applies to M-mode. When set, the
2391+ PMP entry is enforced for all privilege modes. When clear, the PMP entry
2392+ applies only to S and U modes.
2393+
2394+ \subsubsection* {Address Matching }
2395+
2396+ The A field in a PMP entry's configuration register encodes the
2397+ address-matching mode of the associated PMP address register. As
2398+ Figure~\ref {pmpcfg-a } shows, two address-matching modes are supported:
2399+ naturally aligned power-of-2 regions (NAPOT), including the special case of
2400+ naturally aligned four-byte regions (NA4); and the top boundary of an
2401+ arbitrary range (TOR). These modes support four-byte granularity.
2402+
2403+ \begin {table* }[h!]
2404+ \begin {center }
2405+ \begin {tabular }{|r|c|l|}
2406+ \hline
2407+ A & Name & Description \\
2408+ \hline
2409+ 0 & NA4 & Naturally aligned four-byte region \\
2410+ 1 & NAPOT & Naturally aligned power-of-two region, $ \ge $ 8 bytes \\
2411+ 2 & TOR & Top of range \\
2412+ 3 & --- & {\em Reserved} \\
2413+ \hline
2414+ \end {tabular }
2415+ \end {center }
2416+ \caption {Encoding of A field in PMP configuration registers.}
2417+ \label {pmpcfg-a }
2418+ \end {table* }
2419+
2420+ Figure~\ref {pmpcfg-napot }
2421+ shows how the configuration and address registers encode naturally aligned
2422+ power-of-2 ranges.
2423+
2424+ If TOR is selected, the associated address register forms the top
2425+ of the address range, and the next-lowest-numbered PMP address register forms
2426+ the bottom of the address range. If PMP entry $ i$ 's A field is set to TOR,
2427+ the entry matches addresses in the range
2428+ $ \left [{\tt pmpaddr}_{i-1},~{\tt pmpaddr}_i\right )$ .
2429+ If PMP entry 0's A field is set to TOR, zero is used for the lower bound,
2430+ such that the entry matches addresses in the range
2431+ $ \left [0 ,~{\tt pmpaddr}_i\right )$ .
2432+
2433+ The PMP configuration registers are densely packed into CSRs to minimize
2434+ context-switch time. For RV32, four CSRs, {\tt pmpcfg0}--{\tt pmpcfg3},
2435+ hold the configuration for the 16 PMP entries, as shown in
2436+ Figure~\ref {pmpcfg-rv32 }. For RV64, {\tt pmpcfg0} and {\tt pmpcfg2} hold
2437+ the configuration settings for the 16 PMP entries, as shown in
2438+ Figure~\ref {pmpcfg-rv64 }.
2439+
2440+ \subsubsection* {Locking }
2441+
2442+ The L bit in a PMP entry's configuration register indicates that this entry is
2443+ locked, i.e., writes to this PMP entry and associated address registers are
2444+ ignored. Locked PMPs may only be unlocked with a system reset.
2445+
2446+ If PMP entry $ i$ is locked, writes to its configuration register and writes
2447+ to {\tt pmpaddr}$ i$ are ignored. Additionally, if PMP entry $ i$ 's A field
2448+ is set to TOR, writes to {\tt pmpaddr}$ i-1 $ are ignored.
2449+
2450+ \subsubsection* {Priority and Matching Logic }
2451+
2452+ PMP entries are statically prioritized. The lowest-numbered PMP entry that
2453+ matches any byte of an access determines whether that access succeeds or
2454+ fails. The matching PMP entry must match all bytes of an access, or the
2455+ access fails, irrespective of the M, R, W, and X bits. For example, if a PMP
2456+ entry is configured to match the four-byte range {\tt 0xC}--{\tt 0xF}, then an
2457+ 8-byte access to the range {\tt 0x8}--{\tt 0xF} will match with that PMP
2458+ entry, but the access will fail.
2459+
2460+ If a PMP entry matches all bytes of an access, then the M, R, W, and X bits
2461+ determine whether the access succeeds or fails. If the M bit is clear,
2462+ any matching M-mode access will succeed. Otherwise, if the M bit is set
2463+ or the privilege mode of the access is S or U, then the access succeeds
2464+ if and only if the corresponding R, W, or X bit is set.
2465+
2466+ Failed accesses generate a load, store, or instruction access exception.
0 commit comments