diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-05-23 11:42:08 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-05-23 11:42:08 -0400 |
commit | f4b10bc60a310916bab5413f821b99ef845cac17 (patch) | |
tree | 904532e8cd93b88261f21427c4ec4917d4b3e79d /arch/x86/include | |
parent | 53ee7569ce8beb3fd3fc0817116c29298d72353f (diff) | |
parent | c8cfbb555eb3632bf3dcbe1a591c1f4d0c28681c (diff) |
Merge branch 'kvm-updates/2.6.40' of git://git.kernel.org/pub/scm/virt/kvm/kvm
* 'kvm-updates/2.6.40' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (131 commits)
KVM: MMU: Use ptep_user for cmpxchg_gpte()
KVM: Fix kvm mmu_notifier initialization order
KVM: Add documentation for KVM_CAP_NR_VCPUS
KVM: make guest mode entry to be rcu quiescent state
KVM: x86 emulator: Make jmp far emulation into a separate function
KVM: x86 emulator: Rename emulate_grpX() to em_grpX()
KVM: x86 emulator: Remove unused arg from emulate_pop()
KVM: x86 emulator: Remove unused arg from writeback()
KVM: x86 emulator: Remove unused arg from read_descriptor()
KVM: x86 emulator: Remove unused arg from seg_override()
KVM: Validate userspace_addr of memslot when registered
KVM: MMU: Clean up gpte reading with copy_from_user()
KVM: PPC: booke: add sregs support
KVM: PPC: booke: save/restore VRSAVE (a.k.a. USPRG0)
KVM: PPC: use ticks, not usecs, for exit timing
KVM: PPC: fix exit accounting for SPRs, tlbwe, tlbsx
KVM: PPC: e500: emulate SVR
KVM: VMX: Cache vmcs segment fields
KVM: x86 emulator: consolidate segment accessors
KVM: VMX: Avoid reading %rip unnecessarily when handling exceptions
...
Diffstat (limited to 'arch/x86/include')
-rw-r--r-- | arch/x86/include/asm/kvm_emulate.h | 193 | ||||
-rw-r--r-- | arch/x86/include/asm/kvm_host.h | 55 | ||||
-rw-r--r-- | arch/x86/include/asm/msr-index.h | 1 |
3 files changed, 189 insertions, 60 deletions
diff --git a/arch/x86/include/asm/kvm_emulate.h b/arch/x86/include/asm/kvm_emulate.h index 0f521356432..0049211959c 100644 --- a/arch/x86/include/asm/kvm_emulate.h +++ b/arch/x86/include/asm/kvm_emulate.h | |||
@@ -14,6 +14,8 @@ | |||
14 | #include <asm/desc_defs.h> | 14 | #include <asm/desc_defs.h> |
15 | 15 | ||
16 | struct x86_emulate_ctxt; | 16 | struct x86_emulate_ctxt; |
17 | enum x86_intercept; | ||
18 | enum x86_intercept_stage; | ||
17 | 19 | ||
18 | struct x86_exception { | 20 | struct x86_exception { |
19 | u8 vector; | 21 | u8 vector; |
@@ -24,6 +26,24 @@ struct x86_exception { | |||
24 | }; | 26 | }; |
25 | 27 | ||
26 | /* | 28 | /* |
29 | * This struct is used to carry enough information from the instruction | ||
30 | * decoder to main KVM so that a decision can be made whether the | ||
31 | * instruction needs to be intercepted or not. | ||
32 | */ | ||
33 | struct x86_instruction_info { | ||
34 | u8 intercept; /* which intercept */ | ||
35 | u8 rep_prefix; /* rep prefix? */ | ||
36 | u8 modrm_mod; /* mod part of modrm */ | ||
37 | u8 modrm_reg; /* index of register used */ | ||
38 | u8 modrm_rm; /* rm part of modrm */ | ||
39 | u64 src_val; /* value of source operand */ | ||
40 | u8 src_bytes; /* size of source operand */ | ||
41 | u8 dst_bytes; /* size of destination operand */ | ||
42 | u8 ad_bytes; /* size of src/dst address */ | ||
43 | u64 next_rip; /* rip following the instruction */ | ||
44 | }; | ||
45 | |||
46 | /* | ||
27 | * x86_emulate_ops: | 47 | * x86_emulate_ops: |
28 | * | 48 | * |
29 | * These operations represent the instruction emulator's interface to memory. | 49 | * These operations represent the instruction emulator's interface to memory. |
@@ -62,6 +82,7 @@ struct x86_exception { | |||
62 | #define X86EMUL_RETRY_INSTR 3 /* retry the instruction for some reason */ | 82 | #define X86EMUL_RETRY_INSTR 3 /* retry the instruction for some reason */ |
63 | #define X86EMUL_CMPXCHG_FAILED 4 /* cmpxchg did not see expected value */ | 83 | #define X86EMUL_CMPXCHG_FAILED 4 /* cmpxchg did not see expected value */ |
64 | #define X86EMUL_IO_NEEDED 5 /* IO is needed to complete emulation */ | 84 | #define X86EMUL_IO_NEEDED 5 /* IO is needed to complete emulation */ |
85 | #define X86EMUL_INTERCEPTED 6 /* Intercepted by nested VMCB/VMCS */ | ||
65 | 86 | ||
66 | struct x86_emulate_ops { | 87 | struct x86_emulate_ops { |
67 | /* | 88 | /* |
@@ -71,8 +92,9 @@ struct x86_emulate_ops { | |||
71 | * @val: [OUT] Value read from memory, zero-extended to 'u_long'. | 92 | * @val: [OUT] Value read from memory, zero-extended to 'u_long'. |
72 | * @bytes: [IN ] Number of bytes to read from memory. | 93 | * @bytes: [IN ] Number of bytes to read from memory. |
73 | */ | 94 | */ |
74 | int (*read_std)(unsigned long addr, void *val, | 95 | int (*read_std)(struct x86_emulate_ctxt *ctxt, |
75 | unsigned int bytes, struct kvm_vcpu *vcpu, | 96 | unsigned long addr, void *val, |
97 | unsigned int bytes, | ||
76 | struct x86_exception *fault); | 98 | struct x86_exception *fault); |
77 | 99 | ||
78 | /* | 100 | /* |
@@ -82,8 +104,8 @@ struct x86_emulate_ops { | |||
82 | * @val: [OUT] Value write to memory, zero-extended to 'u_long'. | 104 | * @val: [OUT] Value write to memory, zero-extended to 'u_long'. |
83 | * @bytes: [IN ] Number of bytes to write to memory. | 105 | * @bytes: [IN ] Number of bytes to write to memory. |
84 | */ | 106 | */ |
85 | int (*write_std)(unsigned long addr, void *val, | 107 | int (*write_std)(struct x86_emulate_ctxt *ctxt, |
86 | unsigned int bytes, struct kvm_vcpu *vcpu, | 108 | unsigned long addr, void *val, unsigned int bytes, |
87 | struct x86_exception *fault); | 109 | struct x86_exception *fault); |
88 | /* | 110 | /* |
89 | * fetch: Read bytes of standard (non-emulated/special) memory. | 111 | * fetch: Read bytes of standard (non-emulated/special) memory. |
@@ -92,8 +114,8 @@ struct x86_emulate_ops { | |||
92 | * @val: [OUT] Value read from memory, zero-extended to 'u_long'. | 114 | * @val: [OUT] Value read from memory, zero-extended to 'u_long'. |
93 | * @bytes: [IN ] Number of bytes to read from memory. | 115 | * @bytes: [IN ] Number of bytes to read from memory. |
94 | */ | 116 | */ |
95 | int (*fetch)(unsigned long addr, void *val, | 117 | int (*fetch)(struct x86_emulate_ctxt *ctxt, |
96 | unsigned int bytes, struct kvm_vcpu *vcpu, | 118 | unsigned long addr, void *val, unsigned int bytes, |
97 | struct x86_exception *fault); | 119 | struct x86_exception *fault); |
98 | 120 | ||
99 | /* | 121 | /* |
@@ -102,11 +124,9 @@ struct x86_emulate_ops { | |||
102 | * @val: [OUT] Value read from memory, zero-extended to 'u_long'. | 124 | * @val: [OUT] Value read from memory, zero-extended to 'u_long'. |
103 | * @bytes: [IN ] Number of bytes to read from memory. | 125 | * @bytes: [IN ] Number of bytes to read from memory. |
104 | */ | 126 | */ |
105 | int (*read_emulated)(unsigned long addr, | 127 | int (*read_emulated)(struct x86_emulate_ctxt *ctxt, |
106 | void *val, | 128 | unsigned long addr, void *val, unsigned int bytes, |
107 | unsigned int bytes, | 129 | struct x86_exception *fault); |
108 | struct x86_exception *fault, | ||
109 | struct kvm_vcpu *vcpu); | ||
110 | 130 | ||
111 | /* | 131 | /* |
112 | * write_emulated: Write bytes to emulated/special memory area. | 132 | * write_emulated: Write bytes to emulated/special memory area. |
@@ -115,11 +135,10 @@ struct x86_emulate_ops { | |||
115 | * required). | 135 | * required). |
116 | * @bytes: [IN ] Number of bytes to write to memory. | 136 | * @bytes: [IN ] Number of bytes to write to memory. |
117 | */ | 137 | */ |
118 | int (*write_emulated)(unsigned long addr, | 138 | int (*write_emulated)(struct x86_emulate_ctxt *ctxt, |
119 | const void *val, | 139 | unsigned long addr, const void *val, |
120 | unsigned int bytes, | 140 | unsigned int bytes, |
121 | struct x86_exception *fault, | 141 | struct x86_exception *fault); |
122 | struct kvm_vcpu *vcpu); | ||
123 | 142 | ||
124 | /* | 143 | /* |
125 | * cmpxchg_emulated: Emulate an atomic (LOCKed) CMPXCHG operation on an | 144 | * cmpxchg_emulated: Emulate an atomic (LOCKed) CMPXCHG operation on an |
@@ -129,40 +148,54 @@ struct x86_emulate_ops { | |||
129 | * @new: [IN ] Value to write to @addr. | 148 | * @new: [IN ] Value to write to @addr. |
130 | * @bytes: [IN ] Number of bytes to access using CMPXCHG. | 149 | * @bytes: [IN ] Number of bytes to access using CMPXCHG. |
131 | */ | 150 | */ |
132 | int (*cmpxchg_emulated)(unsigned long addr, | 151 | int (*cmpxchg_emulated)(struct x86_emulate_ctxt *ctxt, |
152 | unsigned long addr, | ||
133 | const void *old, | 153 | const void *old, |
134 | const void *new, | 154 | const void *new, |
135 | unsigned int bytes, | 155 | unsigned int bytes, |
136 | struct x86_exception *fault, | 156 | struct x86_exception *fault); |
137 | struct kvm_vcpu *vcpu); | 157 | void (*invlpg)(struct x86_emulate_ctxt *ctxt, ulong addr); |
138 | 158 | ||
139 | int (*pio_in_emulated)(int size, unsigned short port, void *val, | 159 | int (*pio_in_emulated)(struct x86_emulate_ctxt *ctxt, |
140 | unsigned int count, struct kvm_vcpu *vcpu); | 160 | int size, unsigned short port, void *val, |
141 | 161 | unsigned int count); | |
142 | int (*pio_out_emulated)(int size, unsigned short port, const void *val, | 162 | |
143 | unsigned int count, struct kvm_vcpu *vcpu); | 163 | int (*pio_out_emulated)(struct x86_emulate_ctxt *ctxt, |
144 | 164 | int size, unsigned short port, const void *val, | |
145 | bool (*get_cached_descriptor)(struct desc_struct *desc, u32 *base3, | 165 | unsigned int count); |
146 | int seg, struct kvm_vcpu *vcpu); | 166 | |
147 | void (*set_cached_descriptor)(struct desc_struct *desc, u32 base3, | 167 | bool (*get_segment)(struct x86_emulate_ctxt *ctxt, u16 *selector, |
148 | int seg, struct kvm_vcpu *vcpu); | 168 | struct desc_struct *desc, u32 *base3, int seg); |
149 | u16 (*get_segment_selector)(int seg, struct kvm_vcpu *vcpu); | 169 | void (*set_segment)(struct x86_emulate_ctxt *ctxt, u16 selector, |
150 | void (*set_segment_selector)(u16 sel, int seg, struct kvm_vcpu *vcpu); | 170 | struct desc_struct *desc, u32 base3, int seg); |
151 | unsigned long (*get_cached_segment_base)(int seg, struct kvm_vcpu *vcpu); | 171 | unsigned long (*get_cached_segment_base)(struct x86_emulate_ctxt *ctxt, |
152 | void (*get_gdt)(struct desc_ptr *dt, struct kvm_vcpu *vcpu); | 172 | int seg); |
153 | void (*get_idt)(struct desc_ptr *dt, struct kvm_vcpu *vcpu); | 173 | void (*get_gdt)(struct x86_emulate_ctxt *ctxt, struct desc_ptr *dt); |
154 | ulong (*get_cr)(int cr, struct kvm_vcpu *vcpu); | 174 | void (*get_idt)(struct x86_emulate_ctxt *ctxt, struct desc_ptr *dt); |
155 | int (*set_cr)(int cr, ulong val, struct kvm_vcpu *vcpu); | 175 | void (*set_gdt)(struct x86_emulate_ctxt *ctxt, struct desc_ptr *dt); |
156 | int (*cpl)(struct kvm_vcpu *vcpu); | 176 | void (*set_idt)(struct x86_emulate_ctxt *ctxt, struct desc_ptr *dt); |
157 | int (*get_dr)(int dr, unsigned long *dest, struct kvm_vcpu *vcpu); | 177 | ulong (*get_cr)(struct x86_emulate_ctxt *ctxt, int cr); |
158 | int (*set_dr)(int dr, unsigned long value, struct kvm_vcpu *vcpu); | 178 | int (*set_cr)(struct x86_emulate_ctxt *ctxt, int cr, ulong val); |
159 | int (*set_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 data); | 179 | int (*cpl)(struct x86_emulate_ctxt *ctxt); |
160 | int (*get_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata); | 180 | int (*get_dr)(struct x86_emulate_ctxt *ctxt, int dr, ulong *dest); |
181 | int (*set_dr)(struct x86_emulate_ctxt *ctxt, int dr, ulong value); | ||
182 | int (*set_msr)(struct x86_emulate_ctxt *ctxt, u32 msr_index, u64 data); | ||
183 | int (*get_msr)(struct x86_emulate_ctxt *ctxt, u32 msr_index, u64 *pdata); | ||
184 | void (*halt)(struct x86_emulate_ctxt *ctxt); | ||
185 | void (*wbinvd)(struct x86_emulate_ctxt *ctxt); | ||
186 | int (*fix_hypercall)(struct x86_emulate_ctxt *ctxt); | ||
187 | void (*get_fpu)(struct x86_emulate_ctxt *ctxt); /* disables preempt */ | ||
188 | void (*put_fpu)(struct x86_emulate_ctxt *ctxt); /* reenables preempt */ | ||
189 | int (*intercept)(struct x86_emulate_ctxt *ctxt, | ||
190 | struct x86_instruction_info *info, | ||
191 | enum x86_intercept_stage stage); | ||
161 | }; | 192 | }; |
162 | 193 | ||
194 | typedef u32 __attribute__((vector_size(16))) sse128_t; | ||
195 | |||
163 | /* Type, address-of, and value of an instruction's operand. */ | 196 | /* Type, address-of, and value of an instruction's operand. */ |
164 | struct operand { | 197 | struct operand { |
165 | enum { OP_REG, OP_MEM, OP_IMM, OP_NONE } type; | 198 | enum { OP_REG, OP_MEM, OP_IMM, OP_XMM, OP_NONE } type; |
166 | unsigned int bytes; | 199 | unsigned int bytes; |
167 | union { | 200 | union { |
168 | unsigned long orig_val; | 201 | unsigned long orig_val; |
@@ -174,11 +207,13 @@ struct operand { | |||
174 | ulong ea; | 207 | ulong ea; |
175 | unsigned seg; | 208 | unsigned seg; |
176 | } mem; | 209 | } mem; |
210 | unsigned xmm; | ||
177 | } addr; | 211 | } addr; |
178 | union { | 212 | union { |
179 | unsigned long val; | 213 | unsigned long val; |
180 | u64 val64; | 214 | u64 val64; |
181 | char valptr[sizeof(unsigned long) + 2]; | 215 | char valptr[sizeof(unsigned long) + 2]; |
216 | sse128_t vec_val; | ||
182 | }; | 217 | }; |
183 | }; | 218 | }; |
184 | 219 | ||
@@ -197,6 +232,7 @@ struct read_cache { | |||
197 | struct decode_cache { | 232 | struct decode_cache { |
198 | u8 twobyte; | 233 | u8 twobyte; |
199 | u8 b; | 234 | u8 b; |
235 | u8 intercept; | ||
200 | u8 lock_prefix; | 236 | u8 lock_prefix; |
201 | u8 rep_prefix; | 237 | u8 rep_prefix; |
202 | u8 op_bytes; | 238 | u8 op_bytes; |
@@ -209,6 +245,7 @@ struct decode_cache { | |||
209 | u8 seg_override; | 245 | u8 seg_override; |
210 | unsigned int d; | 246 | unsigned int d; |
211 | int (*execute)(struct x86_emulate_ctxt *ctxt); | 247 | int (*execute)(struct x86_emulate_ctxt *ctxt); |
248 | int (*check_perm)(struct x86_emulate_ctxt *ctxt); | ||
212 | unsigned long regs[NR_VCPU_REGS]; | 249 | unsigned long regs[NR_VCPU_REGS]; |
213 | unsigned long eip; | 250 | unsigned long eip; |
214 | /* modrm */ | 251 | /* modrm */ |
@@ -227,17 +264,15 @@ struct x86_emulate_ctxt { | |||
227 | struct x86_emulate_ops *ops; | 264 | struct x86_emulate_ops *ops; |
228 | 265 | ||
229 | /* Register state before/after emulation. */ | 266 | /* Register state before/after emulation. */ |
230 | struct kvm_vcpu *vcpu; | ||
231 | |||
232 | unsigned long eflags; | 267 | unsigned long eflags; |
233 | unsigned long eip; /* eip before instruction emulation */ | 268 | unsigned long eip; /* eip before instruction emulation */ |
234 | /* Emulated execution mode, represented by an X86EMUL_MODE value. */ | 269 | /* Emulated execution mode, represented by an X86EMUL_MODE value. */ |
235 | int mode; | 270 | int mode; |
236 | u32 cs_base; | ||
237 | 271 | ||
238 | /* interruptibility state, as a result of execution of STI or MOV SS */ | 272 | /* interruptibility state, as a result of execution of STI or MOV SS */ |
239 | int interruptibility; | 273 | int interruptibility; |
240 | 274 | ||
275 | bool guest_mode; /* guest running a nested guest */ | ||
241 | bool perm_ok; /* do not check permissions if true */ | 276 | bool perm_ok; /* do not check permissions if true */ |
242 | bool only_vendor_specific_insn; | 277 | bool only_vendor_specific_insn; |
243 | 278 | ||
@@ -249,8 +284,8 @@ struct x86_emulate_ctxt { | |||
249 | }; | 284 | }; |
250 | 285 | ||
251 | /* Repeat String Operation Prefix */ | 286 | /* Repeat String Operation Prefix */ |
252 | #define REPE_PREFIX 1 | 287 | #define REPE_PREFIX 0xf3 |
253 | #define REPNE_PREFIX 2 | 288 | #define REPNE_PREFIX 0xf2 |
254 | 289 | ||
255 | /* Execution mode, passed to the emulator. */ | 290 | /* Execution mode, passed to the emulator. */ |
256 | #define X86EMUL_MODE_REAL 0 /* Real mode. */ | 291 | #define X86EMUL_MODE_REAL 0 /* Real mode. */ |
@@ -259,6 +294,69 @@ struct x86_emulate_ctxt { | |||
259 | #define X86EMUL_MODE_PROT32 4 /* 32-bit protected mode. */ | 294 | #define X86EMUL_MODE_PROT32 4 /* 32-bit protected mode. */ |
260 | #define X86EMUL_MODE_PROT64 8 /* 64-bit (long) mode. */ | 295 | #define X86EMUL_MODE_PROT64 8 /* 64-bit (long) mode. */ |
261 | 296 | ||
297 | /* any protected mode */ | ||
298 | #define X86EMUL_MODE_PROT (X86EMUL_MODE_PROT16|X86EMUL_MODE_PROT32| \ | ||
299 | X86EMUL_MODE_PROT64) | ||
300 | |||
301 | enum x86_intercept_stage { | ||
302 | X86_ICTP_NONE = 0, /* Allow zero-init to not match anything */ | ||
303 | X86_ICPT_PRE_EXCEPT, | ||
304 | X86_ICPT_POST_EXCEPT, | ||
305 | X86_ICPT_POST_MEMACCESS, | ||
306 | }; | ||
307 | |||
308 | enum x86_intercept { | ||
309 | x86_intercept_none, | ||
310 | x86_intercept_cr_read, | ||
311 | x86_intercept_cr_write, | ||
312 | x86_intercept_clts, | ||
313 | x86_intercept_lmsw, | ||
314 | x86_intercept_smsw, | ||
315 | x86_intercept_dr_read, | ||
316 | x86_intercept_dr_write, | ||
317 | x86_intercept_lidt, | ||
318 | x86_intercept_sidt, | ||
319 | x86_intercept_lgdt, | ||
320 | x86_intercept_sgdt, | ||
321 | x86_intercept_lldt, | ||
322 | x86_intercept_sldt, | ||
323 | x86_intercept_ltr, | ||
324 | x86_intercept_str, | ||
325 | x86_intercept_rdtsc, | ||
326 | x86_intercept_rdpmc, | ||
327 | x86_intercept_pushf, | ||
328 | x86_intercept_popf, | ||
329 | x86_intercept_cpuid, | ||
330 | x86_intercept_rsm, | ||
331 | x86_intercept_iret, | ||
332 | x86_intercept_intn, | ||
333 | x86_intercept_invd, | ||
334 | x86_intercept_pause, | ||
335 | x86_intercept_hlt, | ||
336 | x86_intercept_invlpg, | ||
337 | x86_intercept_invlpga, | ||
338 | x86_intercept_vmrun, | ||
339 | x86_intercept_vmload, | ||
340 | x86_intercept_vmsave, | ||
341 | x86_intercept_vmmcall, | ||
342 | x86_intercept_stgi, | ||
343 | x86_intercept_clgi, | ||
344 | x86_intercept_skinit, | ||
345 | x86_intercept_rdtscp, | ||
346 | x86_intercept_icebp, | ||
347 | x86_intercept_wbinvd, | ||
348 | x86_intercept_monitor, | ||
349 | x86_intercept_mwait, | ||
350 | x86_intercept_rdmsr, | ||
351 | x86_intercept_wrmsr, | ||
352 | x86_intercept_in, | ||
353 | x86_intercept_ins, | ||
354 | x86_intercept_out, | ||
355 | x86_intercept_outs, | ||
356 | |||
357 | nr_x86_intercepts | ||
358 | }; | ||
359 | |||
262 | /* Host execution mode. */ | 360 | /* Host execution mode. */ |
263 | #if defined(CONFIG_X86_32) | 361 | #if defined(CONFIG_X86_32) |
264 | #define X86EMUL_MODE_HOST X86EMUL_MODE_PROT32 | 362 | #define X86EMUL_MODE_HOST X86EMUL_MODE_PROT32 |
@@ -270,6 +368,7 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len); | |||
270 | #define EMULATION_FAILED -1 | 368 | #define EMULATION_FAILED -1 |
271 | #define EMULATION_OK 0 | 369 | #define EMULATION_OK 0 |
272 | #define EMULATION_RESTART 1 | 370 | #define EMULATION_RESTART 1 |
371 | #define EMULATION_INTERCEPTED 2 | ||
273 | int x86_emulate_insn(struct x86_emulate_ctxt *ctxt); | 372 | int x86_emulate_insn(struct x86_emulate_ctxt *ctxt); |
274 | int emulator_task_switch(struct x86_emulate_ctxt *ctxt, | 373 | int emulator_task_switch(struct x86_emulate_ctxt *ctxt, |
275 | u16 tss_selector, int reason, | 374 | u16 tss_selector, int reason, |
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index c8af0991fdf..d2ac8e2ee89 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h | |||
@@ -30,14 +30,30 @@ | |||
30 | #define KVM_MEMORY_SLOTS 32 | 30 | #define KVM_MEMORY_SLOTS 32 |
31 | /* memory slots that does not exposed to userspace */ | 31 | /* memory slots that does not exposed to userspace */ |
32 | #define KVM_PRIVATE_MEM_SLOTS 4 | 32 | #define KVM_PRIVATE_MEM_SLOTS 4 |
33 | #define KVM_MMIO_SIZE 16 | ||
33 | 34 | ||
34 | #define KVM_PIO_PAGE_OFFSET 1 | 35 | #define KVM_PIO_PAGE_OFFSET 1 |
35 | #define KVM_COALESCED_MMIO_PAGE_OFFSET 2 | 36 | #define KVM_COALESCED_MMIO_PAGE_OFFSET 2 |
36 | 37 | ||
38 | #define CR0_RESERVED_BITS \ | ||
39 | (~(unsigned long)(X86_CR0_PE | X86_CR0_MP | X86_CR0_EM | X86_CR0_TS \ | ||
40 | | X86_CR0_ET | X86_CR0_NE | X86_CR0_WP | X86_CR0_AM \ | ||
41 | | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG)) | ||
42 | |||
37 | #define CR3_PAE_RESERVED_BITS ((X86_CR3_PWT | X86_CR3_PCD) - 1) | 43 | #define CR3_PAE_RESERVED_BITS ((X86_CR3_PWT | X86_CR3_PCD) - 1) |
38 | #define CR3_NONPAE_RESERVED_BITS ((PAGE_SIZE-1) & ~(X86_CR3_PWT | X86_CR3_PCD)) | 44 | #define CR3_NONPAE_RESERVED_BITS ((PAGE_SIZE-1) & ~(X86_CR3_PWT | X86_CR3_PCD)) |
39 | #define CR3_L_MODE_RESERVED_BITS (CR3_NONPAE_RESERVED_BITS | \ | 45 | #define CR3_L_MODE_RESERVED_BITS (CR3_NONPAE_RESERVED_BITS | \ |
40 | 0xFFFFFF0000000000ULL) | 46 | 0xFFFFFF0000000000ULL) |
47 | #define CR4_RESERVED_BITS \ | ||
48 | (~(unsigned long)(X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | X86_CR4_DE\ | ||
49 | | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_MCE \ | ||
50 | | X86_CR4_PGE | X86_CR4_PCE | X86_CR4_OSFXSR \ | ||
51 | | X86_CR4_OSXSAVE \ | ||
52 | | X86_CR4_OSXMMEXCPT | X86_CR4_VMXE)) | ||
53 | |||
54 | #define CR8_RESERVED_BITS (~(unsigned long)X86_CR8_TPR) | ||
55 | |||
56 | |||
41 | 57 | ||
42 | #define INVALID_PAGE (~(hpa_t)0) | 58 | #define INVALID_PAGE (~(hpa_t)0) |
43 | #define VALID_PAGE(x) ((x) != INVALID_PAGE) | 59 | #define VALID_PAGE(x) ((x) != INVALID_PAGE) |
@@ -118,6 +134,9 @@ enum kvm_reg { | |||
118 | enum kvm_reg_ex { | 134 | enum kvm_reg_ex { |
119 | VCPU_EXREG_PDPTR = NR_VCPU_REGS, | 135 | VCPU_EXREG_PDPTR = NR_VCPU_REGS, |
120 | VCPU_EXREG_CR3, | 136 | VCPU_EXREG_CR3, |
137 | VCPU_EXREG_RFLAGS, | ||
138 | VCPU_EXREG_CPL, | ||
139 | VCPU_EXREG_SEGMENTS, | ||
121 | }; | 140 | }; |
122 | 141 | ||
123 | enum { | 142 | enum { |
@@ -256,7 +275,7 @@ struct kvm_mmu { | |||
256 | struct kvm_mmu_page *sp); | 275 | struct kvm_mmu_page *sp); |
257 | void (*invlpg)(struct kvm_vcpu *vcpu, gva_t gva); | 276 | void (*invlpg)(struct kvm_vcpu *vcpu, gva_t gva); |
258 | void (*update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, | 277 | void (*update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, |
259 | u64 *spte, const void *pte, unsigned long mmu_seq); | 278 | u64 *spte, const void *pte); |
260 | hpa_t root_hpa; | 279 | hpa_t root_hpa; |
261 | int root_level; | 280 | int root_level; |
262 | int shadow_root_level; | 281 | int shadow_root_level; |
@@ -340,7 +359,6 @@ struct kvm_vcpu_arch { | |||
340 | struct fpu guest_fpu; | 359 | struct fpu guest_fpu; |
341 | u64 xcr0; | 360 | u64 xcr0; |
342 | 361 | ||
343 | gva_t mmio_fault_cr2; | ||
344 | struct kvm_pio_request pio; | 362 | struct kvm_pio_request pio; |
345 | void *pio_data; | 363 | void *pio_data; |
346 | 364 | ||
@@ -367,18 +385,22 @@ struct kvm_vcpu_arch { | |||
367 | /* emulate context */ | 385 | /* emulate context */ |
368 | 386 | ||
369 | struct x86_emulate_ctxt emulate_ctxt; | 387 | struct x86_emulate_ctxt emulate_ctxt; |
388 | bool emulate_regs_need_sync_to_vcpu; | ||
389 | bool emulate_regs_need_sync_from_vcpu; | ||
370 | 390 | ||
371 | gpa_t time; | 391 | gpa_t time; |
372 | struct pvclock_vcpu_time_info hv_clock; | 392 | struct pvclock_vcpu_time_info hv_clock; |
373 | unsigned int hw_tsc_khz; | 393 | unsigned int hw_tsc_khz; |
374 | unsigned int time_offset; | 394 | unsigned int time_offset; |
375 | struct page *time_page; | 395 | struct page *time_page; |
376 | u64 last_host_tsc; | ||
377 | u64 last_guest_tsc; | 396 | u64 last_guest_tsc; |
378 | u64 last_kernel_ns; | 397 | u64 last_kernel_ns; |
379 | u64 last_tsc_nsec; | 398 | u64 last_tsc_nsec; |
380 | u64 last_tsc_write; | 399 | u64 last_tsc_write; |
400 | u32 virtual_tsc_khz; | ||
381 | bool tsc_catchup; | 401 | bool tsc_catchup; |
402 | u32 tsc_catchup_mult; | ||
403 | s8 tsc_catchup_shift; | ||
382 | 404 | ||
383 | bool nmi_pending; | 405 | bool nmi_pending; |
384 | bool nmi_injected; | 406 | bool nmi_injected; |
@@ -448,9 +470,6 @@ struct kvm_arch { | |||
448 | u64 last_tsc_nsec; | 470 | u64 last_tsc_nsec; |
449 | u64 last_tsc_offset; | 471 | u64 last_tsc_offset; |
450 | u64 last_tsc_write; | 472 | u64 last_tsc_write; |
451 | u32 virtual_tsc_khz; | ||
452 | u32 virtual_tsc_mult; | ||
453 | s8 virtual_tsc_shift; | ||
454 | 473 | ||
455 | struct kvm_xen_hvm_config xen_hvm_config; | 474 | struct kvm_xen_hvm_config xen_hvm_config; |
456 | 475 | ||
@@ -502,6 +521,8 @@ struct kvm_vcpu_stat { | |||
502 | u32 nmi_injections; | 521 | u32 nmi_injections; |
503 | }; | 522 | }; |
504 | 523 | ||
524 | struct x86_instruction_info; | ||
525 | |||
505 | struct kvm_x86_ops { | 526 | struct kvm_x86_ops { |
506 | int (*cpu_has_kvm_support)(void); /* __init */ | 527 | int (*cpu_has_kvm_support)(void); /* __init */ |
507 | int (*disabled_by_bios)(void); /* __init */ | 528 | int (*disabled_by_bios)(void); /* __init */ |
@@ -586,9 +607,17 @@ struct kvm_x86_ops { | |||
586 | 607 | ||
587 | bool (*has_wbinvd_exit)(void); | 608 | bool (*has_wbinvd_exit)(void); |
588 | 609 | ||
610 | void (*set_tsc_khz)(struct kvm_vcpu *vcpu, u32 user_tsc_khz); | ||
589 | void (*write_tsc_offset)(struct kvm_vcpu *vcpu, u64 offset); | 611 | void (*write_tsc_offset)(struct kvm_vcpu *vcpu, u64 offset); |
590 | 612 | ||
613 | u64 (*compute_tsc_offset)(struct kvm_vcpu *vcpu, u64 target_tsc); | ||
614 | |||
591 | void (*get_exit_info)(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2); | 615 | void (*get_exit_info)(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2); |
616 | |||
617 | int (*check_intercept)(struct kvm_vcpu *vcpu, | ||
618 | struct x86_instruction_info *info, | ||
619 | enum x86_intercept_stage stage); | ||
620 | |||
592 | const struct trace_print_flags *exit_reasons_str; | 621 | const struct trace_print_flags *exit_reasons_str; |
593 | }; | 622 | }; |
594 | 623 | ||
@@ -627,6 +656,13 @@ u8 kvm_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn); | |||
627 | 656 | ||
628 | extern bool tdp_enabled; | 657 | extern bool tdp_enabled; |
629 | 658 | ||
659 | /* control of guest tsc rate supported? */ | ||
660 | extern bool kvm_has_tsc_control; | ||
661 | /* minimum supported tsc_khz for guests */ | ||
662 | extern u32 kvm_min_guest_tsc_khz; | ||
663 | /* maximum supported tsc_khz for guests */ | ||
664 | extern u32 kvm_max_guest_tsc_khz; | ||
665 | |||
630 | enum emulation_result { | 666 | enum emulation_result { |
631 | EMULATE_DONE, /* no further processing */ | 667 | EMULATE_DONE, /* no further processing */ |
632 | EMULATE_DO_MMIO, /* kvm_run filled with mmio request */ | 668 | EMULATE_DO_MMIO, /* kvm_run filled with mmio request */ |
@@ -645,9 +681,6 @@ static inline int emulate_instruction(struct kvm_vcpu *vcpu, | |||
645 | return x86_emulate_instruction(vcpu, 0, emulation_type, NULL, 0); | 681 | return x86_emulate_instruction(vcpu, 0, emulation_type, NULL, 0); |
646 | } | 682 | } |
647 | 683 | ||
648 | void realmode_lgdt(struct kvm_vcpu *vcpu, u16 size, unsigned long address); | ||
649 | void realmode_lidt(struct kvm_vcpu *vcpu, u16 size, unsigned long address); | ||
650 | |||
651 | void kvm_enable_efer_bits(u64); | 684 | void kvm_enable_efer_bits(u64); |
652 | int kvm_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *data); | 685 | int kvm_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *data); |
653 | int kvm_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data); | 686 | int kvm_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data); |
@@ -657,8 +690,6 @@ struct x86_emulate_ctxt; | |||
657 | int kvm_fast_pio_out(struct kvm_vcpu *vcpu, int size, unsigned short port); | 690 | int kvm_fast_pio_out(struct kvm_vcpu *vcpu, int size, unsigned short port); |
658 | void kvm_emulate_cpuid(struct kvm_vcpu *vcpu); | 691 | void kvm_emulate_cpuid(struct kvm_vcpu *vcpu); |
659 | int kvm_emulate_halt(struct kvm_vcpu *vcpu); | 692 | int kvm_emulate_halt(struct kvm_vcpu *vcpu); |
660 | int emulate_invlpg(struct kvm_vcpu *vcpu, gva_t address); | ||
661 | int emulate_clts(struct kvm_vcpu *vcpu); | ||
662 | int kvm_emulate_wbinvd(struct kvm_vcpu *vcpu); | 693 | int kvm_emulate_wbinvd(struct kvm_vcpu *vcpu); |
663 | 694 | ||
664 | void kvm_get_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg); | 695 | void kvm_get_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg); |
@@ -721,8 +752,6 @@ gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva, | |||
721 | 752 | ||
722 | int kvm_emulate_hypercall(struct kvm_vcpu *vcpu); | 753 | int kvm_emulate_hypercall(struct kvm_vcpu *vcpu); |
723 | 754 | ||
724 | int kvm_fix_hypercall(struct kvm_vcpu *vcpu); | ||
725 | |||
726 | int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva, u32 error_code, | 755 | int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva, u32 error_code, |
727 | void *insn, int insn_len); | 756 | void *insn, int insn_len); |
728 | void kvm_mmu_invlpg(struct kvm_vcpu *vcpu, gva_t gva); | 757 | void kvm_mmu_invlpg(struct kvm_vcpu *vcpu, gva_t gva); |
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index 3cce71413d0..485b4f1f079 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h | |||
@@ -118,6 +118,7 @@ | |||
118 | complete list. */ | 118 | complete list. */ |
119 | 119 | ||
120 | #define MSR_AMD64_PATCH_LEVEL 0x0000008b | 120 | #define MSR_AMD64_PATCH_LEVEL 0x0000008b |
121 | #define MSR_AMD64_TSC_RATIO 0xc0000104 | ||
121 | #define MSR_AMD64_NB_CFG 0xc001001f | 122 | #define MSR_AMD64_NB_CFG 0xc001001f |
122 | #define MSR_AMD64_PATCH_LOADER 0xc0010020 | 123 | #define MSR_AMD64_PATCH_LOADER 0xc0010020 |
123 | #define MSR_AMD64_OSVW_ID_LENGTH 0xc0010140 | 124 | #define MSR_AMD64_OSVW_ID_LENGTH 0xc0010140 |