Commit 1f840c0e authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm

Pull kvm fixes from Paolo Bonzini:
 "x86 host:

   - Expose KVM_CAP_ENABLE_CAP since it is supported

   - Disable KVM_HC_CLOCK_PAIRING in TSC catchup mode

   - Ensure async page fault token is nonzero

   - Fix lockdep false negative

   - Fix FPU migration regression from the AMX changes

  x86 guest:

   - Don't use PV TLB/IPI/yield on uniprocessor guests

  PPC:

   - reserve capability id (topic branch for ppc/kvm)"

* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm:
  KVM: x86: nSVM: disallow userspace setting of MSR_AMD64_TSC_RATIO to non default value when tsc scaling disabled
  KVM: x86/mmu: make apf token non-zero to fix bug
  KVM: PPC: reserve capability 210 for KVM_CAP_PPC_AIL_MODE_3
  x86/kvm: Don't use pv tlb/ipi/sched_yield if on 1 vCPU
  x86/kvm: Fix compilation warning in non-x86_64 builds
  x86/kvm/fpu: Remove kvm_vcpu_arch.guest_supported_xcr0
  x86/kvm/fpu: Limit guest user_xfeatures to supported bits of XCR0
  kvm: x86: Disable KVM_HC_CLOCK_PAIRING if tsc is in always catchup mode
  KVM: Fix lockdep false negative during host resume
  KVM: x86: Add KVM_CAP_ENABLE_CAP to x86
parents d8152cfe e910a53f
...@@ -1394,7 +1394,7 @@ documentation when it pops into existence). ...@@ -1394,7 +1394,7 @@ documentation when it pops into existence).
------------------- -------------------
:Capability: KVM_CAP_ENABLE_CAP :Capability: KVM_CAP_ENABLE_CAP
:Architectures: mips, ppc, s390 :Architectures: mips, ppc, s390, x86
:Type: vcpu ioctl :Type: vcpu ioctl
:Parameters: struct kvm_enable_cap (in) :Parameters: struct kvm_enable_cap (in)
:Returns: 0 on success; -1 on error :Returns: 0 on success; -1 on error
...@@ -6997,6 +6997,20 @@ indicated by the fd to the VM this is called on. ...@@ -6997,6 +6997,20 @@ indicated by the fd to the VM this is called on.
This is intended to support intra-host migration of VMs between userspace VMMs, This is intended to support intra-host migration of VMs between userspace VMMs,
upgrading the VMM process without interrupting the guest. upgrading the VMM process without interrupting the guest.
7.30 KVM_CAP_PPC_AIL_MODE_3
-------------------------------
:Capability: KVM_CAP_PPC_AIL_MODE_3
:Architectures: ppc
:Type: vm
This capability indicates that the kernel supports the mode 3 setting for the
"Address Translation Mode on Interrupt" aka "Alternate Interrupt Location"
resource that is controlled with the H_SET_MODE hypercall.
This capability allows a guest kernel to use a better-performance mode for
handling interrupts and system calls.
8. Other capabilities. 8. Other capabilities.
====================== ======================
......
...@@ -703,7 +703,6 @@ struct kvm_vcpu_arch { ...@@ -703,7 +703,6 @@ struct kvm_vcpu_arch {
struct fpu_guest guest_fpu; struct fpu_guest guest_fpu;
u64 xcr0; u64 xcr0;
u64 guest_supported_xcr0;
struct kvm_pio_request pio; struct kvm_pio_request pio;
void *pio_data; void *pio_data;
......
...@@ -1558,7 +1558,10 @@ static int fpstate_realloc(u64 xfeatures, unsigned int ksize, ...@@ -1558,7 +1558,10 @@ static int fpstate_realloc(u64 xfeatures, unsigned int ksize,
fpregs_restore_userregs(); fpregs_restore_userregs();
newfps->xfeatures = curfps->xfeatures | xfeatures; newfps->xfeatures = curfps->xfeatures | xfeatures;
newfps->user_xfeatures = curfps->user_xfeatures | xfeatures;
if (!guest_fpu)
newfps->user_xfeatures = curfps->user_xfeatures | xfeatures;
newfps->xfd = curfps->xfd & ~xfeatures; newfps->xfd = curfps->xfd & ~xfeatures;
/* Do the final updates within the locked region */ /* Do the final updates within the locked region */
......
...@@ -462,19 +462,22 @@ static bool pv_tlb_flush_supported(void) ...@@ -462,19 +462,22 @@ static bool pv_tlb_flush_supported(void)
{ {
return (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) && return (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) &&
!kvm_para_has_hint(KVM_HINTS_REALTIME) && !kvm_para_has_hint(KVM_HINTS_REALTIME) &&
kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)); kvm_para_has_feature(KVM_FEATURE_STEAL_TIME) &&
(num_possible_cpus() != 1));
} }
static bool pv_ipi_supported(void) static bool pv_ipi_supported(void)
{ {
return kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI); return (kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI) &&
(num_possible_cpus() != 1));
} }
static bool pv_sched_yield_supported(void) static bool pv_sched_yield_supported(void)
{ {
return (kvm_para_has_feature(KVM_FEATURE_PV_SCHED_YIELD) && return (kvm_para_has_feature(KVM_FEATURE_PV_SCHED_YIELD) &&
!kvm_para_has_hint(KVM_HINTS_REALTIME) && !kvm_para_has_hint(KVM_HINTS_REALTIME) &&
kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)); kvm_para_has_feature(KVM_FEATURE_STEAL_TIME) &&
(num_possible_cpus() != 1));
} }
#define KVM_IPI_CLUSTER_SIZE (2 * BITS_PER_LONG) #define KVM_IPI_CLUSTER_SIZE (2 * BITS_PER_LONG)
......
...@@ -282,6 +282,7 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) ...@@ -282,6 +282,7 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
{ {
struct kvm_lapic *apic = vcpu->arch.apic; struct kvm_lapic *apic = vcpu->arch.apic;
struct kvm_cpuid_entry2 *best; struct kvm_cpuid_entry2 *best;
u64 guest_supported_xcr0;
best = kvm_find_cpuid_entry(vcpu, 1, 0); best = kvm_find_cpuid_entry(vcpu, 1, 0);
if (best && apic) { if (best && apic) {
...@@ -293,9 +294,11 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) ...@@ -293,9 +294,11 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
kvm_apic_set_version(vcpu); kvm_apic_set_version(vcpu);
} }
vcpu->arch.guest_supported_xcr0 = guest_supported_xcr0 =
cpuid_get_supported_xcr0(vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent); cpuid_get_supported_xcr0(vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent);
vcpu->arch.guest_fpu.fpstate->user_xfeatures = guest_supported_xcr0;
kvm_update_pv_runtime(vcpu); kvm_update_pv_runtime(vcpu);
vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu); vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu);
......
...@@ -3889,12 +3889,23 @@ static void shadow_page_table_clear_flood(struct kvm_vcpu *vcpu, gva_t addr) ...@@ -3889,12 +3889,23 @@ static void shadow_page_table_clear_flood(struct kvm_vcpu *vcpu, gva_t addr)
walk_shadow_page_lockless_end(vcpu); walk_shadow_page_lockless_end(vcpu);
} }
static u32 alloc_apf_token(struct kvm_vcpu *vcpu)
{
/* make sure the token value is not 0 */
u32 id = vcpu->arch.apf.id;
if (id << 12 == 0)
vcpu->arch.apf.id = 1;
return (vcpu->arch.apf.id++ << 12) | vcpu->vcpu_id;
}
static bool kvm_arch_setup_async_pf(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, static bool kvm_arch_setup_async_pf(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
gfn_t gfn) gfn_t gfn)
{ {
struct kvm_arch_async_pf arch; struct kvm_arch_async_pf arch;
arch.token = (vcpu->arch.apf.id++ << 12) | vcpu->vcpu_id; arch.token = alloc_apf_token(vcpu);
arch.gfn = gfn; arch.gfn = gfn;
arch.direct_map = vcpu->arch.mmu->direct_map; arch.direct_map = vcpu->arch.mmu->direct_map;
arch.cr3 = vcpu->arch.mmu->get_guest_pgd(vcpu); arch.cr3 = vcpu->arch.mmu->get_guest_pgd(vcpu);
......
...@@ -2693,8 +2693,23 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) ...@@ -2693,8 +2693,23 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
u64 data = msr->data; u64 data = msr->data;
switch (ecx) { switch (ecx) {
case MSR_AMD64_TSC_RATIO: case MSR_AMD64_TSC_RATIO:
if (!msr->host_initiated && !svm->tsc_scaling_enabled)
return 1; if (!svm->tsc_scaling_enabled) {
if (!msr->host_initiated)
return 1;
/*
* In case TSC scaling is not enabled, always
* leave this MSR at the default value.
*
* Due to bug in qemu 6.2.0, it would try to set
* this msr to 0 if tsc scaling is not enabled.
* Ignore this value as well.
*/
if (data != 0 && data != svm->tsc_ratio_msr)
return 1;
break;
}
if (data & TSC_RATIO_RSVD) if (data & TSC_RATIO_RSVD)
return 1; return 1;
......
...@@ -984,6 +984,18 @@ void kvm_load_host_xsave_state(struct kvm_vcpu *vcpu) ...@@ -984,6 +984,18 @@ void kvm_load_host_xsave_state(struct kvm_vcpu *vcpu)
} }
EXPORT_SYMBOL_GPL(kvm_load_host_xsave_state); EXPORT_SYMBOL_GPL(kvm_load_host_xsave_state);
static inline u64 kvm_guest_supported_xcr0(struct kvm_vcpu *vcpu)
{
return vcpu->arch.guest_fpu.fpstate->user_xfeatures;
}
#ifdef CONFIG_X86_64
static inline u64 kvm_guest_supported_xfd(struct kvm_vcpu *vcpu)
{
return kvm_guest_supported_xcr0(vcpu) & XFEATURE_MASK_USER_DYNAMIC;
}
#endif
static int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr) static int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr)
{ {
u64 xcr0 = xcr; u64 xcr0 = xcr;
...@@ -1003,7 +1015,7 @@ static int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr) ...@@ -1003,7 +1015,7 @@ static int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr)
* saving. However, xcr0 bit 0 is always set, even if the * saving. However, xcr0 bit 0 is always set, even if the
* emulated CPU does not support XSAVE (see kvm_vcpu_reset()). * emulated CPU does not support XSAVE (see kvm_vcpu_reset()).
*/ */
valid_bits = vcpu->arch.guest_supported_xcr0 | XFEATURE_MASK_FP; valid_bits = kvm_guest_supported_xcr0(vcpu) | XFEATURE_MASK_FP;
if (xcr0 & ~valid_bits) if (xcr0 & ~valid_bits)
return 1; return 1;
...@@ -2351,10 +2363,12 @@ static u64 compute_guest_tsc(struct kvm_vcpu *vcpu, s64 kernel_ns) ...@@ -2351,10 +2363,12 @@ static u64 compute_guest_tsc(struct kvm_vcpu *vcpu, s64 kernel_ns)
return tsc; return tsc;
} }
#ifdef CONFIG_X86_64
static inline int gtod_is_based_on_tsc(int mode) static inline int gtod_is_based_on_tsc(int mode)
{ {
return mode == VDSO_CLOCKMODE_TSC || mode == VDSO_CLOCKMODE_HVCLOCK; return mode == VDSO_CLOCKMODE_TSC || mode == VDSO_CLOCKMODE_HVCLOCK;
} }
#endif
static void kvm_track_tsc_matching(struct kvm_vcpu *vcpu) static void kvm_track_tsc_matching(struct kvm_vcpu *vcpu)
{ {
...@@ -3706,8 +3720,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) ...@@ -3706,8 +3720,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
!guest_cpuid_has(vcpu, X86_FEATURE_XFD)) !guest_cpuid_has(vcpu, X86_FEATURE_XFD))
return 1; return 1;
if (data & ~(XFEATURE_MASK_USER_DYNAMIC & if (data & ~kvm_guest_supported_xfd(vcpu))
vcpu->arch.guest_supported_xcr0))
return 1; return 1;
fpu_update_guest_xfd(&vcpu->arch.guest_fpu, data); fpu_update_guest_xfd(&vcpu->arch.guest_fpu, data);
...@@ -3717,8 +3730,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) ...@@ -3717,8 +3730,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
!guest_cpuid_has(vcpu, X86_FEATURE_XFD)) !guest_cpuid_has(vcpu, X86_FEATURE_XFD))
return 1; return 1;
if (data & ~(XFEATURE_MASK_USER_DYNAMIC & if (data & ~kvm_guest_supported_xfd(vcpu))
vcpu->arch.guest_supported_xcr0))
return 1; return 1;
vcpu->arch.guest_fpu.xfd_err = data; vcpu->arch.guest_fpu.xfd_err = data;
...@@ -4233,6 +4245,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) ...@@ -4233,6 +4245,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
case KVM_CAP_EXIT_ON_EMULATION_FAILURE: case KVM_CAP_EXIT_ON_EMULATION_FAILURE:
case KVM_CAP_VCPU_ATTRIBUTES: case KVM_CAP_VCPU_ATTRIBUTES:
case KVM_CAP_SYS_ATTRIBUTES: case KVM_CAP_SYS_ATTRIBUTES:
case KVM_CAP_ENABLE_CAP:
r = 1; r = 1;
break; break;
case KVM_CAP_EXIT_HYPERCALL: case KVM_CAP_EXIT_HYPERCALL:
...@@ -8942,6 +8955,13 @@ static int kvm_pv_clock_pairing(struct kvm_vcpu *vcpu, gpa_t paddr, ...@@ -8942,6 +8955,13 @@ static int kvm_pv_clock_pairing(struct kvm_vcpu *vcpu, gpa_t paddr,
if (clock_type != KVM_CLOCK_PAIRING_WALLCLOCK) if (clock_type != KVM_CLOCK_PAIRING_WALLCLOCK)
return -KVM_EOPNOTSUPP; return -KVM_EOPNOTSUPP;
/*
* When tsc is in permanent catchup mode guests won't be able to use
* pvclock_read_retry loop to get consistent view of pvclock
*/
if (vcpu->arch.tsc_always_catchup)
return -KVM_EOPNOTSUPP;
if (!kvm_get_walltime_and_clockread(&ts, &cycle)) if (!kvm_get_walltime_and_clockread(&ts, &cycle))
return -KVM_EOPNOTSUPP; return -KVM_EOPNOTSUPP;
......
...@@ -1134,6 +1134,7 @@ struct kvm_ppc_resize_hpt { ...@@ -1134,6 +1134,7 @@ struct kvm_ppc_resize_hpt {
#define KVM_CAP_VM_GPA_BITS 207 #define KVM_CAP_VM_GPA_BITS 207
#define KVM_CAP_XSAVE2 208 #define KVM_CAP_XSAVE2 208
#define KVM_CAP_SYS_ATTRIBUTES 209 #define KVM_CAP_SYS_ATTRIBUTES 209
#define KVM_CAP_PPC_AIL_MODE_3 210
#ifdef KVM_CAP_IRQ_ROUTING #ifdef KVM_CAP_IRQ_ROUTING
......
...@@ -1134,6 +1134,7 @@ struct kvm_ppc_resize_hpt { ...@@ -1134,6 +1134,7 @@ struct kvm_ppc_resize_hpt {
#define KVM_CAP_VM_GPA_BITS 207 #define KVM_CAP_VM_GPA_BITS 207
#define KVM_CAP_XSAVE2 208 #define KVM_CAP_XSAVE2 208
#define KVM_CAP_SYS_ATTRIBUTES 209 #define KVM_CAP_SYS_ATTRIBUTES 209
#define KVM_CAP_PPC_AIL_MODE_3 210
#ifdef KVM_CAP_IRQ_ROUTING #ifdef KVM_CAP_IRQ_ROUTING
......
...@@ -5528,9 +5528,7 @@ static int kvm_suspend(void) ...@@ -5528,9 +5528,7 @@ static int kvm_suspend(void)
static void kvm_resume(void) static void kvm_resume(void)
{ {
if (kvm_usage_count) { if (kvm_usage_count) {
#ifdef CONFIG_LOCKDEP lockdep_assert_not_held(&kvm_count_lock);
WARN_ON(lockdep_is_held(&kvm_count_lock));
#endif
hardware_enable_nolock(NULL); hardware_enable_nolock(NULL);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment