Commit b145b0eb authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull KVM fixes from Paolo Bonzini:
 "ARM and x86 bugfixes of all kinds.

  The most visible one is that migrating a nested hypervisor has always
  been busted on Broadwell and newer processors, and that has finally
  been fixed"

* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (22 commits)
  KVM: x86: omit "impossible" pmu MSRs from MSR list
  KVM: nVMX: Fix consistency check on injected exception error code
  KVM: x86: omit absent pmu MSRs from MSR list
  selftests: kvm: Fix libkvm build error
  kvm: vmx: Limit guest PMCs to those supported on the host
  kvm: x86, powerpc: do not allow clearing largepages debugfs entry
  KVM: selftests: x86: clarify what is reported on KVM_GET_MSRS failure
  KVM: VMX: Set VMENTER_L1D_FLUSH_NOT_REQUIRED if !X86_BUG_L1TF
  selftests: kvm: add test for dirty logging inside nested guests
  KVM: x86: fix nested guest live migration with PML
  KVM: x86: assign two bits to track SPTE kinds
  KVM: x86: Expose XSAVEERPTR to the guest
  kvm: x86: Enumerate support for CLZERO instruction
  kvm: x86: Use AMD CPUID semantics for AMD vCPUs
  kvm: x86: Improve emulation of CPUID leaves 0BH and 1FH
  KVM: X86: Fix userspace set invalid CR4
  kvm: x86: Fix a spurious -E2BIG in __do_cpuid_func
  KVM: LAPIC: Loosen filter for adaptive tuning of lapic_timer_advance_ns
  KVM: arm/arm64: vgic: Use the appropriate TRACE_INCLUDE_PATH
  arm64: KVM: Kill hyp_alternate_select()
  ...
parents 50dfd03d cf05a67b
Loading
Loading
Loading
Loading
+0 −24
Original line number Original line Diff line number Diff line
@@ -47,30 +47,6 @@
#define read_sysreg_el2(r)	read_sysreg_elx(r, _EL2, _EL1)
#define read_sysreg_el2(r)	read_sysreg_elx(r, _EL2, _EL1)
#define write_sysreg_el2(v,r)	write_sysreg_elx(v, r, _EL2, _EL1)
#define write_sysreg_el2(v,r)	write_sysreg_elx(v, r, _EL2, _EL1)


/**
 * hyp_alternate_select - Generates patchable code sequences that are
 * used to switch between two implementations of a function, depending
 * on the availability of a feature.
 *
 * @fname: a symbol name that will be defined as a function returning a
 * function pointer whose type will match @orig and @alt
 * @orig: A pointer to the default function, as returned by @fname when
 * @cond doesn't hold
 * @alt: A pointer to the alternate function, as returned by @fname
 * when @cond holds
 * @cond: a CPU feature (as described in asm/cpufeature.h)
 */
#define hyp_alternate_select(fname, orig, alt, cond)			\
typeof(orig) * __hyp_text fname(void)					\
{									\
	typeof(alt) *val = orig;					\
	asm volatile(ALTERNATIVE("nop		\n",			\
				 "mov	%0, %1	\n",			\
				 cond)					\
		     : "+r" (val) : "r" (alt));				\
	return val;							\
}

int __vgic_v2_perform_cpuif_access(struct kvm_vcpu *vcpu);
int __vgic_v2_perform_cpuif_access(struct kvm_vcpu *vcpu);


void __vgic_v3_save_state(struct kvm_vcpu *vcpu);
void __vgic_v3_save_state(struct kvm_vcpu *vcpu);
+2 −15
Original line number Original line Diff line number Diff line
@@ -229,20 +229,6 @@ static void __hyp_text __hyp_vgic_restore_state(struct kvm_vcpu *vcpu)
	}
	}
}
}


static bool __hyp_text __true_value(void)
{
	return true;
}

static bool __hyp_text __false_value(void)
{
	return false;
}

static hyp_alternate_select(__check_arm_834220,
			    __false_value, __true_value,
			    ARM64_WORKAROUND_834220);

static bool __hyp_text __translate_far_to_hpfar(u64 far, u64 *hpfar)
static bool __hyp_text __translate_far_to_hpfar(u64 far, u64 *hpfar)
{
{
	u64 par, tmp;
	u64 par, tmp;
@@ -298,7 +284,8 @@ static bool __hyp_text __populate_fault_info(struct kvm_vcpu *vcpu)
	 * resolve the IPA using the AT instruction.
	 * resolve the IPA using the AT instruction.
	 */
	 */
	if (!(esr & ESR_ELx_S1PTW) &&
	if (!(esr & ESR_ELx_S1PTW) &&
	    (__check_arm_834220()() || (esr & ESR_ELx_FSC_TYPE) == FSC_PERM)) {
	    (cpus_have_const_cap(ARM64_WORKAROUND_834220) ||
	     (esr & ESR_ELx_FSC_TYPE) == FSC_PERM)) {
		if (!__translate_far_to_hpfar(far, &hpfar))
		if (!__translate_far_to_hpfar(far, &hpfar))
			return false;
			return false;
	} else {
	} else {
+22 −14
Original line number Original line Diff line number Diff line
@@ -67,10 +67,14 @@ static void __hyp_text __tlb_switch_to_guest_nvhe(struct kvm *kvm,
	isb();
	isb();
}
}


static hyp_alternate_select(__tlb_switch_to_guest,
static void __hyp_text __tlb_switch_to_guest(struct kvm *kvm,
			    __tlb_switch_to_guest_nvhe,
					     struct tlb_inv_context *cxt)
			    __tlb_switch_to_guest_vhe,
{
			    ARM64_HAS_VIRT_HOST_EXTN);
	if (has_vhe())
		__tlb_switch_to_guest_vhe(kvm, cxt);
	else
		__tlb_switch_to_guest_nvhe(kvm, cxt);
}


static void __hyp_text __tlb_switch_to_host_vhe(struct kvm *kvm,
static void __hyp_text __tlb_switch_to_host_vhe(struct kvm *kvm,
						struct tlb_inv_context *cxt)
						struct tlb_inv_context *cxt)
@@ -98,10 +102,14 @@ static void __hyp_text __tlb_switch_to_host_nvhe(struct kvm *kvm,
	write_sysreg(0, vttbr_el2);
	write_sysreg(0, vttbr_el2);
}
}


static hyp_alternate_select(__tlb_switch_to_host,
static void __hyp_text __tlb_switch_to_host(struct kvm *kvm,
			    __tlb_switch_to_host_nvhe,
					    struct tlb_inv_context *cxt)
			    __tlb_switch_to_host_vhe,
{
			    ARM64_HAS_VIRT_HOST_EXTN);
	if (has_vhe())
		__tlb_switch_to_host_vhe(kvm, cxt);
	else
		__tlb_switch_to_host_nvhe(kvm, cxt);
}


void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
{
{
@@ -111,7 +119,7 @@ void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)


	/* Switch to requested VMID */
	/* Switch to requested VMID */
	kvm = kern_hyp_va(kvm);
	kvm = kern_hyp_va(kvm);
	__tlb_switch_to_guest()(kvm, &cxt);
	__tlb_switch_to_guest(kvm, &cxt);


	/*
	/*
	 * We could do so much better if we had the VA as well.
	 * We could do so much better if we had the VA as well.
@@ -154,7 +162,7 @@ void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
	if (!has_vhe() && icache_is_vpipt())
	if (!has_vhe() && icache_is_vpipt())
		__flush_icache_all();
		__flush_icache_all();


	__tlb_switch_to_host()(kvm, &cxt);
	__tlb_switch_to_host(kvm, &cxt);
}
}


void __hyp_text __kvm_tlb_flush_vmid(struct kvm *kvm)
void __hyp_text __kvm_tlb_flush_vmid(struct kvm *kvm)
@@ -165,13 +173,13 @@ void __hyp_text __kvm_tlb_flush_vmid(struct kvm *kvm)


	/* Switch to requested VMID */
	/* Switch to requested VMID */
	kvm = kern_hyp_va(kvm);
	kvm = kern_hyp_va(kvm);
	__tlb_switch_to_guest()(kvm, &cxt);
	__tlb_switch_to_guest(kvm, &cxt);


	__tlbi(vmalls12e1is);
	__tlbi(vmalls12e1is);
	dsb(ish);
	dsb(ish);
	isb();
	isb();


	__tlb_switch_to_host()(kvm, &cxt);
	__tlb_switch_to_host(kvm, &cxt);
}
}


void __hyp_text __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu)
void __hyp_text __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu)
@@ -180,13 +188,13 @@ void __hyp_text __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu)
	struct tlb_inv_context cxt;
	struct tlb_inv_context cxt;


	/* Switch to requested VMID */
	/* Switch to requested VMID */
	__tlb_switch_to_guest()(kvm, &cxt);
	__tlb_switch_to_guest(kvm, &cxt);


	__tlbi(vmalle1);
	__tlbi(vmalle1);
	dsb(nsh);
	dsb(nsh);
	isb();
	isb();


	__tlb_switch_to_host()(kvm, &cxt);
	__tlb_switch_to_host(kvm, &cxt);
}
}


void __hyp_text __kvm_flush_vm_context(void)
void __hyp_text __kvm_flush_vm_context(void)
+4 −4
Original line number Original line Diff line number Diff line
@@ -36,8 +36,8 @@
#include "book3s.h"
#include "book3s.h"
#include "trace.h"
#include "trace.h"


#define VM_STAT(x) offsetof(struct kvm, stat.x), KVM_STAT_VM
#define VM_STAT(x, ...) offsetof(struct kvm, stat.x), KVM_STAT_VM, ## __VA_ARGS__
#define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU
#define VCPU_STAT(x, ...) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU, ## __VA_ARGS__


/* #define EXIT_DEBUG */
/* #define EXIT_DEBUG */


@@ -69,8 +69,8 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
	{ "pthru_all",       VCPU_STAT(pthru_all) },
	{ "pthru_all",       VCPU_STAT(pthru_all) },
	{ "pthru_host",      VCPU_STAT(pthru_host) },
	{ "pthru_host",      VCPU_STAT(pthru_host) },
	{ "pthru_bad_aff",   VCPU_STAT(pthru_bad_aff) },
	{ "pthru_bad_aff",   VCPU_STAT(pthru_bad_aff) },
	{ "largepages_2M",    VM_STAT(num_2M_pages) },
	{ "largepages_2M",    VM_STAT(num_2M_pages, .mode = 0444) },
	{ "largepages_1G",    VM_STAT(num_1G_pages) },
	{ "largepages_1G",    VM_STAT(num_1G_pages, .mode = 0444) },
	{ NULL }
	{ NULL }
};
};


+0 −7
Original line number Original line Diff line number Diff line
@@ -219,13 +219,6 @@ enum {
				 PFERR_WRITE_MASK |		\
				 PFERR_WRITE_MASK |		\
				 PFERR_PRESENT_MASK)
				 PFERR_PRESENT_MASK)


/*
 * The mask used to denote special SPTEs, which can be either MMIO SPTEs or
 * Access Tracking SPTEs. We use bit 62 instead of bit 63 to avoid conflicting
 * with the SVE bit in EPT PTEs.
 */
#define SPTE_SPECIAL_MASK (1ULL << 62)

/* apic attention bits */
/* apic attention bits */
#define KVM_APIC_CHECK_VAPIC	0
#define KVM_APIC_CHECK_VAPIC	0
/*
/*
Loading