[PATCH v5 35/37] KVM: arm64: Make PAN conditions part of the S1 walk context

Marc Zyngier
2024-10-23T14:53:58Z

Move the conditions describing PAN as part of the s1_walk_info
structure, in an effort to declutter the permission processing.

Signed-off-by: Marc Zyngier <maz@kernel.org>
---
arch/arm64/kvm/at.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/arch/arm64/kvm/at.c b/arch/arm64/kvm/at.c
index 8d1dc6327ec5b..2ab2c3578c3a0 100644
--- a/arch/arm64/kvm/at.c
+++ b/arch/arm64/kvm/at.c
@@ -26,6 +26,7 @@ struct s1_walk_info {
bool hpd;
bool e0poe;
bool poe;
+ bool pan;
bool be;
bool s2;
};
@@ -151,6 +152,8 @@ static int setup_s1_walk(struct kvm_vcpu *vcpu, u32 op, struct s1_walk_info *wi,

wi->regime = compute_translation_regime(vcpu, op);
as_el0 = (op == OP_AT_S1E0R || op == OP_AT_S1E0W);
+ wi->pan = (op == OP_AT_S1E1RP || op == OP_AT_S1E1WP) &&
+ (*vcpu_cpsr(vcpu) & PSR_PAN_BIT);

va55 = va & BIT(55);

@@ -1020,10 +1023,12 @@ static void compute_s1_indirect_permissions(struct kvm_vcpu *vcpu,
}
}

-static void compute_s1_permissions(struct kvm_vcpu *vcpu, u32 op,
+static void compute_s1_permissions(struct kvm_vcpu *vcpu,
struct s1_walk_info *wi,
struct s1_walk_result *wr)
{
+ bool pan;
+
if (!s1pie_enabled(vcpu, wi->regime))
compute_s1_direct_permissions(vcpu, wi, wr);
else
@@ -1032,14 +1037,10 @@ static void compute_s1_permissions(struct kvm_vcpu *vcpu, u32 op,
if (!wi->hpd)
compute_s1_hierarchical_permissions(vcpu, wi, wr);

- if (op == OP_AT_S1E1RP || op == OP_AT_S1E1WP) {
- bool pan;
-
- pan = *vcpu_cpsr(vcpu) & PSR_PAN_BIT;
- pan &= wr->ur || wr->uw || (pan3_enabled(vcpu, wi->regime) && wr->ux);
- wr->pw &= !pan;
- wr->pr &= !pan;
- }
+ pan = wi->pan && (wr->ur || wr->uw ||
+ (pan3_enabled(vcpu, wi->regime) && wr->ux));
+ wr->pw &= !pan;
+ wr->pr &= !pan;
}

static u64 handle_at_slow(struct kvm_vcpu *vcpu, u32 op, u64 vaddr)
@@ -1065,7 +1066,7 @@ static u64 handle_at_slow(struct kvm_vcpu *vcpu, u32 op, u64 vaddr)
if (ret)
goto compute_par;

- compute_s1_permissions(vcpu, op, &wi, &wr);
+ compute_s1_permissions(vcpu, &wi, &wr);

switch (op) {
case OP_AT_S1E1RP:
--
2.39.2