diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-07-18 14:08:44 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-07-18 14:08:44 -0400 |
commit | 47f7dc4b845a9fe60c53b84b8c88cf14efd0de7f (patch) | |
tree | 5a2f8f10c9e49235ff63bd6858c663ee099470bf | |
parent | 3c53776e29f81719efcf8f7a6e30cdf753bee94d (diff) | |
parent | e10f7805032365cc11c739a97f226ebb48aee042 (diff) |
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull kvm fixes from Paolo Bonzini:
"Miscellaneous bugfixes, plus a small patchlet related to Spectre v2"
* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm:
kvmclock: fix TSC calibration for nested guests
KVM: VMX: Mark VMXArea with revision_id of physical CPU even when eVMCS enabled
KVM: irqfd: fix race between EPOLLHUP and irq_bypass_register_consumer
KVM/Eventfd: Avoid crash when assign and deassign specific eventfd in parallel.
x86/kvmclock: set pvti_cpu0_va after enabling kvmclock
x86/kvm/Kconfig: Ensure CRYPTO_DEV_CCP_DD state at minimum matches KVM_AMD
kvm: nVMX: Restore exit qual for VM-entry failure due to MSR loading
x86/kvm/vmx: don't read current->thread.{fs,gs}base of legacy tasks
KVM: VMX: support MSR_IA32_ARCH_CAPABILITIES as a feature MSR
-rw-r--r-- | arch/x86/kernel/kvmclock.c | 12 | ||||
-rw-r--r-- | arch/x86/kvm/Kconfig | 2 | ||||
-rw-r--r-- | arch/x86/kvm/vmx.c | 61 | ||||
-rw-r--r-- | arch/x86/kvm/x86.c | 4 | ||||
-rw-r--r-- | virt/kvm/eventfd.c | 17 |
5 files changed, 63 insertions, 33 deletions
diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index bf8d1eb7fca3..3b8e7c13c614 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c | |||
@@ -138,6 +138,7 @@ static unsigned long kvm_get_tsc_khz(void) | |||
138 | src = &hv_clock[cpu].pvti; | 138 | src = &hv_clock[cpu].pvti; |
139 | tsc_khz = pvclock_tsc_khz(src); | 139 | tsc_khz = pvclock_tsc_khz(src); |
140 | put_cpu(); | 140 | put_cpu(); |
141 | setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ); | ||
141 | return tsc_khz; | 142 | return tsc_khz; |
142 | } | 143 | } |
143 | 144 | ||
@@ -319,6 +320,8 @@ void __init kvmclock_init(void) | |||
319 | printk(KERN_INFO "kvm-clock: Using msrs %x and %x", | 320 | printk(KERN_INFO "kvm-clock: Using msrs %x and %x", |
320 | msr_kvm_system_time, msr_kvm_wall_clock); | 321 | msr_kvm_system_time, msr_kvm_wall_clock); |
321 | 322 | ||
323 | pvclock_set_pvti_cpu0_va(hv_clock); | ||
324 | |||
322 | if (kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE_STABLE_BIT)) | 325 | if (kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE_STABLE_BIT)) |
323 | pvclock_set_flags(PVCLOCK_TSC_STABLE_BIT); | 326 | pvclock_set_flags(PVCLOCK_TSC_STABLE_BIT); |
324 | 327 | ||
@@ -366,14 +369,11 @@ int __init kvm_setup_vsyscall_timeinfo(void) | |||
366 | vcpu_time = &hv_clock[cpu].pvti; | 369 | vcpu_time = &hv_clock[cpu].pvti; |
367 | flags = pvclock_read_flags(vcpu_time); | 370 | flags = pvclock_read_flags(vcpu_time); |
368 | 371 | ||
369 | if (!(flags & PVCLOCK_TSC_STABLE_BIT)) { | ||
370 | put_cpu(); | ||
371 | return 1; | ||
372 | } | ||
373 | |||
374 | pvclock_set_pvti_cpu0_va(hv_clock); | ||
375 | put_cpu(); | 372 | put_cpu(); |
376 | 373 | ||
374 | if (!(flags & PVCLOCK_TSC_STABLE_BIT)) | ||
375 | return 1; | ||
376 | |||
377 | kvm_clock.archdata.vclock_mode = VCLOCK_PVCLOCK; | 377 | kvm_clock.archdata.vclock_mode = VCLOCK_PVCLOCK; |
378 | #endif | 378 | #endif |
379 | return 0; | 379 | return 0; |
diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig index 92fd433c50b9..1bbec387d289 100644 --- a/arch/x86/kvm/Kconfig +++ b/arch/x86/kvm/Kconfig | |||
@@ -85,7 +85,7 @@ config KVM_AMD_SEV | |||
85 | def_bool y | 85 | def_bool y |
86 | bool "AMD Secure Encrypted Virtualization (SEV) support" | 86 | bool "AMD Secure Encrypted Virtualization (SEV) support" |
87 | depends on KVM_AMD && X86_64 | 87 | depends on KVM_AMD && X86_64 |
88 | depends on CRYPTO_DEV_CCP && CRYPTO_DEV_CCP_DD && CRYPTO_DEV_SP_PSP | 88 | depends on CRYPTO_DEV_SP_PSP && !(KVM_AMD=y && CRYPTO_DEV_CCP_DD=m) |
89 | ---help--- | 89 | ---help--- |
90 | Provides support for launching Encrypted VMs on AMD processors. | 90 | Provides support for launching Encrypted VMs on AMD processors. |
91 | 91 | ||
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 1689f433f3a0..e30da9a2430c 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c | |||
@@ -2571,6 +2571,7 @@ static void vmx_save_host_state(struct kvm_vcpu *vcpu) | |||
2571 | struct vcpu_vmx *vmx = to_vmx(vcpu); | 2571 | struct vcpu_vmx *vmx = to_vmx(vcpu); |
2572 | #ifdef CONFIG_X86_64 | 2572 | #ifdef CONFIG_X86_64 |
2573 | int cpu = raw_smp_processor_id(); | 2573 | int cpu = raw_smp_processor_id(); |
2574 | unsigned long fs_base, kernel_gs_base; | ||
2574 | #endif | 2575 | #endif |
2575 | int i; | 2576 | int i; |
2576 | 2577 | ||
@@ -2586,12 +2587,20 @@ static void vmx_save_host_state(struct kvm_vcpu *vcpu) | |||
2586 | vmx->host_state.gs_ldt_reload_needed = vmx->host_state.ldt_sel; | 2587 | vmx->host_state.gs_ldt_reload_needed = vmx->host_state.ldt_sel; |
2587 | 2588 | ||
2588 | #ifdef CONFIG_X86_64 | 2589 | #ifdef CONFIG_X86_64 |
2589 | save_fsgs_for_kvm(); | 2590 | if (likely(is_64bit_mm(current->mm))) { |
2590 | vmx->host_state.fs_sel = current->thread.fsindex; | 2591 | save_fsgs_for_kvm(); |
2591 | vmx->host_state.gs_sel = current->thread.gsindex; | 2592 | vmx->host_state.fs_sel = current->thread.fsindex; |
2592 | #else | 2593 | vmx->host_state.gs_sel = current->thread.gsindex; |
2593 | savesegment(fs, vmx->host_state.fs_sel); | 2594 | fs_base = current->thread.fsbase; |
2594 | savesegment(gs, vmx->host_state.gs_sel); | 2595 | kernel_gs_base = current->thread.gsbase; |
2596 | } else { | ||
2597 | #endif | ||
2598 | savesegment(fs, vmx->host_state.fs_sel); | ||
2599 | savesegment(gs, vmx->host_state.gs_sel); | ||
2600 | #ifdef CONFIG_X86_64 | ||
2601 | fs_base = read_msr(MSR_FS_BASE); | ||
2602 | kernel_gs_base = read_msr(MSR_KERNEL_GS_BASE); | ||
2603 | } | ||
2595 | #endif | 2604 | #endif |
2596 | if (!(vmx->host_state.fs_sel & 7)) { | 2605 | if (!(vmx->host_state.fs_sel & 7)) { |
2597 | vmcs_write16(HOST_FS_SELECTOR, vmx->host_state.fs_sel); | 2606 | vmcs_write16(HOST_FS_SELECTOR, vmx->host_state.fs_sel); |
@@ -2611,10 +2620,10 @@ static void vmx_save_host_state(struct kvm_vcpu *vcpu) | |||
2611 | savesegment(ds, vmx->host_state.ds_sel); | 2620 | savesegment(ds, vmx->host_state.ds_sel); |
2612 | savesegment(es, vmx->host_state.es_sel); | 2621 | savesegment(es, vmx->host_state.es_sel); |
2613 | 2622 | ||
2614 | vmcs_writel(HOST_FS_BASE, current->thread.fsbase); | 2623 | vmcs_writel(HOST_FS_BASE, fs_base); |
2615 | vmcs_writel(HOST_GS_BASE, cpu_kernelmode_gs_base(cpu)); | 2624 | vmcs_writel(HOST_GS_BASE, cpu_kernelmode_gs_base(cpu)); |
2616 | 2625 | ||
2617 | vmx->msr_host_kernel_gs_base = current->thread.gsbase; | 2626 | vmx->msr_host_kernel_gs_base = kernel_gs_base; |
2618 | if (is_long_mode(&vmx->vcpu)) | 2627 | if (is_long_mode(&vmx->vcpu)) |
2619 | wrmsrl(MSR_KERNEL_GS_BASE, vmx->msr_guest_kernel_gs_base); | 2628 | wrmsrl(MSR_KERNEL_GS_BASE, vmx->msr_guest_kernel_gs_base); |
2620 | #else | 2629 | #else |
@@ -4322,11 +4331,7 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf) | |||
4322 | vmcs_conf->order = get_order(vmcs_conf->size); | 4331 | vmcs_conf->order = get_order(vmcs_conf->size); |
4323 | vmcs_conf->basic_cap = vmx_msr_high & ~0x1fff; | 4332 | vmcs_conf->basic_cap = vmx_msr_high & ~0x1fff; |
4324 | 4333 | ||
4325 | /* KVM supports Enlightened VMCS v1 only */ | 4334 | vmcs_conf->revision_id = vmx_msr_low; |
4326 | if (static_branch_unlikely(&enable_evmcs)) | ||
4327 | vmcs_conf->revision_id = KVM_EVMCS_VERSION; | ||
4328 | else | ||
4329 | vmcs_conf->revision_id = vmx_msr_low; | ||
4330 | 4335 | ||
4331 | vmcs_conf->pin_based_exec_ctrl = _pin_based_exec_control; | 4336 | vmcs_conf->pin_based_exec_ctrl = _pin_based_exec_control; |
4332 | vmcs_conf->cpu_based_exec_ctrl = _cpu_based_exec_control; | 4337 | vmcs_conf->cpu_based_exec_ctrl = _cpu_based_exec_control; |
@@ -4396,7 +4401,13 @@ static struct vmcs *alloc_vmcs_cpu(int cpu) | |||
4396 | return NULL; | 4401 | return NULL; |
4397 | vmcs = page_address(pages); | 4402 | vmcs = page_address(pages); |
4398 | memset(vmcs, 0, vmcs_config.size); | 4403 | memset(vmcs, 0, vmcs_config.size); |
4399 | vmcs->revision_id = vmcs_config.revision_id; /* vmcs revision id */ | 4404 | |
4405 | /* KVM supports Enlightened VMCS v1 only */ | ||
4406 | if (static_branch_unlikely(&enable_evmcs)) | ||
4407 | vmcs->revision_id = KVM_EVMCS_VERSION; | ||
4408 | else | ||
4409 | vmcs->revision_id = vmcs_config.revision_id; | ||
4410 | |||
4400 | return vmcs; | 4411 | return vmcs; |
4401 | } | 4412 | } |
4402 | 4413 | ||
@@ -4564,6 +4575,19 @@ static __init int alloc_kvm_area(void) | |||
4564 | return -ENOMEM; | 4575 | return -ENOMEM; |
4565 | } | 4576 | } |
4566 | 4577 | ||
4578 | /* | ||
4579 | * When eVMCS is enabled, alloc_vmcs_cpu() sets | ||
4580 | * vmcs->revision_id to KVM_EVMCS_VERSION instead of | ||
4581 | * revision_id reported by MSR_IA32_VMX_BASIC. | ||
4582 | * | ||
4583 | * However, even though not explictly documented by | ||
4584 | * TLFS, VMXArea passed as VMXON argument should | ||
4585 | * still be marked with revision_id reported by | ||
4586 | * physical CPU. | ||
4587 | */ | ||
4588 | if (static_branch_unlikely(&enable_evmcs)) | ||
4589 | vmcs->revision_id = vmcs_config.revision_id; | ||
4590 | |||
4567 | per_cpu(vmxarea, cpu) = vmcs; | 4591 | per_cpu(vmxarea, cpu) = vmcs; |
4568 | } | 4592 | } |
4569 | return 0; | 4593 | return 0; |
@@ -11753,7 +11777,6 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu) | |||
11753 | { | 11777 | { |
11754 | struct vcpu_vmx *vmx = to_vmx(vcpu); | 11778 | struct vcpu_vmx *vmx = to_vmx(vcpu); |
11755 | struct vmcs12 *vmcs12 = get_vmcs12(vcpu); | 11779 | struct vmcs12 *vmcs12 = get_vmcs12(vcpu); |
11756 | u32 msr_entry_idx; | ||
11757 | u32 exit_qual; | 11780 | u32 exit_qual; |
11758 | int r; | 11781 | int r; |
11759 | 11782 | ||
@@ -11775,10 +11798,10 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu) | |||
11775 | nested_get_vmcs12_pages(vcpu, vmcs12); | 11798 | nested_get_vmcs12_pages(vcpu, vmcs12); |
11776 | 11799 | ||
11777 | r = EXIT_REASON_MSR_LOAD_FAIL; | 11800 | r = EXIT_REASON_MSR_LOAD_FAIL; |
11778 | msr_entry_idx = nested_vmx_load_msr(vcpu, | 11801 | exit_qual = nested_vmx_load_msr(vcpu, |
11779 | vmcs12->vm_entry_msr_load_addr, | 11802 | vmcs12->vm_entry_msr_load_addr, |
11780 | vmcs12->vm_entry_msr_load_count); | 11803 | vmcs12->vm_entry_msr_load_count); |
11781 | if (msr_entry_idx) | 11804 | if (exit_qual) |
11782 | goto fail; | 11805 | goto fail; |
11783 | 11806 | ||
11784 | /* | 11807 | /* |
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 0046aa70205a..2b812b3c5088 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -1097,6 +1097,7 @@ static u32 msr_based_features[] = { | |||
1097 | 1097 | ||
1098 | MSR_F10H_DECFG, | 1098 | MSR_F10H_DECFG, |
1099 | MSR_IA32_UCODE_REV, | 1099 | MSR_IA32_UCODE_REV, |
1100 | MSR_IA32_ARCH_CAPABILITIES, | ||
1100 | }; | 1101 | }; |
1101 | 1102 | ||
1102 | static unsigned int num_msr_based_features; | 1103 | static unsigned int num_msr_based_features; |
@@ -1105,7 +1106,8 @@ static int kvm_get_msr_feature(struct kvm_msr_entry *msr) | |||
1105 | { | 1106 | { |
1106 | switch (msr->index) { | 1107 | switch (msr->index) { |
1107 | case MSR_IA32_UCODE_REV: | 1108 | case MSR_IA32_UCODE_REV: |
1108 | rdmsrl(msr->index, msr->data); | 1109 | case MSR_IA32_ARCH_CAPABILITIES: |
1110 | rdmsrl_safe(msr->index, &msr->data); | ||
1109 | break; | 1111 | break; |
1110 | default: | 1112 | default: |
1111 | if (kvm_x86_ops->get_msr_feature(msr)) | 1113 | if (kvm_x86_ops->get_msr_feature(msr)) |
diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c index 90d30fbe95ae..b20b751286fc 100644 --- a/virt/kvm/eventfd.c +++ b/virt/kvm/eventfd.c | |||
@@ -119,8 +119,12 @@ irqfd_shutdown(struct work_struct *work) | |||
119 | { | 119 | { |
120 | struct kvm_kernel_irqfd *irqfd = | 120 | struct kvm_kernel_irqfd *irqfd = |
121 | container_of(work, struct kvm_kernel_irqfd, shutdown); | 121 | container_of(work, struct kvm_kernel_irqfd, shutdown); |
122 | struct kvm *kvm = irqfd->kvm; | ||
122 | u64 cnt; | 123 | u64 cnt; |
123 | 124 | ||
125 | /* Make sure irqfd has been initalized in assign path. */ | ||
126 | synchronize_srcu(&kvm->irq_srcu); | ||
127 | |||
124 | /* | 128 | /* |
125 | * Synchronize with the wait-queue and unhook ourselves to prevent | 129 | * Synchronize with the wait-queue and unhook ourselves to prevent |
126 | * further events. | 130 | * further events. |
@@ -387,7 +391,6 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args) | |||
387 | 391 | ||
388 | idx = srcu_read_lock(&kvm->irq_srcu); | 392 | idx = srcu_read_lock(&kvm->irq_srcu); |
389 | irqfd_update(kvm, irqfd); | 393 | irqfd_update(kvm, irqfd); |
390 | srcu_read_unlock(&kvm->irq_srcu, idx); | ||
391 | 394 | ||
392 | list_add_tail(&irqfd->list, &kvm->irqfds.items); | 395 | list_add_tail(&irqfd->list, &kvm->irqfds.items); |
393 | 396 | ||
@@ -402,11 +405,6 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args) | |||
402 | if (events & EPOLLIN) | 405 | if (events & EPOLLIN) |
403 | schedule_work(&irqfd->inject); | 406 | schedule_work(&irqfd->inject); |
404 | 407 | ||
405 | /* | ||
406 | * do not drop the file until the irqfd is fully initialized, otherwise | ||
407 | * we might race against the EPOLLHUP | ||
408 | */ | ||
409 | fdput(f); | ||
410 | #ifdef CONFIG_HAVE_KVM_IRQ_BYPASS | 408 | #ifdef CONFIG_HAVE_KVM_IRQ_BYPASS |
411 | if (kvm_arch_has_irq_bypass()) { | 409 | if (kvm_arch_has_irq_bypass()) { |
412 | irqfd->consumer.token = (void *)irqfd->eventfd; | 410 | irqfd->consumer.token = (void *)irqfd->eventfd; |
@@ -421,6 +419,13 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args) | |||
421 | } | 419 | } |
422 | #endif | 420 | #endif |
423 | 421 | ||
422 | srcu_read_unlock(&kvm->irq_srcu, idx); | ||
423 | |||
424 | /* | ||
425 | * do not drop the file until the irqfd is fully initialized, otherwise | ||
426 | * we might race against the EPOLLHUP | ||
427 | */ | ||
428 | fdput(f); | ||
424 | return 0; | 429 | return 0; |
425 | 430 | ||
426 | fail: | 431 | fail: |