Skip to content

Commit fcce4a9

Browse files
apply ACPERM rules in order (#427)
Also update table to clarify the SL value for GCPERM. Fixes #426 Fixes #428 Signed-off-by: Tariq Kurd <tariq.kurd@codasip.com> Co-authored-by: Alexander Richardson <alexrichardson@google.com>
1 parent 9561fff commit fcce4a9

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

src/cap-description.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ specifications must provide key primitives, such as permissions and bounds,
3030
from this specification while using a different encoding that, for example,
3131
changes the granularity of bounds or adds new features. For simplicity of
3232
expression, the text is written as if this was the only possible capability
33-
encoding possible for CHERI RISC-V.
33+
encoding for CHERI RISC-V.
3434

3535
[#section_cap_encoding]
3636
=== Capability Encoding

src/insns/acperm_32bit.adoc

+31-27
Original file line numberDiff line numberDiff line change
@@ -29,41 +29,45 @@ ACPERM performs the following operations:
2929
format shown in xref:acperm_bit_field[xrefstyle=short].
3030
. Calculate the bitwise AND of the bit field with the mask `rs2`.
3131
. If the AP and <<m_bit>> field in `cs1` could not have been produced by <<ACPERM>> then
32-
clear all AP permissions and the <<m_bit>>, and skip the next step
32+
clear all AP permissions, and the <<m_bit>> to {CAP_MODE_VALUE}. Skip the next step.
3333
. Clear AP permissions as required to meet the rules below.
34-
. Encode the AP permissions for MXLEN=32 according to <<cap_perms_encoding32>>.
34+
. Encode the AP permissions for RV32 according to <<cap_perms_encoding32>>.
3535
. Copy `cs1` to `cd`, and update the AP and SDP fields with the newly calculated versions.
3636
. Set `cd.tag=0` if `cs1` is sealed or if any reserved fields of `cs1` are set.
3737
+
3838
Some combinations of permissions cannot be encoded for MXLEN=32, and are not useful when MXLEN=64.
3939
These cases are defined to return useful minimal sets of permissions, which may be no permissions.
4040
+
4141
NOTE: Future extensions may allow more combinations of permissions, especially for MXLEN=64.
42-
43-
The common rules are:
44-
45-
. <<asr_perm>> cannot be set without <<x_perm>> being set
46-
.. Clear <<asr_perm>> unless <<x_perm>> is set
47-
. <<c_perm>> cannot be set without at least one of <<r_perm>> or <<w_perm>> being set.
48-
.. Clear <<c_perm>> unless <<r_perm>> or <<w_perm>> are set.
49-
. <<m_bit>> cannot be set without <<x_perm>> being set
50-
.. Clear <<m_bit>> unless <<x_perm>> is set
51-
. <<lm_perm>> cannot be set without <<c_perm>> being set
52-
.. Clear <<lm_perm>> unless <<c_perm>> is set.
53-
. <<sl_perm>> cannot be set without <<c_perm>> being set
54-
.. Zero <<sl_perm>> unless <<c_perm>> is set.
55-
. <<el_perm>> cannot be set without <<c_perm>> being set
56-
.. Zero <<el_perm>> unless <<c_perm>> is set.
57-
58-
NOTE: The combination of <<x_perm>> clear and <<m_bit>> set is reserved for future extensions.
59-
60-
The MXLEN=32 additional rules are:
61-
62-
. Clear <<asr_perm>> unless _all_ other permissions are set
63-
. Clear <<c_perm>> and <<x_perm>> if <<r_perm>> is not set
64-
. Clear <<w_perm>> if <<c_perm>> _is_ set, but <<lm_perm>> _is not_ set.
65-
. Clear <<x_perm>> if <<x_perm>> and <<r_perm>> are set, and <<c_perm>> and <<w_perm>> are both clear.
66-
. If removing <<lm_perm>> results in unrepresentable permissions, then set <<r_perm>> and <<c_perm>> only.
42+
The rules from <<acperm_rules>> must be followed when removing permissions.
43+
44+
[#acperm_rules]
45+
.ACPERM common rules
46+
[float="center",align="center",cols="2,2,4",options="header"]
47+
|===
48+
| Rule | Permission | Only valid if
49+
| 1 (RV32 only) | <<asr_perm>> | All other permissions are set.
50+
| 2 | <<c_perm>> | <<r_perm>> or <<w_perm>>
51+
| 3 (RV32 only) | <<c_perm>> | <<r_perm>>
52+
| 4 (RV32 only) | <<x_perm>> | <<r_perm>>
53+
| 5 (RV32 only) | <<w_perm>> | not(<<c_perm>>) or <<lm_perm>>
54+
| 6 (RV32 only) | <<x_perm>> | <<w_perm>> or <<c_perm>>
55+
| 7 | <<el_perm>> | <<c_perm>> and <<r_perm>>
56+
| 8 | <<lm_perm>> | <<c_perm>> and <<r_perm>>
57+
| 9 | <<sl_perm>> | <<c_perm>>
58+
| 10 (RV32 only) | <<x_perm>> | (<<c_perm>> and <<lm_perm>> and <<el_perm>> and (<<sl_perm>> == ∞)) or +
59+
(not(<<c_perm>> and not(<<lm_perm>>) and not(<<el_perm>>) and (<<sl_perm>>==0)))^1^
60+
| 11 | <<asr_perm>> | <<x_perm>>
61+
| 12 | <<m_bit>> | <<x_perm>>
62+
|===
63+
64+
^1^ All the listed permissions in the set are either minimum or maximum.
65+
66+
The behaviour of currently illegal combinations from <<acperm_rules>> is to clear the permission if invalid (or in the case of <<sl_perm>> set it to 0 (_local_)).
67+
68+
* For RV64 all such combinations may be redefined by future extensions.
69+
* The RV32 only rules are added because they remove combinations which do not meet the encoding requirements for <<cap_perms_encoding32>>, or
70+
<<cap_perms_encoding_levels32>> if <<cheri_levels_ext,{cheri_levels_ext_name}>> is implemented.
6771
6872
.Capability permissions bit field
6973
[#acperm_bit_field]

src/level-ext.adoc

+6-4
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ endif::[]
7474
11+| bit[0] - <<m_bit>> ({CAP_MODE_VALUE}-{cheri_cap_mode_name}, {INT_MODE_VALUE}-{cheri_int_mode_name})
7575
|Bits[4:3]| R | W | C | LM | EL | SL | X | ASR | Mode^1^ |
7676
| 0-1 | ✔ | ✔ | ✔ | ✔ | ✔ | ∞ | ✔ | ✔ | Mode^1^ | Execute + ASR (see <<infinite-cap>>)
77-
| 2-3 | ✔ | | ✔ | ✔ | ✔ | ∞ | ✔ | | Mode^1^ | Execute + Data & Cap RO
77+
| 2-3 | ✔ | | ✔ | ✔ | ✔ | ∞^1^| ✔ | | Mode^1^ | Execute + Data & Cap RO
7878
| 4-5 | ✔ | ✔ | ✔ | ✔ | ✔ | ∞ | ✔ | | Mode^1^ | Execute + Data & Cap RW
79-
| 6-7 | ✔ | ✔ | | | | N/A | ✔ | | Mode^1^ | Execute + Data RW
79+
| 6-7 | ✔ | ✔ | | | | 0^1^| ✔ | | Mode^1^ | Execute + Data RW
8080
11+| *Quadrant 2: Restricted capability data read/write*
8181
11+| bit[2] = write, bit[1:0] = store level. R and C implicitly granted, LM dependent on W permission.
8282
|Bits[4:3]| R | W | C | LM | EL | SL | X | ASR | Mode^1^ |
8383
| 0-2 10+| reserved
84-
| 3 | ✔ | | ✔ | | | N/A | | | N/A | Data & Cap R0 (without <<lm_perm>>)
84+
| 3 | ✔ | | ✔ | | | 0^1^ | | | N/A | Data & Cap R0 (without <<lm_perm>>)
8585
| 4 | ✔ | ✔ | ✔ | ✔ | | _(3)_ | | | N/A | Reserved for `LVLBITS=2`
8686
| 5 | ✔ | ✔ | ✔ | ✔ | | _(2)_ | | | N/A | Reserved for `LVLBITS=2`
8787
| 6 | ✔ | ✔ | ✔ | ✔ | | 1 | | | N/A | Data & Cap RW (with store _local_, no <<el_perm>>)
@@ -91,13 +91,15 @@ endif::[]
9191
11+| _Reserved bits for future extensions must be 1 so they are implicitly granted_
9292
|Bits[4:3]| R | W | C | LM | EL | SL | X | ASR | Mode^1^ |
9393
| 0-2 10+| reserved
94-
| 3 | ✔ | | ✔ | ✔ | ✔ | N/A | | | N/A | Data & Cap R0
94+
| 3 | ✔ | | ✔ | ✔ | ✔ | 0^1^ | | | N/A | Data & Cap R0
9595
| 4 | ✔ | ✔ | ✔ | ✔ | ✔ | _(3)_ | | | N/A | Reserved for `LVLBITS=2`
9696
| 5 | ✔ | ✔ | ✔ | ✔ | ✔ | _(2)_ | | | N/A | Reserved for `LVLBITS=2`
9797
| 6 | ✔ | ✔ | ✔ | ✔ | ✔ | 1 | | | N/A | Data & Cap RW (with store _local_)
9898
| 7 | ✔ | ✔ | ✔ | ✔ | ✔ | 0 | | | N/A | Data & Cap RW (no store _local_)
9999
|==============================================================================
100100

101+
^1^ SL isn't applicable in these cases, but this value is reported by <<GCPERM>> to simplify the rules followed by <<ACPERM>>
102+
101103
[#section_cap_level_change]
102104
=== Changing capability levels and permissions
103105
While capability levels (<<section_cap_level,CL>>) are conceptually a label on the capability rather than a permission granted by the capability, they are adjusted using the <<ACPERM>> instruction.

0 commit comments

Comments
 (0)