2 * Kernel-based Virtual Machine driver for Linux
4 * This module enables machines with Intel VT-x extensions to run virtual
5 * machines without emulation or binary translation.
7 * Copyright (C) 2006 Qumranet, Inc.
10 * Avi Kivity <avi@qumranet.com>
11 * Yaniv Kamay <yaniv@qumranet.com>
13 * This work is licensed under the terms of the GNU GPL, version 2. See
14 * the COPYING file in the top-level directory.
20 #include <linux/kvm_host.h>
21 #include <linux/kvm.h>
22 #include <linux/module.h>
23 #include <linux/errno.h>
24 #include <linux/percpu.h>
25 #include <linux/gfp.h>
27 #include <linux/miscdevice.h>
28 #include <linux/vmalloc.h>
29 #include <linux/reboot.h>
30 #include <linux/debugfs.h>
31 #include <linux/highmem.h>
32 #include <linux/file.h>
33 #include <linux/sysdev.h>
34 #include <linux/cpu.h>
35 #include <linux/sched.h>
36 #include <linux/cpumask.h>
37 #include <linux/smp.h>
38 #include <linux/anon_inodes.h>
39 #include <linux/profile.h>
40 #include <linux/kvm_para.h>
41 #include <linux/pagemap.h>
42 #include <linux/mman.h>
43 #include <linux/swap.h>
45 #include <asm/processor.h>
47 #include <asm/uaccess.h>
48 #include <asm/pgtable.h>
50 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
51 #include "coalesced_mmio.h"
54 MODULE_AUTHOR("Qumranet");
55 MODULE_LICENSE("GPL");
57 DEFINE_SPINLOCK(kvm_lock
);
60 static cpumask_t cpus_hardware_enabled
;
62 struct kmem_cache
*kvm_vcpu_cache
;
63 EXPORT_SYMBOL_GPL(kvm_vcpu_cache
);
65 static __read_mostly
struct preempt_ops kvm_preempt_ops
;
67 struct dentry
*kvm_debugfs_dir
;
69 static long kvm_vcpu_ioctl(struct file
*file
, unsigned int ioctl
,
74 static inline int valid_vcpu(int n
)
76 return likely(n
>= 0 && n
< KVM_MAX_VCPUS
);
79 static inline int is_mmio_pfn(pfn_t pfn
)
82 return PageReserved(pfn_to_page(pfn
));
88 * Switches to specified vcpu, until a matching vcpu_put()
90 void vcpu_load(struct kvm_vcpu
*vcpu
)
94 mutex_lock(&vcpu
->mutex
);
96 preempt_notifier_register(&vcpu
->preempt_notifier
);
97 kvm_arch_vcpu_load(vcpu
, cpu
);
101 void vcpu_put(struct kvm_vcpu
*vcpu
)
104 kvm_arch_vcpu_put(vcpu
);
105 preempt_notifier_unregister(&vcpu
->preempt_notifier
);
107 mutex_unlock(&vcpu
->mutex
);
110 static void ack_flush(void *_completed
)
114 void kvm_flush_remote_tlbs(struct kvm
*kvm
)
118 struct kvm_vcpu
*vcpu
;
122 for (i
= 0; i
< KVM_MAX_VCPUS
; ++i
) {
123 vcpu
= kvm
->vcpus
[i
];
126 if (test_and_set_bit(KVM_REQ_TLB_FLUSH
, &vcpu
->requests
))
129 if (cpu
!= -1 && cpu
!= me
)
132 if (cpus_empty(cpus
))
134 ++kvm
->stat
.remote_tlb_flush
;
135 smp_call_function_mask(cpus
, ack_flush
, NULL
, 1);
140 void kvm_reload_remote_mmus(struct kvm
*kvm
)
144 struct kvm_vcpu
*vcpu
;
148 for (i
= 0; i
< KVM_MAX_VCPUS
; ++i
) {
149 vcpu
= kvm
->vcpus
[i
];
152 if (test_and_set_bit(KVM_REQ_MMU_RELOAD
, &vcpu
->requests
))
155 if (cpu
!= -1 && cpu
!= me
)
158 if (cpus_empty(cpus
))
160 smp_call_function_mask(cpus
, ack_flush
, NULL
, 1);
166 int kvm_vcpu_init(struct kvm_vcpu
*vcpu
, struct kvm
*kvm
, unsigned id
)
171 mutex_init(&vcpu
->mutex
);
175 init_waitqueue_head(&vcpu
->wq
);
177 page
= alloc_page(GFP_KERNEL
| __GFP_ZERO
);
182 vcpu
->run
= page_address(page
);
184 r
= kvm_arch_vcpu_init(vcpu
);
190 free_page((unsigned long)vcpu
->run
);
194 EXPORT_SYMBOL_GPL(kvm_vcpu_init
);
196 void kvm_vcpu_uninit(struct kvm_vcpu
*vcpu
)
198 kvm_arch_vcpu_uninit(vcpu
);
199 free_page((unsigned long)vcpu
->run
);
201 EXPORT_SYMBOL_GPL(kvm_vcpu_uninit
);
203 #if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
204 static inline struct kvm
*mmu_notifier_to_kvm(struct mmu_notifier
*mn
)
206 return container_of(mn
, struct kvm
, mmu_notifier
);
209 static void kvm_mmu_notifier_invalidate_page(struct mmu_notifier
*mn
,
210 struct mm_struct
*mm
,
211 unsigned long address
)
213 struct kvm
*kvm
= mmu_notifier_to_kvm(mn
);
217 * When ->invalidate_page runs, the linux pte has been zapped
218 * already but the page is still allocated until
219 * ->invalidate_page returns. So if we increase the sequence
220 * here the kvm page fault will notice if the spte can't be
221 * established because the page is going to be freed. If
222 * instead the kvm page fault establishes the spte before
223 * ->invalidate_page runs, kvm_unmap_hva will release it
226 * The sequence increase only need to be seen at spin_unlock
227 * time, and not at spin_lock time.
229 * Increasing the sequence after the spin_unlock would be
230 * unsafe because the kvm page fault could then establish the
231 * pte after kvm_unmap_hva returned, without noticing the page
232 * is going to be freed.
234 spin_lock(&kvm
->mmu_lock
);
235 kvm
->mmu_notifier_seq
++;
236 need_tlb_flush
= kvm_unmap_hva(kvm
, address
);
237 spin_unlock(&kvm
->mmu_lock
);
239 /* we've to flush the tlb before the pages can be freed */
241 kvm_flush_remote_tlbs(kvm
);
245 static void kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier
*mn
,
246 struct mm_struct
*mm
,
250 struct kvm
*kvm
= mmu_notifier_to_kvm(mn
);
251 int need_tlb_flush
= 0;
253 spin_lock(&kvm
->mmu_lock
);
255 * The count increase must become visible at unlock time as no
256 * spte can be established without taking the mmu_lock and
257 * count is also read inside the mmu_lock critical section.
259 kvm
->mmu_notifier_count
++;
260 for (; start
< end
; start
+= PAGE_SIZE
)
261 need_tlb_flush
|= kvm_unmap_hva(kvm
, start
);
262 spin_unlock(&kvm
->mmu_lock
);
264 /* we've to flush the tlb before the pages can be freed */
266 kvm_flush_remote_tlbs(kvm
);
269 static void kvm_mmu_notifier_invalidate_range_end(struct mmu_notifier
*mn
,
270 struct mm_struct
*mm
,
274 struct kvm
*kvm
= mmu_notifier_to_kvm(mn
);
276 spin_lock(&kvm
->mmu_lock
);
278 * This sequence increase will notify the kvm page fault that
279 * the page that is going to be mapped in the spte could have
282 kvm
->mmu_notifier_seq
++;
284 * The above sequence increase must be visible before the
285 * below count decrease but both values are read by the kvm
286 * page fault under mmu_lock spinlock so we don't need to add
287 * a smb_wmb() here in between the two.
289 kvm
->mmu_notifier_count
--;
290 spin_unlock(&kvm
->mmu_lock
);
292 BUG_ON(kvm
->mmu_notifier_count
< 0);
295 static int kvm_mmu_notifier_clear_flush_young(struct mmu_notifier
*mn
,
296 struct mm_struct
*mm
,
297 unsigned long address
)
299 struct kvm
*kvm
= mmu_notifier_to_kvm(mn
);
302 spin_lock(&kvm
->mmu_lock
);
303 young
= kvm_age_hva(kvm
, address
);
304 spin_unlock(&kvm
->mmu_lock
);
307 kvm_flush_remote_tlbs(kvm
);
312 static const struct mmu_notifier_ops kvm_mmu_notifier_ops
= {
313 .invalidate_page
= kvm_mmu_notifier_invalidate_page
,
314 .invalidate_range_start
= kvm_mmu_notifier_invalidate_range_start
,
315 .invalidate_range_end
= kvm_mmu_notifier_invalidate_range_end
,
316 .clear_flush_young
= kvm_mmu_notifier_clear_flush_young
,
318 #endif /* CONFIG_MMU_NOTIFIER && KVM_ARCH_WANT_MMU_NOTIFIER */
320 static struct kvm
*kvm_create_vm(void)
322 struct kvm
*kvm
= kvm_arch_create_vm();
323 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
330 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
331 page
= alloc_page(GFP_KERNEL
| __GFP_ZERO
);
334 return ERR_PTR(-ENOMEM
);
336 kvm
->coalesced_mmio_ring
=
337 (struct kvm_coalesced_mmio_ring
*)page_address(page
);
340 #if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
343 kvm
->mmu_notifier
.ops
= &kvm_mmu_notifier_ops
;
344 err
= mmu_notifier_register(&kvm
->mmu_notifier
, current
->mm
);
346 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
355 kvm
->mm
= current
->mm
;
356 atomic_inc(&kvm
->mm
->mm_count
);
357 spin_lock_init(&kvm
->mmu_lock
);
358 kvm_io_bus_init(&kvm
->pio_bus
);
359 mutex_init(&kvm
->lock
);
360 kvm_io_bus_init(&kvm
->mmio_bus
);
361 init_rwsem(&kvm
->slots_lock
);
362 atomic_set(&kvm
->users_count
, 1);
363 spin_lock(&kvm_lock
);
364 list_add(&kvm
->vm_list
, &vm_list
);
365 spin_unlock(&kvm_lock
);
366 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
367 kvm_coalesced_mmio_init(kvm
);
374 * Free any memory in @free but not in @dont.
376 static void kvm_free_physmem_slot(struct kvm_memory_slot
*free
,
377 struct kvm_memory_slot
*dont
)
379 if (!dont
|| free
->rmap
!= dont
->rmap
)
382 if (!dont
|| free
->dirty_bitmap
!= dont
->dirty_bitmap
)
383 vfree(free
->dirty_bitmap
);
385 if (!dont
|| free
->lpage_info
!= dont
->lpage_info
)
386 vfree(free
->lpage_info
);
389 free
->dirty_bitmap
= NULL
;
391 free
->lpage_info
= NULL
;
394 void kvm_free_physmem(struct kvm
*kvm
)
398 for (i
= 0; i
< kvm
->nmemslots
; ++i
)
399 kvm_free_physmem_slot(&kvm
->memslots
[i
], NULL
);
402 static void kvm_destroy_vm(struct kvm
*kvm
)
404 struct mm_struct
*mm
= kvm
->mm
;
406 spin_lock(&kvm_lock
);
407 list_del(&kvm
->vm_list
);
408 spin_unlock(&kvm_lock
);
409 kvm_io_bus_destroy(&kvm
->pio_bus
);
410 kvm_io_bus_destroy(&kvm
->mmio_bus
);
411 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
412 if (kvm
->coalesced_mmio_ring
!= NULL
)
413 free_page((unsigned long)kvm
->coalesced_mmio_ring
);
415 #if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
416 mmu_notifier_unregister(&kvm
->mmu_notifier
, kvm
->mm
);
418 kvm_arch_destroy_vm(kvm
);
422 void kvm_get_kvm(struct kvm
*kvm
)
424 atomic_inc(&kvm
->users_count
);
426 EXPORT_SYMBOL_GPL(kvm_get_kvm
);
428 void kvm_put_kvm(struct kvm
*kvm
)
430 if (atomic_dec_and_test(&kvm
->users_count
))
433 EXPORT_SYMBOL_GPL(kvm_put_kvm
);
436 static int kvm_vm_release(struct inode
*inode
, struct file
*filp
)
438 struct kvm
*kvm
= filp
->private_data
;
445 * Allocate some memory and give it an address in the guest physical address
448 * Discontiguous memory is allowed, mostly for framebuffers.
450 * Must be called holding mmap_sem for write.
452 int __kvm_set_memory_region(struct kvm
*kvm
,
453 struct kvm_userspace_memory_region
*mem
,
458 unsigned long npages
;
460 struct kvm_memory_slot
*memslot
;
461 struct kvm_memory_slot old
, new;
464 /* General sanity checks */
465 if (mem
->memory_size
& (PAGE_SIZE
- 1))
467 if (mem
->guest_phys_addr
& (PAGE_SIZE
- 1))
469 if (mem
->slot
>= KVM_MEMORY_SLOTS
+ KVM_PRIVATE_MEM_SLOTS
)
471 if (mem
->guest_phys_addr
+ mem
->memory_size
< mem
->guest_phys_addr
)
474 memslot
= &kvm
->memslots
[mem
->slot
];
475 base_gfn
= mem
->guest_phys_addr
>> PAGE_SHIFT
;
476 npages
= mem
->memory_size
>> PAGE_SHIFT
;
479 mem
->flags
&= ~KVM_MEM_LOG_DIRTY_PAGES
;
481 new = old
= *memslot
;
483 new.base_gfn
= base_gfn
;
485 new.flags
= mem
->flags
;
487 /* Disallow changing a memory slot's size. */
489 if (npages
&& old
.npages
&& npages
!= old
.npages
)
492 /* Check for overlaps */
494 for (i
= 0; i
< KVM_MEMORY_SLOTS
; ++i
) {
495 struct kvm_memory_slot
*s
= &kvm
->memslots
[i
];
499 if (!((base_gfn
+ npages
<= s
->base_gfn
) ||
500 (base_gfn
>= s
->base_gfn
+ s
->npages
)))
504 /* Free page dirty bitmap if unneeded */
505 if (!(new.flags
& KVM_MEM_LOG_DIRTY_PAGES
))
506 new.dirty_bitmap
= NULL
;
510 /* Allocate if a slot is being created */
512 if (npages
&& !new.rmap
) {
513 new.rmap
= vmalloc(npages
* sizeof(struct page
*));
518 memset(new.rmap
, 0, npages
* sizeof(*new.rmap
));
520 new.user_alloc
= user_alloc
;
522 * hva_to_rmmap() serialzies with the mmu_lock and to be
523 * safe it has to ignore memslots with !user_alloc &&
527 new.userspace_addr
= mem
->userspace_addr
;
529 new.userspace_addr
= 0;
531 if (npages
&& !new.lpage_info
) {
532 int largepages
= npages
/ KVM_PAGES_PER_HPAGE
;
533 if (npages
% KVM_PAGES_PER_HPAGE
)
535 if (base_gfn
% KVM_PAGES_PER_HPAGE
)
538 new.lpage_info
= vmalloc(largepages
* sizeof(*new.lpage_info
));
543 memset(new.lpage_info
, 0, largepages
* sizeof(*new.lpage_info
));
545 if (base_gfn
% KVM_PAGES_PER_HPAGE
)
546 new.lpage_info
[0].write_count
= 1;
547 if ((base_gfn
+npages
) % KVM_PAGES_PER_HPAGE
)
548 new.lpage_info
[largepages
-1].write_count
= 1;
551 /* Allocate page dirty bitmap if needed */
552 if ((new.flags
& KVM_MEM_LOG_DIRTY_PAGES
) && !new.dirty_bitmap
) {
553 unsigned dirty_bytes
= ALIGN(npages
, BITS_PER_LONG
) / 8;
555 new.dirty_bitmap
= vmalloc(dirty_bytes
);
556 if (!new.dirty_bitmap
)
558 memset(new.dirty_bitmap
, 0, dirty_bytes
);
560 #endif /* not defined CONFIG_S390 */
563 kvm_arch_flush_shadow(kvm
);
565 spin_lock(&kvm
->mmu_lock
);
566 if (mem
->slot
>= kvm
->nmemslots
)
567 kvm
->nmemslots
= mem
->slot
+ 1;
570 spin_unlock(&kvm
->mmu_lock
);
572 r
= kvm_arch_set_memory_region(kvm
, mem
, old
, user_alloc
);
574 spin_lock(&kvm
->mmu_lock
);
576 spin_unlock(&kvm
->mmu_lock
);
580 kvm_free_physmem_slot(&old
, &new);
584 kvm_free_physmem_slot(&new, &old
);
589 EXPORT_SYMBOL_GPL(__kvm_set_memory_region
);
591 int kvm_set_memory_region(struct kvm
*kvm
,
592 struct kvm_userspace_memory_region
*mem
,
597 down_write(&kvm
->slots_lock
);
598 r
= __kvm_set_memory_region(kvm
, mem
, user_alloc
);
599 up_write(&kvm
->slots_lock
);
602 EXPORT_SYMBOL_GPL(kvm_set_memory_region
);
604 int kvm_vm_ioctl_set_memory_region(struct kvm
*kvm
,
606 kvm_userspace_memory_region
*mem
,
609 if (mem
->slot
>= KVM_MEMORY_SLOTS
)
611 return kvm_set_memory_region(kvm
, mem
, user_alloc
);
614 int kvm_get_dirty_log(struct kvm
*kvm
,
615 struct kvm_dirty_log
*log
, int *is_dirty
)
617 struct kvm_memory_slot
*memslot
;
620 unsigned long any
= 0;
623 if (log
->slot
>= KVM_MEMORY_SLOTS
)
626 memslot
= &kvm
->memslots
[log
->slot
];
628 if (!memslot
->dirty_bitmap
)
631 n
= ALIGN(memslot
->npages
, BITS_PER_LONG
) / 8;
633 for (i
= 0; !any
&& i
< n
/sizeof(long); ++i
)
634 any
= memslot
->dirty_bitmap
[i
];
637 if (copy_to_user(log
->dirty_bitmap
, memslot
->dirty_bitmap
, n
))
648 int is_error_page(struct page
*page
)
650 return page
== bad_page
;
652 EXPORT_SYMBOL_GPL(is_error_page
);
654 int is_error_pfn(pfn_t pfn
)
656 return pfn
== bad_pfn
;
658 EXPORT_SYMBOL_GPL(is_error_pfn
);
660 static inline unsigned long bad_hva(void)
665 int kvm_is_error_hva(unsigned long addr
)
667 return addr
== bad_hva();
669 EXPORT_SYMBOL_GPL(kvm_is_error_hva
);
671 static struct kvm_memory_slot
*__gfn_to_memslot(struct kvm
*kvm
, gfn_t gfn
)
675 for (i
= 0; i
< kvm
->nmemslots
; ++i
) {
676 struct kvm_memory_slot
*memslot
= &kvm
->memslots
[i
];
678 if (gfn
>= memslot
->base_gfn
679 && gfn
< memslot
->base_gfn
+ memslot
->npages
)
685 struct kvm_memory_slot
*gfn_to_memslot(struct kvm
*kvm
, gfn_t gfn
)
687 gfn
= unalias_gfn(kvm
, gfn
);
688 return __gfn_to_memslot(kvm
, gfn
);
691 int kvm_is_visible_gfn(struct kvm
*kvm
, gfn_t gfn
)
695 gfn
= unalias_gfn(kvm
, gfn
);
696 for (i
= 0; i
< KVM_MEMORY_SLOTS
; ++i
) {
697 struct kvm_memory_slot
*memslot
= &kvm
->memslots
[i
];
699 if (gfn
>= memslot
->base_gfn
700 && gfn
< memslot
->base_gfn
+ memslot
->npages
)
705 EXPORT_SYMBOL_GPL(kvm_is_visible_gfn
);
707 unsigned long gfn_to_hva(struct kvm
*kvm
, gfn_t gfn
)
709 struct kvm_memory_slot
*slot
;
711 gfn
= unalias_gfn(kvm
, gfn
);
712 slot
= __gfn_to_memslot(kvm
, gfn
);
715 return (slot
->userspace_addr
+ (gfn
- slot
->base_gfn
) * PAGE_SIZE
);
717 EXPORT_SYMBOL_GPL(gfn_to_hva
);
720 * Requires current->mm->mmap_sem to be held
722 pfn_t
gfn_to_pfn(struct kvm
*kvm
, gfn_t gfn
)
724 struct page
*page
[1];
731 addr
= gfn_to_hva(kvm
, gfn
);
732 if (kvm_is_error_hva(addr
)) {
734 return page_to_pfn(bad_page
);
737 npages
= get_user_pages(current
, current
->mm
, addr
, 1, 1, 0, page
,
740 if (unlikely(npages
!= 1)) {
741 struct vm_area_struct
*vma
;
743 vma
= find_vma(current
->mm
, addr
);
744 if (vma
== NULL
|| addr
< vma
->vm_start
||
745 !(vma
->vm_flags
& VM_PFNMAP
)) {
747 return page_to_pfn(bad_page
);
750 pfn
= ((addr
- vma
->vm_start
) >> PAGE_SHIFT
) + vma
->vm_pgoff
;
751 BUG_ON(!is_mmio_pfn(pfn
));
753 pfn
= page_to_pfn(page
[0]);
758 EXPORT_SYMBOL_GPL(gfn_to_pfn
);
760 struct page
*gfn_to_page(struct kvm
*kvm
, gfn_t gfn
)
764 pfn
= gfn_to_pfn(kvm
, gfn
);
765 if (!is_mmio_pfn(pfn
))
766 return pfn_to_page(pfn
);
768 WARN_ON(is_mmio_pfn(pfn
));
774 EXPORT_SYMBOL_GPL(gfn_to_page
);
776 void kvm_release_page_clean(struct page
*page
)
778 kvm_release_pfn_clean(page_to_pfn(page
));
780 EXPORT_SYMBOL_GPL(kvm_release_page_clean
);
782 void kvm_release_pfn_clean(pfn_t pfn
)
784 if (!is_mmio_pfn(pfn
))
785 put_page(pfn_to_page(pfn
));
787 EXPORT_SYMBOL_GPL(kvm_release_pfn_clean
);
789 void kvm_release_page_dirty(struct page
*page
)
791 kvm_release_pfn_dirty(page_to_pfn(page
));
793 EXPORT_SYMBOL_GPL(kvm_release_page_dirty
);
795 void kvm_release_pfn_dirty(pfn_t pfn
)
797 kvm_set_pfn_dirty(pfn
);
798 kvm_release_pfn_clean(pfn
);
800 EXPORT_SYMBOL_GPL(kvm_release_pfn_dirty
);
802 void kvm_set_page_dirty(struct page
*page
)
804 kvm_set_pfn_dirty(page_to_pfn(page
));
806 EXPORT_SYMBOL_GPL(kvm_set_page_dirty
);
808 void kvm_set_pfn_dirty(pfn_t pfn
)
810 if (!is_mmio_pfn(pfn
)) {
811 struct page
*page
= pfn_to_page(pfn
);
812 if (!PageReserved(page
))
816 EXPORT_SYMBOL_GPL(kvm_set_pfn_dirty
);
818 void kvm_set_pfn_accessed(pfn_t pfn
)
820 if (!is_mmio_pfn(pfn
))
821 mark_page_accessed(pfn_to_page(pfn
));
823 EXPORT_SYMBOL_GPL(kvm_set_pfn_accessed
);
825 void kvm_get_pfn(pfn_t pfn
)
827 if (!is_mmio_pfn(pfn
))
828 get_page(pfn_to_page(pfn
));
830 EXPORT_SYMBOL_GPL(kvm_get_pfn
);
832 static int next_segment(unsigned long len
, int offset
)
834 if (len
> PAGE_SIZE
- offset
)
835 return PAGE_SIZE
- offset
;
840 int kvm_read_guest_page(struct kvm
*kvm
, gfn_t gfn
, void *data
, int offset
,
846 addr
= gfn_to_hva(kvm
, gfn
);
847 if (kvm_is_error_hva(addr
))
849 r
= copy_from_user(data
, (void __user
*)addr
+ offset
, len
);
854 EXPORT_SYMBOL_GPL(kvm_read_guest_page
);
856 int kvm_read_guest(struct kvm
*kvm
, gpa_t gpa
, void *data
, unsigned long len
)
858 gfn_t gfn
= gpa
>> PAGE_SHIFT
;
860 int offset
= offset_in_page(gpa
);
863 while ((seg
= next_segment(len
, offset
)) != 0) {
864 ret
= kvm_read_guest_page(kvm
, gfn
, data
, offset
, seg
);
874 EXPORT_SYMBOL_GPL(kvm_read_guest
);
876 int kvm_read_guest_atomic(struct kvm
*kvm
, gpa_t gpa
, void *data
,
881 gfn_t gfn
= gpa
>> PAGE_SHIFT
;
882 int offset
= offset_in_page(gpa
);
884 addr
= gfn_to_hva(kvm
, gfn
);
885 if (kvm_is_error_hva(addr
))
888 r
= __copy_from_user_inatomic(data
, (void __user
*)addr
+ offset
, len
);
894 EXPORT_SYMBOL(kvm_read_guest_atomic
);
896 int kvm_write_guest_page(struct kvm
*kvm
, gfn_t gfn
, const void *data
,
902 addr
= gfn_to_hva(kvm
, gfn
);
903 if (kvm_is_error_hva(addr
))
905 r
= copy_to_user((void __user
*)addr
+ offset
, data
, len
);
908 mark_page_dirty(kvm
, gfn
);
911 EXPORT_SYMBOL_GPL(kvm_write_guest_page
);
913 int kvm_write_guest(struct kvm
*kvm
, gpa_t gpa
, const void *data
,
916 gfn_t gfn
= gpa
>> PAGE_SHIFT
;
918 int offset
= offset_in_page(gpa
);
921 while ((seg
= next_segment(len
, offset
)) != 0) {
922 ret
= kvm_write_guest_page(kvm
, gfn
, data
, offset
, seg
);
933 int kvm_clear_guest_page(struct kvm
*kvm
, gfn_t gfn
, int offset
, int len
)
935 return kvm_write_guest_page(kvm
, gfn
, empty_zero_page
, offset
, len
);
937 EXPORT_SYMBOL_GPL(kvm_clear_guest_page
);
939 int kvm_clear_guest(struct kvm
*kvm
, gpa_t gpa
, unsigned long len
)
941 gfn_t gfn
= gpa
>> PAGE_SHIFT
;
943 int offset
= offset_in_page(gpa
);
946 while ((seg
= next_segment(len
, offset
)) != 0) {
947 ret
= kvm_clear_guest_page(kvm
, gfn
, offset
, seg
);
956 EXPORT_SYMBOL_GPL(kvm_clear_guest
);
958 void mark_page_dirty(struct kvm
*kvm
, gfn_t gfn
)
960 struct kvm_memory_slot
*memslot
;
962 gfn
= unalias_gfn(kvm
, gfn
);
963 memslot
= __gfn_to_memslot(kvm
, gfn
);
964 if (memslot
&& memslot
->dirty_bitmap
) {
965 unsigned long rel_gfn
= gfn
- memslot
->base_gfn
;
968 if (!test_bit(rel_gfn
, memslot
->dirty_bitmap
))
969 set_bit(rel_gfn
, memslot
->dirty_bitmap
);
974 * The vCPU has executed a HLT instruction with in-kernel mode enabled.
976 void kvm_vcpu_block(struct kvm_vcpu
*vcpu
)
981 prepare_to_wait(&vcpu
->wq
, &wait
, TASK_INTERRUPTIBLE
);
983 if (kvm_cpu_has_interrupt(vcpu
))
985 if (kvm_cpu_has_pending_timer(vcpu
))
987 if (kvm_arch_vcpu_runnable(vcpu
))
989 if (signal_pending(current
))
997 finish_wait(&vcpu
->wq
, &wait
);
1000 void kvm_resched(struct kvm_vcpu
*vcpu
)
1002 if (!need_resched())
1006 EXPORT_SYMBOL_GPL(kvm_resched
);
1008 static int kvm_vcpu_fault(struct vm_area_struct
*vma
, struct vm_fault
*vmf
)
1010 struct kvm_vcpu
*vcpu
= vma
->vm_file
->private_data
;
1013 if (vmf
->pgoff
== 0)
1014 page
= virt_to_page(vcpu
->run
);
1016 else if (vmf
->pgoff
== KVM_PIO_PAGE_OFFSET
)
1017 page
= virt_to_page(vcpu
->arch
.pio_data
);
1019 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
1020 else if (vmf
->pgoff
== KVM_COALESCED_MMIO_PAGE_OFFSET
)
1021 page
= virt_to_page(vcpu
->kvm
->coalesced_mmio_ring
);
1024 return VM_FAULT_SIGBUS
;
1030 static struct vm_operations_struct kvm_vcpu_vm_ops
= {
1031 .fault
= kvm_vcpu_fault
,
1034 static int kvm_vcpu_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1036 vma
->vm_ops
= &kvm_vcpu_vm_ops
;
1040 static int kvm_vcpu_release(struct inode
*inode
, struct file
*filp
)
1042 struct kvm_vcpu
*vcpu
= filp
->private_data
;
1044 kvm_put_kvm(vcpu
->kvm
);
1048 static const struct file_operations kvm_vcpu_fops
= {
1049 .release
= kvm_vcpu_release
,
1050 .unlocked_ioctl
= kvm_vcpu_ioctl
,
1051 .compat_ioctl
= kvm_vcpu_ioctl
,
1052 .mmap
= kvm_vcpu_mmap
,
1056 * Allocates an inode for the vcpu.
1058 static int create_vcpu_fd(struct kvm_vcpu
*vcpu
)
1060 int fd
= anon_inode_getfd("kvm-vcpu", &kvm_vcpu_fops
, vcpu
, 0);
1062 kvm_put_kvm(vcpu
->kvm
);
1067 * Creates some virtual cpus. Good luck creating more than one.
1069 static int kvm_vm_ioctl_create_vcpu(struct kvm
*kvm
, int n
)
1072 struct kvm_vcpu
*vcpu
;
1077 vcpu
= kvm_arch_vcpu_create(kvm
, n
);
1079 return PTR_ERR(vcpu
);
1081 preempt_notifier_init(&vcpu
->preempt_notifier
, &kvm_preempt_ops
);
1083 r
= kvm_arch_vcpu_setup(vcpu
);
1087 mutex_lock(&kvm
->lock
);
1088 if (kvm
->vcpus
[n
]) {
1090 mutex_unlock(&kvm
->lock
);
1093 kvm
->vcpus
[n
] = vcpu
;
1094 mutex_unlock(&kvm
->lock
);
1096 /* Now it's all set up, let userspace reach it */
1098 r
= create_vcpu_fd(vcpu
);
1104 mutex_lock(&kvm
->lock
);
1105 kvm
->vcpus
[n
] = NULL
;
1106 mutex_unlock(&kvm
->lock
);
1108 kvm_arch_vcpu_destroy(vcpu
);
1112 static int kvm_vcpu_ioctl_set_sigmask(struct kvm_vcpu
*vcpu
, sigset_t
*sigset
)
1115 sigdelsetmask(sigset
, sigmask(SIGKILL
)|sigmask(SIGSTOP
));
1116 vcpu
->sigset_active
= 1;
1117 vcpu
->sigset
= *sigset
;
1119 vcpu
->sigset_active
= 0;
1123 static long kvm_vcpu_ioctl(struct file
*filp
,
1124 unsigned int ioctl
, unsigned long arg
)
1126 struct kvm_vcpu
*vcpu
= filp
->private_data
;
1127 void __user
*argp
= (void __user
*)arg
;
1129 struct kvm_fpu
*fpu
= NULL
;
1130 struct kvm_sregs
*kvm_sregs
= NULL
;
1132 if (vcpu
->kvm
->mm
!= current
->mm
)
1139 r
= kvm_arch_vcpu_ioctl_run(vcpu
, vcpu
->run
);
1141 case KVM_GET_REGS
: {
1142 struct kvm_regs
*kvm_regs
;
1145 kvm_regs
= kzalloc(sizeof(struct kvm_regs
), GFP_KERNEL
);
1148 r
= kvm_arch_vcpu_ioctl_get_regs(vcpu
, kvm_regs
);
1152 if (copy_to_user(argp
, kvm_regs
, sizeof(struct kvm_regs
)))
1159 case KVM_SET_REGS
: {
1160 struct kvm_regs
*kvm_regs
;
1163 kvm_regs
= kzalloc(sizeof(struct kvm_regs
), GFP_KERNEL
);
1167 if (copy_from_user(kvm_regs
, argp
, sizeof(struct kvm_regs
)))
1169 r
= kvm_arch_vcpu_ioctl_set_regs(vcpu
, kvm_regs
);
1177 case KVM_GET_SREGS
: {
1178 kvm_sregs
= kzalloc(sizeof(struct kvm_sregs
), GFP_KERNEL
);
1182 r
= kvm_arch_vcpu_ioctl_get_sregs(vcpu
, kvm_sregs
);
1186 if (copy_to_user(argp
, kvm_sregs
, sizeof(struct kvm_sregs
)))
1191 case KVM_SET_SREGS
: {
1192 kvm_sregs
= kmalloc(sizeof(struct kvm_sregs
), GFP_KERNEL
);
1197 if (copy_from_user(kvm_sregs
, argp
, sizeof(struct kvm_sregs
)))
1199 r
= kvm_arch_vcpu_ioctl_set_sregs(vcpu
, kvm_sregs
);
1205 case KVM_GET_MP_STATE
: {
1206 struct kvm_mp_state mp_state
;
1208 r
= kvm_arch_vcpu_ioctl_get_mpstate(vcpu
, &mp_state
);
1212 if (copy_to_user(argp
, &mp_state
, sizeof mp_state
))
1217 case KVM_SET_MP_STATE
: {
1218 struct kvm_mp_state mp_state
;
1221 if (copy_from_user(&mp_state
, argp
, sizeof mp_state
))
1223 r
= kvm_arch_vcpu_ioctl_set_mpstate(vcpu
, &mp_state
);
1229 case KVM_TRANSLATE
: {
1230 struct kvm_translation tr
;
1233 if (copy_from_user(&tr
, argp
, sizeof tr
))
1235 r
= kvm_arch_vcpu_ioctl_translate(vcpu
, &tr
);
1239 if (copy_to_user(argp
, &tr
, sizeof tr
))
1244 case KVM_DEBUG_GUEST
: {
1245 struct kvm_debug_guest dbg
;
1248 if (copy_from_user(&dbg
, argp
, sizeof dbg
))
1250 r
= kvm_arch_vcpu_ioctl_debug_guest(vcpu
, &dbg
);
1256 case KVM_SET_SIGNAL_MASK
: {
1257 struct kvm_signal_mask __user
*sigmask_arg
= argp
;
1258 struct kvm_signal_mask kvm_sigmask
;
1259 sigset_t sigset
, *p
;
1264 if (copy_from_user(&kvm_sigmask
, argp
,
1265 sizeof kvm_sigmask
))
1268 if (kvm_sigmask
.len
!= sizeof sigset
)
1271 if (copy_from_user(&sigset
, sigmask_arg
->sigset
,
1276 r
= kvm_vcpu_ioctl_set_sigmask(vcpu
, &sigset
);
1280 fpu
= kzalloc(sizeof(struct kvm_fpu
), GFP_KERNEL
);
1284 r
= kvm_arch_vcpu_ioctl_get_fpu(vcpu
, fpu
);
1288 if (copy_to_user(argp
, fpu
, sizeof(struct kvm_fpu
)))
1294 fpu
= kmalloc(sizeof(struct kvm_fpu
), GFP_KERNEL
);
1299 if (copy_from_user(fpu
, argp
, sizeof(struct kvm_fpu
)))
1301 r
= kvm_arch_vcpu_ioctl_set_fpu(vcpu
, fpu
);
1308 r
= kvm_arch_vcpu_ioctl(filp
, ioctl
, arg
);
1316 static long kvm_vm_ioctl(struct file
*filp
,
1317 unsigned int ioctl
, unsigned long arg
)
1319 struct kvm
*kvm
= filp
->private_data
;
1320 void __user
*argp
= (void __user
*)arg
;
1323 if (kvm
->mm
!= current
->mm
)
1326 case KVM_CREATE_VCPU
:
1327 r
= kvm_vm_ioctl_create_vcpu(kvm
, arg
);
1331 case KVM_SET_USER_MEMORY_REGION
: {
1332 struct kvm_userspace_memory_region kvm_userspace_mem
;
1335 if (copy_from_user(&kvm_userspace_mem
, argp
,
1336 sizeof kvm_userspace_mem
))
1339 r
= kvm_vm_ioctl_set_memory_region(kvm
, &kvm_userspace_mem
, 1);
1344 case KVM_GET_DIRTY_LOG
: {
1345 struct kvm_dirty_log log
;
1348 if (copy_from_user(&log
, argp
, sizeof log
))
1350 r
= kvm_vm_ioctl_get_dirty_log(kvm
, &log
);
1355 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
1356 case KVM_REGISTER_COALESCED_MMIO
: {
1357 struct kvm_coalesced_mmio_zone zone
;
1359 if (copy_from_user(&zone
, argp
, sizeof zone
))
1362 r
= kvm_vm_ioctl_register_coalesced_mmio(kvm
, &zone
);
1368 case KVM_UNREGISTER_COALESCED_MMIO
: {
1369 struct kvm_coalesced_mmio_zone zone
;
1371 if (copy_from_user(&zone
, argp
, sizeof zone
))
1374 r
= kvm_vm_ioctl_unregister_coalesced_mmio(kvm
, &zone
);
1382 r
= kvm_arch_vm_ioctl(filp
, ioctl
, arg
);
1388 static int kvm_vm_fault(struct vm_area_struct
*vma
, struct vm_fault
*vmf
)
1390 struct kvm
*kvm
= vma
->vm_file
->private_data
;
1393 if (!kvm_is_visible_gfn(kvm
, vmf
->pgoff
))
1394 return VM_FAULT_SIGBUS
;
1395 page
= gfn_to_page(kvm
, vmf
->pgoff
);
1396 if (is_error_page(page
)) {
1397 kvm_release_page_clean(page
);
1398 return VM_FAULT_SIGBUS
;
1404 static struct vm_operations_struct kvm_vm_vm_ops
= {
1405 .fault
= kvm_vm_fault
,
1408 static int kvm_vm_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1410 vma
->vm_ops
= &kvm_vm_vm_ops
;
1414 static const struct file_operations kvm_vm_fops
= {
1415 .release
= kvm_vm_release
,
1416 .unlocked_ioctl
= kvm_vm_ioctl
,
1417 .compat_ioctl
= kvm_vm_ioctl
,
1418 .mmap
= kvm_vm_mmap
,
1421 static int kvm_dev_ioctl_create_vm(void)
1426 kvm
= kvm_create_vm();
1428 return PTR_ERR(kvm
);
1429 fd
= anon_inode_getfd("kvm-vm", &kvm_vm_fops
, kvm
, 0);
1436 static long kvm_dev_ioctl(struct file
*filp
,
1437 unsigned int ioctl
, unsigned long arg
)
1442 case KVM_GET_API_VERSION
:
1446 r
= KVM_API_VERSION
;
1452 r
= kvm_dev_ioctl_create_vm();
1454 case KVM_CHECK_EXTENSION
:
1455 r
= kvm_dev_ioctl_check_extension(arg
);
1457 case KVM_GET_VCPU_MMAP_SIZE
:
1461 r
= PAGE_SIZE
; /* struct kvm_run */
1463 r
+= PAGE_SIZE
; /* pio data page */
1465 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
1466 r
+= PAGE_SIZE
; /* coalesced mmio ring page */
1469 case KVM_TRACE_ENABLE
:
1470 case KVM_TRACE_PAUSE
:
1471 case KVM_TRACE_DISABLE
:
1472 r
= kvm_trace_ioctl(ioctl
, arg
);
1475 return kvm_arch_dev_ioctl(filp
, ioctl
, arg
);
1481 static struct file_operations kvm_chardev_ops
= {
1482 .unlocked_ioctl
= kvm_dev_ioctl
,
1483 .compat_ioctl
= kvm_dev_ioctl
,
1486 static struct miscdevice kvm_dev
= {
1492 static void hardware_enable(void *junk
)
1494 int cpu
= raw_smp_processor_id();
1496 if (cpu_isset(cpu
, cpus_hardware_enabled
))
1498 cpu_set(cpu
, cpus_hardware_enabled
);
1499 kvm_arch_hardware_enable(NULL
);
1502 static void hardware_disable(void *junk
)
1504 int cpu
= raw_smp_processor_id();
1506 if (!cpu_isset(cpu
, cpus_hardware_enabled
))
1508 cpu_clear(cpu
, cpus_hardware_enabled
);
1509 kvm_arch_hardware_disable(NULL
);
1512 static int kvm_cpu_hotplug(struct notifier_block
*notifier
, unsigned long val
,
1517 val
&= ~CPU_TASKS_FROZEN
;
1520 printk(KERN_INFO
"kvm: disabling virtualization on CPU%d\n",
1522 hardware_disable(NULL
);
1524 case CPU_UP_CANCELED
:
1525 printk(KERN_INFO
"kvm: disabling virtualization on CPU%d\n",
1527 smp_call_function_single(cpu
, hardware_disable
, NULL
, 1);
1530 printk(KERN_INFO
"kvm: enabling virtualization on CPU%d\n",
1532 smp_call_function_single(cpu
, hardware_enable
, NULL
, 1);
1539 asmlinkage
void kvm_handle_fault_on_reboot(void)
1542 /* spin while reset goes on */
1545 /* Fault while not rebooting. We want the trace. */
1548 EXPORT_SYMBOL_GPL(kvm_handle_fault_on_reboot
);
1550 static int kvm_reboot(struct notifier_block
*notifier
, unsigned long val
,
1553 if (val
== SYS_RESTART
) {
1555 * Some (well, at least mine) BIOSes hang on reboot if
1558 printk(KERN_INFO
"kvm: exiting hardware virtualization\n");
1559 kvm_rebooting
= true;
1560 on_each_cpu(hardware_disable
, NULL
, 1);
1565 static struct notifier_block kvm_reboot_notifier
= {
1566 .notifier_call
= kvm_reboot
,
1570 void kvm_io_bus_init(struct kvm_io_bus
*bus
)
1572 memset(bus
, 0, sizeof(*bus
));
1575 void kvm_io_bus_destroy(struct kvm_io_bus
*bus
)
1579 for (i
= 0; i
< bus
->dev_count
; i
++) {
1580 struct kvm_io_device
*pos
= bus
->devs
[i
];
1582 kvm_iodevice_destructor(pos
);
1586 struct kvm_io_device
*kvm_io_bus_find_dev(struct kvm_io_bus
*bus
,
1587 gpa_t addr
, int len
, int is_write
)
1591 for (i
= 0; i
< bus
->dev_count
; i
++) {
1592 struct kvm_io_device
*pos
= bus
->devs
[i
];
1594 if (pos
->in_range(pos
, addr
, len
, is_write
))
1601 void kvm_io_bus_register_dev(struct kvm_io_bus
*bus
, struct kvm_io_device
*dev
)
1603 BUG_ON(bus
->dev_count
> (NR_IOBUS_DEVS
-1));
1605 bus
->devs
[bus
->dev_count
++] = dev
;
1608 static struct notifier_block kvm_cpu_notifier
= {
1609 .notifier_call
= kvm_cpu_hotplug
,
1610 .priority
= 20, /* must be > scheduler priority */
1613 static int vm_stat_get(void *_offset
, u64
*val
)
1615 unsigned offset
= (long)_offset
;
1619 spin_lock(&kvm_lock
);
1620 list_for_each_entry(kvm
, &vm_list
, vm_list
)
1621 *val
+= *(u32
*)((void *)kvm
+ offset
);
1622 spin_unlock(&kvm_lock
);
1626 DEFINE_SIMPLE_ATTRIBUTE(vm_stat_fops
, vm_stat_get
, NULL
, "%llu\n");
1628 static int vcpu_stat_get(void *_offset
, u64
*val
)
1630 unsigned offset
= (long)_offset
;
1632 struct kvm_vcpu
*vcpu
;
1636 spin_lock(&kvm_lock
);
1637 list_for_each_entry(kvm
, &vm_list
, vm_list
)
1638 for (i
= 0; i
< KVM_MAX_VCPUS
; ++i
) {
1639 vcpu
= kvm
->vcpus
[i
];
1641 *val
+= *(u32
*)((void *)vcpu
+ offset
);
1643 spin_unlock(&kvm_lock
);
1647 DEFINE_SIMPLE_ATTRIBUTE(vcpu_stat_fops
, vcpu_stat_get
, NULL
, "%llu\n");
1649 static struct file_operations
*stat_fops
[] = {
1650 [KVM_STAT_VCPU
] = &vcpu_stat_fops
,
1651 [KVM_STAT_VM
] = &vm_stat_fops
,
1654 static void kvm_init_debug(void)
1656 struct kvm_stats_debugfs_item
*p
;
1658 kvm_debugfs_dir
= debugfs_create_dir("kvm", NULL
);
1659 for (p
= debugfs_entries
; p
->name
; ++p
)
1660 p
->dentry
= debugfs_create_file(p
->name
, 0444, kvm_debugfs_dir
,
1661 (void *)(long)p
->offset
,
1662 stat_fops
[p
->kind
]);
1665 static void kvm_exit_debug(void)
1667 struct kvm_stats_debugfs_item
*p
;
1669 for (p
= debugfs_entries
; p
->name
; ++p
)
1670 debugfs_remove(p
->dentry
);
1671 debugfs_remove(kvm_debugfs_dir
);
1674 static int kvm_suspend(struct sys_device
*dev
, pm_message_t state
)
1676 hardware_disable(NULL
);
1680 static int kvm_resume(struct sys_device
*dev
)
1682 hardware_enable(NULL
);
1686 static struct sysdev_class kvm_sysdev_class
= {
1688 .suspend
= kvm_suspend
,
1689 .resume
= kvm_resume
,
1692 static struct sys_device kvm_sysdev
= {
1694 .cls
= &kvm_sysdev_class
,
1697 struct page
*bad_page
;
1701 struct kvm_vcpu
*preempt_notifier_to_vcpu(struct preempt_notifier
*pn
)
1703 return container_of(pn
, struct kvm_vcpu
, preempt_notifier
);
1706 static void kvm_sched_in(struct preempt_notifier
*pn
, int cpu
)
1708 struct kvm_vcpu
*vcpu
= preempt_notifier_to_vcpu(pn
);
1710 kvm_arch_vcpu_load(vcpu
, cpu
);
1713 static void kvm_sched_out(struct preempt_notifier
*pn
,
1714 struct task_struct
*next
)
1716 struct kvm_vcpu
*vcpu
= preempt_notifier_to_vcpu(pn
);
1718 kvm_arch_vcpu_put(vcpu
);
1721 int kvm_init(void *opaque
, unsigned int vcpu_size
,
1722 struct module
*module
)
1729 r
= kvm_arch_init(opaque
);
1733 bad_page
= alloc_page(GFP_KERNEL
| __GFP_ZERO
);
1735 if (bad_page
== NULL
) {
1740 bad_pfn
= page_to_pfn(bad_page
);
1742 r
= kvm_arch_hardware_setup();
1746 for_each_online_cpu(cpu
) {
1747 smp_call_function_single(cpu
,
1748 kvm_arch_check_processor_compat
,
1754 on_each_cpu(hardware_enable
, NULL
, 1);
1755 r
= register_cpu_notifier(&kvm_cpu_notifier
);
1758 register_reboot_notifier(&kvm_reboot_notifier
);
1760 r
= sysdev_class_register(&kvm_sysdev_class
);
1764 r
= sysdev_register(&kvm_sysdev
);
1768 /* A kmem cache lets us meet the alignment requirements of fx_save. */
1769 kvm_vcpu_cache
= kmem_cache_create("kvm_vcpu", vcpu_size
,
1770 __alignof__(struct kvm_vcpu
),
1772 if (!kvm_vcpu_cache
) {
1777 kvm_chardev_ops
.owner
= module
;
1779 r
= misc_register(&kvm_dev
);
1781 printk(KERN_ERR
"kvm: misc device register failed\n");
1785 kvm_preempt_ops
.sched_in
= kvm_sched_in
;
1786 kvm_preempt_ops
.sched_out
= kvm_sched_out
;
1791 kmem_cache_destroy(kvm_vcpu_cache
);
1793 sysdev_unregister(&kvm_sysdev
);
1795 sysdev_class_unregister(&kvm_sysdev_class
);
1797 unregister_reboot_notifier(&kvm_reboot_notifier
);
1798 unregister_cpu_notifier(&kvm_cpu_notifier
);
1800 on_each_cpu(hardware_disable
, NULL
, 1);
1802 kvm_arch_hardware_unsetup();
1804 __free_page(bad_page
);
1811 EXPORT_SYMBOL_GPL(kvm_init
);
1815 kvm_trace_cleanup();
1816 misc_deregister(&kvm_dev
);
1817 kmem_cache_destroy(kvm_vcpu_cache
);
1818 sysdev_unregister(&kvm_sysdev
);
1819 sysdev_class_unregister(&kvm_sysdev_class
);
1820 unregister_reboot_notifier(&kvm_reboot_notifier
);
1821 unregister_cpu_notifier(&kvm_cpu_notifier
);
1822 on_each_cpu(hardware_disable
, NULL
, 1);
1823 kvm_arch_hardware_unsetup();
1826 __free_page(bad_page
);
1828 EXPORT_SYMBOL_GPL(kvm_exit
);