Skip to content

Commit 5152977

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Follow specification when implementing WXN
The R_QXXPC and R_NPBXC rules have some interesting (and pretty sharp) corners when defining the behaviour of of WXN at S1: - when S1 overlay is enabled, WXN applies to the overlay and will remove W - when S1 overlay is disabled, WXN applies to the base permissions and will remove X. Today, we lumb the two together in a way that doesn't really match the rules, making things awkward to follow what is happening, in particular when overlays are enabled. Split these two rules over two distinct paths, which makes things a lot easier to read and validate against the architecture rules. Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent a508d5a commit 5152977

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

arch/arm64/kvm/at.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,10 @@ static void compute_s1_overlay_permissions(struct kvm_vcpu *vcpu,
10631063
if (pov_perms & ~POE_RWX)
10641064
pov_perms = POE_NONE;
10651065

1066+
/* R_QXXPC, S1PrivOverflow enabled */
1067+
if (wr->pwxn && (pov_perms & POE_X))
1068+
pov_perms &= ~POE_W;
1069+
10661070
wr->pr &= pov_perms & POE_R;
10671071
wr->pw &= pov_perms & POE_W;
10681072
wr->px &= pov_perms & POE_X;
@@ -1084,6 +1088,10 @@ static void compute_s1_overlay_permissions(struct kvm_vcpu *vcpu,
10841088
if (uov_perms & ~POE_RWX)
10851089
uov_perms = POE_NONE;
10861090

1091+
/* R_NPBXC, S1UnprivOverlay enabled */
1092+
if (wr->uwxn && (uov_perms & POE_X))
1093+
uov_perms &= ~POE_W;
1094+
10871095
wr->ur &= uov_perms & POE_R;
10881096
wr->uw &= uov_perms & POE_W;
10891097
wr->ux &= uov_perms & POE_X;
@@ -1106,21 +1114,13 @@ static void compute_s1_permissions(struct kvm_vcpu *vcpu,
11061114

11071115
compute_s1_overlay_permissions(vcpu, wi, wr);
11081116

1109-
/* R_QXXPC */
1110-
if (wr->pwxn) {
1111-
if (!wr->pov && wr->pw)
1112-
wr->px = false;
1113-
if (wr->pov && wr->px)
1114-
wr->pw = false;
1115-
}
1117+
/* R_QXXPC, S1PrivOverlay disabled */
1118+
if (!wr->pov)
1119+
wr->px &= !(wr->pwxn && wr->pw);
11161120

1117-
/* R_NPBXC */
1118-
if (wr->uwxn) {
1119-
if (!wr->uov && wr->uw)
1120-
wr->ux = false;
1121-
if (wr->uov && wr->ux)
1122-
wr->uw = false;
1123-
}
1121+
/* R_NPBXC, S1UnprivOverlay disabled */
1122+
if (!wr->uov)
1123+
wr->ux &= !(wr->uwxn && wr->uw);
11241124

11251125
pan = wi->pan && (wr->ur || wr->uw ||
11261126
(pan3_enabled(vcpu, wi->regime) && wr->ux));

0 commit comments

Comments
 (0)