@@ -241,98 +241,6 @@ static int unhandled_vmexit_handler(__unused struct vcpu *vcpu)
241
241
return 0 ;
242
242
}
243
243
244
- static int write_cr0 (struct vcpu * vcpu , uint64_t value )
245
- {
246
- uint32_t value32 ;
247
- uint64_t value64 ;
248
-
249
- pr_dbg ("VMM: Guest trying to write 0x%08x to CR0" , value );
250
-
251
- /* Read host mask value */
252
- value64 = exec_vmread (VMX_CR0_MASK );
253
-
254
- /* Clear all bits being written by guest that are owned by host */
255
- value &= ~value64 ;
256
-
257
- /* Update CR0 in guest state */
258
- vcpu -> arch_vcpu .contexts [vcpu -> arch_vcpu .cur_context ].cr0 |= value ;
259
- exec_vmwrite (VMX_GUEST_CR0 ,
260
- vcpu -> arch_vcpu .contexts [vcpu -> arch_vcpu .cur_context ].cr0 );
261
- pr_dbg ("VMM: Guest allowed to write 0x%08x to CR0" ,
262
- vcpu -> arch_vcpu .contexts [vcpu -> arch_vcpu .cur_context ].cr0 );
263
-
264
- /* If guest is trying to transition vcpu from unpaged real mode to page
265
- * protected mode make necessary changes to VMCS structure to reflect
266
- * transition from real mode to paged-protected mode
267
- */
268
- if (!is_vcpu_bsp (vcpu ) &&
269
- (vcpu -> arch_vcpu .cpu_mode == CPU_MODE_REAL ) &&
270
- (value & CR0_PG ) && (value & CR0_PE )) {
271
- /* Enable protected mode */
272
- value32 = exec_vmread (VMX_ENTRY_CONTROLS );
273
- value32 |= (VMX_ENTRY_CTLS_IA32E_MODE |
274
- VMX_ENTRY_CTLS_LOAD_PAT |
275
- VMX_ENTRY_CTLS_LOAD_EFER );
276
- exec_vmwrite (VMX_ENTRY_CONTROLS , value32 );
277
- pr_dbg ("VMX_ENTRY_CONTROLS: 0x%x " , value32 );
278
-
279
- /* Set up EFER */
280
- value64 = exec_vmread64 (VMX_GUEST_IA32_EFER_FULL );
281
- value64 |= (MSR_IA32_EFER_SCE_BIT |
282
- MSR_IA32_EFER_LME_BIT |
283
- MSR_IA32_EFER_LMA_BIT | MSR_IA32_EFER_NXE_BIT );
284
- exec_vmwrite64 (VMX_GUEST_IA32_EFER_FULL , value64 );
285
- pr_dbg ("VMX_GUEST_IA32_EFER: 0x%016llx " , value64 );
286
- }
287
-
288
- return 0 ;
289
- }
290
-
291
- static int write_cr3 (struct vcpu * vcpu , uint64_t value )
292
- {
293
- /* Write to guest's CR3 */
294
- vcpu -> arch_vcpu .contexts [vcpu -> arch_vcpu .cur_context ].cr3 = value ;
295
-
296
- /* Commit new value to VMCS */
297
- exec_vmwrite (VMX_GUEST_CR3 ,
298
- vcpu -> arch_vcpu .contexts [vcpu -> arch_vcpu .cur_context ].cr3 );
299
-
300
- return 0 ;
301
- }
302
-
303
- static int write_cr4 (struct vcpu * vcpu , uint64_t value )
304
- {
305
- uint64_t temp64 ;
306
-
307
- pr_dbg ("VMM: Guest trying to write 0x%08x to CR4" , value );
308
-
309
- /* Read host mask value */
310
- temp64 = exec_vmread (VMX_CR4_MASK );
311
-
312
- /* Clear all bits being written by guest that are owned by host */
313
- value &= ~temp64 ;
314
-
315
- /* Write updated CR4 (bitwise OR of allowed guest bits and CR4 host
316
- * value)
317
- */
318
- vcpu -> arch_vcpu .contexts [vcpu -> arch_vcpu .cur_context ].cr4 |= value ;
319
- exec_vmwrite (VMX_GUEST_CR4 ,
320
- vcpu -> arch_vcpu .contexts [vcpu -> arch_vcpu .cur_context ].cr4 );
321
- pr_dbg ("VMM: Guest allowed to write 0x%08x to CR4" ,
322
- vcpu -> arch_vcpu .contexts [vcpu -> arch_vcpu .cur_context ].cr4 );
323
-
324
- return 0 ;
325
- }
326
-
327
- static int read_cr3 (struct vcpu * vcpu , uint64_t * value )
328
- {
329
- * value = vcpu -> arch_vcpu .contexts [vcpu -> arch_vcpu .cur_context ].cr3 ;
330
-
331
- pr_dbg ("VMM: reading 0x%08x from CR3" , * value );
332
-
333
- return 0 ;
334
- }
335
-
336
244
int cpuid_vmexit_handler (struct vcpu * vcpu )
337
245
{
338
246
struct run_context * cur_context =
@@ -382,22 +290,22 @@ int cr_access_vmexit_handler(struct vcpu *vcpu)
382
290
VM_EXIT_CR_ACCESS_CR_NUM (vcpu -> arch_vcpu .exit_qualification )) {
383
291
case 0x00 :
384
292
/* mov to cr0 */
385
- write_cr0 (vcpu , * regptr );
293
+ vmx_write_cr0 (vcpu , * regptr );
386
294
break ;
387
295
388
296
case 0x03 :
389
297
/* mov to cr3 */
390
- write_cr3 (vcpu , * regptr );
298
+ vmx_write_cr3 (vcpu , * regptr );
391
299
break ;
392
300
393
301
case 0x04 :
394
302
/* mov to cr4 */
395
- write_cr4 (vcpu , * regptr );
303
+ vmx_write_cr4 (vcpu , * regptr );
396
304
break ;
397
305
398
306
case 0x13 :
399
307
/* mov from cr3 */
400
- read_cr3 (vcpu , regptr );
308
+ vmx_read_cr3 (vcpu , regptr );
401
309
break ;
402
310
#if 0
403
311
case 0x14 :
0 commit comments