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
);
80 * Switches to specified vcpu, until a matching vcpu_put()
82 void vcpu_load(struct kvm_vcpu
*vcpu
)
86 mutex_lock(&vcpu
->mutex
);
88 preempt_notifier_register(&vcpu
->preempt_notifier
);
89 kvm_arch_vcpu_load(vcpu
, cpu
);
93 void vcpu_put(struct kvm_vcpu
*vcpu
)
96 kvm_arch_vcpu_put(vcpu
);
97 preempt_notifier_unregister(&vcpu
->preempt_notifier
);
99 mutex_unlock(&vcpu
->mutex
);
102 static void ack_flush(void *_completed
)
106 void kvm_flush_remote_tlbs(struct kvm
*kvm
)
110 struct kvm_vcpu
*vcpu
;
114 for (i
= 0; i
< KVM_MAX_VCPUS
; ++i
) {
115 vcpu
= kvm
->vcpus
[i
];
118 if (test_and_set_bit(KVM_REQ_TLB_FLUSH
, &vcpu
->requests
))
121 if (cpu
!= -1 && cpu
!= me
)
124 if (cpus_empty(cpus
))
126 ++kvm
->stat
.remote_tlb_flush
;
127 smp_call_function_mask(cpus
, ack_flush
, NULL
, 1);
132 void kvm_reload_remote_mmus(struct kvm
*kvm
)
136 struct kvm_vcpu
*vcpu
;
140 for (i
= 0; i
< KVM_MAX_VCPUS
; ++i
) {
141 vcpu
= kvm
->vcpus
[i
];
144 if (test_and_set_bit(KVM_REQ_MMU_RELOAD
, &vcpu
->requests
))
147 if (cpu
!= -1 && cpu
!= me
)
150 if (cpus_empty(cpus
))
152 smp_call_function_mask(cpus
, ack_flush
, NULL
, 1);
158 int kvm_vcpu_init(struct kvm_vcpu
*vcpu
, struct kvm
*kvm
, unsigned id
)
163 mutex_init(&vcpu
->mutex
);
167 init_waitqueue_head(&vcpu
->wq
);
169 page
= alloc_page(GFP_KERNEL
| __GFP_ZERO
);
174 vcpu
->run
= page_address(page
);
176 r
= kvm_arch_vcpu_init(vcpu
);
182 free_page((unsigned long)vcpu
->run
);
186 EXPORT_SYMBOL_GPL(kvm_vcpu_init
);
188 void kvm_vcpu_uninit(struct kvm_vcpu
*vcpu
)
190 kvm_arch_vcpu_uninit(vcpu
);
191 free_page((unsigned long)vcpu
->run
);
193 EXPORT_SYMBOL_GPL(kvm_vcpu_uninit
);
195 #if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
196 static inline struct kvm
*mmu_notifier_to_kvm(struct mmu_notifier
*mn
)
198 return container_of(mn
, struct kvm
, mmu_notifier
);
201 static void kvm_mmu_notifier_invalidate_page(struct mmu_notifier
*mn
,
202 struct mm_struct
*mm
,
203 unsigned long address
)
205 struct kvm
*kvm
= mmu_notifier_to_kvm(mn
);
209 * When ->invalidate_page runs, the linux pte has been zapped
210 * already but the page is still allocated until
211 * ->invalidate_page returns. So if we increase the sequence
212 * here the kvm page fault will notice if the spte can't be
213 * established because the page is going to be freed. If
214 * instead the kvm page fault establishes the spte before
215 * ->invalidate_page runs, kvm_unmap_hva will release it
218 * The sequence increase only need to be seen at spin_unlock
219 * time, and not at spin_lock time.
221 * Increasing the sequence after the spin_unlock would be
222 * unsafe because the kvm page fault could then establish the
223 * pte after kvm_unmap_hva returned, without noticing the page
224 * is going to be freed.
226 spin_lock(&kvm
->mmu_lock
);
227 kvm
->mmu_notifier_seq
++;
228 need_tlb_flush
= kvm_unmap_hva(kvm
, address
);
229 spin_unlock(&kvm
->mmu_lock
);
231 /* we've to flush the tlb before the pages can be freed */
233 kvm_flush_remote_tlbs(kvm
);
237 static void kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier
*mn
,
238 struct mm_struct
*mm
,
242 struct kvm
*kvm
= mmu_notifier_to_kvm(mn
);
243 int need_tlb_flush
= 0;
245 spin_lock(&kvm
->mmu_lock
);
247 * The count increase must become visible at unlock time as no
248 * spte can be established without taking the mmu_lock and
249 * count is also read inside the mmu_lock critical section.
251 kvm
->mmu_notifier_count
++;
252 for (; start
< end
; start
+= PAGE_SIZE
)
253 need_tlb_flush
|= kvm_unmap_hva(kvm
, start
);
254 spin_unlock(&kvm
->mmu_lock
);
256 /* we've to flush the tlb before the pages can be freed */
258 kvm_flush_remote_tlbs(kvm
);
261 static void kvm_mmu_notifier_invalidate_range_end(struct mmu_notifier
*mn
,
262 struct mm_struct
*mm
,
266 struct kvm
*kvm
= mmu_notifier_to_kvm(mn
);
268 spin_lock(&kvm
->mmu_lock
);
270 * This sequence increase will notify the kvm page fault that
271 * the page that is going to be mapped in the spte could have
274 kvm
->mmu_notifier_seq
++;
276 * The above sequence increase must be visible before the
277 * below count decrease but both values are read by the kvm
278 * page fault under mmu_lock spinlock so we don't need to add
279 * a smb_wmb() here in between the two.
281 kvm
->mmu_notifier_count
--;
282 spin_unlock(&kvm
->mmu_lock
);
284 BUG_ON(kvm
->mmu_notifier_count
< 0);
287 static int kvm_mmu_notifier_clear_flush_young(struct mmu_notifier
*mn
,
288 struct mm_struct
*mm
,
289 unsigned long address
)
291 struct kvm
*kvm
= mmu_notifier_to_kvm(mn
);
294 spin_lock(&kvm
->mmu_lock
);
295 young
= kvm_age_hva(kvm
, address
);
296 spin_unlock(&kvm
->mmu_lock
);
299 kvm_flush_remote_tlbs(kvm
);
304 static const struct mmu_notifier_ops kvm_mmu_notifier_ops
= {
305 .invalidate_page
= kvm_mmu_notifier_invalidate_page
,
306 .invalidate_range_start
= kvm_mmu_notifier_invalidate_range_start
,
307 .invalidate_range_end
= kvm_mmu_notifier_invalidate_range_end
,
308 .clear_flush_young
= kvm_mmu_notifier_clear_flush_young
,
310 #endif /* CONFIG_MMU_NOTIFIER && KVM_ARCH_WANT_MMU_NOTIFIER */
312 static struct kvm
*kvm_create_vm(void)
314 struct kvm
*kvm
= kvm_arch_create_vm();
315 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
322 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
323 page
= alloc_page(GFP_KERNEL
| __GFP_ZERO
);
326 return ERR_PTR(-ENOMEM
);
328 kvm
->coalesced_mmio_ring
=
329 (struct kvm_coalesced_mmio_ring
*)page_address(page
);
332 #if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
335 kvm
->mmu_notifier
.ops
= &kvm_mmu_notifier_ops
;
336 err
= mmu_notifier_register(&kvm
->mmu_notifier
, current
->mm
);
338 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
347 kvm
->mm
= current
->mm
;
348 atomic_inc(&kvm
->mm
->mm_count
);
349 spin_lock_init(&kvm
->mmu_lock
);
350 kvm_io_bus_init(&kvm
->pio_bus
);
351 mutex_init(&kvm
->lock
);
352 kvm_io_bus_init(&kvm
->mmio_bus
);
353 init_rwsem(&kvm
->slots_lock
);
354 atomic_set(&kvm
->users_count
, 1);
355 spin_lock(&kvm_lock
);
356 list_add(&kvm
->vm_list
, &vm_list
);
357 spin_unlock(&kvm_lock
);
358 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
359 kvm_coalesced_mmio_init(kvm
);
366 * Free any memory in @free but not in @dont.
368 static void kvm_free_physmem_slot(struct kvm_memory_slot
*free
,
369 struct kvm_memory_slot
*dont
)
371 if (!dont
|| free
->rmap
!= dont
->rmap
)
374 if (!dont
|| free
->dirty_bitmap
!= dont
->dirty_bitmap
)
375 vfree(free
->dirty_bitmap
);
377 if (!dont
|| free
->lpage_info
!= dont
->lpage_info
)
378 vfree(free
->lpage_info
);
381 free
->dirty_bitmap
= NULL
;
383 free
->lpage_info
= NULL
;
386 void kvm_free_physmem(struct kvm
*kvm
)
390 for (i
= 0; i
< kvm
->nmemslots
; ++i
)
391 kvm_free_physmem_slot(&kvm
->memslots
[i
], NULL
);
394 static void kvm_destroy_vm(struct kvm
*kvm
)
396 struct mm_struct
*mm
= kvm
->mm
;
398 spin_lock(&kvm_lock
);
399 list_del(&kvm
->vm_list
);
400 spin_unlock(&kvm_lock
);
401 kvm_io_bus_destroy(&kvm
->pio_bus
);
402 kvm_io_bus_destroy(&kvm
->mmio_bus
);
403 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
404 if (kvm
->coalesced_mmio_ring
!= NULL
)
405 free_page((unsigned long)kvm
->coalesced_mmio_ring
);
407 #if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
408 mmu_notifier_unregister(&kvm
->mmu_notifier
, kvm
->mm
);
410 kvm_arch_destroy_vm(kvm
);
414 void kvm_get_kvm(struct kvm
*kvm
)
416 atomic_inc(&kvm
->users_count
);
418 EXPORT_SYMBOL_GPL(kvm_get_kvm
);
420 void kvm_put_kvm(struct kvm
*kvm
)
422 if (atomic_dec_and_test(&kvm
->users_count
))
425 EXPORT_SYMBOL_GPL(kvm_put_kvm
);
428 static int kvm_vm_release(struct inode
*inode
, struct file
*filp
)
430 struct kvm
*kvm
= filp
->private_data
;
437 * Allocate some memory and give it an address in the guest physical address
440 * Discontiguous memory is allowed, mostly for framebuffers.
442 * Must be called holding mmap_sem for write.
444 int __kvm_set_memory_region(struct kvm
*kvm
,
445 struct kvm_userspace_memory_region
*mem
,
450 unsigned long npages
;
452 struct kvm_memory_slot
*memslot
;
453 struct kvm_memory_slot old
, new;
456 /* General sanity checks */
457 if (mem
->memory_size
& (PAGE_SIZE
- 1))
459 if (mem
->guest_phys_addr
& (PAGE_SIZE
- 1))
461 if (mem
->slot
>= KVM_MEMORY_SLOTS
+ KVM_PRIVATE_MEM_SLOTS
)
463 if (mem
->guest_phys_addr
+ mem
->memory_size
< mem
->guest_phys_addr
)
466 memslot
= &kvm
->memslots
[mem
->slot
];
467 base_gfn
= mem
->guest_phys_addr
>> PAGE_SHIFT
;
468 npages
= mem
->memory_size
>> PAGE_SHIFT
;
471 mem
->flags
&= ~KVM_MEM_LOG_DIRTY_PAGES
;
473 new = old
= *memslot
;
475 new.base_gfn
= base_gfn
;
477 new.flags
= mem
->flags
;
479 /* Disallow changing a memory slot's size. */
481 if (npages
&& old
.npages
&& npages
!= old
.npages
)
484 /* Check for overlaps */
486 for (i
= 0; i
< KVM_MEMORY_SLOTS
; ++i
) {
487 struct kvm_memory_slot
*s
= &kvm
->memslots
[i
];
491 if (!((base_gfn
+ npages
<= s
->base_gfn
) ||
492 (base_gfn
>= s
->base_gfn
+ s
->npages
)))
496 /* Free page dirty bitmap if unneeded */
497 if (!(new.flags
& KVM_MEM_LOG_DIRTY_PAGES
))
498 new.dirty_bitmap
= NULL
;
502 /* Allocate if a slot is being created */
504 if (npages
&& !new.rmap
) {
505 new.rmap
= vmalloc(npages
* sizeof(struct page
*));
510 memset(new.rmap
, 0, npages
* sizeof(*new.rmap
));
512 new.user_alloc
= user_alloc
;
514 * hva_to_rmmap() serialzies with the mmu_lock and to be
515 * safe it has to ignore memslots with !user_alloc &&
519 new.userspace_addr
= mem
->userspace_addr
;
521 new.userspace_addr
= 0;
523 if (npages
&& !new.lpage_info
) {
524 int largepages
= npages
/ KVM_PAGES_PER_HPAGE
;
525 if (npages
% KVM_PAGES_PER_HPAGE
)
527 if (base_gfn
% KVM_PAGES_PER_HPAGE
)
530 new.lpage_info
= vmalloc(largepages
* sizeof(*new.lpage_info
));
535 memset(new.lpage_info
, 0, largepages
* sizeof(*new.lpage_info
));
537 if (base_gfn
% KVM_PAGES_PER_HPAGE
)
538 new.lpage_info
[0].write_count
= 1;
539 if ((base_gfn
+npages
) % KVM_PAGES_PER_HPAGE
)
540 new.lpage_info
[largepages
-1].write_count
= 1;
543 /* Allocate page dirty bitmap if needed */
544 if ((new.flags
& KVM_MEM_LOG_DIRTY_PAGES
) && !new.dirty_bitmap
) {
545 unsigned dirty_bytes
= ALIGN(npages
, BITS_PER_LONG
) / 8;
547 new.dirty_bitmap
= vmalloc(dirty_bytes
);
548 if (!new.dirty_bitmap
)
550 memset(new.dirty_bitmap
, 0, dirty_bytes
);
552 #endif /* not defined CONFIG_S390 */
555 kvm_arch_flush_shadow(kvm
);
557 spin_lock(&kvm
->mmu_lock
);
558 if (mem
->slot
>= kvm
->nmemslots
)
559 kvm
->nmemslots
= mem
->slot
+ 1;
562 spin_unlock(&kvm
->mmu_lock
);
564 r
= kvm_arch_set_memory_region(kvm
, mem
, old
, user_alloc
);
566 spin_lock(&kvm
->mmu_lock
);
568 spin_unlock(&kvm
->mmu_lock
);
572 kvm_free_physmem_slot(&old
, &new);
576 kvm_free_physmem_slot(&new, &old
);
581 EXPORT_SYMBOL_GPL(__kvm_set_memory_region
);
583 int kvm_set_memory_region(struct kvm
*kvm
,
584 struct kvm_userspace_memory_region
*mem
,
589 down_write(&kvm
->slots_lock
);
590 r
= __kvm_set_memory_region(kvm
, mem
, user_alloc
);
591 up_write(&kvm
->slots_lock
);
594 EXPORT_SYMBOL_GPL(kvm_set_memory_region
);
596 int kvm_vm_ioctl_set_memory_region(struct kvm
*kvm
,
598 kvm_userspace_memory_region
*mem
,
601 if (mem
->slot
>= KVM_MEMORY_SLOTS
)
603 return kvm_set_memory_region(kvm
, mem
, user_alloc
);
606 int kvm_get_dirty_log(struct kvm
*kvm
,
607 struct kvm_dirty_log
*log
, int *is_dirty
)
609 struct kvm_memory_slot
*memslot
;
612 unsigned long any
= 0;
615 if (log
->slot
>= KVM_MEMORY_SLOTS
)
618 memslot
= &kvm
->memslots
[log
->slot
];
620 if (!memslot
->dirty_bitmap
)
623 n
= ALIGN(memslot
->npages
, BITS_PER_LONG
) / 8;
625 for (i
= 0; !any
&& i
< n
/sizeof(long); ++i
)
626 any
= memslot
->dirty_bitmap
[i
];
629 if (copy_to_user(log
->dirty_bitmap
, memslot
->dirty_bitmap
, n
))
640 int is_error_page(struct page
*page
)
642 return page
== bad_page
;
644 EXPORT_SYMBOL_GPL(is_error_page
);
646 int is_error_pfn(pfn_t pfn
)
648 return pfn
== bad_pfn
;
650 EXPORT_SYMBOL_GPL(is_error_pfn
);
652 static inline unsigned long bad_hva(void)
657 int kvm_is_error_hva(unsigned long addr
)
659 return addr
== bad_hva();
661 EXPORT_SYMBOL_GPL(kvm_is_error_hva
);
663 static struct kvm_memory_slot
*__gfn_to_memslot(struct kvm
*kvm
, gfn_t gfn
)
667 for (i
= 0; i
< kvm
->nmemslots
; ++i
) {
668 struct kvm_memory_slot
*memslot
= &kvm
->memslots
[i
];
670 if (gfn
>= memslot
->base_gfn
671 && gfn
< memslot
->base_gfn
+ memslot
->npages
)
677 struct kvm_memory_slot
*gfn_to_memslot(struct kvm
*kvm
, gfn_t gfn
)
679 gfn
= unalias_gfn(kvm
, gfn
);
680 return __gfn_to_memslot(kvm
, gfn
);
683 int kvm_is_visible_gfn(struct kvm
*kvm
, gfn_t gfn
)
687 gfn
= unalias_gfn(kvm
, gfn
);
688 for (i
= 0; i
< KVM_MEMORY_SLOTS
; ++i
) {
689 struct kvm_memory_slot
*memslot
= &kvm
->memslots
[i
];
691 if (gfn
>= memslot
->base_gfn
692 && gfn
< memslot
->base_gfn
+ memslot
->npages
)
697 EXPORT_SYMBOL_GPL(kvm_is_visible_gfn
);
699 unsigned long gfn_to_hva(struct kvm
*kvm
, gfn_t gfn
)
701 struct kvm_memory_slot
*slot
;
703 gfn
= unalias_gfn(kvm
, gfn
);
704 slot
= __gfn_to_memslot(kvm
, gfn
);
707 return (slot
->userspace_addr
+ (gfn
- slot
->base_gfn
) * PAGE_SIZE
);
709 EXPORT_SYMBOL_GPL(gfn_to_hva
);
712 * Requires current->mm->mmap_sem to be held
714 pfn_t
gfn_to_pfn(struct kvm
*kvm
, gfn_t gfn
)
716 struct page
*page
[1];
723 addr
= gfn_to_hva(kvm
, gfn
);
724 if (kvm_is_error_hva(addr
)) {
726 return page_to_pfn(bad_page
);
729 npages
= get_user_pages(current
, current
->mm
, addr
, 1, 1, 1, page
,
732 if (unlikely(npages
!= 1)) {
733 struct vm_area_struct
*vma
;
735 vma
= find_vma(current
->mm
, addr
);
736 if (vma
== NULL
|| addr
< vma
->vm_start
||
737 !(vma
->vm_flags
& VM_PFNMAP
)) {
739 return page_to_pfn(bad_page
);
742 pfn
= ((addr
- vma
->vm_start
) >> PAGE_SHIFT
) + vma
->vm_pgoff
;
743 BUG_ON(pfn_valid(pfn
));
745 pfn
= page_to_pfn(page
[0]);
750 EXPORT_SYMBOL_GPL(gfn_to_pfn
);
752 struct page
*gfn_to_page(struct kvm
*kvm
, gfn_t gfn
)
756 pfn
= gfn_to_pfn(kvm
, gfn
);
758 return pfn_to_page(pfn
);
760 WARN_ON(!pfn_valid(pfn
));
766 EXPORT_SYMBOL_GPL(gfn_to_page
);
768 void kvm_release_page_clean(struct page
*page
)
770 kvm_release_pfn_clean(page_to_pfn(page
));
772 EXPORT_SYMBOL_GPL(kvm_release_page_clean
);
774 void kvm_release_pfn_clean(pfn_t pfn
)
777 put_page(pfn_to_page(pfn
));
779 EXPORT_SYMBOL_GPL(kvm_release_pfn_clean
);
781 void kvm_release_page_dirty(struct page
*page
)
783 kvm_release_pfn_dirty(page_to_pfn(page
));
785 EXPORT_SYMBOL_GPL(kvm_release_page_dirty
);
787 void kvm_release_pfn_dirty(pfn_t pfn
)
789 kvm_set_pfn_dirty(pfn
);
790 kvm_release_pfn_clean(pfn
);
792 EXPORT_SYMBOL_GPL(kvm_release_pfn_dirty
);
794 void kvm_set_page_dirty(struct page
*page
)
796 kvm_set_pfn_dirty(page_to_pfn(page
));
798 EXPORT_SYMBOL_GPL(kvm_set_page_dirty
);
800 void kvm_set_pfn_dirty(pfn_t pfn
)
802 if (pfn_valid(pfn
)) {
803 struct page
*page
= pfn_to_page(pfn
);
804 if (!PageReserved(page
))
808 EXPORT_SYMBOL_GPL(kvm_set_pfn_dirty
);
810 void kvm_set_pfn_accessed(pfn_t pfn
)
813 mark_page_accessed(pfn_to_page(pfn
));
815 EXPORT_SYMBOL_GPL(kvm_set_pfn_accessed
);
817 void kvm_get_pfn(pfn_t pfn
)
820 get_page(pfn_to_page(pfn
));
822 EXPORT_SYMBOL_GPL(kvm_get_pfn
);
824 static int next_segment(unsigned long len
, int offset
)
826 if (len
> PAGE_SIZE
- offset
)
827 return PAGE_SIZE
- offset
;
832 int kvm_read_guest_page(struct kvm
*kvm
, gfn_t gfn
, void *data
, int offset
,
838 addr
= gfn_to_hva(kvm
, gfn
);
839 if (kvm_is_error_hva(addr
))
841 r
= copy_from_user(data
, (void __user
*)addr
+ offset
, len
);
846 EXPORT_SYMBOL_GPL(kvm_read_guest_page
);
848 int kvm_read_guest(struct kvm
*kvm
, gpa_t gpa
, void *data
, unsigned long len
)
850 gfn_t gfn
= gpa
>> PAGE_SHIFT
;
852 int offset
= offset_in_page(gpa
);
855 while ((seg
= next_segment(len
, offset
)) != 0) {
856 ret
= kvm_read_guest_page(kvm
, gfn
, data
, offset
, seg
);
866 EXPORT_SYMBOL_GPL(kvm_read_guest
);
868 int kvm_read_guest_atomic(struct kvm
*kvm
, gpa_t gpa
, void *data
,
873 gfn_t gfn
= gpa
>> PAGE_SHIFT
;
874 int offset
= offset_in_page(gpa
);
876 addr
= gfn_to_hva(kvm
, gfn
);
877 if (kvm_is_error_hva(addr
))
880 r
= __copy_from_user_inatomic(data
, (void __user
*)addr
+ offset
, len
);
886 EXPORT_SYMBOL(kvm_read_guest_atomic
);
888 int kvm_write_guest_page(struct kvm
*kvm
, gfn_t gfn
, const void *data
,
894 addr
= gfn_to_hva(kvm
, gfn
);
895 if (kvm_is_error_hva(addr
))
897 r
= copy_to_user((void __user
*)addr
+ offset
, data
, len
);
900 mark_page_dirty(kvm
, gfn
);
903 EXPORT_SYMBOL_GPL(kvm_write_guest_page
);
905 int kvm_write_guest(struct kvm
*kvm
, gpa_t gpa
, const void *data
,
908 gfn_t gfn
= gpa
>> PAGE_SHIFT
;
910 int offset
= offset_in_page(gpa
);
913 while ((seg
= next_segment(len
, offset
)) != 0) {
914 ret
= kvm_write_guest_page(kvm
, gfn
, data
, offset
, seg
);
925 int kvm_clear_guest_page(struct kvm
*kvm
, gfn_t gfn
, int offset
, int len
)
927 return kvm_write_guest_page(kvm
, gfn
, empty_zero_page
, offset
, len
);
929 EXPORT_SYMBOL_GPL(kvm_clear_guest_page
);
931 int kvm_clear_guest(struct kvm
*kvm
, gpa_t gpa
, unsigned long len
)
933 gfn_t gfn
= gpa
>> PAGE_SHIFT
;
935 int offset
= offset_in_page(gpa
);
938 while ((seg
= next_segment(len
, offset
)) != 0) {
939 ret
= kvm_clear_guest_page(kvm
, gfn
, offset
, seg
);
948 EXPORT_SYMBOL_GPL(kvm_clear_guest
);
950 void mark_page_dirty(struct kvm
*kvm
, gfn_t gfn
)
952 struct kvm_memory_slot
*memslot
;
954 gfn
= unalias_gfn(kvm
, gfn
);
955 memslot
= __gfn_to_memslot(kvm
, gfn
);
956 if (memslot
&& memslot
->dirty_bitmap
) {
957 unsigned long rel_gfn
= gfn
- memslot
->base_gfn
;
960 if (!test_bit(rel_gfn
, memslot
->dirty_bitmap
))
961 set_bit(rel_gfn
, memslot
->dirty_bitmap
);
966 * The vCPU has executed a HLT instruction with in-kernel mode enabled.
968 void kvm_vcpu_block(struct kvm_vcpu
*vcpu
)
973 prepare_to_wait(&vcpu
->wq
, &wait
, TASK_INTERRUPTIBLE
);
975 if (kvm_cpu_has_interrupt(vcpu
))
977 if (kvm_cpu_has_pending_timer(vcpu
))
979 if (kvm_arch_vcpu_runnable(vcpu
))
981 if (signal_pending(current
))
989 finish_wait(&vcpu
->wq
, &wait
);
992 void kvm_resched(struct kvm_vcpu
*vcpu
)
998 EXPORT_SYMBOL_GPL(kvm_resched
);
1000 static int kvm_vcpu_fault(struct vm_area_struct
*vma
, struct vm_fault
*vmf
)
1002 struct kvm_vcpu
*vcpu
= vma
->vm_file
->private_data
;
1005 if (vmf
->pgoff
== 0)
1006 page
= virt_to_page(vcpu
->run
);
1008 else if (vmf
->pgoff
== KVM_PIO_PAGE_OFFSET
)
1009 page
= virt_to_page(vcpu
->arch
.pio_data
);
1011 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
1012 else if (vmf
->pgoff
== KVM_COALESCED_MMIO_PAGE_OFFSET
)
1013 page
= virt_to_page(vcpu
->kvm
->coalesced_mmio_ring
);
1016 return VM_FAULT_SIGBUS
;
1022 static struct vm_operations_struct kvm_vcpu_vm_ops
= {
1023 .fault
= kvm_vcpu_fault
,
1026 static int kvm_vcpu_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1028 vma
->vm_ops
= &kvm_vcpu_vm_ops
;
1032 static int kvm_vcpu_release(struct inode
*inode
, struct file
*filp
)
1034 struct kvm_vcpu
*vcpu
= filp
->private_data
;
1036 kvm_put_kvm(vcpu
->kvm
);
1040 static const struct file_operations kvm_vcpu_fops
= {
1041 .release
= kvm_vcpu_release
,
1042 .unlocked_ioctl
= kvm_vcpu_ioctl
,
1043 .compat_ioctl
= kvm_vcpu_ioctl
,
1044 .mmap
= kvm_vcpu_mmap
,
1048 * Allocates an inode for the vcpu.
1050 static int create_vcpu_fd(struct kvm_vcpu
*vcpu
)
1052 int fd
= anon_inode_getfd("kvm-vcpu", &kvm_vcpu_fops
, vcpu
, 0);
1054 kvm_put_kvm(vcpu
->kvm
);
1059 * Creates some virtual cpus. Good luck creating more than one.
1061 static int kvm_vm_ioctl_create_vcpu(struct kvm
*kvm
, int n
)
1064 struct kvm_vcpu
*vcpu
;
1069 vcpu
= kvm_arch_vcpu_create(kvm
, n
);
1071 return PTR_ERR(vcpu
);
1073 preempt_notifier_init(&vcpu
->preempt_notifier
, &kvm_preempt_ops
);
1075 r
= kvm_arch_vcpu_setup(vcpu
);
1079 mutex_lock(&kvm
->lock
);
1080 if (kvm
->vcpus
[n
]) {
1082 mutex_unlock(&kvm
->lock
);
1085 kvm
->vcpus
[n
] = vcpu
;
1086 mutex_unlock(&kvm
->lock
);
1088 /* Now it's all set up, let userspace reach it */
1090 r
= create_vcpu_fd(vcpu
);
1096 mutex_lock(&kvm
->lock
);
1097 kvm
->vcpus
[n
] = NULL
;
1098 mutex_unlock(&kvm
->lock
);
1100 kvm_arch_vcpu_destroy(vcpu
);
1104 static int kvm_vcpu_ioctl_set_sigmask(struct kvm_vcpu
*vcpu
, sigset_t
*sigset
)
1107 sigdelsetmask(sigset
, sigmask(SIGKILL
)|sigmask(SIGSTOP
));
1108 vcpu
->sigset_active
= 1;
1109 vcpu
->sigset
= *sigset
;
1111 vcpu
->sigset_active
= 0;
1115 static long kvm_vcpu_ioctl(struct file
*filp
,
1116 unsigned int ioctl
, unsigned long arg
)
1118 struct kvm_vcpu
*vcpu
= filp
->private_data
;
1119 void __user
*argp
= (void __user
*)arg
;
1122 if (vcpu
->kvm
->mm
!= current
->mm
)
1129 r
= kvm_arch_vcpu_ioctl_run(vcpu
, vcpu
->run
);
1131 case KVM_GET_REGS
: {
1132 struct kvm_regs
*kvm_regs
;
1135 kvm_regs
= kzalloc(sizeof(struct kvm_regs
), GFP_KERNEL
);
1138 r
= kvm_arch_vcpu_ioctl_get_regs(vcpu
, kvm_regs
);
1142 if (copy_to_user(argp
, kvm_regs
, sizeof(struct kvm_regs
)))
1149 case KVM_SET_REGS
: {
1150 struct kvm_regs
*kvm_regs
;
1153 kvm_regs
= kzalloc(sizeof(struct kvm_regs
), GFP_KERNEL
);
1157 if (copy_from_user(kvm_regs
, argp
, sizeof(struct kvm_regs
)))
1159 r
= kvm_arch_vcpu_ioctl_set_regs(vcpu
, kvm_regs
);
1167 case KVM_GET_SREGS
: {
1168 struct kvm_sregs kvm_sregs
;
1170 memset(&kvm_sregs
, 0, sizeof kvm_sregs
);
1171 r
= kvm_arch_vcpu_ioctl_get_sregs(vcpu
, &kvm_sregs
);
1175 if (copy_to_user(argp
, &kvm_sregs
, sizeof kvm_sregs
))
1180 case KVM_SET_SREGS
: {
1181 struct kvm_sregs kvm_sregs
;
1184 if (copy_from_user(&kvm_sregs
, argp
, sizeof kvm_sregs
))
1186 r
= kvm_arch_vcpu_ioctl_set_sregs(vcpu
, &kvm_sregs
);
1192 case KVM_GET_MP_STATE
: {
1193 struct kvm_mp_state mp_state
;
1195 r
= kvm_arch_vcpu_ioctl_get_mpstate(vcpu
, &mp_state
);
1199 if (copy_to_user(argp
, &mp_state
, sizeof mp_state
))
1204 case KVM_SET_MP_STATE
: {
1205 struct kvm_mp_state mp_state
;
1208 if (copy_from_user(&mp_state
, argp
, sizeof mp_state
))
1210 r
= kvm_arch_vcpu_ioctl_set_mpstate(vcpu
, &mp_state
);
1216 case KVM_TRANSLATE
: {
1217 struct kvm_translation tr
;
1220 if (copy_from_user(&tr
, argp
, sizeof tr
))
1222 r
= kvm_arch_vcpu_ioctl_translate(vcpu
, &tr
);
1226 if (copy_to_user(argp
, &tr
, sizeof tr
))
1231 case KVM_DEBUG_GUEST
: {
1232 struct kvm_debug_guest dbg
;
1235 if (copy_from_user(&dbg
, argp
, sizeof dbg
))
1237 r
= kvm_arch_vcpu_ioctl_debug_guest(vcpu
, &dbg
);
1243 case KVM_SET_SIGNAL_MASK
: {
1244 struct kvm_signal_mask __user
*sigmask_arg
= argp
;
1245 struct kvm_signal_mask kvm_sigmask
;
1246 sigset_t sigset
, *p
;
1251 if (copy_from_user(&kvm_sigmask
, argp
,
1252 sizeof kvm_sigmask
))
1255 if (kvm_sigmask
.len
!= sizeof sigset
)
1258 if (copy_from_user(&sigset
, sigmask_arg
->sigset
,
1263 r
= kvm_vcpu_ioctl_set_sigmask(vcpu
, &sigset
);
1269 memset(&fpu
, 0, sizeof fpu
);
1270 r
= kvm_arch_vcpu_ioctl_get_fpu(vcpu
, &fpu
);
1274 if (copy_to_user(argp
, &fpu
, sizeof fpu
))
1283 if (copy_from_user(&fpu
, argp
, sizeof fpu
))
1285 r
= kvm_arch_vcpu_ioctl_set_fpu(vcpu
, &fpu
);
1292 r
= kvm_arch_vcpu_ioctl(filp
, ioctl
, arg
);
1298 static long kvm_vm_ioctl(struct file
*filp
,
1299 unsigned int ioctl
, unsigned long arg
)
1301 struct kvm
*kvm
= filp
->private_data
;
1302 void __user
*argp
= (void __user
*)arg
;
1305 if (kvm
->mm
!= current
->mm
)
1308 case KVM_CREATE_VCPU
:
1309 r
= kvm_vm_ioctl_create_vcpu(kvm
, arg
);
1313 case KVM_SET_USER_MEMORY_REGION
: {
1314 struct kvm_userspace_memory_region kvm_userspace_mem
;
1317 if (copy_from_user(&kvm_userspace_mem
, argp
,
1318 sizeof kvm_userspace_mem
))
1321 r
= kvm_vm_ioctl_set_memory_region(kvm
, &kvm_userspace_mem
, 1);
1326 case KVM_GET_DIRTY_LOG
: {
1327 struct kvm_dirty_log log
;
1330 if (copy_from_user(&log
, argp
, sizeof log
))
1332 r
= kvm_vm_ioctl_get_dirty_log(kvm
, &log
);
1337 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
1338 case KVM_REGISTER_COALESCED_MMIO
: {
1339 struct kvm_coalesced_mmio_zone zone
;
1341 if (copy_from_user(&zone
, argp
, sizeof zone
))
1344 r
= kvm_vm_ioctl_register_coalesced_mmio(kvm
, &zone
);
1350 case KVM_UNREGISTER_COALESCED_MMIO
: {
1351 struct kvm_coalesced_mmio_zone zone
;
1353 if (copy_from_user(&zone
, argp
, sizeof zone
))
1356 r
= kvm_vm_ioctl_unregister_coalesced_mmio(kvm
, &zone
);
1364 r
= kvm_arch_vm_ioctl(filp
, ioctl
, arg
);
1370 static int kvm_vm_fault(struct vm_area_struct
*vma
, struct vm_fault
*vmf
)
1372 struct kvm
*kvm
= vma
->vm_file
->private_data
;
1375 if (!kvm_is_visible_gfn(kvm
, vmf
->pgoff
))
1376 return VM_FAULT_SIGBUS
;
1377 page
= gfn_to_page(kvm
, vmf
->pgoff
);
1378 if (is_error_page(page
)) {
1379 kvm_release_page_clean(page
);
1380 return VM_FAULT_SIGBUS
;
1386 static struct vm_operations_struct kvm_vm_vm_ops
= {
1387 .fault
= kvm_vm_fault
,
1390 static int kvm_vm_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1392 vma
->vm_ops
= &kvm_vm_vm_ops
;
1396 static const struct file_operations kvm_vm_fops
= {
1397 .release
= kvm_vm_release
,
1398 .unlocked_ioctl
= kvm_vm_ioctl
,
1399 .compat_ioctl
= kvm_vm_ioctl
,
1400 .mmap
= kvm_vm_mmap
,
1403 static int kvm_dev_ioctl_create_vm(void)
1408 kvm
= kvm_create_vm();
1410 return PTR_ERR(kvm
);
1411 fd
= anon_inode_getfd("kvm-vm", &kvm_vm_fops
, kvm
, 0);
1418 static long kvm_dev_ioctl(struct file
*filp
,
1419 unsigned int ioctl
, unsigned long arg
)
1424 case KVM_GET_API_VERSION
:
1428 r
= KVM_API_VERSION
;
1434 r
= kvm_dev_ioctl_create_vm();
1436 case KVM_CHECK_EXTENSION
:
1437 r
= kvm_dev_ioctl_check_extension(arg
);
1439 case KVM_GET_VCPU_MMAP_SIZE
:
1443 r
= PAGE_SIZE
; /* struct kvm_run */
1445 r
+= PAGE_SIZE
; /* pio data page */
1447 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
1448 r
+= PAGE_SIZE
; /* coalesced mmio ring page */
1451 case KVM_TRACE_ENABLE
:
1452 case KVM_TRACE_PAUSE
:
1453 case KVM_TRACE_DISABLE
:
1454 r
= kvm_trace_ioctl(ioctl
, arg
);
1457 return kvm_arch_dev_ioctl(filp
, ioctl
, arg
);
1463 static struct file_operations kvm_chardev_ops
= {
1464 .unlocked_ioctl
= kvm_dev_ioctl
,
1465 .compat_ioctl
= kvm_dev_ioctl
,
1468 static struct miscdevice kvm_dev
= {
1474 static void hardware_enable(void *junk
)
1476 int cpu
= raw_smp_processor_id();
1478 if (cpu_isset(cpu
, cpus_hardware_enabled
))
1480 cpu_set(cpu
, cpus_hardware_enabled
);
1481 kvm_arch_hardware_enable(NULL
);
1484 static void hardware_disable(void *junk
)
1486 int cpu
= raw_smp_processor_id();
1488 if (!cpu_isset(cpu
, cpus_hardware_enabled
))
1490 cpu_clear(cpu
, cpus_hardware_enabled
);
1491 kvm_arch_hardware_disable(NULL
);
1494 static int kvm_cpu_hotplug(struct notifier_block
*notifier
, unsigned long val
,
1499 val
&= ~CPU_TASKS_FROZEN
;
1502 printk(KERN_INFO
"kvm: disabling virtualization on CPU%d\n",
1504 hardware_disable(NULL
);
1506 case CPU_UP_CANCELED
:
1507 printk(KERN_INFO
"kvm: disabling virtualization on CPU%d\n",
1509 smp_call_function_single(cpu
, hardware_disable
, NULL
, 1);
1512 printk(KERN_INFO
"kvm: enabling virtualization on CPU%d\n",
1514 smp_call_function_single(cpu
, hardware_enable
, NULL
, 1);
1521 asmlinkage
void kvm_handle_fault_on_reboot(void)
1524 /* spin while reset goes on */
1527 /* Fault while not rebooting. We want the trace. */
1530 EXPORT_SYMBOL_GPL(kvm_handle_fault_on_reboot
);
1532 static int kvm_reboot(struct notifier_block
*notifier
, unsigned long val
,
1535 if (val
== SYS_RESTART
) {
1537 * Some (well, at least mine) BIOSes hang on reboot if
1540 printk(KERN_INFO
"kvm: exiting hardware virtualization\n");
1541 kvm_rebooting
= true;
1542 on_each_cpu(hardware_disable
, NULL
, 1);
1547 static struct notifier_block kvm_reboot_notifier
= {
1548 .notifier_call
= kvm_reboot
,
1552 void kvm_io_bus_init(struct kvm_io_bus
*bus
)
1554 memset(bus
, 0, sizeof(*bus
));
1557 void kvm_io_bus_destroy(struct kvm_io_bus
*bus
)
1561 for (i
= 0; i
< bus
->dev_count
; i
++) {
1562 struct kvm_io_device
*pos
= bus
->devs
[i
];
1564 kvm_iodevice_destructor(pos
);
1568 struct kvm_io_device
*kvm_io_bus_find_dev(struct kvm_io_bus
*bus
,
1569 gpa_t addr
, int len
, int is_write
)
1573 for (i
= 0; i
< bus
->dev_count
; i
++) {
1574 struct kvm_io_device
*pos
= bus
->devs
[i
];
1576 if (pos
->in_range(pos
, addr
, len
, is_write
))
1583 void kvm_io_bus_register_dev(struct kvm_io_bus
*bus
, struct kvm_io_device
*dev
)
1585 BUG_ON(bus
->dev_count
> (NR_IOBUS_DEVS
-1));
1587 bus
->devs
[bus
->dev_count
++] = dev
;
1590 static struct notifier_block kvm_cpu_notifier
= {
1591 .notifier_call
= kvm_cpu_hotplug
,
1592 .priority
= 20, /* must be > scheduler priority */
1595 static int vm_stat_get(void *_offset
, u64
*val
)
1597 unsigned offset
= (long)_offset
;
1601 spin_lock(&kvm_lock
);
1602 list_for_each_entry(kvm
, &vm_list
, vm_list
)
1603 *val
+= *(u32
*)((void *)kvm
+ offset
);
1604 spin_unlock(&kvm_lock
);
1608 DEFINE_SIMPLE_ATTRIBUTE(vm_stat_fops
, vm_stat_get
, NULL
, "%llu\n");
1610 static int vcpu_stat_get(void *_offset
, u64
*val
)
1612 unsigned offset
= (long)_offset
;
1614 struct kvm_vcpu
*vcpu
;
1618 spin_lock(&kvm_lock
);
1619 list_for_each_entry(kvm
, &vm_list
, vm_list
)
1620 for (i
= 0; i
< KVM_MAX_VCPUS
; ++i
) {
1621 vcpu
= kvm
->vcpus
[i
];
1623 *val
+= *(u32
*)((void *)vcpu
+ offset
);
1625 spin_unlock(&kvm_lock
);
1629 DEFINE_SIMPLE_ATTRIBUTE(vcpu_stat_fops
, vcpu_stat_get
, NULL
, "%llu\n");
1631 static struct file_operations
*stat_fops
[] = {
1632 [KVM_STAT_VCPU
] = &vcpu_stat_fops
,
1633 [KVM_STAT_VM
] = &vm_stat_fops
,
1636 static void kvm_init_debug(void)
1638 struct kvm_stats_debugfs_item
*p
;
1640 kvm_debugfs_dir
= debugfs_create_dir("kvm", NULL
);
1641 for (p
= debugfs_entries
; p
->name
; ++p
)
1642 p
->dentry
= debugfs_create_file(p
->name
, 0444, kvm_debugfs_dir
,
1643 (void *)(long)p
->offset
,
1644 stat_fops
[p
->kind
]);
1647 static void kvm_exit_debug(void)
1649 struct kvm_stats_debugfs_item
*p
;
1651 for (p
= debugfs_entries
; p
->name
; ++p
)
1652 debugfs_remove(p
->dentry
);
1653 debugfs_remove(kvm_debugfs_dir
);
1656 static int kvm_suspend(struct sys_device
*dev
, pm_message_t state
)
1658 hardware_disable(NULL
);
1662 static int kvm_resume(struct sys_device
*dev
)
1664 hardware_enable(NULL
);
1668 static struct sysdev_class kvm_sysdev_class
= {
1670 .suspend
= kvm_suspend
,
1671 .resume
= kvm_resume
,
1674 static struct sys_device kvm_sysdev
= {
1676 .cls
= &kvm_sysdev_class
,
1679 struct page
*bad_page
;
1683 struct kvm_vcpu
*preempt_notifier_to_vcpu(struct preempt_notifier
*pn
)
1685 return container_of(pn
, struct kvm_vcpu
, preempt_notifier
);
1688 static void kvm_sched_in(struct preempt_notifier
*pn
, int cpu
)
1690 struct kvm_vcpu
*vcpu
= preempt_notifier_to_vcpu(pn
);
1692 kvm_arch_vcpu_load(vcpu
, cpu
);
1695 static void kvm_sched_out(struct preempt_notifier
*pn
,
1696 struct task_struct
*next
)
1698 struct kvm_vcpu
*vcpu
= preempt_notifier_to_vcpu(pn
);
1700 kvm_arch_vcpu_put(vcpu
);
1703 int kvm_init(void *opaque
, unsigned int vcpu_size
,
1704 struct module
*module
)
1711 r
= kvm_arch_init(opaque
);
1715 bad_page
= alloc_page(GFP_KERNEL
| __GFP_ZERO
);
1717 if (bad_page
== NULL
) {
1722 bad_pfn
= page_to_pfn(bad_page
);
1724 r
= kvm_arch_hardware_setup();
1728 for_each_online_cpu(cpu
) {
1729 smp_call_function_single(cpu
,
1730 kvm_arch_check_processor_compat
,
1736 on_each_cpu(hardware_enable
, NULL
, 1);
1737 r
= register_cpu_notifier(&kvm_cpu_notifier
);
1740 register_reboot_notifier(&kvm_reboot_notifier
);
1742 r
= sysdev_class_register(&kvm_sysdev_class
);
1746 r
= sysdev_register(&kvm_sysdev
);
1750 /* A kmem cache lets us meet the alignment requirements of fx_save. */
1751 kvm_vcpu_cache
= kmem_cache_create("kvm_vcpu", vcpu_size
,
1752 __alignof__(struct kvm_vcpu
),
1754 if (!kvm_vcpu_cache
) {
1759 kvm_chardev_ops
.owner
= module
;
1761 r
= misc_register(&kvm_dev
);
1763 printk(KERN_ERR
"kvm: misc device register failed\n");
1767 kvm_preempt_ops
.sched_in
= kvm_sched_in
;
1768 kvm_preempt_ops
.sched_out
= kvm_sched_out
;
1773 kmem_cache_destroy(kvm_vcpu_cache
);
1775 sysdev_unregister(&kvm_sysdev
);
1777 sysdev_class_unregister(&kvm_sysdev_class
);
1779 unregister_reboot_notifier(&kvm_reboot_notifier
);
1780 unregister_cpu_notifier(&kvm_cpu_notifier
);
1782 on_each_cpu(hardware_disable
, NULL
, 1);
1784 kvm_arch_hardware_unsetup();
1786 __free_page(bad_page
);
1793 EXPORT_SYMBOL_GPL(kvm_init
);
1797 kvm_trace_cleanup();
1798 misc_deregister(&kvm_dev
);
1799 kmem_cache_destroy(kvm_vcpu_cache
);
1800 sysdev_unregister(&kvm_sysdev
);
1801 sysdev_class_unregister(&kvm_sysdev_class
);
1802 unregister_reboot_notifier(&kvm_reboot_notifier
);
1803 unregister_cpu_notifier(&kvm_cpu_notifier
);
1804 on_each_cpu(hardware_disable
, NULL
, 1);
1805 kvm_arch_hardware_unsetup();
1808 __free_page(bad_page
);
1810 EXPORT_SYMBOL_GPL(kvm_exit
);