History

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

Pull kvm fixes from Paolo Bonzini: "generic: - fix memory leak on failure to create VM x86: - fix MMU corner case with AMD nested paging disabled" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: vmx, svm: always run with EFER.NXE=1 when shadow paging is active kvm: call kvm_arch_destroy_vm if vm creation fails kvm: Allocate memslots and buses before calling kvm_arch_init_vm

Linus Torvalds committed 7 years ago

Commit b88866b2 parents 1461624 9167ab73 files · +37 −35Browse files

Unified · Split

3 files
  1. arch/x86/kvm/svm.c +8 −2
  2. arch/x86/kvm/vmx/vmx.c +3 −11
  3. virt/kvm/kvm_main.c +26 −22
arch/x86/kvm/svm.c+8−2
@@ -734,8 +734,14 @@ static int get_npt_level(struct kvm_vcpu *vcpu) · 733 unmodified lines
734734 static void svm_set_efer(struct kvm_vcpu *vcpu, u64 efer)
735735 {
736736 vcpu->arch.efer = efer;
737− if (!npt_enabled && !(efer & EFER_LMA))
738− efer &= ~EFER_LME;
737+
738+ if (!npt_enabled) {
739+ /* Shadow paging assumes NX to be available. */
740+ efer |= EFER_NX;
741+
742+ if (!(efer & EFER_LMA))
743+ efer &= ~EFER_LME;
744+ }
739745
740746 to_svm(vcpu)->vmcb->save.efer = efer | EFER_SVME;
741747 mark_dirty(to_svm(vcpu)->vmcb, VMCB_CR);
arch/x86/kvm/vmx/vmx.c+3−11
@@ -969,17 +969,9 @@ static bool update_transition_efer(struct vcpu_vmx *vmx, int efer_offset) · 968 unmodified lines
969969 u64 guest_efer = vmx->vcpu.arch.efer;
970970 u64 ignore_bits = 0;
971971
972− if (!enable_ept) {
973− /*
974− * NX is needed to handle CR0.WP=1, CR4.SMEP=1. Testing
975− * host CPUID is more efficient than testing guest CPUID
976− * or CR4. Host SMEP is anyway a requirement for guest SMEP.
977− */
978− if (boot_cpu_has(X86_FEATURE_SMEP))
979− guest_efer |= EFER_NX;
980− else if (!(guest_efer & EFER_NX))
981− ignore_bits |= EFER_NX;
982− }
972+ /* Shadow paging assumes NX to be available. */
973+ if (!enable_ept)
974+ guest_efer |= EFER_NX;
983975
984976 /*
985977 * LMA and LME handled by hardware; SCE meaningless outside long mode.
virt/kvm/kvm_main.c+26−22
@@ -627,8 +627,9 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, int fd) · 626 unmodified lines
627627
628628 static struct kvm *kvm_create_vm(unsigned long type)
629629 {
630− int r, i;
631630 struct kvm *kvm = kvm_arch_alloc_vm();
631+ int r = -ENOMEM;
632+ int i;
632633
633634 if (!kvm)
634635 return ERR_PTR(-ENOMEM);
@@ -640,44 +641,45 @@ static struct kvm *kvm_create_vm(unsigned long type) · 5 unmodified lines
640641 mutex_init(&kvm->lock);
641642 mutex_init(&kvm->irq_lock);
642643 mutex_init(&kvm->slots_lock);
643− refcount_set(&kvm->users_count, 1);
644644 INIT_LIST_HEAD(&kvm->devices);
645645
646− r = kvm_arch_init_vm(kvm, type);
647− if (r)
648− goto out_err_no_disable;
649−
650− r = hardware_enable_all();
651− if (r)
652− goto out_err_no_disable;
653−
654−#ifdef CONFIG_HAVE_KVM_IRQFD
655− INIT_HLIST_HEAD(&kvm->irq_ack_notifier_list);
656−#endif
657−
658646 BUILD_BUG_ON(KVM_MEM_SLOTS_NUM > SHRT_MAX);
659647
660− r = -ENOMEM;
661648 for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) {
662649 struct kvm_memslots *slots = kvm_alloc_memslots();
650+
663651 if (!slots)
664− goto out_err_no_srcu;
652+ goto out_err_no_arch_destroy_vm;
665653 /* Generations must be different for each address space. */
666654 slots->generation = i;
667655 rcu_assign_pointer(kvm->memslots[i], slots);
668656 }
669657
670− if (init_srcu_struct(&kvm->srcu))
671− goto out_err_no_srcu;
672− if (init_srcu_struct(&kvm->irq_srcu))
673− goto out_err_no_irq_srcu;
674658 for (i = 0; i < KVM_NR_BUSES; i++) {
675659 rcu_assign_pointer(kvm->buses[i],
676660 kzalloc(sizeof(struct kvm_io_bus), GFP_KERNEL_ACCOUNT));
677661 if (!kvm->buses[i])
678− goto out_err;
662+ goto out_err_no_arch_destroy_vm;
679663 }
680664
665+ refcount_set(&kvm->users_count, 1);
666+ r = kvm_arch_init_vm(kvm, type);
667+ if (r)
668+ goto out_err_no_arch_destroy_vm;
669+
670+ r = hardware_enable_all();
671+ if (r)
672+ goto out_err_no_disable;
673+
674+#ifdef CONFIG_HAVE_KVM_IRQFD
675+ INIT_HLIST_HEAD(&kvm->irq_ack_notifier_list);
676+#endif
677+
678+ if (init_srcu_struct(&kvm->srcu))
679+ goto out_err_no_srcu;
680+ if (init_srcu_struct(&kvm->irq_srcu))
681+ goto out_err_no_irq_srcu;
682+
681683 r = kvm_init_mmu_notifier(kvm);
682684 if (r)
683685 goto out_err;
@@ -697,7 +699,9 @@ out_err_no_irq_srcu: · 13 unmodified lines
697699 out_err_no_srcu:
698700 hardware_disable_all();
699701 out_err_no_disable:
700− refcount_set(&kvm->users_count, 0);
702+ kvm_arch_destroy_vm(kvm);
703+ WARN_ON_ONCE(!refcount_dec_and_test(&kvm->users_count));
704+out_err_no_arch_destroy_vm:
701705 for (i = 0; i < KVM_NR_BUSES; i++)
702706 kfree(kvm_get_bus(kvm, i));
703707 for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t