]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
KVM: arm64: Unconditionally configure fine-grain traps
authorMark Rutland <mark.rutland@arm.com>
Tue, 19 Nov 2024 13:57:22 +0000 (13:57 +0000)
committerMarc Zyngier <maz@kernel.org>
Tue, 6 May 2025 16:35:25 +0000 (17:35 +0100)
... otherwise we can inherit the host configuration if this differs from
the KVM configuration.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
[maz: simplified a couple of things]
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/kvm/hyp/include/hyp/switch.h

index 027d05f308f75b2d3a940919e1c0e8a91c10a0e0..925a3288bd5be79525b6275754c398fd4c6c4c71 100644 (file)
@@ -107,7 +107,8 @@ static inline void __activate_traps_fpsimd32(struct kvm_vcpu *vcpu)
 
 #define update_fgt_traps_cs(hctxt, vcpu, kvm, reg, clr, set)           \
        do {                                                            \
-               u64 c = 0, s = 0;                                       \
+               u64 c = clr, s = set;                                   \
+               u64 val;                                                \
                                                                        \
                ctxt_sys_reg(hctxt, reg) = read_sysreg_s(SYS_ ## reg);  \
                if (vcpu_has_nv(vcpu) && !is_hyp_ctxt(vcpu))            \
@@ -115,14 +116,10 @@ static inline void __activate_traps_fpsimd32(struct kvm_vcpu *vcpu)
                                                                        \
                compute_undef_clr_set(vcpu, kvm, reg, c, s);            \
                                                                        \
-               s |= set;                                               \
-               c |= clr;                                               \
-               if (c || s) {                                           \
-                       u64 val = __ ## reg ## _nMASK;                  \
-                       val |= s;                                       \
-                       val &= ~c;                                      \
-                       write_sysreg_s(val, SYS_ ## reg);               \
-               }                                                       \
+               val = __ ## reg ## _nMASK;                              \
+               val |= s;                                               \
+               val &= ~c;                                              \
+               write_sysreg_s(val, SYS_ ## reg);                       \
        } while(0)
 
 #define update_fgt_traps(hctxt, vcpu, kvm, reg)                \
@@ -175,33 +172,27 @@ static inline void __activate_traps_hfgxtr(struct kvm_vcpu *vcpu)
                update_fgt_traps(hctxt, vcpu, kvm, HAFGRTR_EL2);
 }
 
-#define __deactivate_fgt(htcxt, vcpu, kvm, reg)                                \
+#define __deactivate_fgt(htcxt, vcpu, reg)                             \
        do {                                                            \
-               if ((vcpu_has_nv(vcpu) && !is_hyp_ctxt(vcpu)) ||        \
-                   kvm->arch.fgu[reg_to_fgt_group_id(reg)])            \
-                       write_sysreg_s(ctxt_sys_reg(hctxt, reg),        \
-                                      SYS_ ## reg);                    \
+               write_sysreg_s(ctxt_sys_reg(hctxt, reg),                \
+                              SYS_ ## reg);                            \
        } while(0)
 
 static inline void __deactivate_traps_hfgxtr(struct kvm_vcpu *vcpu)
 {
        struct kvm_cpu_context *hctxt = host_data_ptr(host_ctxt);
-       struct kvm *kvm = kern_hyp_va(vcpu->kvm);
 
        if (!cpus_have_final_cap(ARM64_HAS_FGT))
                return;
 
-       __deactivate_fgt(hctxt, vcpu, kvm, HFGRTR_EL2);
-       if (cpus_have_final_cap(ARM64_WORKAROUND_AMPERE_AC03_CPU_38))
-               write_sysreg_s(ctxt_sys_reg(hctxt, HFGWTR_EL2), SYS_HFGWTR_EL2);
-       else
-               __deactivate_fgt(hctxt, vcpu, kvm, HFGWTR_EL2);
-       __deactivate_fgt(hctxt, vcpu, kvm, HFGITR_EL2);
-       __deactivate_fgt(hctxt, vcpu, kvm, HDFGRTR_EL2);
-       __deactivate_fgt(hctxt, vcpu, kvm, HDFGWTR_EL2);
+       __deactivate_fgt(hctxt, vcpu, HFGRTR_EL2);
+       __deactivate_fgt(hctxt, vcpu, HFGWTR_EL2);
+       __deactivate_fgt(hctxt, vcpu, HFGITR_EL2);
+       __deactivate_fgt(hctxt, vcpu, HDFGRTR_EL2);
+       __deactivate_fgt(hctxt, vcpu, HDFGWTR_EL2);
 
        if (cpu_has_amu())
-               __deactivate_fgt(hctxt, vcpu, kvm, HAFGRTR_EL2);
+               __deactivate_fgt(hctxt, vcpu, HAFGRTR_EL2);
 }
 
 static inline void  __activate_traps_mpam(struct kvm_vcpu *vcpu)