From: Suravee Suthikulpanit Date: Wed, 4 May 2016 19:09:42 +0000 (-0500) Subject: KVM: x86: Introducing kvm_x86_ops VM init/destroy hooks X-Git-Tag: v4.1.12-124.31.3~642 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=3b3811c583b91ae19be9ba21bb28e01a2b584b30;p=users%2Fjedix%2Flinux-maple.git KVM: x86: Introducing kvm_x86_ops VM init/destroy hooks Adding function pointers in struct kvm_x86_ops for processor-specific layer to provide hooks for when KVM initialize and destroy VM. Signed-off-by: Suravee Suthikulpanit Signed-off-by: Paolo Bonzini Orabug: 28220674 CVE: CVE-2018-3646 (cherry picked from commit 03543133cea646406307870823343912c1ef0a3a) Signed-off-by: Mihai Carabas Reviewed-by: Darren Kenny Reviewed-by: Boris Ostrovsky Conflicts: arch/x86/kvm/x86.c Contextual: different content The commit was necessary for 47009da5 "x86/KVM: Warn user if KVM is loaded SMT and L1TF CPU bug being present" --- diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 4b3cc2be7260..10dd34d36ccd 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -711,6 +711,9 @@ struct kvm_x86_ops { bool (*has_emulated_msr)(int index); void (*cpuid_update)(struct kvm_vcpu *vcpu); + int (*vm_init)(struct kvm *kvm); + void (*vm_destroy)(struct kvm *kvm); + /* Create, but do not attach this VCPU */ struct kvm_vcpu *(*vcpu_create)(struct kvm *kvm, unsigned id); void (*vcpu_free)(struct kvm_vcpu *vcpu); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 70c5796c14e8..d128875fd642 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7456,6 +7456,9 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) INIT_DELAYED_WORK(&kvm->arch.kvmclock_update_work, kvmclock_update_fn); INIT_DELAYED_WORK(&kvm->arch.kvmclock_sync_work, kvmclock_sync_fn); + if (kvm_x86_ops->vm_init) + return kvm_x86_ops->vm_init(kvm); + return 0; } @@ -7518,6 +7521,8 @@ void kvm_arch_destroy_vm(struct kvm *kvm) mem.slot = TSS_PRIVATE_MEMSLOT; kvm_set_memory_region(kvm, &mem); } + if (kvm_x86_ops->vm_destroy) + kvm_x86_ops->vm_destroy(kvm); kvm_iommu_unmap_guest(kvm); kfree(kvm->arch.vpic); kfree(kvm->arch.vioapic);