Skip to content

Commit 36f998d

Browse files
author
Marc Zyngier
committed
KVM: arm64: nv: Apply RESx settings to sysreg reset values
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 <[email protected]> Reviewed-by: Joey Gouly <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent c139b6d commit 36f998d

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

arch/arm64/include/asm/kvm_nested.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ static inline bool kvm_supported_tlbi_s1e2_op(struct kvm_vcpu *vpcu, u32 instr)
186186
return true;
187187
}
188188

189-
int kvm_init_nv_sysregs(struct kvm *kvm);
189+
int kvm_init_nv_sysregs(struct kvm_vcpu *vcpu);
190190

191191
#ifdef CONFIG_ARM64_PTR_AUTH
192192
bool kvm_auth_eretax(struct kvm_vcpu *vcpu, u64 *elr);

arch/arm64/kvm/nested.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -963,14 +963,15 @@ static __always_inline void set_sysreg_masks(struct kvm *kvm, int sr, u64 res0,
963963
kvm->arch.sysreg_masks->mask[i].res1 = res1;
964964
}
965965

966-
int kvm_init_nv_sysregs(struct kvm *kvm)
966+
int kvm_init_nv_sysregs(struct kvm_vcpu *vcpu)
967967
{
968+
struct kvm *kvm = vcpu->kvm;
968969
u64 res0, res1;
969970

970971
lockdep_assert_held(&kvm->arch.config_lock);
971972

972973
if (kvm->arch.sysreg_masks)
973-
return 0;
974+
goto out;
974975

975976
kvm->arch.sysreg_masks = kzalloc(sizeof(*(kvm->arch.sysreg_masks)),
976977
GFP_KERNEL_ACCOUNT);
@@ -1271,6 +1272,10 @@ int kvm_init_nv_sysregs(struct kvm *kvm)
12711272
res0 |= MDCR_EL2_EnSTEPOP;
12721273
set_sysreg_masks(kvm, MDCR_EL2, res0, res1);
12731274

1275+
out:
1276+
for (enum vcpu_sysreg sr = __SANITISED_REG_START__; sr < NR_SYS_REGS; sr++)
1277+
(void)__vcpu_sys_reg(vcpu, sr);
1278+
12741279
return 0;
12751280
}
12761281

arch/arm64/kvm/sys_regs.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4396,6 +4396,9 @@ void kvm_reset_sys_regs(struct kvm_vcpu *vcpu)
43964396
reset_vcpu_ftr_id_reg(vcpu, r);
43974397
else
43984398
r->reset(vcpu, r);
4399+
4400+
if (r->reg >= __SANITISED_REG_START__ && r->reg < NR_SYS_REGS)
4401+
(void)__vcpu_sys_reg(vcpu, r->reg);
43994402
}
44004403

44014404
set_bit(KVM_ARCH_FLAG_ID_REGS_INITIALIZED, &kvm->arch.flags);
@@ -4999,7 +5002,7 @@ int kvm_finalize_sys_regs(struct kvm_vcpu *vcpu)
49995002
}
50005003

50015004
if (vcpu_has_nv(vcpu)) {
5002-
int ret = kvm_init_nv_sysregs(kvm);
5005+
int ret = kvm_init_nv_sysregs(vcpu);
50035006
if (ret)
50045007
return ret;
50055008
}

0 commit comments

Comments
 (0)