Skip to content

Commit a508d5a

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Remove the wi->{e0,}poe vs wr->{p,u}ov confusion
Some of the POE computation is a bit confused. Specifically, there is an element of confusion between what wi->{e0,}poe an wr->{p,u}ov actually represent. - wi->{e0,}poe is an *input* to the walk, and indicates whether POE is enabled at EL0 or EL{1,2} - wr->{p,u}ov is a *result* of the walk, and indicates whether overlays are enabled. Crutially, it is possible to have POE enabled, and yet overlays disabled, while the converse isn't true What this all means is that once the base permissions have been established, checking for wi->{e0,}poe makes little sense, because the truth about overlays resides in wr->{p,u}ov. So constructs checking for (wi->poe && wr->pov) only add perplexity. Refactor compute_s1_overlay_permissions() and the way it is called according to the above principles. Take the opportunity to avoid reading registers that are not strictly required. Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 4530256 commit a508d5a

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

arch/arm64/kvm/at.c

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,34 +1047,43 @@ static void compute_s1_overlay_permissions(struct kvm_vcpu *vcpu,
10471047

10481048
idx = FIELD_GET(PTE_PO_IDX_MASK, wr->desc);
10491049

1050-
switch (wi->regime) {
1051-
case TR_EL10:
1052-
pov_perms = perm_idx(vcpu, POR_EL1, idx);
1053-
uov_perms = perm_idx(vcpu, POR_EL0, idx);
1054-
break;
1055-
case TR_EL20:
1056-
pov_perms = perm_idx(vcpu, POR_EL2, idx);
1057-
uov_perms = perm_idx(vcpu, POR_EL0, idx);
1058-
break;
1059-
case TR_EL2:
1060-
pov_perms = perm_idx(vcpu, POR_EL2, idx);
1061-
uov_perms = 0;
1062-
break;
1063-
}
1050+
if (wr->pov) {
1051+
switch (wi->regime) {
1052+
case TR_EL10:
1053+
pov_perms = perm_idx(vcpu, POR_EL1, idx);
1054+
break;
1055+
case TR_EL20:
1056+
pov_perms = perm_idx(vcpu, POR_EL2, idx);
1057+
break;
1058+
case TR_EL2:
1059+
pov_perms = perm_idx(vcpu, POR_EL2, idx);
1060+
break;
1061+
}
10641062

1065-
if (pov_perms & ~POE_RWX)
1066-
pov_perms = POE_NONE;
1063+
if (pov_perms & ~POE_RWX)
1064+
pov_perms = POE_NONE;
10671065

1068-
if (wi->poe && wr->pov) {
10691066
wr->pr &= pov_perms & POE_R;
10701067
wr->pw &= pov_perms & POE_W;
10711068
wr->px &= pov_perms & POE_X;
10721069
}
10731070

1074-
if (uov_perms & ~POE_RWX)
1075-
uov_perms = POE_NONE;
1071+
if (wr->uov) {
1072+
switch (wi->regime) {
1073+
case TR_EL10:
1074+
uov_perms = perm_idx(vcpu, POR_EL0, idx);
1075+
break;
1076+
case TR_EL20:
1077+
uov_perms = perm_idx(vcpu, POR_EL0, idx);
1078+
break;
1079+
case TR_EL2:
1080+
uov_perms = 0;
1081+
break;
1082+
}
1083+
1084+
if (uov_perms & ~POE_RWX)
1085+
uov_perms = POE_NONE;
10761086

1077-
if (wi->e0poe && wr->uov) {
10781087
wr->ur &= uov_perms & POE_R;
10791088
wr->uw &= uov_perms & POE_W;
10801089
wr->ux &= uov_perms & POE_X;
@@ -1095,8 +1104,7 @@ static void compute_s1_permissions(struct kvm_vcpu *vcpu,
10951104
if (!wi->hpd)
10961105
compute_s1_hierarchical_permissions(vcpu, wi, wr);
10971106

1098-
if (wi->poe || wi->e0poe)
1099-
compute_s1_overlay_permissions(vcpu, wi, wr);
1107+
compute_s1_overlay_permissions(vcpu, wi, wr);
11001108

11011109
/* R_QXXPC */
11021110
if (wr->pwxn) {

0 commit comments

Comments
 (0)