aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/kvm/kvm.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/kvm/kvm.h')
-rw-r--r--drivers/kvm/kvm.h100
1 files changed, 68 insertions, 32 deletions
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 0d122bf889db..41634fde8e13 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -51,16 +51,19 @@
51#define UNMAPPED_GVA (~(gpa_t)0) 51#define UNMAPPED_GVA (~(gpa_t)0)
52 52
53#define KVM_MAX_VCPUS 1 53#define KVM_MAX_VCPUS 1
54#define KVM_ALIAS_SLOTS 4
54#define KVM_MEMORY_SLOTS 4 55#define KVM_MEMORY_SLOTS 4
55#define KVM_NUM_MMU_PAGES 256 56#define KVM_NUM_MMU_PAGES 256
56#define KVM_MIN_FREE_MMU_PAGES 5 57#define KVM_MIN_FREE_MMU_PAGES 5
57#define KVM_REFILL_PAGES 25 58#define KVM_REFILL_PAGES 25
59#define KVM_MAX_CPUID_ENTRIES 40
58 60
59#define FX_IMAGE_SIZE 512 61#define FX_IMAGE_SIZE 512
60#define FX_IMAGE_ALIGN 16 62#define FX_IMAGE_ALIGN 16
61#define FX_BUF_SIZE (2 * FX_IMAGE_SIZE + FX_IMAGE_ALIGN) 63#define FX_BUF_SIZE (2 * FX_IMAGE_SIZE + FX_IMAGE_ALIGN)
62 64
63#define DE_VECTOR 0 65#define DE_VECTOR 0
66#define NM_VECTOR 7
64#define DF_VECTOR 8 67#define DF_VECTOR 8
65#define TS_VECTOR 10 68#define TS_VECTOR 10
66#define NP_VECTOR 11 69#define NP_VECTOR 11
@@ -73,6 +76,8 @@
73 76
74#define IOPL_SHIFT 12 77#define IOPL_SHIFT 12
75 78
79#define KVM_PIO_PAGE_OFFSET 1
80
76/* 81/*
77 * Address types: 82 * Address types:
78 * 83 *
@@ -106,6 +111,7 @@ struct kvm_pte_chain {
106 * bits 4:7 - page table level for this shadow (1-4) 111 * bits 4:7 - page table level for this shadow (1-4)
107 * bits 8:9 - page table quadrant for 2-level guests 112 * bits 8:9 - page table quadrant for 2-level guests
108 * bit 16 - "metaphysical" - gfn is not a real page (huge page/real mode) 113 * bit 16 - "metaphysical" - gfn is not a real page (huge page/real mode)
114 * bits 17:18 - "access" - the user and writable bits of a huge page pde
109 */ 115 */
110union kvm_mmu_page_role { 116union kvm_mmu_page_role {
111 unsigned word; 117 unsigned word;
@@ -115,6 +121,7 @@ union kvm_mmu_page_role {
115 unsigned quadrant : 2; 121 unsigned quadrant : 2;
116 unsigned pad_for_nice_hex_output : 6; 122 unsigned pad_for_nice_hex_output : 6;
117 unsigned metaphysical : 1; 123 unsigned metaphysical : 1;
124 unsigned hugepage_access : 2;
118 }; 125 };
119}; 126};
120 127
@@ -133,7 +140,6 @@ struct kvm_mmu_page {
133 unsigned long slot_bitmap; /* One bit set per slot which has memory 140 unsigned long slot_bitmap; /* One bit set per slot which has memory
134 * in this shadow page. 141 * in this shadow page.
135 */ 142 */
136 int global; /* Set if all ptes in this page are global */
137 int multimapped; /* More than one parent_pte? */ 143 int multimapped; /* More than one parent_pte? */
138 int root_count; /* Currently serving as active root */ 144 int root_count; /* Currently serving as active root */
139 union { 145 union {
@@ -219,6 +225,34 @@ enum {
219 VCPU_SREG_LDTR, 225 VCPU_SREG_LDTR,
220}; 226};
221 227
228struct kvm_pio_request {
229 unsigned long count;
230 int cur_count;
231 struct page *guest_pages[2];
232 unsigned guest_page_offset;
233 int in;
234 int size;
235 int string;
236 int down;
237 int rep;
238};
239
240struct kvm_stat {
241 u32 pf_fixed;
242 u32 pf_guest;
243 u32 tlb_flush;
244 u32 invlpg;
245
246 u32 exits;
247 u32 io_exits;
248 u32 mmio_exits;
249 u32 signal_exits;
250 u32 irq_window_exits;
251 u32 halt_exits;
252 u32 request_irq_exits;
253 u32 irq_exits;
254};
255
222struct kvm_vcpu { 256struct kvm_vcpu {
223 struct kvm *kvm; 257 struct kvm *kvm;
224 union { 258 union {
@@ -228,6 +262,8 @@ struct kvm_vcpu {
228 struct mutex mutex; 262 struct mutex mutex;
229 int cpu; 263 int cpu;
230 int launched; 264 int launched;
265 u64 host_tsc;
266 struct kvm_run *run;
231 int interrupt_window_open; 267 int interrupt_window_open;
232 unsigned long irq_summary; /* bit vector: 1 per word in irq_pending */ 268 unsigned long irq_summary; /* bit vector: 1 per word in irq_pending */
233#define NR_IRQ_WORDS KVM_IRQ_BITMAP_SIZE(unsigned long) 269#define NR_IRQ_WORDS KVM_IRQ_BITMAP_SIZE(unsigned long)
@@ -266,6 +302,7 @@ struct kvm_vcpu {
266 char fx_buf[FX_BUF_SIZE]; 302 char fx_buf[FX_BUF_SIZE];
267 char *host_fx_image; 303 char *host_fx_image;
268 char *guest_fx_image; 304 char *guest_fx_image;
305 int fpu_active;
269 306
270 int mmio_needed; 307 int mmio_needed;
271 int mmio_read_completed; 308 int mmio_read_completed;
@@ -273,6 +310,14 @@ struct kvm_vcpu {
273 int mmio_size; 310 int mmio_size;
274 unsigned char mmio_data[8]; 311 unsigned char mmio_data[8];
275 gpa_t mmio_phys_addr; 312 gpa_t mmio_phys_addr;
313 gva_t mmio_fault_cr2;
314 struct kvm_pio_request pio;
315 void *pio_data;
316
317 int sigset_active;
318 sigset_t sigset;
319
320 struct kvm_stat stat;
276 321
277 struct { 322 struct {
278 int active; 323 int active;
@@ -284,6 +329,15 @@ struct kvm_vcpu {
284 u32 ar; 329 u32 ar;
285 } tr, es, ds, fs, gs; 330 } tr, es, ds, fs, gs;
286 } rmode; 331 } rmode;
332
333 int cpuid_nent;
334 struct kvm_cpuid_entry cpuid_entries[KVM_MAX_CPUID_ENTRIES];
335};
336
337struct kvm_mem_alias {
338 gfn_t base_gfn;
339 unsigned long npages;
340 gfn_t target_gfn;
287}; 341};
288 342
289struct kvm_memory_slot { 343struct kvm_memory_slot {
@@ -296,6 +350,8 @@ struct kvm_memory_slot {
296 350
297struct kvm { 351struct kvm {
298 spinlock_t lock; /* protects everything except vcpus */ 352 spinlock_t lock; /* protects everything except vcpus */
353 int naliases;
354 struct kvm_mem_alias aliases[KVM_ALIAS_SLOTS];
299 int nmemslots; 355 int nmemslots;
300 struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS]; 356 struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS];
301 /* 357 /*
@@ -312,22 +368,6 @@ struct kvm {
312 struct file *filp; 368 struct file *filp;
313}; 369};
314 370
315struct kvm_stat {
316 u32 pf_fixed;
317 u32 pf_guest;
318 u32 tlb_flush;
319 u32 invlpg;
320
321 u32 exits;
322 u32 io_exits;
323 u32 mmio_exits;
324 u32 signal_exits;
325 u32 irq_window_exits;
326 u32 halt_exits;
327 u32 request_irq_exits;
328 u32 irq_exits;
329};
330
331struct descriptor_table { 371struct descriptor_table {
332 u16 limit; 372 u16 limit;
333 unsigned long base; 373 unsigned long base;
@@ -358,10 +398,8 @@ struct kvm_arch_ops {
358 void (*set_segment)(struct kvm_vcpu *vcpu, 398 void (*set_segment)(struct kvm_vcpu *vcpu,
359 struct kvm_segment *var, int seg); 399 struct kvm_segment *var, int seg);
360 void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l); 400 void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l);
361 void (*decache_cr0_cr4_guest_bits)(struct kvm_vcpu *vcpu); 401 void (*decache_cr4_guest_bits)(struct kvm_vcpu *vcpu);
362 void (*set_cr0)(struct kvm_vcpu *vcpu, unsigned long cr0); 402 void (*set_cr0)(struct kvm_vcpu *vcpu, unsigned long cr0);
363 void (*set_cr0_no_modeswitch)(struct kvm_vcpu *vcpu,
364 unsigned long cr0);
365 void (*set_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3); 403 void (*set_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3);
366 void (*set_cr4)(struct kvm_vcpu *vcpu, unsigned long cr4); 404 void (*set_cr4)(struct kvm_vcpu *vcpu, unsigned long cr4);
367 void (*set_efer)(struct kvm_vcpu *vcpu, u64 efer); 405 void (*set_efer)(struct kvm_vcpu *vcpu, u64 efer);
@@ -391,7 +429,6 @@ struct kvm_arch_ops {
391 unsigned char *hypercall_addr); 429 unsigned char *hypercall_addr);
392}; 430};
393 431
394extern struct kvm_stat kvm_stat;
395extern struct kvm_arch_ops *kvm_arch_ops; 432extern struct kvm_arch_ops *kvm_arch_ops;
396 433
397#define kvm_printf(kvm, fmt ...) printk(KERN_DEBUG fmt) 434#define kvm_printf(kvm, fmt ...) printk(KERN_DEBUG fmt)
@@ -400,28 +437,29 @@ extern struct kvm_arch_ops *kvm_arch_ops;
400int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module); 437int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module);
401void kvm_exit_arch(void); 438void kvm_exit_arch(void);
402 439
440int kvm_mmu_module_init(void);
441void kvm_mmu_module_exit(void);
442
403void kvm_mmu_destroy(struct kvm_vcpu *vcpu); 443void kvm_mmu_destroy(struct kvm_vcpu *vcpu);
404int kvm_mmu_create(struct kvm_vcpu *vcpu); 444int kvm_mmu_create(struct kvm_vcpu *vcpu);
405int kvm_mmu_setup(struct kvm_vcpu *vcpu); 445int kvm_mmu_setup(struct kvm_vcpu *vcpu);
406 446
407int kvm_mmu_reset_context(struct kvm_vcpu *vcpu); 447int kvm_mmu_reset_context(struct kvm_vcpu *vcpu);
408void kvm_mmu_slot_remove_write_access(struct kvm_vcpu *vcpu, int slot); 448void kvm_mmu_slot_remove_write_access(struct kvm_vcpu *vcpu, int slot);
449void kvm_mmu_zap_all(struct kvm_vcpu *vcpu);
409 450
410hpa_t gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa); 451hpa_t gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa);
411#define HPA_MSB ((sizeof(hpa_t) * 8) - 1) 452#define HPA_MSB ((sizeof(hpa_t) * 8) - 1)
412#define HPA_ERR_MASK ((hpa_t)1 << HPA_MSB) 453#define HPA_ERR_MASK ((hpa_t)1 << HPA_MSB)
413static inline int is_error_hpa(hpa_t hpa) { return hpa >> HPA_MSB; } 454static inline int is_error_hpa(hpa_t hpa) { return hpa >> HPA_MSB; }
414hpa_t gva_to_hpa(struct kvm_vcpu *vcpu, gva_t gva); 455hpa_t gva_to_hpa(struct kvm_vcpu *vcpu, gva_t gva);
456struct page *gva_to_page(struct kvm_vcpu *vcpu, gva_t gva);
415 457
416void kvm_emulator_want_group7_invlpg(void); 458void kvm_emulator_want_group7_invlpg(void);
417 459
418extern hpa_t bad_page_address; 460extern hpa_t bad_page_address;
419 461
420static inline struct page *gfn_to_page(struct kvm_memory_slot *slot, gfn_t gfn) 462struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn);
421{
422 return slot->phys_mem[gfn - slot->base_gfn];
423}
424
425struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn); 463struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);
426void mark_page_dirty(struct kvm *kvm, gfn_t gfn); 464void mark_page_dirty(struct kvm *kvm, gfn_t gfn);
427 465
@@ -444,6 +482,10 @@ void realmode_set_cr(struct kvm_vcpu *vcpu, int cr, unsigned long value,
444 482
445struct x86_emulate_ctxt; 483struct x86_emulate_ctxt;
446 484
485int kvm_setup_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
486 int size, unsigned long count, int string, int down,
487 gva_t address, int rep, unsigned port);
488void kvm_emulate_cpuid(struct kvm_vcpu *vcpu);
447int emulate_invlpg(struct kvm_vcpu *vcpu, gva_t address); 489int emulate_invlpg(struct kvm_vcpu *vcpu, gva_t address);
448int emulate_clts(struct kvm_vcpu *vcpu); 490int emulate_clts(struct kvm_vcpu *vcpu);
449int emulator_get_dr(struct x86_emulate_ctxt* ctxt, int dr, 491int emulator_get_dr(struct x86_emulate_ctxt* ctxt, int dr,
@@ -493,12 +535,6 @@ static inline int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva,
493 return vcpu->mmu.page_fault(vcpu, gva, error_code); 535 return vcpu->mmu.page_fault(vcpu, gva, error_code);
494} 536}
495 537
496static inline struct page *_gfn_to_page(struct kvm *kvm, gfn_t gfn)
497{
498 struct kvm_memory_slot *slot = gfn_to_memslot(kvm, gfn);
499 return (slot) ? slot->phys_mem[gfn - slot->base_gfn] : NULL;
500}
501
502static inline int is_long_mode(struct kvm_vcpu *vcpu) 538static inline int is_long_mode(struct kvm_vcpu *vcpu)
503{ 539{
504#ifdef CONFIG_X86_64 540#ifdef CONFIG_X86_64