Skip to content

Commit 73e1b62

Browse files
author
Marc Zyngier
committed
KVM: arm64: nv: Program host's VNCR_EL2 to the fixmap address
Since we now have a way to map the guest's VNCR_EL2 on the host, we can point the host's VNCR_EL2 to it and go full circle! Note that we unconditionally assign the fixmap to VNCR_EL2, irrespective of the guest's version being mapped or not. We want to take a fault on first access, so the fixmap either contains something guranteed to be either invalid or a guest mapping. Reviewed-by: Oliver Upton <oliver.upton@linux.dev> Link: https://lore.kernel.org/r/20250514103501.2225951-13-maz@kernel.org Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent 7270cc9 commit 73e1b62

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

arch/arm64/kvm/hyp/vhe/switch.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ DEFINE_PER_CPU(unsigned long, kvm_hyp_vector);
4848

4949
static u64 __compute_hcr(struct kvm_vcpu *vcpu)
5050
{
51+
u64 guest_hcr = __vcpu_sys_reg(vcpu, HCR_EL2);
5152
u64 hcr = vcpu->arch.hcr_el2;
5253

5354
if (!vcpu_has_nv(vcpu))
@@ -70,9 +71,23 @@ static u64 __compute_hcr(struct kvm_vcpu *vcpu)
7071
write_sysreg_s(vcpu->arch.ctxt.vncr_array, SYS_VNCR_EL2);
7172
} else {
7273
host_data_clear_flag(VCPU_IN_HYP_CONTEXT);
74+
75+
if (guest_hcr & HCR_NV) {
76+
u64 va = __fix_to_virt(vncr_fixmap(smp_processor_id()));
77+
78+
/* Inherit the low bits from the actual register */
79+
va |= __vcpu_sys_reg(vcpu, VNCR_EL2) & GENMASK(PAGE_SHIFT - 1, 0);
80+
write_sysreg_s(va, SYS_VNCR_EL2);
81+
82+
/* Force NV2 in case the guest is forgetful... */
83+
guest_hcr |= HCR_NV2;
84+
}
7385
}
7486

75-
return hcr | (__vcpu_sys_reg(vcpu, HCR_EL2) & ~NV_HCR_GUEST_EXCLUDE);
87+
BUG_ON(host_data_test_flag(VCPU_IN_HYP_CONTEXT) &&
88+
host_data_test_flag(L1_VNCR_MAPPED));
89+
90+
return hcr | (guest_hcr & ~NV_HCR_GUEST_EXCLUDE);
7691
}
7792

7893
static void __activate_cptr_traps(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)