diff options
Diffstat (limited to 'drivers/kvm/kvm.h')
-rw-r--r-- | drivers/kvm/kvm.h | 106 |
1 files changed, 88 insertions, 18 deletions
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h index 100df6f38d92..91e0c75aca8f 100644 --- a/drivers/kvm/kvm.h +++ b/drivers/kvm/kvm.h | |||
@@ -52,6 +52,8 @@ | |||
52 | #define KVM_MAX_VCPUS 1 | 52 | #define KVM_MAX_VCPUS 1 |
53 | #define KVM_MEMORY_SLOTS 4 | 53 | #define KVM_MEMORY_SLOTS 4 |
54 | #define KVM_NUM_MMU_PAGES 256 | 54 | #define KVM_NUM_MMU_PAGES 256 |
55 | #define KVM_MIN_FREE_MMU_PAGES 5 | ||
56 | #define KVM_REFILL_PAGES 25 | ||
55 | 57 | ||
56 | #define FX_IMAGE_SIZE 512 | 58 | #define FX_IMAGE_SIZE 512 |
57 | #define FX_IMAGE_ALIGN 16 | 59 | #define FX_IMAGE_ALIGN 16 |
@@ -89,14 +91,54 @@ typedef unsigned long hva_t; | |||
89 | typedef u64 hpa_t; | 91 | typedef u64 hpa_t; |
90 | typedef unsigned long hfn_t; | 92 | typedef unsigned long hfn_t; |
91 | 93 | ||
94 | #define NR_PTE_CHAIN_ENTRIES 5 | ||
95 | |||
96 | struct kvm_pte_chain { | ||
97 | u64 *parent_ptes[NR_PTE_CHAIN_ENTRIES]; | ||
98 | struct hlist_node link; | ||
99 | }; | ||
100 | |||
101 | /* | ||
102 | * kvm_mmu_page_role, below, is defined as: | ||
103 | * | ||
104 | * bits 0:3 - total guest paging levels (2-4, or zero for real mode) | ||
105 | * bits 4:7 - page table level for this shadow (1-4) | ||
106 | * bits 8:9 - page table quadrant for 2-level guests | ||
107 | * bit 16 - "metaphysical" - gfn is not a real page (huge page/real mode) | ||
108 | */ | ||
109 | union kvm_mmu_page_role { | ||
110 | unsigned word; | ||
111 | struct { | ||
112 | unsigned glevels : 4; | ||
113 | unsigned level : 4; | ||
114 | unsigned quadrant : 2; | ||
115 | unsigned pad_for_nice_hex_output : 6; | ||
116 | unsigned metaphysical : 1; | ||
117 | }; | ||
118 | }; | ||
119 | |||
92 | struct kvm_mmu_page { | 120 | struct kvm_mmu_page { |
93 | struct list_head link; | 121 | struct list_head link; |
122 | struct hlist_node hash_link; | ||
123 | |||
124 | /* | ||
125 | * The following two entries are used to key the shadow page in the | ||
126 | * hash table. | ||
127 | */ | ||
128 | gfn_t gfn; | ||
129 | union kvm_mmu_page_role role; | ||
130 | |||
94 | hpa_t page_hpa; | 131 | hpa_t page_hpa; |
95 | unsigned long slot_bitmap; /* One bit set per slot which has memory | 132 | unsigned long slot_bitmap; /* One bit set per slot which has memory |
96 | * in this shadow page. | 133 | * in this shadow page. |
97 | */ | 134 | */ |
98 | int global; /* Set if all ptes in this page are global */ | 135 | int global; /* Set if all ptes in this page are global */ |
99 | u64 *parent_pte; | 136 | int multimapped; /* More than one parent_pte? */ |
137 | int root_count; /* Currently serving as active root */ | ||
138 | union { | ||
139 | u64 *parent_pte; /* !multimapped */ | ||
140 | struct hlist_head parent_ptes; /* multimapped, kvm_pte_chain */ | ||
141 | }; | ||
100 | }; | 142 | }; |
101 | 143 | ||
102 | struct vmcs { | 144 | struct vmcs { |
@@ -117,14 +159,26 @@ struct kvm_vcpu; | |||
117 | struct kvm_mmu { | 159 | struct kvm_mmu { |
118 | void (*new_cr3)(struct kvm_vcpu *vcpu); | 160 | void (*new_cr3)(struct kvm_vcpu *vcpu); |
119 | int (*page_fault)(struct kvm_vcpu *vcpu, gva_t gva, u32 err); | 161 | int (*page_fault)(struct kvm_vcpu *vcpu, gva_t gva, u32 err); |
120 | void (*inval_page)(struct kvm_vcpu *vcpu, gva_t gva); | ||
121 | void (*free)(struct kvm_vcpu *vcpu); | 162 | void (*free)(struct kvm_vcpu *vcpu); |
122 | gpa_t (*gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t gva); | 163 | gpa_t (*gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t gva); |
123 | hpa_t root_hpa; | 164 | hpa_t root_hpa; |
124 | int root_level; | 165 | int root_level; |
125 | int shadow_root_level; | 166 | int shadow_root_level; |
167 | |||
168 | u64 *pae_root; | ||
169 | }; | ||
170 | |||
171 | #define KVM_NR_MEM_OBJS 20 | ||
172 | |||
173 | struct kvm_mmu_memory_cache { | ||
174 | int nobjs; | ||
175 | void *objects[KVM_NR_MEM_OBJS]; | ||
126 | }; | 176 | }; |
127 | 177 | ||
178 | /* | ||
179 | * We don't want allocation failures within the mmu code, so we preallocate | ||
180 | * enough memory for a single page fault in a cache. | ||
181 | */ | ||
128 | struct kvm_guest_debug { | 182 | struct kvm_guest_debug { |
129 | int enabled; | 183 | int enabled; |
130 | unsigned long bp[4]; | 184 | unsigned long bp[4]; |
@@ -173,6 +227,7 @@ struct kvm_vcpu { | |||
173 | struct mutex mutex; | 227 | struct mutex mutex; |
174 | int cpu; | 228 | int cpu; |
175 | int launched; | 229 | int launched; |
230 | int interrupt_window_open; | ||
176 | unsigned long irq_summary; /* bit vector: 1 per word in irq_pending */ | 231 | unsigned long irq_summary; /* bit vector: 1 per word in irq_pending */ |
177 | #define NR_IRQ_WORDS KVM_IRQ_BITMAP_SIZE(unsigned long) | 232 | #define NR_IRQ_WORDS KVM_IRQ_BITMAP_SIZE(unsigned long) |
178 | unsigned long irq_pending[NR_IRQ_WORDS]; | 233 | unsigned long irq_pending[NR_IRQ_WORDS]; |
@@ -184,6 +239,7 @@ struct kvm_vcpu { | |||
184 | unsigned long cr3; | 239 | unsigned long cr3; |
185 | unsigned long cr4; | 240 | unsigned long cr4; |
186 | unsigned long cr8; | 241 | unsigned long cr8; |
242 | u64 pdptrs[4]; /* pae */ | ||
187 | u64 shadow_efer; | 243 | u64 shadow_efer; |
188 | u64 apic_base; | 244 | u64 apic_base; |
189 | int nmsrs; | 245 | int nmsrs; |
@@ -194,6 +250,12 @@ struct kvm_vcpu { | |||
194 | struct kvm_mmu_page page_header_buf[KVM_NUM_MMU_PAGES]; | 250 | struct kvm_mmu_page page_header_buf[KVM_NUM_MMU_PAGES]; |
195 | struct kvm_mmu mmu; | 251 | struct kvm_mmu mmu; |
196 | 252 | ||
253 | struct kvm_mmu_memory_cache mmu_pte_chain_cache; | ||
254 | struct kvm_mmu_memory_cache mmu_rmap_desc_cache; | ||
255 | |||
256 | gfn_t last_pt_write_gfn; | ||
257 | int last_pt_write_count; | ||
258 | |||
197 | struct kvm_guest_debug guest_debug; | 259 | struct kvm_guest_debug guest_debug; |
198 | 260 | ||
199 | char fx_buf[FX_BUF_SIZE]; | 261 | char fx_buf[FX_BUF_SIZE]; |
@@ -231,10 +293,16 @@ struct kvm { | |||
231 | spinlock_t lock; /* protects everything except vcpus */ | 293 | spinlock_t lock; /* protects everything except vcpus */ |
232 | int nmemslots; | 294 | int nmemslots; |
233 | struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS]; | 295 | struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS]; |
296 | /* | ||
297 | * Hash table of struct kvm_mmu_page. | ||
298 | */ | ||
234 | struct list_head active_mmu_pages; | 299 | struct list_head active_mmu_pages; |
300 | int n_free_mmu_pages; | ||
301 | struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES]; | ||
235 | struct kvm_vcpu vcpus[KVM_MAX_VCPUS]; | 302 | struct kvm_vcpu vcpus[KVM_MAX_VCPUS]; |
236 | int memory_config_version; | 303 | int memory_config_version; |
237 | int busy; | 304 | int busy; |
305 | unsigned long rmap_overflow; | ||
238 | }; | 306 | }; |
239 | 307 | ||
240 | struct kvm_stat { | 308 | struct kvm_stat { |
@@ -247,6 +315,9 @@ struct kvm_stat { | |||
247 | u32 io_exits; | 315 | u32 io_exits; |
248 | u32 mmio_exits; | 316 | u32 mmio_exits; |
249 | u32 signal_exits; | 317 | u32 signal_exits; |
318 | u32 irq_window_exits; | ||
319 | u32 halt_exits; | ||
320 | u32 request_irq_exits; | ||
250 | u32 irq_exits; | 321 | u32 irq_exits; |
251 | }; | 322 | }; |
252 | 323 | ||
@@ -279,6 +350,7 @@ struct kvm_arch_ops { | |||
279 | void (*set_segment)(struct kvm_vcpu *vcpu, | 350 | void (*set_segment)(struct kvm_vcpu *vcpu, |
280 | struct kvm_segment *var, int seg); | 351 | struct kvm_segment *var, int seg); |
281 | void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l); | 352 | void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l); |
353 | void (*decache_cr0_cr4_guest_bits)(struct kvm_vcpu *vcpu); | ||
282 | void (*set_cr0)(struct kvm_vcpu *vcpu, unsigned long cr0); | 354 | void (*set_cr0)(struct kvm_vcpu *vcpu, unsigned long cr0); |
283 | void (*set_cr0_no_modeswitch)(struct kvm_vcpu *vcpu, | 355 | void (*set_cr0_no_modeswitch)(struct kvm_vcpu *vcpu, |
284 | unsigned long cr0); | 356 | unsigned long cr0); |
@@ -323,7 +395,7 @@ int kvm_mmu_create(struct kvm_vcpu *vcpu); | |||
323 | int kvm_mmu_setup(struct kvm_vcpu *vcpu); | 395 | int kvm_mmu_setup(struct kvm_vcpu *vcpu); |
324 | 396 | ||
325 | int kvm_mmu_reset_context(struct kvm_vcpu *vcpu); | 397 | int kvm_mmu_reset_context(struct kvm_vcpu *vcpu); |
326 | void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot); | 398 | void kvm_mmu_slot_remove_write_access(struct kvm_vcpu *vcpu, int slot); |
327 | 399 | ||
328 | hpa_t gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa); | 400 | hpa_t gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa); |
329 | #define HPA_MSB ((sizeof(hpa_t) * 8) - 1) | 401 | #define HPA_MSB ((sizeof(hpa_t) * 8) - 1) |
@@ -396,6 +468,19 @@ int kvm_write_guest(struct kvm_vcpu *vcpu, | |||
396 | 468 | ||
397 | unsigned long segment_base(u16 selector); | 469 | unsigned long segment_base(u16 selector); |
398 | 470 | ||
471 | void kvm_mmu_pre_write(struct kvm_vcpu *vcpu, gpa_t gpa, int bytes); | ||
472 | void kvm_mmu_post_write(struct kvm_vcpu *vcpu, gpa_t gpa, int bytes); | ||
473 | int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva); | ||
474 | void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu); | ||
475 | |||
476 | static inline int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva, | ||
477 | u32 error_code) | ||
478 | { | ||
479 | if (unlikely(vcpu->kvm->n_free_mmu_pages < KVM_MIN_FREE_MMU_PAGES)) | ||
480 | kvm_mmu_free_some_pages(vcpu); | ||
481 | return vcpu->mmu.page_fault(vcpu, gva, error_code); | ||
482 | } | ||
483 | |||
399 | static inline struct page *_gfn_to_page(struct kvm *kvm, gfn_t gfn) | 484 | static inline struct page *_gfn_to_page(struct kvm *kvm, gfn_t gfn) |
400 | { | 485 | { |
401 | struct kvm_memory_slot *slot = gfn_to_memslot(kvm, gfn); | 486 | struct kvm_memory_slot *slot = gfn_to_memslot(kvm, gfn); |
@@ -541,19 +626,4 @@ static inline u32 get_rdx_init_val(void) | |||
541 | #define TSS_REDIRECTION_SIZE (256 / 8) | 626 | #define TSS_REDIRECTION_SIZE (256 / 8) |
542 | #define RMODE_TSS_SIZE (TSS_BASE_SIZE + TSS_REDIRECTION_SIZE + TSS_IOPB_SIZE + 1) | 627 | #define RMODE_TSS_SIZE (TSS_BASE_SIZE + TSS_REDIRECTION_SIZE + TSS_IOPB_SIZE + 1) |
543 | 628 | ||
544 | #ifdef CONFIG_X86_64 | ||
545 | |||
546 | /* | ||
547 | * When emulating 32-bit mode, cr3 is only 32 bits even on x86_64. Therefore | ||
548 | * we need to allocate shadow page tables in the first 4GB of memory, which | ||
549 | * happens to fit the DMA32 zone. | ||
550 | */ | ||
551 | #define GFP_KVM_MMU (GFP_KERNEL | __GFP_DMA32) | ||
552 | |||
553 | #else | ||
554 | |||
555 | #define GFP_KVM_MMU GFP_KERNEL | ||
556 | |||
557 | #endif | ||
558 | |||
559 | #endif | 629 | #endif |