blob: 0d3555bf533360f0711d491b4f13aff9c0db7138 [file] [log] [blame]
Avi Kivity6aa8b732006-12-10 02:21:36 -08001#ifndef __KVM_H
2#define __KVM_H
3
4/*
5 * This work is licensed under the terms of the GNU GPL, version 2. See
6 * the COPYING file in the top-level directory.
7 */
8
9#include <linux/types.h>
Christian Borntraegere56a7a22007-10-18 14:39:10 +020010#include <linux/hardirq.h>
Avi Kivity6aa8b732006-12-10 02:21:36 -080011#include <linux/list.h>
12#include <linux/mutex.h>
13#include <linux/spinlock.h>
Markus Rechberger06ff0d32007-05-27 10:46:52 +030014#include <linux/signal.h>
15#include <linux/sched.h>
Avi Kivity6aa8b732006-12-10 02:21:36 -080016#include <linux/mm.h>
Avi Kivity15ad7142007-07-11 18:17:21 +030017#include <linux/preempt.h>
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +040018#include <asm/signal.h>
Avi Kivity6aa8b732006-12-10 02:21:36 -080019
Avi Kivity6aa8b732006-12-10 02:21:36 -080020#include <linux/kvm.h>
Ingo Molnar102d8322007-02-19 14:37:47 +020021#include <linux/kvm_para.h>
Avi Kivity6aa8b732006-12-10 02:21:36 -080022
Hollis Blanchardd77a39d92007-12-03 15:30:23 -060023#include "types.h"
24
Avi Kivityef9254d2007-06-05 14:37:09 +030025#define KVM_MAX_VCPUS 4
Avi Kivitye8207542007-03-30 16:54:30 +030026#define KVM_ALIAS_SLOTS 4
Izik Eidus2e2c6182007-08-20 18:11:00 +030027#define KVM_MEMORY_SLOTS 8
Izik Eiduse0d62c72007-10-24 23:57:46 +020028/* memory slots that does not exposed to userspace */
29#define KVM_PRIVATE_MEM_SLOTS 4
Izik Eidus82ce2c92007-10-02 18:52:55 +020030#define KVM_PERMILLE_MMU_PAGES 20
31#define KVM_MIN_ALLOC_MMU_PAGES 64
Avi Kivity7494c0c2007-05-01 18:24:38 +030032#define KVM_NUM_MMU_PAGES 1024
Avi Kivityebeace82007-01-05 16:36:47 -080033#define KVM_MIN_FREE_MMU_PAGES 5
34#define KVM_REFILL_PAGES 25
Avi Kivity06465c52007-02-28 20:46:53 +020035#define KVM_MAX_CPUID_ENTRIES 40
Avi Kivity6aa8b732006-12-10 02:21:36 -080036
Avi Kivity039576c2007-03-20 12:46:50 +020037#define KVM_PIO_PAGE_OFFSET 1
38
Avi Kivity6aa8b732006-12-10 02:21:36 -080039/*
Avi Kivityd9e368d2007-06-07 19:18:30 +030040 * vcpu->requests bit members
41 */
Avi Kivity3176bc32007-10-16 17:22:08 +020042#define KVM_REQ_TLB_FLUSH 0
Avi Kivityd9e368d2007-06-07 19:18:30 +030043
Avi Kivitycea0f0e2007-01-05 16:36:43 -080044#define NR_PTE_CHAIN_ENTRIES 5
45
46struct kvm_pte_chain {
47 u64 *parent_ptes[NR_PTE_CHAIN_ENTRIES];
48 struct hlist_node link;
49};
50
51/*
52 * kvm_mmu_page_role, below, is defined as:
53 *
54 * bits 0:3 - total guest paging levels (2-4, or zero for real mode)
55 * bits 4:7 - page table level for this shadow (1-4)
56 * bits 8:9 - page table quadrant for 2-level guests
57 * bit 16 - "metaphysical" - gfn is not a real page (huge page/real mode)
Avi Kivityd55e2cb2007-07-10 17:50:55 +030058 * bits 17:19 - "access" - the user, writable, and nx bits of a huge page pde
Avi Kivitycea0f0e2007-01-05 16:36:43 -080059 */
60union kvm_mmu_page_role {
61 unsigned word;
62 struct {
63 unsigned glevels : 4;
64 unsigned level : 4;
65 unsigned quadrant : 2;
66 unsigned pad_for_nice_hex_output : 6;
67 unsigned metaphysical : 1;
Avi Kivityd55e2cb2007-07-10 17:50:55 +030068 unsigned hugepage_access : 3;
Avi Kivitycea0f0e2007-01-05 16:36:43 -080069 };
70};
71
Avi Kivity6aa8b732006-12-10 02:21:36 -080072struct kvm_mmu_page {
73 struct list_head link;
Avi Kivitycea0f0e2007-01-05 16:36:43 -080074 struct hlist_node hash_link;
75
76 /*
77 * The following two entries are used to key the shadow page in the
78 * hash table.
79 */
80 gfn_t gfn;
81 union kvm_mmu_page_role role;
82
Avi Kivity47ad8e62007-05-06 15:50:58 +030083 u64 *spt;
Izik Eidus290fc382007-09-27 14:11:22 +020084 /* hold the gfn of each spte inside spt */
85 gfn_t *gfns;
Avi Kivity6aa8b732006-12-10 02:21:36 -080086 unsigned long slot_bitmap; /* One bit set per slot which has memory
87 * in this shadow page.
88 */
Avi Kivitycea0f0e2007-01-05 16:36:43 -080089 int multimapped; /* More than one parent_pte? */
Avi Kivity3bb65a22007-01-05 16:36:51 -080090 int root_count; /* Currently serving as active root */
Avi Kivitycea0f0e2007-01-05 16:36:43 -080091 union {
92 u64 *parent_pte; /* !multimapped */
93 struct hlist_head parent_ptes; /* multimapped, kvm_pte_chain */
94 };
Avi Kivity6aa8b732006-12-10 02:21:36 -080095};
96
Avi Kivity6aa8b732006-12-10 02:21:36 -080097struct kvm_vcpu;
Rusty Russellc16f8622007-07-30 21:12:19 +100098extern struct kmem_cache *kvm_vcpu_cache;
Avi Kivity6aa8b732006-12-10 02:21:36 -080099
100/*
101 * x86 supports 3 paging modes (4-level 64-bit, 3-level 64-bit, and 2-level
102 * 32-bit). The kvm_mmu structure abstracts the details of the current mmu
103 * mode.
104 */
105struct kvm_mmu {
106 void (*new_cr3)(struct kvm_vcpu *vcpu);
107 int (*page_fault)(struct kvm_vcpu *vcpu, gva_t gva, u32 err);
Avi Kivity6aa8b732006-12-10 02:21:36 -0800108 void (*free)(struct kvm_vcpu *vcpu);
109 gpa_t (*gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t gva);
Avi Kivityc7addb92007-09-16 18:58:32 +0200110 void (*prefetch_page)(struct kvm_vcpu *vcpu,
111 struct kvm_mmu_page *page);
Avi Kivity6aa8b732006-12-10 02:21:36 -0800112 hpa_t root_hpa;
113 int root_level;
114 int shadow_root_level;
Avi Kivity17ac10a2007-01-05 16:36:40 -0800115
116 u64 *pae_root;
Avi Kivity6aa8b732006-12-10 02:21:36 -0800117};
118
Izik Eidus290fc382007-09-27 14:11:22 +0200119#define KVM_NR_MEM_OBJS 40
Avi Kivity714b93d2007-01-05 16:36:53 -0800120
Hollis Blanchard7faa8f62007-11-19 14:04:44 -0600121/*
122 * We don't want allocation failures within the mmu code, so we preallocate
123 * enough memory for a single page fault in a cache.
124 */
Avi Kivity714b93d2007-01-05 16:36:53 -0800125struct kvm_mmu_memory_cache {
126 int nobjs;
127 void *objects[KVM_NR_MEM_OBJS];
128};
129
Avi Kivity6aa8b732006-12-10 02:21:36 -0800130struct kvm_guest_debug {
131 int enabled;
132 unsigned long bp[4];
133 int singlestep;
134};
135
Avi Kivity039576c2007-03-20 12:46:50 +0200136struct kvm_pio_request {
137 unsigned long count;
138 int cur_count;
139 struct page *guest_pages[2];
140 unsigned guest_page_offset;
141 int in;
Eddie Dong74906342007-06-19 18:05:03 +0300142 int port;
Avi Kivity039576c2007-03-20 12:46:50 +0200143 int size;
144 int string;
145 int down;
146 int rep;
147};
148
Avi Kivityba1389b2007-11-18 16:24:12 +0200149struct kvm_vcpu_stat {
Avi Kivity1165f5f2007-04-19 17:27:43 +0300150 u32 pf_fixed;
151 u32 pf_guest;
152 u32 tlb_flush;
153 u32 invlpg;
154
155 u32 exits;
156 u32 io_exits;
157 u32 mmio_exits;
158 u32 signal_exits;
159 u32 irq_window_exits;
160 u32 halt_exits;
Eddie Dongb6958ce2007-07-18 12:15:21 +0300161 u32 halt_wakeup;
Avi Kivity1165f5f2007-04-19 17:27:43 +0300162 u32 request_irq_exits;
163 u32 irq_exits;
Avi Kivitye1beb1d2007-11-18 13:50:24 +0200164 u32 host_state_reload;
Eddie Dong2cc51562007-05-21 07:28:09 +0300165 u32 efer_reload;
Avi Kivityf096ed82007-11-18 13:54:33 +0200166 u32 fpu_reload;
Avi Kivityf2b57562007-11-18 15:17:51 +0200167 u32 insn_emulation;
168 u32 insn_emulation_fail;
Avi Kivity1165f5f2007-04-19 17:27:43 +0300169};
170
Gregory Haskins2eeb2e92007-05-31 14:08:53 -0400171/*
172 * It would be nice to use something smarter than a linear search, TBD...
173 * Thankfully we dont expect many devices to register (famous last words :),
174 * so until then it will suffice. At least its abstracted so we can change
175 * in one place.
176 */
177struct kvm_io_bus {
178 int dev_count;
179#define NR_IOBUS_DEVS 6
180 struct kvm_io_device *devs[NR_IOBUS_DEVS];
181};
182
183void kvm_io_bus_init(struct kvm_io_bus *bus);
184void kvm_io_bus_destroy(struct kvm_io_bus *bus);
185struct kvm_io_device *kvm_io_bus_find_dev(struct kvm_io_bus *bus, gpa_t addr);
186void kvm_io_bus_register_dev(struct kvm_io_bus *bus,
187 struct kvm_io_device *dev);
188
Zhang Xiantao34c16ee2007-10-20 15:34:38 +0800189#ifdef CONFIG_HAS_IOMEM
190#define KVM_VCPU_MMIO \
191 int mmio_needed; \
192 int mmio_read_completed; \
193 int mmio_is_write; \
194 int mmio_size; \
195 unsigned char mmio_data[8]; \
Avi Kivity6aa8b732006-12-10 02:21:36 -0800196 gpa_t mmio_phys_addr;
197
Zhang Xiantao34c16ee2007-10-20 15:34:38 +0800198#else
199#define KVM_VCPU_MMIO
Avi Kivity1961d272007-03-05 19:46:05 +0200200
Zhang Xiantao34c16ee2007-10-20 15:34:38 +0800201#endif
Avi Kivity1165f5f2007-04-19 17:27:43 +0300202
Zhang Xiantao34c16ee2007-10-20 15:34:38 +0800203#define KVM_VCPU_COMM \
204 struct kvm *kvm; \
205 struct preempt_notifier preempt_notifier; \
206 int vcpu_id; \
207 struct mutex mutex; \
208 int cpu; \
209 struct kvm_run *run; \
210 int guest_mode; \
211 unsigned long requests; \
212 struct kvm_guest_debug guest_debug; \
213 int fpu_active; \
214 int guest_fpu_loaded; \
215 wait_queue_head_t wq; \
216 int sigset_active; \
217 sigset_t sigset; \
Avi Kivityba1389b2007-11-18 16:24:12 +0200218 struct kvm_vcpu_stat stat; \
Zhang Xiantao34c16ee2007-10-20 15:34:38 +0800219 KVM_VCPU_MMIO
Avi Kivity6aa8b732006-12-10 02:21:36 -0800220
Avi Kivitye8207542007-03-30 16:54:30 +0300221struct kvm_mem_alias {
222 gfn_t base_gfn;
223 unsigned long npages;
224 gfn_t target_gfn;
225};
226
Avi Kivity6aa8b732006-12-10 02:21:36 -0800227struct kvm_memory_slot {
228 gfn_t base_gfn;
229 unsigned long npages;
230 unsigned long flags;
Izik Eidus290fc382007-09-27 14:11:22 +0200231 unsigned long *rmap;
Avi Kivity6aa8b732006-12-10 02:21:36 -0800232 unsigned long *dirty_bitmap;
Izik Eidus8a7ae052007-10-18 11:09:33 +0200233 unsigned long userspace_addr;
Izik Eidus80b14b52007-10-25 11:54:04 +0200234 int user_alloc;
Avi Kivity6aa8b732006-12-10 02:21:36 -0800235};
236
Avi Kivityba1389b2007-11-18 16:24:12 +0200237struct kvm_vm_stat {
Avi Kivity4cee5762007-11-18 16:37:07 +0200238 u32 mmu_shadow_zapped;
239 u32 mmu_pte_write;
240 u32 mmu_pte_updated;
241 u32 mmu_pde_zapped;
242 u32 mmu_flooded;
243 u32 mmu_recycled;
Avi Kivity0f74a242007-11-20 23:01:14 +0200244 u32 remote_tlb_flush;
Avi Kivityba1389b2007-11-18 16:24:12 +0200245};
246
Avi Kivity6aa8b732006-12-10 02:21:36 -0800247struct kvm {
Shaohua Li11ec2802007-07-23 14:51:37 +0800248 struct mutex lock; /* protects everything except vcpus */
Avi Kivity6d4e4c42007-11-21 16:41:05 +0200249 struct mm_struct *mm; /* userspace tied to this vm */
Avi Kivitye8207542007-03-30 16:54:30 +0300250 int naliases;
251 struct kvm_mem_alias aliases[KVM_ALIAS_SLOTS];
Avi Kivity6aa8b732006-12-10 02:21:36 -0800252 int nmemslots;
Izik Eiduse0d62c72007-10-24 23:57:46 +0200253 struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS +
254 KVM_PRIVATE_MEM_SLOTS];
Avi Kivitycea0f0e2007-01-05 16:36:43 -0800255 /*
256 * Hash table of struct kvm_mmu_page.
257 */
Avi Kivity6aa8b732006-12-10 02:21:36 -0800258 struct list_head active_mmu_pages;
Izik Eidus82ce2c92007-10-02 18:52:55 +0200259 unsigned int n_free_mmu_pages;
260 unsigned int n_requested_mmu_pages;
261 unsigned int n_alloc_mmu_pages;
Avi Kivitycea0f0e2007-01-05 16:36:43 -0800262 struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
Rusty Russellfb3f0f52007-07-27 17:16:56 +1000263 struct kvm_vcpu *vcpus[KVM_MAX_VCPUS];
Avi Kivity133de902007-02-12 00:54:44 -0800264 struct list_head vm_list;
Avi Kivitybccf2152007-02-21 18:04:26 +0200265 struct file *filp;
Gregory Haskins2eeb2e92007-05-31 14:08:53 -0400266 struct kvm_io_bus mmio_bus;
Eddie Dong74906342007-06-19 18:05:03 +0300267 struct kvm_io_bus pio_bus;
Eddie Dong85f455f2007-07-06 12:20:49 +0300268 struct kvm_pic *vpic;
Eddie Dong1fd4f2a2007-07-18 12:03:39 +0300269 struct kvm_ioapic *vioapic;
He, Qing932f72a2007-09-03 17:01:36 +0300270 int round_robin_prev_vcpu;
Izik Eiduscbc94022007-10-25 00:29:55 +0200271 unsigned int tss_addr;
Sheng Yangf78e0e22007-10-29 09:40:42 +0800272 struct page *apic_access_page;
Avi Kivityba1389b2007-11-18 16:24:12 +0200273 struct kvm_vm_stat stat;
Avi Kivity6aa8b732006-12-10 02:21:36 -0800274};
275
Eddie Dong85f455f2007-07-06 12:20:49 +0300276static inline struct kvm_pic *pic_irqchip(struct kvm *kvm)
277{
278 return kvm->vpic;
279}
280
Eddie Dong1fd4f2a2007-07-18 12:03:39 +0300281static inline struct kvm_ioapic *ioapic_irqchip(struct kvm *kvm)
282{
283 return kvm->vioapic;
284}
285
Eddie Dong85f455f2007-07-06 12:20:49 +0300286static inline int irqchip_in_kernel(struct kvm *kvm)
287{
Joe Perches56919c52007-11-12 20:06:51 -0800288 return pic_irqchip(kvm) != NULL;
Eddie Dong85f455f2007-07-06 12:20:49 +0300289}
290
Rusty Russellf0242472007-08-01 10:48:02 +1000291/* The guest did something we don't support. */
292#define pr_unimpl(vcpu, fmt, ...) \
293 do { \
294 if (printk_ratelimit()) \
295 printk(KERN_ERR "kvm: %i: cpu%i " fmt, \
296 current->tgid, (vcpu)->vcpu_id , ## __VA_ARGS__); \
Mike Dayd77c26f2007-10-08 09:02:08 -0400297 } while (0)
Rusty Russellf0242472007-08-01 10:48:02 +1000298
Avi Kivity6aa8b732006-12-10 02:21:36 -0800299#define kvm_printf(kvm, fmt ...) printk(KERN_DEBUG fmt)
300#define vcpu_printf(vcpu, fmt...) kvm_printf(vcpu->kvm, fmt)
301
Rusty Russellfb3f0f52007-07-27 17:16:56 +1000302int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id);
303void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
304
Carsten Otte313a3dc2007-10-11 19:16:52 +0200305void vcpu_load(struct kvm_vcpu *vcpu);
306void vcpu_put(struct kvm_vcpu *vcpu);
307
Zhang Xiantaoe9b11c12007-11-14 20:38:21 +0800308void decache_vcpus_on_cpu(int cpu);
309
Carsten Otte313a3dc2007-10-11 19:16:52 +0200310
Zhang Xiantaof8c16bb2007-11-14 20:40:21 +0800311int kvm_init(void *opaque, unsigned int vcpu_size,
Rusty Russellc16f8622007-07-30 21:12:19 +1000312 struct module *module);
Zhang Xiantaocb498ea2007-11-14 20:39:31 +0800313void kvm_exit(void);
Avi Kivity6aa8b732006-12-10 02:21:36 -0800314
Avi Kivity6aa8b732006-12-10 02:21:36 -0800315#define HPA_MSB ((sizeof(hpa_t) * 8) - 1)
316#define HPA_ERR_MASK ((hpa_t)1 << HPA_MSB)
317static inline int is_error_hpa(hpa_t hpa) { return hpa >> HPA_MSB; }
Avi Kivity039576c2007-03-20 12:46:50 +0200318struct page *gva_to_page(struct kvm_vcpu *vcpu, gva_t gva);
Avi Kivity6aa8b732006-12-10 02:21:36 -0800319
Izik Eiduscea7bb22007-10-17 19:17:48 +0200320extern struct page *bad_page;
Avi Kivity6aa8b732006-12-10 02:21:36 -0800321
Izik Eiduscea7bb22007-10-17 19:17:48 +0200322int is_error_page(struct page *page);
Izik Eidusf9d46eb2007-11-11 22:02:22 +0200323int kvm_is_error_hva(unsigned long addr);
Izik Eidus210c7c42007-10-24 23:52:57 +0200324int kvm_set_memory_region(struct kvm *kvm,
325 struct kvm_userspace_memory_region *mem,
326 int user_alloc);
Sheng Yangf78e0e22007-10-29 09:40:42 +0800327int __kvm_set_memory_region(struct kvm *kvm,
328 struct kvm_userspace_memory_region *mem,
329 int user_alloc);
Zhang Xiantao0de10342007-11-20 16:25:04 +0800330int kvm_arch_set_memory_region(struct kvm *kvm,
331 struct kvm_userspace_memory_region *mem,
332 struct kvm_memory_slot old,
333 int user_alloc);
Izik Eidus290fc382007-09-27 14:11:22 +0200334gfn_t unalias_gfn(struct kvm *kvm, gfn_t gfn);
Avi Kivity954bbbc2007-03-30 14:02:32 +0300335struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn);
Izik Eidusb4231d62007-11-20 11:49:33 +0200336void kvm_release_page_clean(struct page *page);
337void kvm_release_page_dirty(struct page *page);
Izik Eidus195aefd2007-10-01 22:14:18 +0200338int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset,
339 int len);
340int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len);
341int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data,
342 int offset, int len);
343int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data,
344 unsigned long len);
345int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len);
346int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len);
Avi Kivity6aa8b732006-12-10 02:21:36 -0800347struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);
Izik Eiduse0d62c72007-10-24 23:57:46 +0200348int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn);
Avi Kivity6aa8b732006-12-10 02:21:36 -0800349void mark_page_dirty(struct kvm *kvm, gfn_t gfn);
350
Hollis Blanchard8776e512007-10-31 17:24:24 -0500351void kvm_vcpu_block(struct kvm_vcpu *vcpu);
Avi Kivity6aa8b732006-12-10 02:21:36 -0800352void kvm_resched(struct kvm_vcpu *vcpu);
Avi Kivity7702fd12007-06-14 16:27:40 +0300353void kvm_load_guest_fpu(struct kvm_vcpu *vcpu);
354void kvm_put_guest_fpu(struct kvm_vcpu *vcpu);
Avi Kivityd9e368d2007-06-07 19:18:30 +0300355void kvm_flush_remote_tlbs(struct kvm *kvm);
Avi Kivity6aa8b732006-12-10 02:21:36 -0800356
Carsten Otte043405e2007-10-10 17:16:19 +0200357long kvm_arch_dev_ioctl(struct file *filp,
358 unsigned int ioctl, unsigned long arg);
Carsten Otte313a3dc2007-10-11 19:16:52 +0200359long kvm_arch_vcpu_ioctl(struct file *filp,
360 unsigned int ioctl, unsigned long arg);
361void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
362void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu);
Zhang Xiantao018d00d2007-11-15 23:07:47 +0800363
364int kvm_dev_ioctl_check_extension(long ext);
365
Zhang Xiantao5bb064d2007-11-18 20:29:43 +0800366int kvm_get_dirty_log(struct kvm *kvm,
367 struct kvm_dirty_log *log, int *is_dirty);
368int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
369 struct kvm_dirty_log *log);
370
Carsten Otte1fe779f2007-10-29 16:08:35 +0100371int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
372 struct
373 kvm_userspace_memory_region *mem,
374 int user_alloc);
375long kvm_arch_vm_ioctl(struct file *filp,
376 unsigned int ioctl, unsigned long arg);
377void kvm_arch_destroy_vm(struct kvm *kvm);
Carsten Otte313a3dc2007-10-11 19:16:52 +0200378
Hollis Blanchardd0752062007-10-31 17:24:25 -0500379int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu);
380int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu);
381
Zhang Xiantao8b006792007-11-16 13:05:55 +0800382int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
383 struct kvm_translation *tr);
384
Hollis Blanchardb6c7a5d2007-11-01 14:16:10 -0500385int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs);
386int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs);
387int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
388 struct kvm_sregs *sregs);
389int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
390 struct kvm_sregs *sregs);
391int kvm_arch_vcpu_ioctl_debug_guest(struct kvm_vcpu *vcpu,
392 struct kvm_debug_guest *dbg);
393int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
394
Zhang Xiantaof8c16bb2007-11-14 20:40:21 +0800395int kvm_arch_init(void *opaque);
396void kvm_arch_exit(void);
Carsten Otte043405e2007-10-10 17:16:19 +0200397
Zhang Xiantaoe9b11c12007-11-14 20:38:21 +0800398int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
399void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu);
400
401void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu);
402void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
403void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu);
404struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id);
Avi Kivity26e52152007-11-20 15:30:24 +0200405int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu);
Hollis Blanchardd40ccc62007-11-19 14:04:43 -0600406void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu);
Zhang Xiantaoe9b11c12007-11-14 20:38:21 +0800407
408int kvm_arch_vcpu_reset(struct kvm_vcpu *vcpu);
409void kvm_arch_hardware_enable(void *garbage);
410void kvm_arch_hardware_disable(void *garbage);
411int kvm_arch_hardware_setup(void);
412void kvm_arch_hardware_unsetup(void);
413void kvm_arch_check_processor_compat(void *rtn);
414
Zhang Xiantaod19a9cd2007-11-18 18:43:45 +0800415void kvm_free_physmem(struct kvm *kvm);
416
417struct kvm *kvm_arch_create_vm(void);
418void kvm_arch_destroy_vm(struct kvm *kvm);
Zhang Xiantaoe9b11c12007-11-14 20:38:21 +0800419
Laurent Vivierd172fcd2007-10-15 17:00:19 +0200420static inline void kvm_guest_enter(void)
421{
Christian Borntraegere56a7a22007-10-18 14:39:10 +0200422 account_system_vtime(current);
Laurent Vivierd172fcd2007-10-15 17:00:19 +0200423 current->flags |= PF_VCPU;
424}
425
426static inline void kvm_guest_exit(void)
427{
Christian Borntraegere56a7a22007-10-18 14:39:10 +0200428 account_system_vtime(current);
Laurent Vivierd172fcd2007-10-15 17:00:19 +0200429 current->flags &= ~PF_VCPU;
430}
431
Avi Kivity6aa8b732006-12-10 02:21:36 -0800432static inline int memslot_id(struct kvm *kvm, struct kvm_memory_slot *slot)
433{
434 return slot - kvm->memslots;
435}
436
Avi Kivity1755fbc2007-11-21 14:44:45 +0200437static inline gpa_t gfn_to_gpa(gfn_t gfn)
438{
439 return (gpa_t)gfn << PAGE_SHIFT;
440}
Avi Kivity6aa8b732006-12-10 02:21:36 -0800441
Avi Kivityba1389b2007-11-18 16:24:12 +0200442enum kvm_stat_kind {
443 KVM_STAT_VM,
444 KVM_STAT_VCPU,
445};
446
Hollis Blanchard417bc302007-10-31 17:24:23 -0500447struct kvm_stats_debugfs_item {
448 const char *name;
449 int offset;
Avi Kivityba1389b2007-11-18 16:24:12 +0200450 enum kvm_stat_kind kind;
Hollis Blanchard417bc302007-10-31 17:24:23 -0500451 struct dentry *dentry;
452};
453extern struct kvm_stats_debugfs_item debugfs_entries[];
454
Hollis Blancharde01a1b52007-12-03 15:30:25 -0600455#if defined(CONFIG_X86)
456#include "x86.h"
457#endif
458
Avi Kivity6aa8b732006-12-10 02:21:36 -0800459#endif