Skip to content

Commit 5c80367

Browse files
clarify PTE fault exception priority, and add into instruction pages (#485)
Fixes #484 --------- Signed-off-by: Tariq Kurd <tariqandlaura@gmail.com>
1 parent a7ab1b2 commit 5c80367

5 files changed

+54
-14
lines changed

src/cheri-pte-ext.adoc

+8-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ If the CW bit is clear then:
100100

101101
* When a capability load or AMO instruction is executed, the implementation
102102
clears the tag bit of the capability read from the virtual page.
103-
* When CRG is clear, the "no capability state", a store page fault exception
103+
* When CRG is clear, the "no capability state", a store/AMO page fault exception
104104
is raised when a capability store or AMO instruction is executed and the tag bit
105105
of the capability being written is set.
106106
* When CRG is set, the "pre-CW state", two schemes are permitted (also see <<section_hardware_pte_updates>>):
@@ -164,9 +164,16 @@ and the capability read from memory optionally has its tag set^1^.
164164
It is legal for the implementation to fault even if the tag is not set since this behavior is only an optimization for software.
165165
This means it is also legal to only check the tag under certain conditions and conservatively fault otherwise.
166166
Taking a trap when the tag is not set will introduce additional traps during revocation sweeps.
167+
Checking the loaded tag affects the exception priority, see <<exception-priority>>.
167168

168169
^2^ See <<section_hardware_pte_updates>>.
169170

171+
The exceptions added by {cheri_pte_ext_name} reuse the load page fault and store/AMO page fault exception cause values,
172+
and so the cause of the exception can be determined by software by checking the value in <<mtval2>>,
173+
<<stval2>> etc.
174+
175+
The behavior when multiple page fault types are detected at once is shown in <<mtval2-page-fault>>.
176+
170177
[#section_hardware_pte_updates]
171178
=== Enabling Software or Hardware PTE updates
172179

src/insns/load_exceptions.adoc

+6
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,11 @@ listed below; in this case, _CHERI data fault_ is reported in the <<mtval2>> or
2323

2424
|==============================================================================
2525
+
26+
If {cheri_pte_ext_name} is implemented, and virtual memory is enabled, then the state of
27+
<<cheri_pte_ext,PTE>>.CW and <<cheri_pte_ext,PTE>>.CRG from the current virtual memory page,
28+
together with <<sstatusreg_pte,sstatus>>.CRG may cause a CHERI <<cheri_pte_ext,PTE>> page fault exception
29+
in addition to a normal RISC-V page fault exception.
30+
See <<mtval2-page-fault>> for the exception reporting in this case.
31+
+
2632
:!load_res:
2733
:!has_cap_data:

src/insns/store_exceptions.adoc

+5
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,10 @@ listed below; in this case, _CHERI data fault_ is reported in the <<mtval2>> or
2222
| Bounds violation | At least one byte accessed is outside the authority capability bounds, or the capability has <<section_cap_malformed,malformed>> bounds
2323
|==============================================================================
2424
+
25+
If {cheri_pte_ext_name} is implemented, and virtual memory is enabled, then the state of
26+
<<cheri_pte_ext,PTE>>.CW and <<cheri_pte_ext,PTE>>.CRG from the current virtual memory page may
27+
cause a CHERI <<cheri_pte_ext,PTE>> page fault exception in addition to a normal RISC-V page fault.
28+
See <<mtval2-page-fault>> for the exception reporting in this case.
29+
+
2530
:!store_cond:
2631
:!has_cap_data:

src/riscv-integration.adoc

+28-10
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ _Reserved_
698698

699699
[[exception-priority]]
700700
.Synchronous exception priority in decreasing priority order. Entries added in {cheri_base_ext_name} are in *bold*
701-
[%autowidth,float="center",align="center",cols="<,>,<",options="header"]
701+
[float="center",align="center",cols="<1,>1,<8",options="header"]
702702
|===
703703
|Priority |Exc.Code |Description
704704
|_Highest_ |3 |Instruction address breakpoint
@@ -729,14 +729,21 @@ Load/store/AMO address breakpoint
729729
Optionally: +
730730
Load/store/AMO address misaligned
731731
| .>|13, 15, 5, 7 .<|During address translation for an explicit memory access: +
732-
First encountered page fault or access fault
732+
First encountered *CHERI PTE page fault*^12^, page fault or access fault
733733
| .>|5,7 .<|With physical address for an explicit memory access: +
734734
Load/store/AMO access fault
735-
.>|_Lowest_ .>|4,6 .<|If not higher priority: +
736-
Load/store/AMO address misaligned
735+
| .>|4,6 .<|If not higher priority: +
736+
.>|_Lowest_ .>|13 .<|If not higher priority: +
737+
CHERI load PTE fault^3^
737738
|===
738739

739-
NOTE: The full details of the CHERI exceptions are in xref:cheri_exception_combs_descriptions[xrefstyle=short].
740+
^1^ The higher priority CHERI <<cheri_pte_ext,PTE>> page fault covers capability loads or atomics where the loaded tag _is not_ checked, and all capability stores and atomics where the stored tag is set.
741+
742+
^2^ CHERI <<cheri_pte_ext,PTE>> page fault exceptions have the same priority against access faults as normal RISC-V page faults. If a normal RISC-V page fault _and_ a CHERI <<cheri_pte_ext,PTE>> fault are both detected simultaneously, then both are recorded as shown in <<mtval2-page-fault>>.
743+
744+
^3^ The lower priority <<cheri_pte_ext,PTE>> fault only covers capability loads and atomics where the loaded tag _is_ checked.
745+
746+
NOTE: The full details of the CHERI exceptions with cause value {cheri_excep_mcause} are in xref:cheri_exception_combs_descriptions[xrefstyle=short].
740747

741748
[#medeleg,reftext="medeleg"]
742749
==== Machine Trap Delegation Register (medeleg)
@@ -830,13 +837,24 @@ CHERI violations have the following order in priority:
830837
. Invalid address violation
831838
. Bounds violation (_Lowest_)
832839

833-
===== mtval2 values for Load Page Faults
840+
===== mtval2 values for Load/Store/AMO Page Faults
834841

835-
If a load page fault is caused by a CHERI <<cheri_pte_ext,PTE>> fault, then set bit zero of <<mtval2>> to 1 and all other bits to 0, otherwise set all bits to zero.
842+
Page faults can be caused by normal RISC-V page faults and also by CHERI <<cheri_pte_ext,PTE>> faults.
843+
If both are detected at once, then both are recorded.
836844

837-
===== mtval2 values for Store Page Faults
845+
.mtval2 for page faults
846+
[#mtval2-page-fault,width=70%,float="center",align="center",cols="2,1",options=header]
847+
|==============================================================================
848+
| Fault | Value
849+
| RISC-V page fault | 0
850+
| CHERI <<cheri_pte_ext,PTE>> fault | 1
851+
| RISC-V page fault and CHERI <<cheri_pte_ext,PTE>> fault | 2
852+
|==============================================================================
838853

839-
If a store page fault is caused by a CHERI <<cheri_pte_ext,PTE>> fault, then set bit zero of <<mtval2>> to 1 and all other bits to 0, otherwise set all bits to zero.
854+
NOTE: Reporting both allows the software the choice about which action to take first, for example a write to a
855+
page with no write permission, _and_ the incorrect value of PTE.CRG requires two actions.
856+
Software can then decide whether to prioritize the copy-on-write procedure to fix the lack of write
857+
permission, or to sweep the page.
840858

841859
[#supervisor-level-csrs-section]
842860
=== Supervisor-Level CSRs
@@ -1051,7 +1069,7 @@ address is 0x14b.
10511069
which are delegated to S-mode.
10521070

10531071
The fields are identical to <<mtval2>> for CHERI exceptions, and for load and
1054-
store page fault exceptions if {cheri_pte_ext_name} is implemented.
1072+
store/AMO page fault exceptions if {cheri_pte_ext_name} is implemented.
10551073

10561074
NOTE: <<stval2>> is not a standard RISC-V CSR, but <<mtval2>> is.
10571075

src/trigger-integration.adoc

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ shown in xref:trigger-exception-priority[xrefstyle=short].
77

88
[[trigger-exception-priority]]
99
.Synchronous exception priority (including triggers) in decreasing priority order. Entries added in {cheri_base_ext_name} are in *bold*
10-
[%autowidth,float="center",align="center",cols="<,>,<,<",options="header"]
10+
[float="center",align="center",cols="<1,>1,<4,<2",options="header"]
1111
|===
1212
|Priority |Exc. Code |Description |Trigger
1313
|_Highest_ |3 +
@@ -22,7 +22,7 @@ mcontrol/mcontrol6 after (on previous instruction)
2222
| .>|*{cheri_excep_mcause}* .<|*Prior to instruction address translation:* +
2323
*CHERI fault due to PCC checks (tag, execute permission, invalid address and bounds)* |
2424
| .>|12, 1 .<|During instruction address translation: +
25-
First encountered page fault or access fault |
25+
First encountered *CHERI PTE page fault*, page fault or access fault |
2626
| .>|1 .<|With physical address for instruction: +
2727
Instruction access fault |
2828

@@ -49,10 +49,14 @@ Environment break |
4949
| .>|4,6 .<|Optionally: +
5050
Load/store/AMO address misaligned |
5151
| .>|13, 15, 5, 7 .<|During address translation for an explicit memory access: +
52-
First encountered page fault or access fault |
52+
First encountered *CHERI <<cheri_pte_ext,PTE>> page fault*, page fault or access fault |
5353
| .>|5,7 .<|With physical address for an explicit memory access: +
5454
Load/store/AMO access fault |
5555
| .>|4,6 .<|If not higher priority: +
5656
Load/store/AMO address misaligned |
57+
| .>|13 .<|If not higher priority: +
58+
CHERI load <<cheri_pte_ext,PTE>> fault |
5759
|_Lowest_ .>|3 .<| |mcontrol/mcontrol6 load data before
5860
|===
61+
62+
NOTE: See the notes beneath <<exception-priority>> for details about CHERI <<cheri_pte_ext,PTE>> page fault priority.

0 commit comments

Comments
 (0)