Skip to content

Commit 050fc52

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull KVM fixes from Paolo Bonzini: "All x86-specific, apart from some arch-independent syzkaller fixes" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: x86: cleanup the page tracking SRCU instance KVM: nVMX: fix nested EPT detection KVM: pci-assign: do not map smm memory slot pages in vt-d page tables KVM: kvm_io_bus_unregister_dev() should never fail KVM: VMX: Fix enable VPID conditions KVM: nVMX: Fix nested VPID vmx exec control KVM: x86: correct async page present tracepoint kvm: vmx: Flush TLB when the APIC-access address changes KVM: x86: use pic/ioapic destructor when destroy vm KVM: x86: check existance before destroy KVM: x86: clear bus pointer when destroyed KVM: Documentation: document MCE ioctls KVM: nVMX: don't reset kvm mmu twice PTP: fix ptr_ret.cocci warnings kvm: fix usage of uninit spinlock in avic_vm_destroy() KVM: VMX: downgrade warning on unexpected exit code
2 parents ad0376e + 2beb6da commit 050fc52

File tree

12 files changed

+153
-35
lines changed

12 files changed

+153
-35
lines changed

Documentation/virtual/kvm/api.txt

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3377,6 +3377,69 @@ struct kvm_ppc_resize_hpt {
33773377
__u32 pad;
33783378
};
33793379

3380+
4.104 KVM_X86_GET_MCE_CAP_SUPPORTED
3381+
3382+
Capability: KVM_CAP_MCE
3383+
Architectures: x86
3384+
Type: system ioctl
3385+
Parameters: u64 mce_cap (out)
3386+
Returns: 0 on success, -1 on error
3387+
3388+
Returns supported MCE capabilities. The u64 mce_cap parameter
3389+
has the same format as the MSR_IA32_MCG_CAP register. Supported
3390+
capabilities will have the corresponding bits set.
3391+
3392+
4.105 KVM_X86_SETUP_MCE
3393+
3394+
Capability: KVM_CAP_MCE
3395+
Architectures: x86
3396+
Type: vcpu ioctl
3397+
Parameters: u64 mcg_cap (in)
3398+
Returns: 0 on success,
3399+
-EFAULT if u64 mcg_cap cannot be read,
3400+
-EINVAL if the requested number of banks is invalid,
3401+
-EINVAL if requested MCE capability is not supported.
3402+
3403+
Initializes MCE support for use. The u64 mcg_cap parameter
3404+
has the same format as the MSR_IA32_MCG_CAP register and
3405+
specifies which capabilities should be enabled. The maximum
3406+
supported number of error-reporting banks can be retrieved when
3407+
checking for KVM_CAP_MCE. The supported capabilities can be
3408+
retrieved with KVM_X86_GET_MCE_CAP_SUPPORTED.
3409+
3410+
4.106 KVM_X86_SET_MCE
3411+
3412+
Capability: KVM_CAP_MCE
3413+
Architectures: x86
3414+
Type: vcpu ioctl
3415+
Parameters: struct kvm_x86_mce (in)
3416+
Returns: 0 on success,
3417+
-EFAULT if struct kvm_x86_mce cannot be read,
3418+
-EINVAL if the bank number is invalid,
3419+
-EINVAL if VAL bit is not set in status field.
3420+
3421+
Inject a machine check error (MCE) into the guest. The input
3422+
parameter is:
3423+
3424+
struct kvm_x86_mce {
3425+
__u64 status;
3426+
__u64 addr;
3427+
__u64 misc;
3428+
__u64 mcg_status;
3429+
__u8 bank;
3430+
__u8 pad1[7];
3431+
__u64 pad2[3];
3432+
};
3433+
3434+
If the MCE being reported is an uncorrected error, KVM will
3435+
inject it as an MCE exception into the guest. If the guest
3436+
MCG_STATUS register reports that an MCE is in progress, KVM
3437+
causes an KVM_EXIT_SHUTDOWN vmexit.
3438+
3439+
Otherwise, if the MCE is a corrected error, KVM will just
3440+
store it in the corresponding bank (provided this bank is
3441+
not holding a previously reported uncorrected error).
3442+
33803443
5. The kvm_run structure
33813444
------------------------
33823445

arch/x86/include/asm/kvm_page_track.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct kvm_page_track_notifier_node {
4646
};
4747

4848
void kvm_page_track_init(struct kvm *kvm);
49+
void kvm_page_track_cleanup(struct kvm *kvm);
4950

5051
void kvm_page_track_free_memslot(struct kvm_memory_slot *free,
5152
struct kvm_memory_slot *dont);

arch/x86/kvm/i8259.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,9 @@ void kvm_pic_destroy(struct kvm *kvm)
657657
{
658658
struct kvm_pic *vpic = kvm->arch.vpic;
659659

660+
if (!vpic)
661+
return;
662+
660663
kvm_io_bus_unregister_dev(vpic->kvm, KVM_PIO_BUS, &vpic->dev_master);
661664
kvm_io_bus_unregister_dev(vpic->kvm, KVM_PIO_BUS, &vpic->dev_slave);
662665
kvm_io_bus_unregister_dev(vpic->kvm, KVM_PIO_BUS, &vpic->dev_eclr);

arch/x86/kvm/ioapic.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,9 @@ void kvm_ioapic_destroy(struct kvm *kvm)
635635
{
636636
struct kvm_ioapic *ioapic = kvm->arch.vioapic;
637637

638+
if (!ioapic)
639+
return;
640+
638641
cancel_delayed_work_sync(&ioapic->eoi_inject);
639642
kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS, &ioapic->dev);
640643
kvm->arch.vioapic = NULL;

arch/x86/kvm/page_track.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ bool kvm_page_track_is_active(struct kvm_vcpu *vcpu, gfn_t gfn,
160160
return !!ACCESS_ONCE(slot->arch.gfn_track[mode][index]);
161161
}
162162

163+
void kvm_page_track_cleanup(struct kvm *kvm)
164+
{
165+
struct kvm_page_track_notifier_head *head;
166+
167+
head = &kvm->arch.track_notifier_head;
168+
cleanup_srcu_struct(&head->track_srcu);
169+
}
170+
163171
void kvm_page_track_init(struct kvm *kvm)
164172
{
165173
struct kvm_page_track_notifier_head *head;

arch/x86/kvm/svm.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,9 @@ static void avic_vm_destroy(struct kvm *kvm)
13791379
unsigned long flags;
13801380
struct kvm_arch *vm_data = &kvm->arch;
13811381

1382+
if (!avic)
1383+
return;
1384+
13821385
avic_free_vm_id(vm_data->avic_vm_id);
13831386

13841387
if (vm_data->avic_logical_id_table_page)

arch/x86/kvm/vmx.c

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,11 @@ static inline bool cpu_has_vmx_invvpid_global(void)
12391239
return vmx_capability.vpid & VMX_VPID_EXTENT_GLOBAL_CONTEXT_BIT;
12401240
}
12411241

1242+
static inline bool cpu_has_vmx_invvpid(void)
1243+
{
1244+
return vmx_capability.vpid & VMX_VPID_INVVPID_BIT;
1245+
}
1246+
12421247
static inline bool cpu_has_vmx_ept(void)
12431248
{
12441249
return vmcs_config.cpu_based_2nd_exec_ctrl &
@@ -2753,7 +2758,6 @@ static void nested_vmx_setup_ctls_msrs(struct vcpu_vmx *vmx)
27532758
SECONDARY_EXEC_RDTSCP |
27542759
SECONDARY_EXEC_DESC |
27552760
SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE |
2756-
SECONDARY_EXEC_ENABLE_VPID |
27572761
SECONDARY_EXEC_APIC_REGISTER_VIRT |
27582762
SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY |
27592763
SECONDARY_EXEC_WBINVD_EXITING |
@@ -2781,10 +2785,12 @@ static void nested_vmx_setup_ctls_msrs(struct vcpu_vmx *vmx)
27812785
* though it is treated as global context. The alternative is
27822786
* not failing the single-context invvpid, and it is worse.
27832787
*/
2784-
if (enable_vpid)
2788+
if (enable_vpid) {
2789+
vmx->nested.nested_vmx_secondary_ctls_high |=
2790+
SECONDARY_EXEC_ENABLE_VPID;
27852791
vmx->nested.nested_vmx_vpid_caps = VMX_VPID_INVVPID_BIT |
27862792
VMX_VPID_EXTENT_SUPPORTED_MASK;
2787-
else
2793+
} else
27882794
vmx->nested.nested_vmx_vpid_caps = 0;
27892795

27902796
if (enable_unrestricted_guest)
@@ -4024,6 +4030,12 @@ static void vmx_flush_tlb(struct kvm_vcpu *vcpu)
40244030
__vmx_flush_tlb(vcpu, to_vmx(vcpu)->vpid);
40254031
}
40264032

4033+
static void vmx_flush_tlb_ept_only(struct kvm_vcpu *vcpu)
4034+
{
4035+
if (enable_ept)
4036+
vmx_flush_tlb(vcpu);
4037+
}
4038+
40274039
static void vmx_decache_cr0_guest_bits(struct kvm_vcpu *vcpu)
40284040
{
40294041
ulong cr0_guest_owned_bits = vcpu->arch.cr0_guest_owned_bits;
@@ -6517,8 +6529,10 @@ static __init int hardware_setup(void)
65176529
if (boot_cpu_has(X86_FEATURE_NX))
65186530
kvm_enable_efer_bits(EFER_NX);
65196531

6520-
if (!cpu_has_vmx_vpid())
6532+
if (!cpu_has_vmx_vpid() || !cpu_has_vmx_invvpid() ||
6533+
!(cpu_has_vmx_invvpid_single() || cpu_has_vmx_invvpid_global()))
65216534
enable_vpid = 0;
6535+
65226536
if (!cpu_has_vmx_shadow_vmcs())
65236537
enable_shadow_vmcs = 0;
65246538
if (enable_shadow_vmcs)
@@ -8501,7 +8515,8 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu)
85018515
&& kvm_vmx_exit_handlers[exit_reason])
85028516
return kvm_vmx_exit_handlers[exit_reason](vcpu);
85038517
else {
8504-
WARN_ONCE(1, "vmx: unexpected exit reason 0x%x\n", exit_reason);
8518+
vcpu_unimpl(vcpu, "vmx: unexpected exit reason 0x%x\n",
8519+
exit_reason);
85058520
kvm_queue_exception(vcpu, UD_VECTOR);
85068521
return 1;
85078522
}
@@ -8547,6 +8562,7 @@ static void vmx_set_virtual_x2apic_mode(struct kvm_vcpu *vcpu, bool set)
85478562
} else {
85488563
sec_exec_control &= ~SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE;
85498564
sec_exec_control |= SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES;
8565+
vmx_flush_tlb_ept_only(vcpu);
85508566
}
85518567
vmcs_write32(SECONDARY_VM_EXEC_CONTROL, sec_exec_control);
85528568

@@ -8572,8 +8588,10 @@ static void vmx_set_apic_access_page_addr(struct kvm_vcpu *vcpu, hpa_t hpa)
85728588
*/
85738589
if (!is_guest_mode(vcpu) ||
85748590
!nested_cpu_has2(get_vmcs12(&vmx->vcpu),
8575-
SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES))
8591+
SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES)) {
85768592
vmcs_write64(APIC_ACCESS_ADDR, hpa);
8593+
vmx_flush_tlb_ept_only(vcpu);
8594+
}
85778595
}
85788596

85798597
static void vmx_hwapic_isr_update(struct kvm_vcpu *vcpu, int max_isr)
@@ -9974,7 +9992,6 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
99749992
{
99759993
struct vcpu_vmx *vmx = to_vmx(vcpu);
99769994
u32 exec_control;
9977-
bool nested_ept_enabled = false;
99789995

99799996
vmcs_write16(GUEST_ES_SELECTOR, vmcs12->guest_es_selector);
99809997
vmcs_write16(GUEST_CS_SELECTOR, vmcs12->guest_cs_selector);
@@ -10121,8 +10138,6 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
1012110138
vmcs12->guest_intr_status);
1012210139
}
1012310140

10124-
nested_ept_enabled = (exec_control & SECONDARY_EXEC_ENABLE_EPT) != 0;
10125-
1012610141
/*
1012710142
* Write an illegal value to APIC_ACCESS_ADDR. Later,
1012810143
* nested_get_vmcs12_pages will either fix it up or
@@ -10255,6 +10270,9 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
1025510270
if (nested_cpu_has_ept(vmcs12)) {
1025610271
kvm_mmu_unload(vcpu);
1025710272
nested_ept_init_mmu_context(vcpu);
10273+
} else if (nested_cpu_has2(vmcs12,
10274+
SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES)) {
10275+
vmx_flush_tlb_ept_only(vcpu);
1025810276
}
1025910277

1026010278
/*
@@ -10282,12 +10300,10 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
1028210300
vmx_set_efer(vcpu, vcpu->arch.efer);
1028310301

1028410302
/* Shadow page tables on either EPT or shadow page tables. */
10285-
if (nested_vmx_load_cr3(vcpu, vmcs12->guest_cr3, nested_ept_enabled,
10303+
if (nested_vmx_load_cr3(vcpu, vmcs12->guest_cr3, nested_cpu_has_ept(vmcs12),
1028610304
entry_failure_code))
1028710305
return 1;
1028810306

10289-
kvm_mmu_reset_context(vcpu);
10290-
1029110307
if (!enable_ept)
1029210308
vcpu->arch.walk_mmu->inject_page_fault = vmx_inject_page_fault_nested;
1029310309

@@ -11056,6 +11072,10 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
1105611072
vmx->nested.change_vmcs01_virtual_x2apic_mode = false;
1105711073
vmx_set_virtual_x2apic_mode(vcpu,
1105811074
vcpu->arch.apic_base & X2APIC_ENABLE);
11075+
} else if (!nested_cpu_has_ept(vmcs12) &&
11076+
nested_cpu_has2(vmcs12,
11077+
SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES)) {
11078+
vmx_flush_tlb_ept_only(vcpu);
1105911079
}
1106011080

1106111081
/* This is needed for same reason as it was needed in prepare_vmcs02 */

arch/x86/kvm/x86.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8153,11 +8153,12 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
81538153
if (kvm_x86_ops->vm_destroy)
81548154
kvm_x86_ops->vm_destroy(kvm);
81558155
kvm_iommu_unmap_guest(kvm);
8156-
kfree(kvm->arch.vpic);
8157-
kfree(kvm->arch.vioapic);
8156+
kvm_pic_destroy(kvm);
8157+
kvm_ioapic_destroy(kvm);
81588158
kvm_free_vcpus(kvm);
81598159
kvfree(rcu_dereference_check(kvm->arch.apic_map, 1));
81608160
kvm_mmu_uninit_vm(kvm);
8161+
kvm_page_track_cleanup(kvm);
81618162
}
81628163

81638164
void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free,
@@ -8566,11 +8567,11 @@ void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
85668567
{
85678568
struct x86_exception fault;
85688569

8569-
trace_kvm_async_pf_ready(work->arch.token, work->gva);
85708570
if (work->wakeup_all)
85718571
work->arch.token = ~0; /* broadcast wakeup */
85728572
else
85738573
kvm_del_async_pf_gfn(vcpu, work->arch.gfn);
8574+
trace_kvm_async_pf_ready(work->arch.token, work->gva);
85748575

85758576
if ((vcpu->arch.apf.msr_val & KVM_ASYNC_PF_ENABLED) &&
85768577
!apf_put_user(vcpu, KVM_PV_REASON_PAGE_READY)) {

drivers/ptp/ptp_kvm.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,7 @@ static int __init ptp_kvm_init(void)
193193

194194
kvm_ptp_clock.ptp_clock = ptp_clock_register(&kvm_ptp_clock.caps, NULL);
195195

196-
if (IS_ERR(kvm_ptp_clock.ptp_clock))
197-
return PTR_ERR(kvm_ptp_clock.ptp_clock);
198-
199-
return 0;
196+
return PTR_ERR_OR_ZERO(kvm_ptp_clock.ptp_clock);
200197
}
201198

202199
module_init(ptp_kvm_init);

include/linux/kvm_host.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ int kvm_io_bus_read(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx, gpa_t addr,
162162
int len, void *val);
163163
int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
164164
int len, struct kvm_io_device *dev);
165-
int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
166-
struct kvm_io_device *dev);
165+
void kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
166+
struct kvm_io_device *dev);
167167
struct kvm_io_device *kvm_io_bus_get_dev(struct kvm *kvm, enum kvm_bus bus_idx,
168168
gpa_t addr);
169169

0 commit comments

Comments
 (0)