Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+37 -35
+8 -2
arch/x86/kvm/svm.c
··· 734 734 static void svm_set_efer(struct kvm_vcpu *vcpu, u64 efer) 735 735 { 736 736 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 + } 739 745 740 746 to_svm(vcpu)->vmcb->save.efer = efer | EFER_SVME; 741 747 mark_dirty(to_svm(vcpu)->vmcb, VMCB_CR);
+3 -11
arch/x86/kvm/vmx/vmx.c
··· 969 969 u64 guest_efer = vmx->vcpu.arch.efer; 970 970 u64 ignore_bits = 0; 971 971 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; 983 975 984 976 /* 985 977 * LMA and LME handled by hardware; SCE meaningless outside long mode.
+26 -22
virt/kvm/kvm_main.c
··· 627 627 628 628 static struct kvm *kvm_create_vm(unsigned long type) 629 629 { 630 - int r, i; 631 630 struct kvm *kvm = kvm_arch_alloc_vm(); 631 + int r = -ENOMEM; 632 + int i; 632 633 633 634 if (!kvm) 634 635 return ERR_PTR(-ENOMEM); ··· 641 640 mutex_init(&kvm->lock); 642 641 mutex_init(&kvm->irq_lock); 643 642 mutex_init(&kvm->slots_lock); 644 - refcount_set(&kvm->users_count, 1); 645 643 INIT_LIST_HEAD(&kvm->devices); 646 644 645 + BUILD_BUG_ON(KVM_MEM_SLOTS_NUM > SHRT_MAX); 646 + 647 + for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) { 648 + struct kvm_memslots *slots = kvm_alloc_memslots(); 649 + 650 + if (!slots) 651 + goto out_err_no_arch_destroy_vm; 652 + /* Generations must be different for each address space. */ 653 + slots->generation = i; 654 + rcu_assign_pointer(kvm->memslots[i], slots); 655 + } 656 + 657 + for (i = 0; i < KVM_NR_BUSES; i++) { 658 + rcu_assign_pointer(kvm->buses[i], 659 + kzalloc(sizeof(struct kvm_io_bus), GFP_KERNEL_ACCOUNT)); 660 + if (!kvm->buses[i]) 661 + goto out_err_no_arch_destroy_vm; 662 + } 663 + 664 + refcount_set(&kvm->users_count, 1); 647 665 r = kvm_arch_init_vm(kvm, type); 648 666 if (r) 649 - goto out_err_no_disable; 667 + goto out_err_no_arch_destroy_vm; 650 668 651 669 r = hardware_enable_all(); 652 670 if (r) ··· 675 655 INIT_HLIST_HEAD(&kvm->irq_ack_notifier_list); 676 656 #endif 677 657 678 - BUILD_BUG_ON(KVM_MEM_SLOTS_NUM > SHRT_MAX); 679 - 680 - r = -ENOMEM; 681 - for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) { 682 - struct kvm_memslots *slots = kvm_alloc_memslots(); 683 - if (!slots) 684 - goto out_err_no_srcu; 685 - /* Generations must be different for each address space. */ 686 - slots->generation = i; 687 - rcu_assign_pointer(kvm->memslots[i], slots); 688 - } 689 - 690 658 if (init_srcu_struct(&kvm->srcu)) 691 659 goto out_err_no_srcu; 692 660 if (init_srcu_struct(&kvm->irq_srcu)) 693 661 goto out_err_no_irq_srcu; 694 - for (i = 0; i < KVM_NR_BUSES; i++) { 695 - rcu_assign_pointer(kvm->buses[i], 696 - kzalloc(sizeof(struct kvm_io_bus), GFP_KERNEL_ACCOUNT)); 697 - if (!kvm->buses[i]) 698 - goto out_err; 699 - } 700 662 701 663 r = kvm_init_mmu_notifier(kvm); 702 664 if (r) ··· 699 697 out_err_no_srcu: 700 698 hardware_disable_all(); 701 699 out_err_no_disable: 702 - refcount_set(&kvm->users_count, 0); 700 + kvm_arch_destroy_vm(kvm); 701 + WARN_ON_ONCE(!refcount_dec_and_test(&kvm->users_count)); 702 + out_err_no_arch_destroy_vm: 703 703 for (i = 0; i < KVM_NR_BUSES; i++) 704 704 kfree(kvm_get_bus(kvm, i)); 705 705 for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++)