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
734static void svm_set_efer(struct kvm_vcpu *vcpu, u64 efer)734static void svm_set_efer(struct kvm_vcpu *vcpu, u64 efer)
735{735{
736 vcpu->arch.efer = efer;736 vcpu->arch.efer = efer;
737 if (!npt_enabled && !(efer & EFER_LMA))737
738 efer &= ~EFER_LME;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 }
739 745
740 to_svm(vcpu)->vmcb->save.efer = efer | EFER_SVME;746 to_svm(vcpu)->vmcb->save.efer = efer | EFER_SVME;
741 mark_dirty(to_svm(vcpu)->vmcb, VMCB_CR);747 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
969 u64 guest_efer = vmx->vcpu.arch.efer;969 u64 guest_efer = vmx->vcpu.arch.efer;
970 u64 ignore_bits = 0;970 u64 ignore_bits = 0;
971 971
972 if (!enable_ept) {972 /* Shadow paging assumes NX to be available. */
973 /*973 if (!enable_ept)
974 * NX is needed to handle CR0.WP=1, CR4.SMEP=1. Testing974 guest_efer |= EFER_NX;
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 }
983 975
984 /*976 /*
985 * LMA and LME handled by hardware; SCE meaningless outside long mode.977 * 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
627 627
628static struct kvm *kvm_create_vm(unsigned long type)628static struct kvm *kvm_create_vm(unsigned long type)
629{629{
630 int r, i;
631 struct kvm *kvm = kvm_arch_alloc_vm();630 struct kvm *kvm = kvm_arch_alloc_vm();
631 int r = -ENOMEM;
632 int i;
632 633
633 if (!kvm)634 if (!kvm)
634 return ERR_PTR(-ENOMEM);635 return ERR_PTR(-ENOMEM);
@@ -640,44 +641,45 @@ static struct kvm *kvm_create_vm(unsigned long type) · 5 unmodified lines
640 mutex_init(&kvm->lock);641 mutex_init(&kvm->lock);
641 mutex_init(&kvm->irq_lock);642 mutex_init(&kvm->irq_lock);
642 mutex_init(&kvm->slots_lock);643 mutex_init(&kvm->slots_lock);
643 refcount_set(&kvm->users_count, 1);
644 INIT_LIST_HEAD(&kvm->devices);644 INIT_LIST_HEAD(&kvm->devices);
645 645
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
658 BUILD_BUG_ON(KVM_MEM_SLOTS_NUM > SHRT_MAX);646 BUILD_BUG_ON(KVM_MEM_SLOTS_NUM > SHRT_MAX);
659 647
660 r = -ENOMEM;
661 for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) {648 for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) {
662 struct kvm_memslots *slots = kvm_alloc_memslots();649 struct kvm_memslots *slots = kvm_alloc_memslots();
650
663 if (!slots)651 if (!slots)
664 goto out_err_no_srcu;652 goto out_err_no_arch_destroy_vm;
665 /* Generations must be different for each address space. */653 /* Generations must be different for each address space. */
666 slots->generation = i;654 slots->generation = i;
667 rcu_assign_pointer(kvm->memslots[i], slots);655 rcu_assign_pointer(kvm->memslots[i], slots);
668 }656 }
669 657
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;
674 for (i = 0; i < KVM_NR_BUSES; i++) {658 for (i = 0; i < KVM_NR_BUSES; i++) {
675 rcu_assign_pointer(kvm->buses[i],659 rcu_assign_pointer(kvm->buses[i],
676 kzalloc(sizeof(struct kvm_io_bus), GFP_KERNEL_ACCOUNT));660 kzalloc(sizeof(struct kvm_io_bus), GFP_KERNEL_ACCOUNT));
677 if (!kvm->buses[i])661 if (!kvm->buses[i])
678 goto out_err;662 goto out_err_no_arch_destroy_vm;
679 }663 }
680 664
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
681 r = kvm_init_mmu_notifier(kvm);683 r = kvm_init_mmu_notifier(kvm);
682 if (r)684 if (r)
683 goto out_err;685 goto out_err;
@@ -697,7 +699,9 @@ out_err_no_irq_srcu: · 13 unmodified lines
697out_err_no_srcu:699out_err_no_srcu:
698 hardware_disable_all();700 hardware_disable_all();
699out_err_no_disable:701out_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));
704out_err_no_arch_destroy_vm:
701 for (i = 0; i < KVM_NR_BUSES; i++)705 for (i = 0; i < KVM_NR_BUSES; i++)
702 kfree(kvm_get_bus(kvm, i));706 kfree(kvm_get_bus(kvm, i));
703 for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++)707 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