diff options
author | Zhang Xiantao <xiantao.zhang@intel.com> | 2007-12-13 20:41:22 -0500 |
---|---|---|
committer | Avi Kivity <avi@qumranet.com> | 2008-01-30 10:58:09 -0500 |
commit | d657a98e3c20537d8b4d44aef51cf4311d96f2b0 (patch) | |
tree | cf1e1e2e3c0d05617ab6baf5c017987708a55d41 | |
parent | 1d737c8a68736db36e0aa502ace9da240704c5ae (diff) |
KVM: Portability: Move kvm_vcpu definition back to kvm.h
This patches moves kvm_vcpu definition to kvm.h, and finally
kvm.h includes x86.h.
Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com>
Acked-by: Carsten Otte <cotte@de.ibm.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
-rw-r--r-- | drivers/kvm/irq.h | 2 | ||||
-rw-r--r-- | drivers/kvm/kvm.h | 113 | ||||
-rw-r--r-- | drivers/kvm/types.h | 13 | ||||
-rw-r--r-- | drivers/kvm/x86.h | 102 |
4 files changed, 117 insertions, 113 deletions
diff --git a/drivers/kvm/irq.h b/drivers/kvm/irq.h index e88d93957d24..a688c51d0a39 100644 --- a/drivers/kvm/irq.h +++ b/drivers/kvm/irq.h | |||
@@ -26,7 +26,7 @@ | |||
26 | #include <linux/hrtimer.h> | 26 | #include <linux/hrtimer.h> |
27 | #include <asm/kvm.h> | 27 | #include <asm/kvm.h> |
28 | #include "iodev.h" | 28 | #include "iodev.h" |
29 | #include "x86.h" | 29 | #include "kvm.h" |
30 | 30 | ||
31 | struct kvm; | 31 | struct kvm; |
32 | struct kvm_vcpu; | 32 | struct kvm_vcpu; |
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h index c040bb3ac819..53717be80bbe 100644 --- a/drivers/kvm/kvm.h +++ b/drivers/kvm/kvm.h | |||
@@ -22,17 +22,13 @@ | |||
22 | 22 | ||
23 | #include "types.h" | 23 | #include "types.h" |
24 | 24 | ||
25 | #include "x86.h" | ||
26 | |||
25 | #define KVM_MAX_VCPUS 4 | 27 | #define KVM_MAX_VCPUS 4 |
26 | #define KVM_ALIAS_SLOTS 4 | 28 | #define KVM_ALIAS_SLOTS 4 |
27 | #define KVM_MEMORY_SLOTS 8 | 29 | #define KVM_MEMORY_SLOTS 8 |
28 | /* memory slots that does not exposed to userspace */ | 30 | /* memory slots that does not exposed to userspace */ |
29 | #define KVM_PRIVATE_MEM_SLOTS 4 | 31 | #define KVM_PRIVATE_MEM_SLOTS 4 |
30 | #define KVM_PERMILLE_MMU_PAGES 20 | ||
31 | #define KVM_MIN_ALLOC_MMU_PAGES 64 | ||
32 | #define KVM_NUM_MMU_PAGES 1024 | ||
33 | #define KVM_MIN_FREE_MMU_PAGES 5 | ||
34 | #define KVM_REFILL_PAGES 25 | ||
35 | #define KVM_MAX_CPUID_ENTRIES 40 | ||
36 | 32 | ||
37 | #define KVM_PIO_PAGE_OFFSET 1 | 33 | #define KVM_PIO_PAGE_OFFSET 1 |
38 | 34 | ||
@@ -41,111 +37,16 @@ | |||
41 | */ | 37 | */ |
42 | #define KVM_REQ_TLB_FLUSH 0 | 38 | #define KVM_REQ_TLB_FLUSH 0 |
43 | 39 | ||
44 | #define NR_PTE_CHAIN_ENTRIES 5 | ||
45 | |||
46 | struct 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) | ||
58 | * bits 17:19 - common access permissions for all ptes in this shadow page | ||
59 | */ | ||
60 | union 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; | ||
68 | unsigned access : 3; | ||
69 | }; | ||
70 | }; | ||
71 | |||
72 | struct kvm_mmu_page { | ||
73 | struct list_head link; | ||
74 | 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 | |||
83 | u64 *spt; | ||
84 | /* hold the gfn of each spte inside spt */ | ||
85 | gfn_t *gfns; | ||
86 | unsigned long slot_bitmap; /* One bit set per slot which has memory | ||
87 | * in this shadow page. | ||
88 | */ | ||
89 | int multimapped; /* More than one parent_pte? */ | ||
90 | int root_count; /* Currently serving as active root */ | ||
91 | union { | ||
92 | u64 *parent_pte; /* !multimapped */ | ||
93 | struct hlist_head parent_ptes; /* multimapped, kvm_pte_chain */ | ||
94 | }; | ||
95 | }; | ||
96 | 40 | ||
97 | struct kvm_vcpu; | 41 | struct kvm_vcpu; |
98 | extern struct kmem_cache *kvm_vcpu_cache; | 42 | extern struct kmem_cache *kvm_vcpu_cache; |
99 | 43 | ||
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 | */ | ||
105 | struct kvm_mmu { | ||
106 | void (*new_cr3)(struct kvm_vcpu *vcpu); | ||
107 | int (*page_fault)(struct kvm_vcpu *vcpu, gva_t gva, u32 err); | ||
108 | void (*free)(struct kvm_vcpu *vcpu); | ||
109 | gpa_t (*gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t gva); | ||
110 | void (*prefetch_page)(struct kvm_vcpu *vcpu, | ||
111 | struct kvm_mmu_page *page); | ||
112 | hpa_t root_hpa; | ||
113 | int root_level; | ||
114 | int shadow_root_level; | ||
115 | |||
116 | u64 *pae_root; | ||
117 | }; | ||
118 | |||
119 | #define KVM_NR_MEM_OBJS 40 | ||
120 | |||
121 | /* | ||
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 | */ | ||
125 | struct kvm_mmu_memory_cache { | ||
126 | int nobjs; | ||
127 | void *objects[KVM_NR_MEM_OBJS]; | ||
128 | }; | ||
129 | |||
130 | struct kvm_guest_debug { | 44 | struct kvm_guest_debug { |
131 | int enabled; | 45 | int enabled; |
132 | unsigned long bp[4]; | 46 | unsigned long bp[4]; |
133 | int singlestep; | 47 | int singlestep; |
134 | }; | 48 | }; |
135 | 49 | ||
136 | struct 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; | ||
142 | int port; | ||
143 | int size; | ||
144 | int string; | ||
145 | int down; | ||
146 | int rep; | ||
147 | }; | ||
148 | |||
149 | struct kvm_vcpu_stat { | 50 | struct kvm_vcpu_stat { |
150 | u32 pf_fixed; | 51 | u32 pf_fixed; |
151 | u32 pf_guest; | 52 | u32 pf_guest; |
@@ -218,6 +119,12 @@ void kvm_io_bus_register_dev(struct kvm_io_bus *bus, | |||
218 | struct kvm_vcpu_stat stat; \ | 119 | struct kvm_vcpu_stat stat; \ |
219 | KVM_VCPU_MMIO | 120 | KVM_VCPU_MMIO |
220 | 121 | ||
122 | struct kvm_vcpu { | ||
123 | KVM_VCPU_COMM; | ||
124 | |||
125 | struct kvm_vcpu_arch arch; | ||
126 | }; | ||
127 | |||
221 | struct kvm_mem_alias { | 128 | struct kvm_mem_alias { |
222 | gfn_t base_gfn; | 129 | gfn_t base_gfn; |
223 | unsigned long npages; | 130 | unsigned long npages; |
@@ -441,8 +348,4 @@ struct kvm_stats_debugfs_item { | |||
441 | }; | 348 | }; |
442 | extern struct kvm_stats_debugfs_item debugfs_entries[]; | 349 | extern struct kvm_stats_debugfs_item debugfs_entries[]; |
443 | 350 | ||
444 | #if defined(CONFIG_X86) | ||
445 | #include "x86.h" | ||
446 | #endif | ||
447 | |||
448 | #endif | 351 | #endif |
diff --git a/drivers/kvm/types.h b/drivers/kvm/types.h index 6ad76231b8ff..1c4e46decb22 100644 --- a/drivers/kvm/types.h +++ b/drivers/kvm/types.h | |||
@@ -38,4 +38,17 @@ typedef unsigned long hva_t; | |||
38 | typedef u64 hpa_t; | 38 | typedef u64 hpa_t; |
39 | typedef unsigned long hfn_t; | 39 | typedef unsigned long hfn_t; |
40 | 40 | ||
41 | struct kvm_pio_request { | ||
42 | unsigned long count; | ||
43 | int cur_count; | ||
44 | struct page *guest_pages[2]; | ||
45 | unsigned guest_page_offset; | ||
46 | int in; | ||
47 | int port; | ||
48 | int size; | ||
49 | int string; | ||
50 | int down; | ||
51 | int rep; | ||
52 | }; | ||
53 | |||
41 | #endif /* __KVM_TYPES_H__ */ | 54 | #endif /* __KVM_TYPES_H__ */ |
diff --git a/drivers/kvm/x86.h b/drivers/kvm/x86.h index 0da4be9b0bad..a0dd4473b8f8 100644 --- a/drivers/kvm/x86.h +++ b/drivers/kvm/x86.h | |||
@@ -11,8 +11,6 @@ | |||
11 | #ifndef KVM_X86_H | 11 | #ifndef KVM_X86_H |
12 | #define KVM_X86_H | 12 | #define KVM_X86_H |
13 | 13 | ||
14 | #include "kvm.h" | ||
15 | |||
16 | #include <linux/types.h> | 14 | #include <linux/types.h> |
17 | #include <linux/mm.h> | 15 | #include <linux/mm.h> |
18 | 16 | ||
@@ -21,6 +19,8 @@ | |||
21 | 19 | ||
22 | #include <asm/desc.h> | 20 | #include <asm/desc.h> |
23 | 21 | ||
22 | #include "types.h" | ||
23 | |||
24 | #define CR3_PAE_RESERVED_BITS ((X86_CR3_PWT | X86_CR3_PCD) - 1) | 24 | #define CR3_PAE_RESERVED_BITS ((X86_CR3_PWT | X86_CR3_PCD) - 1) |
25 | #define CR3_NONPAE_RESERVED_BITS ((PAGE_SIZE-1) & ~(X86_CR3_PWT | X86_CR3_PCD)) | 25 | #define CR3_NONPAE_RESERVED_BITS ((PAGE_SIZE-1) & ~(X86_CR3_PWT | X86_CR3_PCD)) |
26 | #define CR3_L_MODE_RESERVED_BITS (CR3_NONPAE_RESERVED_BITS|0xFFFFFF0000000000ULL) | 26 | #define CR3_L_MODE_RESERVED_BITS (CR3_NONPAE_RESERVED_BITS|0xFFFFFF0000000000ULL) |
@@ -54,9 +54,19 @@ | |||
54 | 54 | ||
55 | #define IOPL_SHIFT 12 | 55 | #define IOPL_SHIFT 12 |
56 | 56 | ||
57 | #define KVM_PERMILLE_MMU_PAGES 20 | ||
58 | #define KVM_MIN_ALLOC_MMU_PAGES 64 | ||
59 | #define KVM_NUM_MMU_PAGES 1024 | ||
60 | #define KVM_MIN_FREE_MMU_PAGES 5 | ||
61 | #define KVM_REFILL_PAGES 25 | ||
62 | #define KVM_MAX_CPUID_ENTRIES 40 | ||
63 | |||
57 | extern spinlock_t kvm_lock; | 64 | extern spinlock_t kvm_lock; |
58 | extern struct list_head vm_list; | 65 | extern struct list_head vm_list; |
59 | 66 | ||
67 | struct kvm_vcpu; | ||
68 | struct kvm; | ||
69 | |||
60 | enum { | 70 | enum { |
61 | VCPU_REGS_RAX = 0, | 71 | VCPU_REGS_RAX = 0, |
62 | VCPU_REGS_RCX = 1, | 72 | VCPU_REGS_RCX = 1, |
@@ -92,6 +102,89 @@ enum { | |||
92 | 102 | ||
93 | #include "x86_emulate.h" | 103 | #include "x86_emulate.h" |
94 | 104 | ||
105 | #define KVM_NR_MEM_OBJS 40 | ||
106 | |||
107 | /* | ||
108 | * We don't want allocation failures within the mmu code, so we preallocate | ||
109 | * enough memory for a single page fault in a cache. | ||
110 | */ | ||
111 | struct kvm_mmu_memory_cache { | ||
112 | int nobjs; | ||
113 | void *objects[KVM_NR_MEM_OBJS]; | ||
114 | }; | ||
115 | |||
116 | #define NR_PTE_CHAIN_ENTRIES 5 | ||
117 | |||
118 | struct kvm_pte_chain { | ||
119 | u64 *parent_ptes[NR_PTE_CHAIN_ENTRIES]; | ||
120 | struct hlist_node link; | ||
121 | }; | ||
122 | |||
123 | /* | ||
124 | * kvm_mmu_page_role, below, is defined as: | ||
125 | * | ||
126 | * bits 0:3 - total guest paging levels (2-4, or zero for real mode) | ||
127 | * bits 4:7 - page table level for this shadow (1-4) | ||
128 | * bits 8:9 - page table quadrant for 2-level guests | ||
129 | * bit 16 - "metaphysical" - gfn is not a real page (huge page/real mode) | ||
130 | * bits 17:19 - common access permissions for all ptes in this shadow page | ||
131 | */ | ||
132 | union kvm_mmu_page_role { | ||
133 | unsigned word; | ||
134 | struct { | ||
135 | unsigned glevels : 4; | ||
136 | unsigned level : 4; | ||
137 | unsigned quadrant : 2; | ||
138 | unsigned pad_for_nice_hex_output : 6; | ||
139 | unsigned metaphysical : 1; | ||
140 | unsigned access : 3; | ||
141 | }; | ||
142 | }; | ||
143 | |||
144 | struct kvm_mmu_page { | ||
145 | struct list_head link; | ||
146 | struct hlist_node hash_link; | ||
147 | |||
148 | /* | ||
149 | * The following two entries are used to key the shadow page in the | ||
150 | * hash table. | ||
151 | */ | ||
152 | gfn_t gfn; | ||
153 | union kvm_mmu_page_role role; | ||
154 | |||
155 | u64 *spt; | ||
156 | /* hold the gfn of each spte inside spt */ | ||
157 | gfn_t *gfns; | ||
158 | unsigned long slot_bitmap; /* One bit set per slot which has memory | ||
159 | * in this shadow page. | ||
160 | */ | ||
161 | int multimapped; /* More than one parent_pte? */ | ||
162 | int root_count; /* Currently serving as active root */ | ||
163 | union { | ||
164 | u64 *parent_pte; /* !multimapped */ | ||
165 | struct hlist_head parent_ptes; /* multimapped, kvm_pte_chain */ | ||
166 | }; | ||
167 | }; | ||
168 | |||
169 | /* | ||
170 | * x86 supports 3 paging modes (4-level 64-bit, 3-level 64-bit, and 2-level | ||
171 | * 32-bit). The kvm_mmu structure abstracts the details of the current mmu | ||
172 | * mode. | ||
173 | */ | ||
174 | struct kvm_mmu { | ||
175 | void (*new_cr3)(struct kvm_vcpu *vcpu); | ||
176 | int (*page_fault)(struct kvm_vcpu *vcpu, gva_t gva, u32 err); | ||
177 | void (*free)(struct kvm_vcpu *vcpu); | ||
178 | gpa_t (*gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t gva); | ||
179 | void (*prefetch_page)(struct kvm_vcpu *vcpu, | ||
180 | struct kvm_mmu_page *page); | ||
181 | hpa_t root_hpa; | ||
182 | int root_level; | ||
183 | int shadow_root_level; | ||
184 | |||
185 | u64 *pae_root; | ||
186 | }; | ||
187 | |||
95 | struct kvm_vcpu_arch { | 188 | struct kvm_vcpu_arch { |
96 | u64 host_tsc; | 189 | u64 host_tsc; |
97 | int interrupt_window_open; | 190 | int interrupt_window_open; |
@@ -162,11 +255,6 @@ struct kvm_vcpu_arch { | |||
162 | struct x86_emulate_ctxt emulate_ctxt; | 255 | struct x86_emulate_ctxt emulate_ctxt; |
163 | }; | 256 | }; |
164 | 257 | ||
165 | struct kvm_vcpu { | ||
166 | KVM_VCPU_COMM; | ||
167 | |||
168 | struct kvm_vcpu_arch arch; | ||
169 | }; | ||
170 | 258 | ||
171 | struct descriptor_table { | 259 | struct descriptor_table { |
172 | u16 limit; | 260 | u16 limit; |