aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhang Xiantao <xiantao.zhang@intel.com>2007-10-20 03:34:38 -0400
committerAvi Kivity <avi@qumranet.com>2008-01-30 10:52:54 -0500
commit34c16eecf78ed4cf01f39ac7211f5b57942ec899 (patch)
tree9a9d6192db411cc3c7ff665cc94a8797eb55aa80
parent8d4e1288ebb753d3140d81cb349f22b0a6829a4a (diff)
KVM: Portability: Split kvm_vcpu into arch dependent and independent parts (part 1)
First step to split kvm_vcpu. Currently, we just use an macro to define the common fields in kvm_vcpu for all archs, and all archs need to define its own kvm_vcpu struct. Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com> Signed-off-by: Avi Kivity <avi@qumranet.com>
-rw-r--r--drivers/kvm/ioapic.c2
-rw-r--r--drivers/kvm/irq.c1
-rw-r--r--drivers/kvm/kvm.h154
-rw-r--r--drivers/kvm/kvm_main.c4
-rw-r--r--drivers/kvm/lapic.c2
-rw-r--r--drivers/kvm/mmu.c1
-rw-r--r--drivers/kvm/svm.c2
-rw-r--r--drivers/kvm/vmx.c1
-rw-r--r--drivers/kvm/x86.h117
-rw-r--r--drivers/kvm/x86_emulate.c1
10 files changed, 155 insertions, 130 deletions
diff --git a/drivers/kvm/ioapic.c b/drivers/kvm/ioapic.c
index 8503d99b8339..e14b7c724e67 100644
--- a/drivers/kvm/ioapic.c
+++ b/drivers/kvm/ioapic.c
@@ -27,6 +27,8 @@
27 */ 27 */
28 28
29#include "kvm.h" 29#include "kvm.h"
30#include "x86.h"
31
30#include <linux/kvm.h> 32#include <linux/kvm.h>
31#include <linux/mm.h> 33#include <linux/mm.h>
32#include <linux/highmem.h> 34#include <linux/highmem.h>
diff --git a/drivers/kvm/irq.c b/drivers/kvm/irq.c
index 7628c7ff628f..59b47c55fc76 100644
--- a/drivers/kvm/irq.c
+++ b/drivers/kvm/irq.c
@@ -22,6 +22,7 @@
22#include <linux/module.h> 22#include <linux/module.h>
23 23
24#include "kvm.h" 24#include "kvm.h"
25#include "x86.h"
25#include "irq.h" 26#include "irq.h"
26 27
27/* 28/*
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index eb006ed696c1..db18d278c1c0 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -308,93 +308,37 @@ struct kvm_io_device *kvm_io_bus_find_dev(struct kvm_io_bus *bus, gpa_t addr);
308void kvm_io_bus_register_dev(struct kvm_io_bus *bus, 308void kvm_io_bus_register_dev(struct kvm_io_bus *bus,
309 struct kvm_io_device *dev); 309 struct kvm_io_device *dev);
310 310
311struct kvm_vcpu { 311#ifdef CONFIG_HAS_IOMEM
312 struct kvm *kvm; 312#define KVM_VCPU_MMIO \
313 struct preempt_notifier preempt_notifier; 313 int mmio_needed; \
314 int vcpu_id; 314 int mmio_read_completed; \
315 struct mutex mutex; 315 int mmio_is_write; \
316 int cpu; 316 int mmio_size; \
317 u64 host_tsc; 317 unsigned char mmio_data[8]; \
318 struct kvm_run *run;
319 int interrupt_window_open;
320 int guest_mode;
321 unsigned long requests;
322 unsigned long irq_summary; /* bit vector: 1 per word in irq_pending */
323 DECLARE_BITMAP(irq_pending, KVM_NR_INTERRUPTS);
324 unsigned long regs[NR_VCPU_REGS]; /* for rsp: vcpu_load_rsp_rip() */
325 unsigned long rip; /* needs vcpu_load_rsp_rip() */
326
327 unsigned long cr0;
328 unsigned long cr2;
329 unsigned long cr3;
330 unsigned long cr4;
331 unsigned long cr8;
332 u64 pdptrs[4]; /* pae */
333 u64 shadow_efer;
334 u64 apic_base;
335 struct kvm_lapic *apic; /* kernel irqchip context */
336#define VCPU_MP_STATE_RUNNABLE 0
337#define VCPU_MP_STATE_UNINITIALIZED 1
338#define VCPU_MP_STATE_INIT_RECEIVED 2
339#define VCPU_MP_STATE_SIPI_RECEIVED 3
340#define VCPU_MP_STATE_HALTED 4
341 int mp_state;
342 int sipi_vector;
343 u64 ia32_misc_enable_msr;
344
345 struct kvm_mmu mmu;
346
347 struct kvm_mmu_memory_cache mmu_pte_chain_cache;
348 struct kvm_mmu_memory_cache mmu_rmap_desc_cache;
349 struct kvm_mmu_memory_cache mmu_page_cache;
350 struct kvm_mmu_memory_cache mmu_page_header_cache;
351
352 gfn_t last_pt_write_gfn;
353 int last_pt_write_count;
354 u64 *last_pte_updated;
355
356 struct kvm_guest_debug guest_debug;
357
358 struct i387_fxsave_struct host_fx_image;
359 struct i387_fxsave_struct guest_fx_image;
360 int fpu_active;
361 int guest_fpu_loaded;
362
363 int mmio_needed;
364 int mmio_read_completed;
365 int mmio_is_write;
366 int mmio_size;
367 unsigned char mmio_data[8];
368 gpa_t mmio_phys_addr; 318 gpa_t mmio_phys_addr;
369 gva_t mmio_fault_cr2;
370 struct kvm_pio_request pio;
371 void *pio_data;
372 wait_queue_head_t wq;
373 319
374 int sigset_active; 320#else
375 sigset_t sigset; 321#define KVM_VCPU_MMIO
376 322
377 struct kvm_stat stat; 323#endif
378 324
379 struct { 325#define KVM_VCPU_COMM \
380 int active; 326 struct kvm *kvm; \
381 u8 save_iopl; 327 struct preempt_notifier preempt_notifier; \
382 struct kvm_save_segment { 328 int vcpu_id; \
383 u16 selector; 329 struct mutex mutex; \
384 unsigned long base; 330 int cpu; \
385 u32 limit; 331 struct kvm_run *run; \
386 u32 ar; 332 int guest_mode; \
387 } tr, es, ds, fs, gs; 333 unsigned long requests; \
388 } rmode; 334 struct kvm_guest_debug guest_debug; \
389 int halt_request; /* real mode on Intel only */ 335 int fpu_active; \
390 336 int guest_fpu_loaded; \
391 int cpuid_nent; 337 wait_queue_head_t wq; \
392 struct kvm_cpuid_entry cpuid_entries[KVM_MAX_CPUID_ENTRIES]; 338 int sigset_active; \
393 339 sigset_t sigset; \
394 /* emulate context */ 340 struct kvm_stat stat; \
395 341 KVM_VCPU_MMIO
396 struct x86_emulate_ctxt emulate_ctxt;
397};
398 342
399struct kvm_mem_alias { 343struct kvm_mem_alias {
400 gfn_t base_gfn; 344 gfn_t base_gfn;
@@ -680,50 +624,6 @@ static inline void kvm_guest_exit(void)
680 current->flags &= ~PF_VCPU; 624 current->flags &= ~PF_VCPU;
681} 625}
682 626
683static inline int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva,
684 u32 error_code)
685{
686 return vcpu->mmu.page_fault(vcpu, gva, error_code);
687}
688
689static inline void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu)
690{
691 if (unlikely(vcpu->kvm->n_free_mmu_pages < KVM_MIN_FREE_MMU_PAGES))
692 __kvm_mmu_free_some_pages(vcpu);
693}
694
695static inline int kvm_mmu_reload(struct kvm_vcpu *vcpu)
696{
697 if (likely(vcpu->mmu.root_hpa != INVALID_PAGE))
698 return 0;
699
700 return kvm_mmu_load(vcpu);
701}
702
703static inline int is_long_mode(struct kvm_vcpu *vcpu)
704{
705#ifdef CONFIG_X86_64
706 return vcpu->shadow_efer & EFER_LME;
707#else
708 return 0;
709#endif
710}
711
712static inline int is_pae(struct kvm_vcpu *vcpu)
713{
714 return vcpu->cr4 & X86_CR4_PAE;
715}
716
717static inline int is_pse(struct kvm_vcpu *vcpu)
718{
719 return vcpu->cr4 & X86_CR4_PSE;
720}
721
722static inline int is_paging(struct kvm_vcpu *vcpu)
723{
724 return vcpu->cr0 & X86_CR0_PG;
725}
726
727static inline int memslot_id(struct kvm *kvm, struct kvm_memory_slot *slot) 627static inline int memslot_id(struct kvm *kvm, struct kvm_memory_slot *slot)
728{ 628{
729 return slot - kvm->memslots; 629 return slot - kvm->memslots;
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 8f6c21d02656..0b23657f434c 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -2244,7 +2244,7 @@ static int kvm_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
2244 if (r) 2244 if (r)
2245 goto out; 2245 goto out;
2246 } 2246 }
2247 2247#if CONFIG_HAS_IOMEM
2248 if (vcpu->mmio_needed) { 2248 if (vcpu->mmio_needed) {
2249 memcpy(vcpu->mmio_data, kvm_run->mmio.data, 8); 2249 memcpy(vcpu->mmio_data, kvm_run->mmio.data, 8);
2250 vcpu->mmio_read_completed = 1; 2250 vcpu->mmio_read_completed = 1;
@@ -2259,7 +2259,7 @@ static int kvm_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
2259 goto out; 2259 goto out;
2260 } 2260 }
2261 } 2261 }
2262 2262#endif
2263 if (kvm_run->exit_reason == KVM_EXIT_HYPERCALL) { 2263 if (kvm_run->exit_reason == KVM_EXIT_HYPERCALL) {
2264 kvm_x86_ops->cache_regs(vcpu); 2264 kvm_x86_ops->cache_regs(vcpu);
2265 vcpu->regs[VCPU_REGS_RAX] = kvm_run->hypercall.ret; 2265 vcpu->regs[VCPU_REGS_RAX] = kvm_run->hypercall.ret;
diff --git a/drivers/kvm/lapic.c b/drivers/kvm/lapic.c
index 8840f9dc0bca..64f74bd7093a 100644
--- a/drivers/kvm/lapic.c
+++ b/drivers/kvm/lapic.c
@@ -18,6 +18,8 @@
18 */ 18 */
19 19
20#include "kvm.h" 20#include "kvm.h"
21#include "x86.h"
22
21#include <linux/kvm.h> 23#include <linux/kvm.h>
22#include <linux/mm.h> 24#include <linux/mm.h>
23#include <linux/highmem.h> 25#include <linux/highmem.h>
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index 5d7af4bde595..d9c5950cfae1 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -19,6 +19,7 @@
19 19
20#include "vmx.h" 20#include "vmx.h"
21#include "kvm.h" 21#include "kvm.h"
22#include "x86.h"
22 23
23#include <linux/types.h> 24#include <linux/types.h>
24#include <linux/string.h> 25#include <linux/string.h>
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index ef068d2dddd7..035c8e6898f1 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -13,7 +13,7 @@
13 * the COPYING file in the top-level directory. 13 * the COPYING file in the top-level directory.
14 * 14 *
15 */ 15 */
16 16#include "x86.h"
17#include "kvm_svm.h" 17#include "kvm_svm.h"
18#include "x86_emulate.h" 18#include "x86_emulate.h"
19#include "irq.h" 19#include "irq.h"
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 9f77ddbeb025..87ff35128825 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -16,6 +16,7 @@
16 */ 16 */
17 17
18#include "kvm.h" 18#include "kvm.h"
19#include "x86.h"
19#include "x86_emulate.h" 20#include "x86_emulate.h"
20#include "irq.h" 21#include "irq.h"
21#include "vmx.h" 22#include "vmx.h"
diff --git a/drivers/kvm/x86.h b/drivers/kvm/x86.h
index 1e2f71bd805d..01452b552db3 100644
--- a/drivers/kvm/x86.h
+++ b/drivers/kvm/x86.h
@@ -13,4 +13,121 @@
13 13
14#include "kvm.h" 14#include "kvm.h"
15 15
16#include <linux/types.h>
17#include <linux/mm.h>
18
19#include <linux/kvm.h>
20#include <linux/kvm_para.h>
21
22struct kvm_vcpu {
23 KVM_VCPU_COMM;
24 u64 host_tsc;
25 int interrupt_window_open;
26 unsigned long irq_summary; /* bit vector: 1 per word in irq_pending */
27 DECLARE_BITMAP(irq_pending, KVM_NR_INTERRUPTS);
28 unsigned long regs[NR_VCPU_REGS]; /* for rsp: vcpu_load_rsp_rip() */
29 unsigned long rip; /* needs vcpu_load_rsp_rip() */
30
31 unsigned long cr0;
32 unsigned long cr2;
33 unsigned long cr3;
34 unsigned long cr4;
35 unsigned long cr8;
36 u64 pdptrs[4]; /* pae */
37 u64 shadow_efer;
38 u64 apic_base;
39 struct kvm_lapic *apic; /* kernel irqchip context */
40#define VCPU_MP_STATE_RUNNABLE 0
41#define VCPU_MP_STATE_UNINITIALIZED 1
42#define VCPU_MP_STATE_INIT_RECEIVED 2
43#define VCPU_MP_STATE_SIPI_RECEIVED 3
44#define VCPU_MP_STATE_HALTED 4
45 int mp_state;
46 int sipi_vector;
47 u64 ia32_misc_enable_msr;
48
49 struct kvm_mmu mmu;
50
51 struct kvm_mmu_memory_cache mmu_pte_chain_cache;
52 struct kvm_mmu_memory_cache mmu_rmap_desc_cache;
53 struct kvm_mmu_memory_cache mmu_page_cache;
54 struct kvm_mmu_memory_cache mmu_page_header_cache;
55
56 gfn_t last_pt_write_gfn;
57 int last_pt_write_count;
58 u64 *last_pte_updated;
59
60
61 struct i387_fxsave_struct host_fx_image;
62 struct i387_fxsave_struct guest_fx_image;
63
64 gva_t mmio_fault_cr2;
65 struct kvm_pio_request pio;
66 void *pio_data;
67
68 struct {
69 int active;
70 u8 save_iopl;
71 struct kvm_save_segment {
72 u16 selector;
73 unsigned long base;
74 u32 limit;
75 u32 ar;
76 } tr, es, ds, fs, gs;
77 } rmode;
78 int halt_request; /* real mode on Intel only */
79
80 int cpuid_nent;
81 struct kvm_cpuid_entry cpuid_entries[KVM_MAX_CPUID_ENTRIES];
82
83 /* emulate context */
84
85 struct x86_emulate_ctxt emulate_ctxt;
86};
87
88static inline int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva,
89 u32 error_code)
90{
91 return vcpu->mmu.page_fault(vcpu, gva, error_code);
92}
93
94static inline void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu)
95{
96 if (unlikely(vcpu->kvm->n_free_mmu_pages < KVM_MIN_FREE_MMU_PAGES))
97 __kvm_mmu_free_some_pages(vcpu);
98}
99
100static inline int kvm_mmu_reload(struct kvm_vcpu *vcpu)
101{
102 if (likely(vcpu->mmu.root_hpa != INVALID_PAGE))
103 return 0;
104
105 return kvm_mmu_load(vcpu);
106}
107
108static inline int is_long_mode(struct kvm_vcpu *vcpu)
109{
110#ifdef CONFIG_X86_64
111 return vcpu->shadow_efer & EFER_LME;
112#else
113 return 0;
114#endif
115}
116
117static inline int is_pae(struct kvm_vcpu *vcpu)
118{
119 return vcpu->cr4 & X86_CR4_PAE;
120}
121
122static inline int is_pse(struct kvm_vcpu *vcpu)
123{
124 return vcpu->cr4 & X86_CR4_PSE;
125}
126
127static inline int is_paging(struct kvm_vcpu *vcpu)
128{
129 return vcpu->cr0 & X86_CR0_PG;
130}
131
132
16#endif 133#endif
diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
index e962de331606..73e3580c88e4 100644
--- a/drivers/kvm/x86_emulate.c
+++ b/drivers/kvm/x86_emulate.c
@@ -26,6 +26,7 @@
26#define DPRINTF(_f, _a ...) printf(_f , ## _a) 26#define DPRINTF(_f, _a ...) printf(_f , ## _a)
27#else 27#else
28#include "kvm.h" 28#include "kvm.h"
29#include "x86.h"
29#define DPRINTF(x...) do {} while (0) 30#define DPRINTF(x...) do {} while (0)
30#endif 31#endif
31#include "x86_emulate.h" 32#include "x86_emulate.h"