Commit | Line | Data |
---|---|---|
a656c8ef | 1 | /* |
043405e1 CO |
2 | * Kernel-based Virtual Machine driver for Linux |
3 | * | |
4 | * This header defines architecture specific interfaces, x86 version | |
5 | * | |
6 | * This work is licensed under the terms of the GNU GPL, version 2. See | |
7 | * the COPYING file in the top-level directory. | |
8 | * | |
9 | */ | |
10 | ||
1965aae3 PA |
11 | #ifndef _ASM_X86_KVM_HOST_H |
12 | #define _ASM_X86_KVM_HOST_H | |
043405e1 | 13 | |
34c16eec ZX |
14 | #include <linux/types.h> |
15 | #include <linux/mm.h> | |
e930bffe | 16 | #include <linux/mmu_notifier.h> |
229456fc | 17 | #include <linux/tracepoint.h> |
f5f48ee1 | 18 | #include <linux/cpumask.h> |
f5132b01 | 19 | #include <linux/irq_work.h> |
34c16eec ZX |
20 | |
21 | #include <linux/kvm.h> | |
22 | #include <linux/kvm_para.h> | |
edf88417 | 23 | #include <linux/kvm_types.h> |
f5132b01 | 24 | #include <linux/perf_event.h> |
d828199e MT |
25 | #include <linux/pvclock_gtod.h> |
26 | #include <linux/clocksource.h> | |
34c16eec | 27 | |
50d0a0f9 | 28 | #include <asm/pvclock-abi.h> |
e01a1b57 | 29 | #include <asm/desc.h> |
0bed3b56 | 30 | #include <asm/mtrr.h> |
9962d032 | 31 | #include <asm/msr-index.h> |
3ee89722 | 32 | #include <asm/asm.h> |
e01a1b57 | 33 | |
8c3ba334 | 34 | #define KVM_MAX_VCPUS 254 |
a59cb29e | 35 | #define KVM_SOFT_MAX_VCPUS 160 |
0f888f5a | 36 | #define KVM_USER_MEM_SLOTS 125 |
0743247f AW |
37 | /* memory slots that are not exposed to userspace */ |
38 | #define KVM_PRIVATE_MEM_SLOTS 3 | |
bbacc0c1 | 39 | #define KVM_MEM_SLOTS_NUM (KVM_USER_MEM_SLOTS + KVM_PRIVATE_MEM_SLOTS) |
93a5cef0 | 40 | |
cef4dea0 | 41 | #define KVM_MMIO_SIZE 16 |
69a9f69b AK |
42 | |
43 | #define KVM_PIO_PAGE_OFFSET 1 | |
542472b5 | 44 | #define KVM_COALESCED_MMIO_PAGE_OFFSET 2 |
69a9f69b | 45 | |
cfec82cb JR |
46 | #define CR0_RESERVED_BITS \ |
47 | (~(unsigned long)(X86_CR0_PE | X86_CR0_MP | X86_CR0_EM | X86_CR0_TS \ | |
48 | | X86_CR0_ET | X86_CR0_NE | X86_CR0_WP | X86_CR0_AM \ | |
49 | | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG)) | |
50 | ||
cd6e8f87 ZX |
51 | #define CR3_PAE_RESERVED_BITS ((X86_CR3_PWT | X86_CR3_PCD) - 1) |
52 | #define CR3_NONPAE_RESERVED_BITS ((PAGE_SIZE-1) & ~(X86_CR3_PWT | X86_CR3_PCD)) | |
ad756a16 | 53 | #define CR3_PCID_ENABLED_RESERVED_BITS 0xFFFFFF0000000000ULL |
7d76b4d3 JP |
54 | #define CR3_L_MODE_RESERVED_BITS (CR3_NONPAE_RESERVED_BITS | \ |
55 | 0xFFFFFF0000000000ULL) | |
cfec82cb JR |
56 | #define CR4_RESERVED_BITS \ |
57 | (~(unsigned long)(X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | X86_CR4_DE\ | |
58 | | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_MCE \ | |
ad756a16 | 59 | | X86_CR4_PGE | X86_CR4_PCE | X86_CR4_OSFXSR | X86_CR4_PCIDE \ |
d9c3476d | 60 | | X86_CR4_OSXSAVE | X86_CR4_SMEP | X86_CR4_RDWRGSFS \ |
cfec82cb JR |
61 | | X86_CR4_OSXMMEXCPT | X86_CR4_VMXE)) |
62 | ||
63 | #define CR8_RESERVED_BITS (~(unsigned long)X86_CR8_TPR) | |
64 | ||
65 | ||
cd6e8f87 | 66 | |
cd6e8f87 | 67 | #define INVALID_PAGE (~(hpa_t)0) |
dd180b3e XG |
68 | #define VALID_PAGE(x) ((x) != INVALID_PAGE) |
69 | ||
cd6e8f87 ZX |
70 | #define UNMAPPED_GVA (~(gpa_t)0) |
71 | ||
ec04b260 | 72 | /* KVM Hugepage definitions for x86 */ |
04326caa | 73 | #define KVM_NR_PAGE_SIZES 3 |
82855413 JR |
74 | #define KVM_HPAGE_GFN_SHIFT(x) (((x) - 1) * 9) |
75 | #define KVM_HPAGE_SHIFT(x) (PAGE_SHIFT + KVM_HPAGE_GFN_SHIFT(x)) | |
ec04b260 JR |
76 | #define KVM_HPAGE_SIZE(x) (1UL << KVM_HPAGE_SHIFT(x)) |
77 | #define KVM_HPAGE_MASK(x) (~(KVM_HPAGE_SIZE(x) - 1)) | |
78 | #define KVM_PAGES_PER_HPAGE(x) (KVM_HPAGE_SIZE(x) / PAGE_SIZE) | |
05da4558 | 79 | |
cd6e8f87 ZX |
80 | #define SELECTOR_TI_MASK (1 << 2) |
81 | #define SELECTOR_RPL_MASK 0x03 | |
82 | ||
83 | #define IOPL_SHIFT 12 | |
84 | ||
d657a98e ZX |
85 | #define KVM_PERMILLE_MMU_PAGES 20 |
86 | #define KVM_MIN_ALLOC_MMU_PAGES 64 | |
1ae0a13d DE |
87 | #define KVM_MMU_HASH_SHIFT 10 |
88 | #define KVM_NUM_MMU_PAGES (1 << KVM_MMU_HASH_SHIFT) | |
d657a98e ZX |
89 | #define KVM_MIN_FREE_MMU_PAGES 5 |
90 | #define KVM_REFILL_PAGES 25 | |
73c1160c | 91 | #define KVM_MAX_CPUID_ENTRIES 80 |
0bed3b56 | 92 | #define KVM_NR_FIXED_MTRR_REGION 88 |
9ba075a6 | 93 | #define KVM_NR_VAR_MTRR 8 |
d657a98e | 94 | |
af585b92 GN |
95 | #define ASYNC_PF_PER_VCPU 64 |
96 | ||
d657a98e ZX |
97 | struct kvm_vcpu; |
98 | struct kvm; | |
af585b92 | 99 | struct kvm_async_pf; |
d657a98e | 100 | |
5fdbf976 | 101 | enum kvm_reg { |
2b3ccfa0 ZX |
102 | VCPU_REGS_RAX = 0, |
103 | VCPU_REGS_RCX = 1, | |
104 | VCPU_REGS_RDX = 2, | |
105 | VCPU_REGS_RBX = 3, | |
106 | VCPU_REGS_RSP = 4, | |
107 | VCPU_REGS_RBP = 5, | |
108 | VCPU_REGS_RSI = 6, | |
109 | VCPU_REGS_RDI = 7, | |
110 | #ifdef CONFIG_X86_64 | |
111 | VCPU_REGS_R8 = 8, | |
112 | VCPU_REGS_R9 = 9, | |
113 | VCPU_REGS_R10 = 10, | |
114 | VCPU_REGS_R11 = 11, | |
115 | VCPU_REGS_R12 = 12, | |
116 | VCPU_REGS_R13 = 13, | |
117 | VCPU_REGS_R14 = 14, | |
118 | VCPU_REGS_R15 = 15, | |
119 | #endif | |
5fdbf976 | 120 | VCPU_REGS_RIP, |
2b3ccfa0 ZX |
121 | NR_VCPU_REGS |
122 | }; | |
123 | ||
6de4f3ad AK |
124 | enum kvm_reg_ex { |
125 | VCPU_EXREG_PDPTR = NR_VCPU_REGS, | |
aff48baa | 126 | VCPU_EXREG_CR3, |
6de12732 | 127 | VCPU_EXREG_RFLAGS, |
69c73028 | 128 | VCPU_EXREG_CPL, |
2fb92db1 | 129 | VCPU_EXREG_SEGMENTS, |
6de4f3ad AK |
130 | }; |
131 | ||
2b3ccfa0 | 132 | enum { |
81609e3e | 133 | VCPU_SREG_ES, |
2b3ccfa0 | 134 | VCPU_SREG_CS, |
81609e3e | 135 | VCPU_SREG_SS, |
2b3ccfa0 | 136 | VCPU_SREG_DS, |
2b3ccfa0 ZX |
137 | VCPU_SREG_FS, |
138 | VCPU_SREG_GS, | |
2b3ccfa0 ZX |
139 | VCPU_SREG_TR, |
140 | VCPU_SREG_LDTR, | |
141 | }; | |
142 | ||
56e82318 | 143 | #include <asm/kvm_emulate.h> |
2b3ccfa0 | 144 | |
d657a98e ZX |
145 | #define KVM_NR_MEM_OBJS 40 |
146 | ||
42dbaa5a JK |
147 | #define KVM_NR_DB_REGS 4 |
148 | ||
149 | #define DR6_BD (1 << 13) | |
150 | #define DR6_BS (1 << 14) | |
151 | #define DR6_FIXED_1 0xffff0ff0 | |
152 | #define DR6_VOLATILE 0x0000e00f | |
153 | ||
154 | #define DR7_BP_EN_MASK 0x000000ff | |
155 | #define DR7_GE (1 << 9) | |
156 | #define DR7_GD (1 << 13) | |
157 | #define DR7_FIXED_1 0x00000400 | |
158 | #define DR7_VOLATILE 0xffff23ff | |
159 | ||
41383771 GN |
160 | /* apic attention bits */ |
161 | #define KVM_APIC_CHECK_VAPIC 0 | |
ae7a2a3f MT |
162 | /* |
163 | * The following bit is set with PV-EOI, unset on EOI. | |
164 | * We detect PV-EOI changes by guest by comparing | |
165 | * this bit with PV-EOI in guest memory. | |
166 | * See the implementation in apic_update_pv_eoi. | |
167 | */ | |
168 | #define KVM_APIC_PV_EOI_PENDING 1 | |
41383771 | 169 | |
d657a98e ZX |
170 | /* |
171 | * We don't want allocation failures within the mmu code, so we preallocate | |
172 | * enough memory for a single page fault in a cache. | |
173 | */ | |
174 | struct kvm_mmu_memory_cache { | |
175 | int nobjs; | |
176 | void *objects[KVM_NR_MEM_OBJS]; | |
177 | }; | |
178 | ||
d657a98e ZX |
179 | /* |
180 | * kvm_mmu_page_role, below, is defined as: | |
181 | * | |
182 | * bits 0:3 - total guest paging levels (2-4, or zero for real mode) | |
183 | * bits 4:7 - page table level for this shadow (1-4) | |
184 | * bits 8:9 - page table quadrant for 2-level guests | |
f6e2c02b AK |
185 | * bit 16 - direct mapping of virtual to physical mapping at gfn |
186 | * used for real mode and two-dimensional paging | |
d657a98e ZX |
187 | * bits 17:19 - common access permissions for all ptes in this shadow page |
188 | */ | |
189 | union kvm_mmu_page_role { | |
190 | unsigned word; | |
191 | struct { | |
7d76b4d3 | 192 | unsigned level:4; |
5b7e0102 | 193 | unsigned cr4_pae:1; |
7d76b4d3 JP |
194 | unsigned quadrant:2; |
195 | unsigned pad_for_nice_hex_output:6; | |
f6e2c02b | 196 | unsigned direct:1; |
7d76b4d3 | 197 | unsigned access:3; |
2e53d63a | 198 | unsigned invalid:1; |
9645bb56 | 199 | unsigned nxe:1; |
3dbe1415 | 200 | unsigned cr0_wp:1; |
411c588d | 201 | unsigned smep_andnot_wp:1; |
d657a98e ZX |
202 | }; |
203 | }; | |
204 | ||
205 | struct kvm_mmu_page { | |
206 | struct list_head link; | |
207 | struct hlist_node hash_link; | |
208 | ||
209 | /* | |
210 | * The following two entries are used to key the shadow page in the | |
211 | * hash table. | |
212 | */ | |
213 | gfn_t gfn; | |
214 | union kvm_mmu_page_role role; | |
215 | ||
216 | u64 *spt; | |
217 | /* hold the gfn of each spte inside spt */ | |
218 | gfn_t *gfns; | |
4731d4c7 | 219 | bool unsync; |
0571d366 | 220 | int root_count; /* Currently serving as active root */ |
60c8aec6 | 221 | unsigned int unsync_children; |
67052b35 | 222 | unsigned long parent_ptes; /* Reverse mapping for parent_pte */ |
0074ff63 | 223 | DECLARE_BITMAP(unsync_child_bitmap, 512); |
c2a2ac2b XG |
224 | |
225 | #ifdef CONFIG_X86_32 | |
226 | int clear_spte_count; | |
227 | #endif | |
228 | ||
a30f47cb | 229 | int write_flooding_count; |
95b0430d | 230 | bool mmio_cached; |
d657a98e ZX |
231 | }; |
232 | ||
1c08364c AK |
233 | struct kvm_pio_request { |
234 | unsigned long count; | |
1c08364c AK |
235 | int in; |
236 | int port; | |
237 | int size; | |
1c08364c AK |
238 | }; |
239 | ||
d657a98e ZX |
240 | /* |
241 | * x86 supports 3 paging modes (4-level 64-bit, 3-level 64-bit, and 2-level | |
242 | * 32-bit). The kvm_mmu structure abstracts the details of the current mmu | |
243 | * mode. | |
244 | */ | |
245 | struct kvm_mmu { | |
246 | void (*new_cr3)(struct kvm_vcpu *vcpu); | |
f43addd4 | 247 | void (*set_cr3)(struct kvm_vcpu *vcpu, unsigned long root); |
5777ed34 | 248 | unsigned long (*get_cr3)(struct kvm_vcpu *vcpu); |
e4e517b4 | 249 | u64 (*get_pdptr)(struct kvm_vcpu *vcpu, int index); |
78b2c54a XG |
250 | int (*page_fault)(struct kvm_vcpu *vcpu, gva_t gva, u32 err, |
251 | bool prefault); | |
6389ee94 AK |
252 | void (*inject_page_fault)(struct kvm_vcpu *vcpu, |
253 | struct x86_exception *fault); | |
d657a98e | 254 | void (*free)(struct kvm_vcpu *vcpu); |
1871c602 | 255 | gpa_t (*gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t gva, u32 access, |
ab9ae313 | 256 | struct x86_exception *exception); |
c30a358d | 257 | gpa_t (*translate_gpa)(struct kvm_vcpu *vcpu, gpa_t gpa, u32 access); |
e8bc217a | 258 | int (*sync_page)(struct kvm_vcpu *vcpu, |
a4a8e6f7 | 259 | struct kvm_mmu_page *sp); |
a7052897 | 260 | void (*invlpg)(struct kvm_vcpu *vcpu, gva_t gva); |
0f53b5b1 | 261 | void (*update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, |
7c562522 | 262 | u64 *spte, const void *pte); |
d657a98e ZX |
263 | hpa_t root_hpa; |
264 | int root_level; | |
265 | int shadow_root_level; | |
a770f6f2 | 266 | union kvm_mmu_page_role base_role; |
c5a78f2b | 267 | bool direct_map; |
d657a98e | 268 | |
97d64b78 AK |
269 | /* |
270 | * Bitmap; bit set = permission fault | |
271 | * Byte index: page fault error code [4:1] | |
272 | * Bit index: pte permissions in ACC_* format | |
273 | */ | |
274 | u8 permissions[16]; | |
275 | ||
d657a98e | 276 | u64 *pae_root; |
81407ca5 | 277 | u64 *lm_root; |
82725b20 | 278 | u64 rsvd_bits_mask[2][4]; |
ff03a073 | 279 | |
6fd01b71 AK |
280 | /* |
281 | * Bitmap: bit set = last pte in walk | |
282 | * index[0:1]: level (zero-based) | |
283 | * index[2]: pte.ps | |
284 | */ | |
285 | u8 last_pte_bitmap; | |
286 | ||
2d48a985 JR |
287 | bool nx; |
288 | ||
ff03a073 | 289 | u64 pdptrs[4]; /* pae */ |
d657a98e ZX |
290 | }; |
291 | ||
f5132b01 GN |
292 | enum pmc_type { |
293 | KVM_PMC_GP = 0, | |
294 | KVM_PMC_FIXED, | |
295 | }; | |
296 | ||
297 | struct kvm_pmc { | |
298 | enum pmc_type type; | |
299 | u8 idx; | |
300 | u64 counter; | |
301 | u64 eventsel; | |
302 | struct perf_event *perf_event; | |
303 | struct kvm_vcpu *vcpu; | |
304 | }; | |
305 | ||
306 | struct kvm_pmu { | |
307 | unsigned nr_arch_gp_counters; | |
308 | unsigned nr_arch_fixed_counters; | |
309 | unsigned available_event_types; | |
310 | u64 fixed_ctr_ctrl; | |
311 | u64 global_ctrl; | |
312 | u64 global_status; | |
313 | u64 global_ovf_ctrl; | |
314 | u64 counter_bitmask[2]; | |
315 | u64 global_ctrl_mask; | |
316 | u8 version; | |
15c7ad51 RR |
317 | struct kvm_pmc gp_counters[INTEL_PMC_MAX_GENERIC]; |
318 | struct kvm_pmc fixed_counters[INTEL_PMC_MAX_FIXED]; | |
f5132b01 GN |
319 | struct irq_work irq_work; |
320 | u64 reprogram_pmi; | |
321 | }; | |
322 | ||
ad312c7c | 323 | struct kvm_vcpu_arch { |
5fdbf976 MT |
324 | /* |
325 | * rip and regs accesses must go through | |
326 | * kvm_{register,rip}_{read,write} functions. | |
327 | */ | |
328 | unsigned long regs[NR_VCPU_REGS]; | |
329 | u32 regs_avail; | |
330 | u32 regs_dirty; | |
34c16eec ZX |
331 | |
332 | unsigned long cr0; | |
e8467fda | 333 | unsigned long cr0_guest_owned_bits; |
34c16eec ZX |
334 | unsigned long cr2; |
335 | unsigned long cr3; | |
336 | unsigned long cr4; | |
fc78f519 | 337 | unsigned long cr4_guest_owned_bits; |
34c16eec | 338 | unsigned long cr8; |
1371d904 | 339 | u32 hflags; |
f6801dff | 340 | u64 efer; |
34c16eec ZX |
341 | u64 apic_base; |
342 | struct kvm_lapic *apic; /* kernel irqchip context */ | |
41383771 | 343 | unsigned long apic_attention; |
e1035715 | 344 | int32_t apic_arb_prio; |
34c16eec | 345 | int mp_state; |
34c16eec | 346 | u64 ia32_misc_enable_msr; |
b209749f | 347 | bool tpr_access_reporting; |
34c16eec | 348 | |
14dfe855 JR |
349 | /* |
350 | * Paging state of the vcpu | |
351 | * | |
352 | * If the vcpu runs in guest mode with two level paging this still saves | |
353 | * the paging mode of the l1 guest. This context is always used to | |
354 | * handle faults. | |
355 | */ | |
34c16eec | 356 | struct kvm_mmu mmu; |
8df25a32 | 357 | |
6539e738 JR |
358 | /* |
359 | * Paging state of an L2 guest (used for nested npt) | |
360 | * | |
361 | * This context will save all necessary information to walk page tables | |
362 | * of the an L2 guest. This context is only initialized for page table | |
363 | * walking and not for faulting since we never handle l2 page faults on | |
364 | * the host. | |
365 | */ | |
366 | struct kvm_mmu nested_mmu; | |
367 | ||
14dfe855 JR |
368 | /* |
369 | * Pointer to the mmu context currently used for | |
370 | * gva_to_gpa translations. | |
371 | */ | |
372 | struct kvm_mmu *walk_mmu; | |
373 | ||
53c07b18 | 374 | struct kvm_mmu_memory_cache mmu_pte_list_desc_cache; |
34c16eec ZX |
375 | struct kvm_mmu_memory_cache mmu_page_cache; |
376 | struct kvm_mmu_memory_cache mmu_page_header_cache; | |
377 | ||
98918833 | 378 | struct fpu guest_fpu; |
2acf923e | 379 | u64 xcr0; |
34c16eec | 380 | |
34c16eec ZX |
381 | struct kvm_pio_request pio; |
382 | void *pio_data; | |
383 | ||
66fd3f7f GN |
384 | u8 event_exit_inst_len; |
385 | ||
298101da AK |
386 | struct kvm_queued_exception { |
387 | bool pending; | |
388 | bool has_error_code; | |
ce7ddec4 | 389 | bool reinject; |
298101da AK |
390 | u8 nr; |
391 | u32 error_code; | |
392 | } exception; | |
393 | ||
937a7eae AK |
394 | struct kvm_queued_interrupt { |
395 | bool pending; | |
66fd3f7f | 396 | bool soft; |
937a7eae AK |
397 | u8 nr; |
398 | } interrupt; | |
399 | ||
34c16eec ZX |
400 | int halt_request; /* real mode on Intel only */ |
401 | ||
402 | int cpuid_nent; | |
07716717 | 403 | struct kvm_cpuid_entry2 cpuid_entries[KVM_MAX_CPUID_ENTRIES]; |
34c16eec ZX |
404 | /* emulate context */ |
405 | ||
406 | struct x86_emulate_ctxt emulate_ctxt; | |
7ae441ea GN |
407 | bool emulate_regs_need_sync_to_vcpu; |
408 | bool emulate_regs_need_sync_from_vcpu; | |
716d51ab | 409 | int (*complete_userspace_io)(struct kvm_vcpu *vcpu); |
18068523 GOC |
410 | |
411 | gpa_t time; | |
50d0a0f9 | 412 | struct pvclock_vcpu_time_info hv_clock; |
e48672fa | 413 | unsigned int hw_tsc_khz; |
0b79459b AH |
414 | struct gfn_to_hva_cache pv_time; |
415 | bool pv_time_enabled; | |
51d59c6b MT |
416 | /* set guest stopped flag in pvclock flags field */ |
417 | bool pvclock_set_guest_stopped_request; | |
c9aaa895 GC |
418 | |
419 | struct { | |
420 | u64 msr_val; | |
421 | u64 last_steal; | |
422 | u64 accum_steal; | |
423 | struct gfn_to_hva_cache stime; | |
424 | struct kvm_steal_time steal; | |
425 | } st; | |
426 | ||
1d5f066e ZA |
427 | u64 last_guest_tsc; |
428 | u64 last_kernel_ns; | |
6f526ec5 | 429 | u64 last_host_tsc; |
0dd6a6ed | 430 | u64 tsc_offset_adjustment; |
e26101b1 ZA |
431 | u64 this_tsc_nsec; |
432 | u64 this_tsc_write; | |
433 | u8 this_tsc_generation; | |
c285545f | 434 | bool tsc_catchup; |
cc578287 ZA |
435 | bool tsc_always_catchup; |
436 | s8 virtual_tsc_shift; | |
437 | u32 virtual_tsc_mult; | |
438 | u32 virtual_tsc_khz; | |
ba904635 | 439 | s64 ia32_tsc_adjust_msr; |
3419ffc8 | 440 | |
7460fb4a AK |
441 | atomic_t nmi_queued; /* unprocessed asynchronous NMIs */ |
442 | unsigned nmi_pending; /* NMI queued after currently running handler */ | |
443 | bool nmi_injected; /* Trying to inject an NMI this entry */ | |
9ba075a6 | 444 | |
0bed3b56 SY |
445 | struct mtrr_state_type mtrr_state; |
446 | u32 pat; | |
42dbaa5a JK |
447 | |
448 | int switch_db_regs; | |
42dbaa5a JK |
449 | unsigned long db[KVM_NR_DB_REGS]; |
450 | unsigned long dr6; | |
451 | unsigned long dr7; | |
452 | unsigned long eff_db[KVM_NR_DB_REGS]; | |
c8639010 | 453 | unsigned long guest_debug_dr7; |
890ca9ae HY |
454 | |
455 | u64 mcg_cap; | |
456 | u64 mcg_status; | |
457 | u64 mcg_ctl; | |
458 | u64 *mce_banks; | |
94fe45da | 459 | |
bebb106a XG |
460 | /* Cache MMIO info */ |
461 | u64 mmio_gva; | |
462 | unsigned access; | |
463 | gfn_t mmio_gfn; | |
464 | ||
f5132b01 GN |
465 | struct kvm_pmu pmu; |
466 | ||
94fe45da | 467 | /* used for guest single stepping over the given code position */ |
94fe45da | 468 | unsigned long singlestep_rip; |
f92653ee | 469 | |
10388a07 GN |
470 | /* fields used by HYPER-V emulation */ |
471 | u64 hv_vapic; | |
f5f48ee1 SY |
472 | |
473 | cpumask_var_t wbinvd_dirty_mask; | |
af585b92 | 474 | |
1cb3f3ae XG |
475 | unsigned long last_retry_eip; |
476 | unsigned long last_retry_addr; | |
477 | ||
af585b92 GN |
478 | struct { |
479 | bool halted; | |
480 | gfn_t gfns[roundup_pow_of_two(ASYNC_PF_PER_VCPU)]; | |
344d9588 GN |
481 | struct gfn_to_hva_cache data; |
482 | u64 msr_val; | |
7c90705b | 483 | u32 id; |
6adba527 | 484 | bool send_user_only; |
af585b92 | 485 | } apf; |
2b036c6b BO |
486 | |
487 | /* OSVW MSRs (AMD only) */ | |
488 | struct { | |
489 | u64 length; | |
490 | u64 status; | |
491 | } osvw; | |
ae7a2a3f MT |
492 | |
493 | struct { | |
494 | u64 msr_val; | |
495 | struct gfn_to_hva_cache data; | |
496 | } pv_eoi; | |
93c05d3e XG |
497 | |
498 | /* | |
499 | * Indicate whether the access faults on its page table in guest | |
500 | * which is set when fix page fault and used to detect unhandeable | |
501 | * instruction. | |
502 | */ | |
503 | bool write_fault_to_shadow_pgtable; | |
34c16eec ZX |
504 | }; |
505 | ||
db3fe4eb | 506 | struct kvm_lpage_info { |
db3fe4eb TY |
507 | int write_count; |
508 | }; | |
509 | ||
510 | struct kvm_arch_memory_slot { | |
d89cc617 | 511 | unsigned long *rmap[KVM_NR_PAGE_SIZES]; |
db3fe4eb TY |
512 | struct kvm_lpage_info *lpage_info[KVM_NR_PAGE_SIZES - 1]; |
513 | }; | |
514 | ||
1e08ec4a GN |
515 | struct kvm_apic_map { |
516 | struct rcu_head rcu; | |
517 | u8 ldr_bits; | |
518 | /* fields bellow are used to decode ldr values in different modes */ | |
519 | u32 cid_shift, cid_mask, lid_mask; | |
520 | struct kvm_lapic *phys_map[256]; | |
521 | /* first index is cluster id second is cpu id in a cluster */ | |
522 | struct kvm_lapic *logical_map[16][16]; | |
523 | }; | |
524 | ||
fef9cce0 | 525 | struct kvm_arch { |
49d5ca26 | 526 | unsigned int n_used_mmu_pages; |
f05e70ac | 527 | unsigned int n_requested_mmu_pages; |
39de71ec | 528 | unsigned int n_max_mmu_pages; |
332b207d | 529 | unsigned int indirect_shadow_pages; |
f05e70ac ZX |
530 | struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES]; |
531 | /* | |
532 | * Hash table of struct kvm_mmu_page. | |
533 | */ | |
534 | struct list_head active_mmu_pages; | |
4d5c5d0f | 535 | struct list_head assigned_dev_head; |
19de40a8 | 536 | struct iommu_domain *iommu_domain; |
522c68c4 | 537 | int iommu_flags; |
d7deeeb0 ZX |
538 | struct kvm_pic *vpic; |
539 | struct kvm_ioapic *vioapic; | |
7837699f | 540 | struct kvm_pit *vpit; |
cc6e462c | 541 | int vapics_in_nmi_mode; |
1e08ec4a GN |
542 | struct mutex apic_map_lock; |
543 | struct kvm_apic_map *apic_map; | |
bfc6d222 | 544 | |
bfc6d222 ZX |
545 | unsigned int tss_addr; |
546 | struct page *apic_access_page; | |
18068523 GOC |
547 | |
548 | gpa_t wall_clock; | |
b7ebfb05 SY |
549 | |
550 | struct page *ept_identity_pagetable; | |
551 | bool ept_identity_pagetable_done; | |
b927a3ce | 552 | gpa_t ept_identity_map_addr; |
5550af4d SY |
553 | |
554 | unsigned long irq_sources_bitmap; | |
afbcf7ab | 555 | s64 kvmclock_offset; |
038f8c11 | 556 | raw_spinlock_t tsc_write_lock; |
f38e098f | 557 | u64 last_tsc_nsec; |
f38e098f | 558 | u64 last_tsc_write; |
5d3cb0f6 | 559 | u32 last_tsc_khz; |
e26101b1 ZA |
560 | u64 cur_tsc_nsec; |
561 | u64 cur_tsc_write; | |
562 | u64 cur_tsc_offset; | |
563 | u8 cur_tsc_generation; | |
b48aa97e | 564 | int nr_vcpus_matched_tsc; |
ffde22ac | 565 | |
d828199e MT |
566 | spinlock_t pvclock_gtod_sync_lock; |
567 | bool use_master_clock; | |
568 | u64 master_kernel_ns; | |
569 | cycle_t master_cycle_now; | |
570 | ||
ffde22ac | 571 | struct kvm_xen_hvm_config xen_hvm_config; |
55cd8e5a GN |
572 | |
573 | /* fields used by HYPER-V emulation */ | |
574 | u64 hv_guest_os_id; | |
575 | u64 hv_hypercall; | |
b034cf01 XG |
576 | |
577 | #ifdef CONFIG_KVM_MMU_AUDIT | |
578 | int audit_point; | |
579 | #endif | |
d69fb81f ZX |
580 | }; |
581 | ||
0711456c ZX |
582 | struct kvm_vm_stat { |
583 | u32 mmu_shadow_zapped; | |
584 | u32 mmu_pte_write; | |
585 | u32 mmu_pte_updated; | |
586 | u32 mmu_pde_zapped; | |
587 | u32 mmu_flooded; | |
588 | u32 mmu_recycled; | |
dfc5aa00 | 589 | u32 mmu_cache_miss; |
4731d4c7 | 590 | u32 mmu_unsync; |
0711456c | 591 | u32 remote_tlb_flush; |
05da4558 | 592 | u32 lpages; |
0711456c ZX |
593 | }; |
594 | ||
77b4c255 ZX |
595 | struct kvm_vcpu_stat { |
596 | u32 pf_fixed; | |
597 | u32 pf_guest; | |
598 | u32 tlb_flush; | |
599 | u32 invlpg; | |
600 | ||
601 | u32 exits; | |
602 | u32 io_exits; | |
603 | u32 mmio_exits; | |
604 | u32 signal_exits; | |
605 | u32 irq_window_exits; | |
f08864b4 | 606 | u32 nmi_window_exits; |
77b4c255 ZX |
607 | u32 halt_exits; |
608 | u32 halt_wakeup; | |
609 | u32 request_irq_exits; | |
610 | u32 irq_exits; | |
611 | u32 host_state_reload; | |
612 | u32 efer_reload; | |
613 | u32 fpu_reload; | |
614 | u32 insn_emulation; | |
615 | u32 insn_emulation_fail; | |
f11c3a8d | 616 | u32 hypercalls; |
fa89a817 | 617 | u32 irq_injections; |
c4abb7c9 | 618 | u32 nmi_injections; |
77b4c255 | 619 | }; |
ad312c7c | 620 | |
8a76d7f2 JR |
621 | struct x86_instruction_info; |
622 | ||
8fe8ab46 WA |
623 | struct msr_data { |
624 | bool host_initiated; | |
625 | u32 index; | |
626 | u64 data; | |
627 | }; | |
628 | ||
ea4a5ff8 ZX |
629 | struct kvm_x86_ops { |
630 | int (*cpu_has_kvm_support)(void); /* __init */ | |
631 | int (*disabled_by_bios)(void); /* __init */ | |
10474ae8 | 632 | int (*hardware_enable)(void *dummy); |
ea4a5ff8 ZX |
633 | void (*hardware_disable)(void *dummy); |
634 | void (*check_processor_compatibility)(void *rtn); | |
635 | int (*hardware_setup)(void); /* __init */ | |
636 | void (*hardware_unsetup)(void); /* __exit */ | |
774ead3a | 637 | bool (*cpu_has_accelerated_tpr)(void); |
0e851880 | 638 | void (*cpuid_update)(struct kvm_vcpu *vcpu); |
ea4a5ff8 ZX |
639 | |
640 | /* Create, but do not attach this VCPU */ | |
641 | struct kvm_vcpu *(*vcpu_create)(struct kvm *kvm, unsigned id); | |
642 | void (*vcpu_free)(struct kvm_vcpu *vcpu); | |
57f252f2 | 643 | void (*vcpu_reset)(struct kvm_vcpu *vcpu); |
ea4a5ff8 ZX |
644 | |
645 | void (*prepare_guest_switch)(struct kvm_vcpu *vcpu); | |
646 | void (*vcpu_load)(struct kvm_vcpu *vcpu, int cpu); | |
647 | void (*vcpu_put)(struct kvm_vcpu *vcpu); | |
ea4a5ff8 | 648 | |
c8639010 | 649 | void (*update_db_bp_intercept)(struct kvm_vcpu *vcpu); |
ea4a5ff8 | 650 | int (*get_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata); |
8fe8ab46 | 651 | int (*set_msr)(struct kvm_vcpu *vcpu, struct msr_data *msr); |
ea4a5ff8 ZX |
652 | u64 (*get_segment_base)(struct kvm_vcpu *vcpu, int seg); |
653 | void (*get_segment)(struct kvm_vcpu *vcpu, | |
654 | struct kvm_segment *var, int seg); | |
2e4d2653 | 655 | int (*get_cpl)(struct kvm_vcpu *vcpu); |
ea4a5ff8 ZX |
656 | void (*set_segment)(struct kvm_vcpu *vcpu, |
657 | struct kvm_segment *var, int seg); | |
658 | void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l); | |
e8467fda | 659 | void (*decache_cr0_guest_bits)(struct kvm_vcpu *vcpu); |
aff48baa | 660 | void (*decache_cr3)(struct kvm_vcpu *vcpu); |
ea4a5ff8 ZX |
661 | void (*decache_cr4_guest_bits)(struct kvm_vcpu *vcpu); |
662 | void (*set_cr0)(struct kvm_vcpu *vcpu, unsigned long cr0); | |
663 | void (*set_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3); | |
5e1746d6 | 664 | int (*set_cr4)(struct kvm_vcpu *vcpu, unsigned long cr4); |
ea4a5ff8 | 665 | void (*set_efer)(struct kvm_vcpu *vcpu, u64 efer); |
89a27f4d GN |
666 | void (*get_idt)(struct kvm_vcpu *vcpu, struct desc_ptr *dt); |
667 | void (*set_idt)(struct kvm_vcpu *vcpu, struct desc_ptr *dt); | |
668 | void (*get_gdt)(struct kvm_vcpu *vcpu, struct desc_ptr *dt); | |
669 | void (*set_gdt)(struct kvm_vcpu *vcpu, struct desc_ptr *dt); | |
020df079 | 670 | void (*set_dr7)(struct kvm_vcpu *vcpu, unsigned long value); |
5fdbf976 | 671 | void (*cache_reg)(struct kvm_vcpu *vcpu, enum kvm_reg reg); |
ea4a5ff8 ZX |
672 | unsigned long (*get_rflags)(struct kvm_vcpu *vcpu); |
673 | void (*set_rflags)(struct kvm_vcpu *vcpu, unsigned long rflags); | |
6b52d186 | 674 | void (*fpu_activate)(struct kvm_vcpu *vcpu); |
02daab21 | 675 | void (*fpu_deactivate)(struct kvm_vcpu *vcpu); |
ea4a5ff8 ZX |
676 | |
677 | void (*tlb_flush)(struct kvm_vcpu *vcpu); | |
ea4a5ff8 | 678 | |
851ba692 AK |
679 | void (*run)(struct kvm_vcpu *vcpu); |
680 | int (*handle_exit)(struct kvm_vcpu *vcpu); | |
ea4a5ff8 | 681 | void (*skip_emulated_instruction)(struct kvm_vcpu *vcpu); |
2809f5d2 GC |
682 | void (*set_interrupt_shadow)(struct kvm_vcpu *vcpu, int mask); |
683 | u32 (*get_interrupt_shadow)(struct kvm_vcpu *vcpu, int mask); | |
ea4a5ff8 ZX |
684 | void (*patch_hypercall)(struct kvm_vcpu *vcpu, |
685 | unsigned char *hypercall_addr); | |
66fd3f7f | 686 | void (*set_irq)(struct kvm_vcpu *vcpu); |
95ba8273 | 687 | void (*set_nmi)(struct kvm_vcpu *vcpu); |
298101da | 688 | void (*queue_exception)(struct kvm_vcpu *vcpu, unsigned nr, |
ce7ddec4 JR |
689 | bool has_error_code, u32 error_code, |
690 | bool reinject); | |
b463a6f7 | 691 | void (*cancel_injection)(struct kvm_vcpu *vcpu); |
78646121 | 692 | int (*interrupt_allowed)(struct kvm_vcpu *vcpu); |
95ba8273 | 693 | int (*nmi_allowed)(struct kvm_vcpu *vcpu); |
3cfc3092 JK |
694 | bool (*get_nmi_mask)(struct kvm_vcpu *vcpu); |
695 | void (*set_nmi_mask)(struct kvm_vcpu *vcpu, bool masked); | |
95ba8273 GN |
696 | void (*enable_nmi_window)(struct kvm_vcpu *vcpu); |
697 | void (*enable_irq_window)(struct kvm_vcpu *vcpu); | |
698 | void (*update_cr8_intercept)(struct kvm_vcpu *vcpu, int tpr, int irr); | |
c7c9c56c YZ |
699 | int (*vm_has_apicv)(struct kvm *kvm); |
700 | void (*hwapic_irr_update)(struct kvm_vcpu *vcpu, int max_irr); | |
701 | void (*hwapic_isr_update)(struct kvm *kvm, int isr); | |
702 | void (*load_eoi_exitmap)(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap); | |
8d14695f | 703 | void (*set_virtual_x2apic_mode)(struct kvm_vcpu *vcpu, bool set); |
a20ed54d YZ |
704 | void (*deliver_posted_interrupt)(struct kvm_vcpu *vcpu, int vector); |
705 | void (*sync_pir_to_irr)(struct kvm_vcpu *vcpu); | |
ea4a5ff8 | 706 | int (*set_tss_addr)(struct kvm *kvm, unsigned int addr); |
67253af5 | 707 | int (*get_tdp_level)(void); |
4b12f0de | 708 | u64 (*get_mt_mask)(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio); |
17cc3935 | 709 | int (*get_lpage_level)(void); |
4e47c7a6 | 710 | bool (*rdtscp_supported)(void); |
ad756a16 | 711 | bool (*invpcid_supported)(void); |
f1e2b260 | 712 | void (*adjust_tsc_offset)(struct kvm_vcpu *vcpu, s64 adjustment, bool host); |
344f414f | 713 | |
1c97f0a0 JR |
714 | void (*set_tdp_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3); |
715 | ||
d4330ef2 JR |
716 | void (*set_supported_cpuid)(u32 func, struct kvm_cpuid_entry2 *entry); |
717 | ||
f5f48ee1 SY |
718 | bool (*has_wbinvd_exit)(void); |
719 | ||
cc578287 | 720 | void (*set_tsc_khz)(struct kvm_vcpu *vcpu, u32 user_tsc_khz, bool scale); |
ba904635 | 721 | u64 (*read_tsc_offset)(struct kvm_vcpu *vcpu); |
99e3e30a ZA |
722 | void (*write_tsc_offset)(struct kvm_vcpu *vcpu, u64 offset); |
723 | ||
857e4099 | 724 | u64 (*compute_tsc_offset)(struct kvm_vcpu *vcpu, u64 target_tsc); |
886b470c | 725 | u64 (*read_l1_tsc)(struct kvm_vcpu *vcpu, u64 host_tsc); |
857e4099 | 726 | |
586f9607 | 727 | void (*get_exit_info)(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2); |
8a76d7f2 JR |
728 | |
729 | int (*check_intercept)(struct kvm_vcpu *vcpu, | |
730 | struct x86_instruction_info *info, | |
731 | enum x86_intercept_stage stage); | |
a547c6db | 732 | void (*handle_external_intr)(struct kvm_vcpu *vcpu); |
ea4a5ff8 ZX |
733 | }; |
734 | ||
af585b92 | 735 | struct kvm_arch_async_pf { |
7c90705b | 736 | u32 token; |
af585b92 | 737 | gfn_t gfn; |
fb67e14f | 738 | unsigned long cr3; |
c4806acd | 739 | bool direct_map; |
af585b92 GN |
740 | }; |
741 | ||
97896d04 ZX |
742 | extern struct kvm_x86_ops *kvm_x86_ops; |
743 | ||
f1e2b260 MT |
744 | static inline void adjust_tsc_offset_guest(struct kvm_vcpu *vcpu, |
745 | s64 adjustment) | |
746 | { | |
747 | kvm_x86_ops->adjust_tsc_offset(vcpu, adjustment, false); | |
748 | } | |
749 | ||
750 | static inline void adjust_tsc_offset_host(struct kvm_vcpu *vcpu, s64 adjustment) | |
751 | { | |
752 | kvm_x86_ops->adjust_tsc_offset(vcpu, adjustment, true); | |
753 | } | |
754 | ||
54f1585a ZX |
755 | int kvm_mmu_module_init(void); |
756 | void kvm_mmu_module_exit(void); | |
757 | ||
758 | void kvm_mmu_destroy(struct kvm_vcpu *vcpu); | |
759 | int kvm_mmu_create(struct kvm_vcpu *vcpu); | |
760 | int kvm_mmu_setup(struct kvm_vcpu *vcpu); | |
7b52345e | 761 | void kvm_mmu_set_mask_ptes(u64 user_mask, u64 accessed_mask, |
4b12f0de | 762 | u64 dirty_mask, u64 nx_mask, u64 x_mask); |
54f1585a ZX |
763 | |
764 | int kvm_mmu_reset_context(struct kvm_vcpu *vcpu); | |
765 | void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot); | |
5dc99b23 TY |
766 | void kvm_mmu_write_protect_pt_masked(struct kvm *kvm, |
767 | struct kvm_memory_slot *slot, | |
768 | gfn_t gfn_offset, unsigned long mask); | |
54f1585a | 769 | void kvm_mmu_zap_all(struct kvm *kvm); |
982b3394 | 770 | void kvm_mmu_zap_mmio_sptes(struct kvm *kvm); |
3ad82a7e | 771 | unsigned int kvm_mmu_calculate_mmu_pages(struct kvm *kvm); |
54f1585a ZX |
772 | void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages); |
773 | ||
ff03a073 | 774 | int load_pdptrs(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, unsigned long cr3); |
cc4b6871 | 775 | |
3200f405 | 776 | int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa, |
9f811285 | 777 | const void *val, int bytes); |
4b12f0de | 778 | u8 kvm_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn); |
2f333bcb MT |
779 | |
780 | extern bool tdp_enabled; | |
9f811285 | 781 | |
a3e06bbe LJ |
782 | u64 vcpu_tsc_khz(struct kvm_vcpu *vcpu); |
783 | ||
92a1f12d JR |
784 | /* control of guest tsc rate supported? */ |
785 | extern bool kvm_has_tsc_control; | |
786 | /* minimum supported tsc_khz for guests */ | |
787 | extern u32 kvm_min_guest_tsc_khz; | |
788 | /* maximum supported tsc_khz for guests */ | |
789 | extern u32 kvm_max_guest_tsc_khz; | |
790 | ||
54f1585a ZX |
791 | enum emulation_result { |
792 | EMULATE_DONE, /* no further processing */ | |
793 | EMULATE_DO_MMIO, /* kvm_run filled with mmio request */ | |
794 | EMULATE_FAIL, /* can't emulate this instruction */ | |
795 | }; | |
796 | ||
571008da SY |
797 | #define EMULTYPE_NO_DECODE (1 << 0) |
798 | #define EMULTYPE_TRAP_UD (1 << 1) | |
ba8afb6b | 799 | #define EMULTYPE_SKIP (1 << 2) |
1cb3f3ae | 800 | #define EMULTYPE_RETRY (1 << 3) |
991eebf9 | 801 | #define EMULTYPE_NO_REEXECUTE (1 << 4) |
dc25e89e AP |
802 | int x86_emulate_instruction(struct kvm_vcpu *vcpu, unsigned long cr2, |
803 | int emulation_type, void *insn, int insn_len); | |
51d8b661 AP |
804 | |
805 | static inline int emulate_instruction(struct kvm_vcpu *vcpu, | |
806 | int emulation_type) | |
807 | { | |
dc25e89e | 808 | return x86_emulate_instruction(vcpu, 0, emulation_type, NULL, 0); |
51d8b661 AP |
809 | } |
810 | ||
f2b4b7dd | 811 | void kvm_enable_efer_bits(u64); |
384bb783 | 812 | bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer); |
54f1585a | 813 | int kvm_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *data); |
8fe8ab46 | 814 | int kvm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr); |
54f1585a ZX |
815 | |
816 | struct x86_emulate_ctxt; | |
817 | ||
cf8f70bf | 818 | int kvm_fast_pio_out(struct kvm_vcpu *vcpu, int size, unsigned short port); |
54f1585a ZX |
819 | void kvm_emulate_cpuid(struct kvm_vcpu *vcpu); |
820 | int kvm_emulate_halt(struct kvm_vcpu *vcpu); | |
f5f48ee1 | 821 | int kvm_emulate_wbinvd(struct kvm_vcpu *vcpu); |
54f1585a | 822 | |
3e6e0aab | 823 | void kvm_get_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg); |
c697518a | 824 | int kvm_load_segment_descriptor(struct kvm_vcpu *vcpu, u16 selector, int seg); |
66450a21 | 825 | void kvm_vcpu_deliver_sipi_vector(struct kvm_vcpu *vcpu, unsigned int vector); |
3e6e0aab | 826 | |
7f3d35fd KW |
827 | int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int idt_index, |
828 | int reason, bool has_error_code, u32 error_code); | |
37817f29 | 829 | |
49a9b07e | 830 | int kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0); |
2390218b | 831 | int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3); |
a83b29c6 | 832 | int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4); |
eea1cff9 | 833 | int kvm_set_cr8(struct kvm_vcpu *vcpu, unsigned long cr8); |
020df079 GN |
834 | int kvm_set_dr(struct kvm_vcpu *vcpu, int dr, unsigned long val); |
835 | int kvm_get_dr(struct kvm_vcpu *vcpu, int dr, unsigned long *val); | |
2d3ad1f4 AK |
836 | unsigned long kvm_get_cr8(struct kvm_vcpu *vcpu); |
837 | void kvm_lmsw(struct kvm_vcpu *vcpu, unsigned long msw); | |
54f1585a | 838 | void kvm_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l); |
2acf923e | 839 | int kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr); |
54f1585a ZX |
840 | |
841 | int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata); | |
8fe8ab46 | 842 | int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr); |
54f1585a | 843 | |
91586a3b JK |
844 | unsigned long kvm_get_rflags(struct kvm_vcpu *vcpu); |
845 | void kvm_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags); | |
022cd0e8 | 846 | bool kvm_rdpmc(struct kvm_vcpu *vcpu); |
91586a3b | 847 | |
298101da AK |
848 | void kvm_queue_exception(struct kvm_vcpu *vcpu, unsigned nr); |
849 | void kvm_queue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code); | |
ce7ddec4 JR |
850 | void kvm_requeue_exception(struct kvm_vcpu *vcpu, unsigned nr); |
851 | void kvm_requeue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code); | |
6389ee94 | 852 | void kvm_inject_page_fault(struct kvm_vcpu *vcpu, struct x86_exception *fault); |
ec92fe44 JR |
853 | int kvm_read_guest_page_mmu(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, |
854 | gfn_t gfn, void *data, int offset, int len, | |
855 | u32 access); | |
6389ee94 | 856 | void kvm_propagate_fault(struct kvm_vcpu *vcpu, struct x86_exception *fault); |
0a79b009 | 857 | bool kvm_require_cpl(struct kvm_vcpu *vcpu, int required_cpl); |
298101da | 858 | |
1a577b72 MT |
859 | static inline int __kvm_irq_line_state(unsigned long *irq_state, |
860 | int irq_source_id, int level) | |
861 | { | |
862 | /* Logical OR for level trig interrupt */ | |
863 | if (level) | |
864 | __set_bit(irq_source_id, irq_state); | |
865 | else | |
866 | __clear_bit(irq_source_id, irq_state); | |
867 | ||
868 | return !!(*irq_state); | |
869 | } | |
870 | ||
871 | int kvm_pic_set_irq(struct kvm_pic *pic, int irq, int irq_source_id, int level); | |
872 | void kvm_pic_clear_all(struct kvm_pic *pic, int irq_source_id); | |
3de42dc0 | 873 | |
3419ffc8 SY |
874 | void kvm_inject_nmi(struct kvm_vcpu *vcpu); |
875 | ||
10ab25cd | 876 | int fx_init(struct kvm_vcpu *vcpu); |
54f1585a | 877 | |
d835dfec | 878 | void kvm_mmu_flush_tlb(struct kvm_vcpu *vcpu); |
54f1585a | 879 | void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa, |
f57f2ef5 | 880 | const u8 *new, int bytes); |
1cb3f3ae | 881 | int kvm_mmu_unprotect_page(struct kvm *kvm, gfn_t gfn); |
54f1585a ZX |
882 | int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva); |
883 | void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu); | |
884 | int kvm_mmu_load(struct kvm_vcpu *vcpu); | |
885 | void kvm_mmu_unload(struct kvm_vcpu *vcpu); | |
0ba73cda | 886 | void kvm_mmu_sync_roots(struct kvm_vcpu *vcpu); |
e459e322 | 887 | gpa_t translate_nested_gpa(struct kvm_vcpu *vcpu, gpa_t gpa, u32 access); |
ab9ae313 AK |
888 | gpa_t kvm_mmu_gva_to_gpa_read(struct kvm_vcpu *vcpu, gva_t gva, |
889 | struct x86_exception *exception); | |
890 | gpa_t kvm_mmu_gva_to_gpa_fetch(struct kvm_vcpu *vcpu, gva_t gva, | |
891 | struct x86_exception *exception); | |
892 | gpa_t kvm_mmu_gva_to_gpa_write(struct kvm_vcpu *vcpu, gva_t gva, | |
893 | struct x86_exception *exception); | |
894 | gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva, | |
895 | struct x86_exception *exception); | |
54f1585a ZX |
896 | |
897 | int kvm_emulate_hypercall(struct kvm_vcpu *vcpu); | |
898 | ||
dc25e89e AP |
899 | int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva, u32 error_code, |
900 | void *insn, int insn_len); | |
a7052897 | 901 | void kvm_mmu_invlpg(struct kvm_vcpu *vcpu, gva_t gva); |
34c16eec | 902 | |
18552672 | 903 | void kvm_enable_tdp(void); |
5f4cb662 | 904 | void kvm_disable_tdp(void); |
18552672 | 905 | |
de7d789a | 906 | int complete_pio(struct kvm_vcpu *vcpu); |
f850e2e6 | 907 | bool kvm_check_iopl(struct kvm_vcpu *vcpu); |
ec6d273d | 908 | |
e459e322 XG |
909 | static inline gpa_t translate_gpa(struct kvm_vcpu *vcpu, gpa_t gpa, u32 access) |
910 | { | |
911 | return gpa; | |
912 | } | |
913 | ||
ec6d273d ZX |
914 | static inline struct kvm_mmu_page *page_header(hpa_t shadow_page) |
915 | { | |
916 | struct page *page = pfn_to_page(shadow_page >> PAGE_SHIFT); | |
917 | ||
918 | return (struct kvm_mmu_page *)page_private(page); | |
919 | } | |
920 | ||
d6e88aec | 921 | static inline u16 kvm_read_ldt(void) |
ec6d273d ZX |
922 | { |
923 | u16 ldt; | |
924 | asm("sldt %0" : "=g"(ldt)); | |
925 | return ldt; | |
926 | } | |
927 | ||
d6e88aec | 928 | static inline void kvm_load_ldt(u16 sel) |
ec6d273d ZX |
929 | { |
930 | asm("lldt %0" : : "rm"(sel)); | |
931 | } | |
ec6d273d | 932 | |
ec6d273d ZX |
933 | #ifdef CONFIG_X86_64 |
934 | static inline unsigned long read_msr(unsigned long msr) | |
935 | { | |
936 | u64 value; | |
937 | ||
938 | rdmsrl(msr, value); | |
939 | return value; | |
940 | } | |
941 | #endif | |
942 | ||
ec6d273d ZX |
943 | static inline u32 get_rdx_init_val(void) |
944 | { | |
945 | return 0x600; /* P6 family */ | |
946 | } | |
947 | ||
c1a5d4f9 AK |
948 | static inline void kvm_inject_gp(struct kvm_vcpu *vcpu, u32 error_code) |
949 | { | |
950 | kvm_queue_exception_e(vcpu, GP_VECTOR, error_code); | |
951 | } | |
952 | ||
ec6d273d ZX |
953 | #define TSS_IOPB_BASE_OFFSET 0x66 |
954 | #define TSS_BASE_SIZE 0x68 | |
955 | #define TSS_IOPB_SIZE (65536 / 8) | |
956 | #define TSS_REDIRECTION_SIZE (256 / 8) | |
7d76b4d3 JP |
957 | #define RMODE_TSS_SIZE \ |
958 | (TSS_BASE_SIZE + TSS_REDIRECTION_SIZE + TSS_IOPB_SIZE + 1) | |
53e0aa7b | 959 | |
37817f29 IE |
960 | enum { |
961 | TASK_SWITCH_CALL = 0, | |
962 | TASK_SWITCH_IRET = 1, | |
963 | TASK_SWITCH_JMP = 2, | |
964 | TASK_SWITCH_GATE = 3, | |
965 | }; | |
966 | ||
1371d904 | 967 | #define HF_GIF_MASK (1 << 0) |
3d6368ef AG |
968 | #define HF_HIF_MASK (1 << 1) |
969 | #define HF_VINTR_MASK (1 << 2) | |
95ba8273 | 970 | #define HF_NMI_MASK (1 << 3) |
44c11430 | 971 | #define HF_IRET_MASK (1 << 4) |
ec9e60b2 | 972 | #define HF_GUEST_MASK (1 << 5) /* VCPU is in guest-mode */ |
1371d904 | 973 | |
4ecac3fd AK |
974 | /* |
975 | * Hardware virtualization extension instructions may fault if a | |
976 | * reboot turns off virtualization while processes are running. | |
977 | * Trap the fault and ignore the instruction if that happens. | |
978 | */ | |
b7c4145b | 979 | asmlinkage void kvm_spurious_fault(void); |
4ecac3fd | 980 | |
5e520e62 | 981 | #define ____kvm_handle_fault_on_reboot(insn, cleanup_insn) \ |
4ecac3fd | 982 | "666: " insn "\n\t" \ |
b7c4145b | 983 | "668: \n\t" \ |
18b13e54 | 984 | ".pushsection .fixup, \"ax\" \n" \ |
4ecac3fd | 985 | "667: \n\t" \ |
5e520e62 | 986 | cleanup_insn "\n\t" \ |
b7c4145b AK |
987 | "cmpb $0, kvm_rebooting \n\t" \ |
988 | "jne 668b \n\t" \ | |
8ceed347 | 989 | __ASM_SIZE(push) " $666b \n\t" \ |
b7c4145b | 990 | "call kvm_spurious_fault \n\t" \ |
4ecac3fd | 991 | ".popsection \n\t" \ |
3ee89722 | 992 | _ASM_EXTABLE(666b, 667b) |
4ecac3fd | 993 | |
5e520e62 AK |
994 | #define __kvm_handle_fault_on_reboot(insn) \ |
995 | ____kvm_handle_fault_on_reboot(insn, "") | |
996 | ||
e930bffe AA |
997 | #define KVM_ARCH_WANT_MMU_NOTIFIER |
998 | int kvm_unmap_hva(struct kvm *kvm, unsigned long hva); | |
b3ae2096 | 999 | int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end); |
e930bffe | 1000 | int kvm_age_hva(struct kvm *kvm, unsigned long hva); |
8ee53820 | 1001 | int kvm_test_age_hva(struct kvm *kvm, unsigned long hva); |
3da0dd43 | 1002 | void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); |
82725b20 | 1003 | int cpuid_maxphyaddr(struct kvm_vcpu *vcpu); |
c7c9c56c | 1004 | int kvm_cpu_has_injectable_intr(struct kvm_vcpu *v); |
a1b37100 GN |
1005 | int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu); |
1006 | int kvm_arch_interrupt_allowed(struct kvm_vcpu *vcpu); | |
0b71785d | 1007 | int kvm_cpu_get_interrupt(struct kvm_vcpu *v); |
66450a21 | 1008 | void kvm_vcpu_reset(struct kvm_vcpu *vcpu); |
e930bffe | 1009 | |
18863bdd | 1010 | void kvm_define_shared_msr(unsigned index, u32 msr); |
d5696725 | 1011 | void kvm_set_shared_msr(unsigned index, u64 val, u64 mask); |
18863bdd | 1012 | |
f92653ee JK |
1013 | bool kvm_is_linear_rip(struct kvm_vcpu *vcpu, unsigned long linear_rip); |
1014 | ||
af585b92 GN |
1015 | void kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu, |
1016 | struct kvm_async_pf *work); | |
1017 | void kvm_arch_async_page_present(struct kvm_vcpu *vcpu, | |
1018 | struct kvm_async_pf *work); | |
56028d08 GN |
1019 | void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu, |
1020 | struct kvm_async_pf *work); | |
7c90705b | 1021 | bool kvm_arch_can_inject_async_page_present(struct kvm_vcpu *vcpu); |
af585b92 GN |
1022 | extern bool kvm_find_async_pf_gfn(struct kvm_vcpu *vcpu, gfn_t gfn); |
1023 | ||
db8fcefa AP |
1024 | void kvm_complete_insn_gp(struct kvm_vcpu *vcpu, int err); |
1025 | ||
f5132b01 GN |
1026 | int kvm_is_in_guest(void); |
1027 | ||
1028 | void kvm_pmu_init(struct kvm_vcpu *vcpu); | |
1029 | void kvm_pmu_destroy(struct kvm_vcpu *vcpu); | |
1030 | void kvm_pmu_reset(struct kvm_vcpu *vcpu); | |
1031 | void kvm_pmu_cpuid_update(struct kvm_vcpu *vcpu); | |
1032 | bool kvm_pmu_msr(struct kvm_vcpu *vcpu, u32 msr); | |
1033 | int kvm_pmu_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *data); | |
afd80d85 | 1034 | int kvm_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info); |
f5132b01 GN |
1035 | int kvm_pmu_read_pmc(struct kvm_vcpu *vcpu, unsigned pmc, u64 *data); |
1036 | void kvm_handle_pmu_event(struct kvm_vcpu *vcpu); | |
1037 | void kvm_deliver_pmi(struct kvm_vcpu *vcpu); | |
1038 | ||
1965aae3 | 1039 | #endif /* _ASM_X86_KVM_HOST_H */ |