Skip to content

Commit 6fcee03

Browse files
Maxim Levitskybonzini
authored andcommitted
KVM: x86: avoid loading a vCPU after .vm_destroy was called
This can cause various unexpected issues, since VM is partially destroyed at that point. For example when AVIC is enabled, this causes avic_vcpu_load to access physical id page entry which is already freed by .vm_destroy. Fixes: 8221c13 ("svm: Manage vcpu load/unload when enable AVIC") Cc: [email protected] Signed-off-by: Maxim Levitsky <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 84e5ffd commit 6fcee03

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

arch/x86/kvm/x86.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11816,20 +11816,15 @@ static void kvm_unload_vcpu_mmu(struct kvm_vcpu *vcpu)
1181611816
vcpu_put(vcpu);
1181711817
}
1181811818

11819-
static void kvm_free_vcpus(struct kvm *kvm)
11819+
static void kvm_unload_vcpu_mmus(struct kvm *kvm)
1182011820
{
1182111821
unsigned long i;
1182211822
struct kvm_vcpu *vcpu;
1182311823

11824-
/*
11825-
* Unpin any mmu pages first.
11826-
*/
1182711824
kvm_for_each_vcpu(i, vcpu, kvm) {
1182811825
kvm_clear_async_pf_completion_queue(vcpu);
1182911826
kvm_unload_vcpu_mmu(vcpu);
1183011827
}
11831-
11832-
kvm_destroy_vcpus(kvm);
1183311828
}
1183411829

1183511830
void kvm_arch_sync_events(struct kvm *kvm)
@@ -11935,11 +11930,12 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
1193511930
__x86_set_memory_region(kvm, TSS_PRIVATE_MEMSLOT, 0, 0);
1193611931
mutex_unlock(&kvm->slots_lock);
1193711932
}
11933+
kvm_unload_vcpu_mmus(kvm);
1193811934
static_call_cond(kvm_x86_vm_destroy)(kvm);
1193911935
kvm_free_msr_filter(srcu_dereference_check(kvm->arch.msr_filter, &kvm->srcu, 1));
1194011936
kvm_pic_destroy(kvm);
1194111937
kvm_ioapic_destroy(kvm);
11942-
kvm_free_vcpus(kvm);
11938+
kvm_destroy_vcpus(kvm);
1194311939
kvfree(rcu_dereference_check(kvm->arch.apic_map, 1));
1194411940
kfree(srcu_dereference_check(kvm->arch.pmu_event_filter, &kvm->srcu, 1));
1194511941
kvm_mmu_uninit_vm(kvm);

0 commit comments

Comments
 (0)