Commit 73e1b621 authored by Marc Zyngier's avatar Marc Zyngier
Browse files

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: default avatarOliver Upton <oliver.upton@linux.dev>
Link: https://lore.kernel.org/r/20250514103501.2225951-13-maz@kernel.org


Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
parent 7270cc91
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ DEFINE_PER_CPU(unsigned long, kvm_hyp_vector);

static u64 __compute_hcr(struct kvm_vcpu *vcpu)
{
	u64 guest_hcr = __vcpu_sys_reg(vcpu, HCR_EL2);
	u64 hcr = vcpu->arch.hcr_el2;

	if (!vcpu_has_nv(vcpu))
@@ -70,9 +71,23 @@ static u64 __compute_hcr(struct kvm_vcpu *vcpu)
		write_sysreg_s(vcpu->arch.ctxt.vncr_array, SYS_VNCR_EL2);
	} else {
		host_data_clear_flag(VCPU_IN_HYP_CONTEXT);

		if (guest_hcr & HCR_NV) {
			u64 va = __fix_to_virt(vncr_fixmap(smp_processor_id()));

			/* Inherit the low bits from the actual register */
			va |= __vcpu_sys_reg(vcpu, VNCR_EL2) & GENMASK(PAGE_SHIFT - 1, 0);
			write_sysreg_s(va, SYS_VNCR_EL2);

			/* Force NV2 in case the guest is forgetful... */
			guest_hcr |= HCR_NV2;
		}
	}

	BUG_ON(host_data_test_flag(VCPU_IN_HYP_CONTEXT) &&
	       host_data_test_flag(L1_VNCR_MAPPED));

	return hcr | (__vcpu_sys_reg(vcpu, HCR_EL2) & ~NV_HCR_GUEST_EXCLUDE);
	return hcr | (guest_hcr & ~NV_HCR_GUEST_EXCLUDE);
}

static void __activate_cptr_traps(struct kvm_vcpu *vcpu)