]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
KVM: arm64: nv: Apply RESx settings to sysreg reset values
authorMarc Zyngier <maz@kernel.org>
Sun, 12 Jan 2025 16:50:29 +0000 (16:50 +0000)
committerMarc Zyngier <maz@kernel.org>
Tue, 14 Jan 2025 11:33:09 +0000 (11:33 +0000)
While we have sanitisation in place for the guest sysregs, we lack
that sanitisation out of reset. So some of the fields could be
evaluated and not reflect their RESx status, which sounds like
a very bad idea.

Apply the RESx masks to the the sysreg file in two situations:

- when going via a reset of the sysregs

- after having computed the RESx masks

Having this separate reset phase from the actual reset handling is
a bit grotty, but we need to apply this after the ID registers are
final.

Tested-by: Joey Gouly <joey.gouly@arm.com>
Reviewed-by: Joey Gouly <joey.gouly@arm.com>
Link: https://lore.kernel.org/r/20250112165029.1181056-3-maz@kernel.org
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/include/asm/kvm_nested.h
arch/arm64/kvm/nested.c
arch/arm64/kvm/sys_regs.c

index 233e65522716441c95f2cf9ddbd56fc825e6bf72..f616e25e204f146558224dae6ab5103fedaa6d1f 100644 (file)
@@ -186,7 +186,7 @@ static inline bool kvm_supported_tlbi_s1e2_op(struct kvm_vcpu *vpcu, u32 instr)
        return true;
 }
 
-int kvm_init_nv_sysregs(struct kvm *kvm);
+int kvm_init_nv_sysregs(struct kvm_vcpu *vcpu);
 
 #ifdef CONFIG_ARM64_PTR_AUTH
 bool kvm_auth_eretax(struct kvm_vcpu *vcpu, u64 *elr);
index 9b36218b48def495708f49b59e5f9211bd86cc0f..dd6480cf90ea5915262d82fdc7be2ada453f1a4e 100644 (file)
@@ -963,14 +963,15 @@ static __always_inline void set_sysreg_masks(struct kvm *kvm, int sr, u64 res0,
        kvm->arch.sysreg_masks->mask[i].res1 = res1;
 }
 
-int kvm_init_nv_sysregs(struct kvm *kvm)
+int kvm_init_nv_sysregs(struct kvm_vcpu *vcpu)
 {
+       struct kvm *kvm = vcpu->kvm;
        u64 res0, res1;
 
        lockdep_assert_held(&kvm->arch.config_lock);
 
        if (kvm->arch.sysreg_masks)
-               return 0;
+               goto out;
 
        kvm->arch.sysreg_masks = kzalloc(sizeof(*(kvm->arch.sysreg_masks)),
                                         GFP_KERNEL_ACCOUNT);
@@ -1271,6 +1272,10 @@ int kvm_init_nv_sysregs(struct kvm *kvm)
                res0 |= MDCR_EL2_EnSTEPOP;
        set_sysreg_masks(kvm, MDCR_EL2, res0, res1);
 
+out:
+       for (enum vcpu_sysreg sr = __SANITISED_REG_START__; sr < NR_SYS_REGS; sr++)
+               (void)__vcpu_sys_reg(vcpu, sr);
+
        return 0;
 }
 
index 83c6b4a07ef56cf0ed9c8751ec80686f45dca6b2..8671d46f53e59286dabc1f280a89ad6f4c52f6c2 100644 (file)
@@ -4396,6 +4396,9 @@ void kvm_reset_sys_regs(struct kvm_vcpu *vcpu)
                        reset_vcpu_ftr_id_reg(vcpu, r);
                else
                        r->reset(vcpu, r);
+
+               if (r->reg >= __SANITISED_REG_START__ && r->reg < NR_SYS_REGS)
+                       (void)__vcpu_sys_reg(vcpu, r->reg);
        }
 
        set_bit(KVM_ARCH_FLAG_ID_REGS_INITIALIZED, &kvm->arch.flags);
@@ -4999,7 +5002,7 @@ int kvm_finalize_sys_regs(struct kvm_vcpu *vcpu)
        }
 
        if (vcpu_has_nv(vcpu)) {
-               int ret = kvm_init_nv_sysregs(kvm);
+               int ret = kvm_init_nv_sysregs(vcpu);
                if (ret)
                        return ret;
        }