kvm_main.c (5b1f6d81e4c63ae30d92678cc35081001add7674) | kvm_main.c (b3ae2096974b12c3af2ad1a4e7716b084949867f) |
---|---|
1/* 2 * Kernel-based Virtual Machine driver for Linux 3 * 4 * This module enables machines with Intel VT-x extensions to run virtual 5 * machines without emulation or binary translation. 6 * 7 * Copyright (C) 2006 Qumranet, Inc. 8 * Copyright 2010 Red Hat, Inc. and/or its affiliates. --- 318 unchanged lines hidden (view full) --- 327 idx = srcu_read_lock(&kvm->srcu); 328 spin_lock(&kvm->mmu_lock); 329 /* 330 * The count increase must become visible at unlock time as no 331 * spte can be established without taking the mmu_lock and 332 * count is also read inside the mmu_lock critical section. 333 */ 334 kvm->mmu_notifier_count++; | 1/* 2 * Kernel-based Virtual Machine driver for Linux 3 * 4 * This module enables machines with Intel VT-x extensions to run virtual 5 * machines without emulation or binary translation. 6 * 7 * Copyright (C) 2006 Qumranet, Inc. 8 * Copyright 2010 Red Hat, Inc. and/or its affiliates. --- 318 unchanged lines hidden (view full) --- 327 idx = srcu_read_lock(&kvm->srcu); 328 spin_lock(&kvm->mmu_lock); 329 /* 330 * The count increase must become visible at unlock time as no 331 * spte can be established without taking the mmu_lock and 332 * count is also read inside the mmu_lock critical section. 333 */ 334 kvm->mmu_notifier_count++; |
335 for (; start < end; start += PAGE_SIZE) 336 need_tlb_flush |= kvm_unmap_hva(kvm, start); | 335 need_tlb_flush = kvm_unmap_hva_range(kvm, start, end); |
337 need_tlb_flush |= kvm->tlbs_dirty; 338 /* we've to flush the tlb before the pages can be freed */ 339 if (need_tlb_flush) 340 kvm_flush_remote_tlbs(kvm); 341 342 spin_unlock(&kvm->mmu_lock); 343 srcu_read_unlock(&kvm->srcu, idx); 344} --- 166 unchanged lines hidden (view full) --- 511out_err_nodisable: 512 for (i = 0; i < KVM_NR_BUSES; i++) 513 kfree(kvm->buses[i]); 514 kfree(kvm->memslots); 515 kvm_arch_free_vm(kvm); 516 return ERR_PTR(r); 517} 518 | 336 need_tlb_flush |= kvm->tlbs_dirty; 337 /* we've to flush the tlb before the pages can be freed */ 338 if (need_tlb_flush) 339 kvm_flush_remote_tlbs(kvm); 340 341 spin_unlock(&kvm->mmu_lock); 342 srcu_read_unlock(&kvm->srcu, idx); 343} --- 166 unchanged lines hidden (view full) --- 510out_err_nodisable: 511 for (i = 0; i < KVM_NR_BUSES; i++) 512 kfree(kvm->buses[i]); 513 kfree(kvm->memslots); 514 kvm_arch_free_vm(kvm); 515 return ERR_PTR(r); 516} 517 |
518/* 519 * Avoid using vmalloc for a small buffer. 520 * Should not be used when the size is statically known. 521 */ 522void *kvm_kvzalloc(unsigned long size) 523{ 524 if (size > PAGE_SIZE) 525 return vzalloc(size); 526 else 527 return kzalloc(size, GFP_KERNEL); 528} 529 530void kvm_kvfree(const void *addr) 531{ 532 if (is_vmalloc_addr(addr)) 533 vfree(addr); 534 else 535 kfree(addr); 536} 537 |
|
519static void kvm_destroy_dirty_bitmap(struct kvm_memory_slot *memslot) 520{ 521 if (!memslot->dirty_bitmap) 522 return; 523 | 538static void kvm_destroy_dirty_bitmap(struct kvm_memory_slot *memslot) 539{ 540 if (!memslot->dirty_bitmap) 541 return; 542 |
524 if (2 * kvm_dirty_bitmap_bytes(memslot) > PAGE_SIZE) 525 vfree(memslot->dirty_bitmap); 526 else 527 kfree(memslot->dirty_bitmap); 528 | 543 kvm_kvfree(memslot->dirty_bitmap); |
529 memslot->dirty_bitmap = NULL; 530} 531 532/* 533 * Free any memory in @free but not in @dont. 534 */ 535static void kvm_free_physmem_slot(struct kvm_memory_slot *free, 536 struct kvm_memory_slot *dont) --- 75 unchanged lines hidden (view full) --- 612 * Allocation size is twice as large as the actual dirty bitmap size. 613 * See x86's kvm_vm_ioctl_get_dirty_log() why this is needed. 614 */ 615static int kvm_create_dirty_bitmap(struct kvm_memory_slot *memslot) 616{ 617#ifndef CONFIG_S390 618 unsigned long dirty_bytes = 2 * kvm_dirty_bitmap_bytes(memslot); 619 | 544 memslot->dirty_bitmap = NULL; 545} 546 547/* 548 * Free any memory in @free but not in @dont. 549 */ 550static void kvm_free_physmem_slot(struct kvm_memory_slot *free, 551 struct kvm_memory_slot *dont) --- 75 unchanged lines hidden (view full) --- 627 * Allocation size is twice as large as the actual dirty bitmap size. 628 * See x86's kvm_vm_ioctl_get_dirty_log() why this is needed. 629 */ 630static int kvm_create_dirty_bitmap(struct kvm_memory_slot *memslot) 631{ 632#ifndef CONFIG_S390 633 unsigned long dirty_bytes = 2 * kvm_dirty_bitmap_bytes(memslot); 634 |
620 if (dirty_bytes > PAGE_SIZE) 621 memslot->dirty_bitmap = vzalloc(dirty_bytes); 622 else 623 memslot->dirty_bitmap = kzalloc(dirty_bytes, GFP_KERNEL); 624 | 635 memslot->dirty_bitmap = kvm_kvzalloc(dirty_bytes); |
625 if (!memslot->dirty_bitmap) 626 return -ENOMEM; 627 628#endif /* !CONFIG_S390 */ 629 return 0; 630} 631 632static int cmp_memslot(const void *slot1, const void *slot2) --- 948 unchanged lines hidden (view full) --- 1581 * We boost the priority of a VCPU that is runnable but not 1582 * currently running, because it got preempted by something 1583 * else and called schedule in __vcpu_run. Hopefully that 1584 * VCPU is holding the lock that we need and will release it. 1585 * We approximate round-robin by starting at the last boosted VCPU. 1586 */ 1587 for (pass = 0; pass < 2 && !yielded; pass++) { 1588 kvm_for_each_vcpu(i, vcpu, kvm) { | 636 if (!memslot->dirty_bitmap) 637 return -ENOMEM; 638 639#endif /* !CONFIG_S390 */ 640 return 0; 641} 642 643static int cmp_memslot(const void *slot1, const void *slot2) --- 948 unchanged lines hidden (view full) --- 1592 * We boost the priority of a VCPU that is runnable but not 1593 * currently running, because it got preempted by something 1594 * else and called schedule in __vcpu_run. Hopefully that 1595 * VCPU is holding the lock that we need and will release it. 1596 * We approximate round-robin by starting at the last boosted VCPU. 1597 */ 1598 for (pass = 0; pass < 2 && !yielded; pass++) { 1599 kvm_for_each_vcpu(i, vcpu, kvm) { |
1589 if (!pass && i < last_boosted_vcpu) { | 1600 if (!pass && i <= last_boosted_vcpu) { |
1590 i = last_boosted_vcpu; 1591 continue; 1592 } else if (pass && i > last_boosted_vcpu) 1593 break; 1594 if (vcpu == me) 1595 continue; 1596 if (waitqueue_active(&vcpu->wq)) 1597 continue; --- 444 unchanged lines hidden (view full) --- 2042 } 2043#endif 2044 case KVM_IRQFD: { 2045 struct kvm_irqfd data; 2046 2047 r = -EFAULT; 2048 if (copy_from_user(&data, argp, sizeof data)) 2049 goto out; | 1601 i = last_boosted_vcpu; 1602 continue; 1603 } else if (pass && i > last_boosted_vcpu) 1604 break; 1605 if (vcpu == me) 1606 continue; 1607 if (waitqueue_active(&vcpu->wq)) 1608 continue; --- 444 unchanged lines hidden (view full) --- 2053 } 2054#endif 2055 case KVM_IRQFD: { 2056 struct kvm_irqfd data; 2057 2058 r = -EFAULT; 2059 if (copy_from_user(&data, argp, sizeof data)) 2060 goto out; |
2050 r = kvm_irqfd(kvm, &data); | 2061 r = kvm_irqfd(kvm, data.fd, data.gsi, data.flags); |
2051 break; 2052 } 2053 case KVM_IOEVENTFD: { 2054 struct kvm_ioeventfd data; 2055 2056 r = -EFAULT; 2057 if (copy_from_user(&data, argp, sizeof data)) 2058 goto out; --- 149 unchanged lines hidden (view full) --- 2208#ifdef CONFIG_KVM_APIC_ARCHITECTURE 2209 case KVM_CAP_SET_BOOT_CPU_ID: 2210#endif 2211 case KVM_CAP_INTERNAL_ERROR_DATA: 2212#ifdef CONFIG_HAVE_KVM_MSI 2213 case KVM_CAP_SIGNAL_MSI: 2214#endif 2215 return 1; | 2062 break; 2063 } 2064 case KVM_IOEVENTFD: { 2065 struct kvm_ioeventfd data; 2066 2067 r = -EFAULT; 2068 if (copy_from_user(&data, argp, sizeof data)) 2069 goto out; --- 149 unchanged lines hidden (view full) --- 2219#ifdef CONFIG_KVM_APIC_ARCHITECTURE 2220 case KVM_CAP_SET_BOOT_CPU_ID: 2221#endif 2222 case KVM_CAP_INTERNAL_ERROR_DATA: 2223#ifdef CONFIG_HAVE_KVM_MSI 2224 case KVM_CAP_SIGNAL_MSI: 2225#endif 2226 return 1; |
2216#ifdef CONFIG_HAVE_KVM_IRQCHIP | 2227#ifdef KVM_CAP_IRQ_ROUTING |
2217 case KVM_CAP_IRQ_ROUTING: 2218 return KVM_MAX_IRQ_ROUTES; 2219#endif 2220 default: 2221 break; 2222 } 2223 return kvm_dev_ioctl_check_extension(arg); 2224} --- 615 unchanged lines hidden (view full) --- 2840 kvm_async_pf_deinit(); 2841 unregister_syscore_ops(&kvm_syscore_ops); 2842 unregister_reboot_notifier(&kvm_reboot_notifier); 2843 unregister_cpu_notifier(&kvm_cpu_notifier); 2844 on_each_cpu(hardware_disable_nolock, NULL, 1); 2845 kvm_arch_hardware_unsetup(); 2846 kvm_arch_exit(); 2847 free_cpumask_var(cpus_hardware_enabled); | 2228 case KVM_CAP_IRQ_ROUTING: 2229 return KVM_MAX_IRQ_ROUTES; 2230#endif 2231 default: 2232 break; 2233 } 2234 return kvm_dev_ioctl_check_extension(arg); 2235} --- 615 unchanged lines hidden (view full) --- 2851 kvm_async_pf_deinit(); 2852 unregister_syscore_ops(&kvm_syscore_ops); 2853 unregister_reboot_notifier(&kvm_reboot_notifier); 2854 unregister_cpu_notifier(&kvm_cpu_notifier); 2855 on_each_cpu(hardware_disable_nolock, NULL, 1); 2856 kvm_arch_hardware_unsetup(); 2857 kvm_arch_exit(); 2858 free_cpumask_var(cpus_hardware_enabled); |
2848 __free_page(fault_page); | |
2849 __free_page(hwpoison_page); 2850 __free_page(bad_page); 2851} 2852EXPORT_SYMBOL_GPL(kvm_exit); | 2859 __free_page(hwpoison_page); 2860 __free_page(bad_page); 2861} 2862EXPORT_SYMBOL_GPL(kvm_exit); |