@@ -8344,12 +8344,14 @@ static bool nested_vmx_exit_reflected(struct kvm_vcpu *vcpu, u32 exit_reason)
8344
8344
struct vcpu_vmx * vmx = to_vmx (vcpu );
8345
8345
struct vmcs12 * vmcs12 = get_vmcs12 (vcpu );
8346
8346
8347
- trace_kvm_nested_vmexit (kvm_rip_read (vcpu ), exit_reason ,
8348
- vmcs_readl (EXIT_QUALIFICATION ),
8349
- vmx -> idt_vectoring_info ,
8350
- intr_info ,
8351
- vmcs_read32 (VM_EXIT_INTR_ERROR_CODE ),
8352
- KVM_ISA_VMX );
8347
+ if (vmx -> nested .nested_run_pending )
8348
+ return false;
8349
+
8350
+ if (unlikely (vmx -> fail )) {
8351
+ pr_info_ratelimited ("%s failed vm entry %x\n" , __func__ ,
8352
+ vmcs_read32 (VM_INSTRUCTION_ERROR ));
8353
+ return true;
8354
+ }
8353
8355
8354
8356
/*
8355
8357
* The host physical addresses of some pages of guest memory
@@ -8363,14 +8365,12 @@ static bool nested_vmx_exit_reflected(struct kvm_vcpu *vcpu, u32 exit_reason)
8363
8365
*/
8364
8366
nested_mark_vmcs12_pages_dirty (vcpu );
8365
8367
8366
- if (vmx -> nested .nested_run_pending )
8367
- return false;
8368
-
8369
- if (unlikely (vmx -> fail )) {
8370
- pr_info_ratelimited ("%s failed vm entry %x\n" , __func__ ,
8371
- vmcs_read32 (VM_INSTRUCTION_ERROR ));
8372
- return true;
8373
- }
8368
+ trace_kvm_nested_vmexit (kvm_rip_read (vcpu ), exit_reason ,
8369
+ vmcs_readl (EXIT_QUALIFICATION ),
8370
+ vmx -> idt_vectoring_info ,
8371
+ intr_info ,
8372
+ vmcs_read32 (VM_EXIT_INTR_ERROR_CODE ),
8373
+ KVM_ISA_VMX );
8374
8374
8375
8375
switch (exit_reason ) {
8376
8376
case EXIT_REASON_EXCEPTION_NMI :
@@ -11395,46 +11395,30 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
11395
11395
{
11396
11396
struct vcpu_vmx * vmx = to_vmx (vcpu );
11397
11397
struct vmcs12 * vmcs12 = get_vmcs12 (vcpu );
11398
- u32 vm_inst_error = 0 ;
11399
11398
11400
11399
/* trying to cancel vmlaunch/vmresume is a bug */
11401
11400
WARN_ON_ONCE (vmx -> nested .nested_run_pending );
11402
11401
11402
+ /*
11403
+ * The only expected VM-instruction error is "VM entry with
11404
+ * invalid control field(s)." Anything else indicates a
11405
+ * problem with L0.
11406
+ */
11407
+ WARN_ON_ONCE (vmx -> fail && (vmcs_read32 (VM_INSTRUCTION_ERROR ) !=
11408
+ VMXERR_ENTRY_INVALID_CONTROL_FIELD ));
11409
+
11403
11410
leave_guest_mode (vcpu );
11404
- prepare_vmcs12 (vcpu , vmcs12 , exit_reason , exit_intr_info ,
11405
- exit_qualification );
11406
11411
11407
- if (nested_vmx_store_msr ( vcpu , vmcs12 -> vm_exit_msr_store_addr ,
11408
- vmcs12 -> vm_exit_msr_store_count ))
11409
- nested_vmx_abort ( vcpu , VMX_ABORT_SAVE_GUEST_MSR_FAIL );
11412
+ if (likely (! vmx -> fail )) {
11413
+ prepare_vmcs12 ( vcpu , vmcs12 , exit_reason , exit_intr_info ,
11414
+ exit_qualification );
11410
11415
11411
- if (unlikely (vmx -> fail ))
11412
- vm_inst_error = vmcs_read32 (VM_INSTRUCTION_ERROR );
11416
+ if (nested_vmx_store_msr (vcpu , vmcs12 -> vm_exit_msr_store_addr ,
11417
+ vmcs12 -> vm_exit_msr_store_count ))
11418
+ nested_vmx_abort (vcpu , VMX_ABORT_SAVE_GUEST_MSR_FAIL );
11419
+ }
11413
11420
11414
11421
vmx_switch_vmcs (vcpu , & vmx -> vmcs01 );
11415
-
11416
- /*
11417
- * TODO: SDM says that with acknowledge interrupt on exit, bit 31 of
11418
- * the VM-exit interrupt information (valid interrupt) is always set to
11419
- * 1 on EXIT_REASON_EXTERNAL_INTERRUPT, so we shouldn't need
11420
- * kvm_cpu_has_interrupt(). See the commit message for details.
11421
- */
11422
- if (nested_exit_intr_ack_set (vcpu ) &&
11423
- exit_reason == EXIT_REASON_EXTERNAL_INTERRUPT &&
11424
- kvm_cpu_has_interrupt (vcpu )) {
11425
- int irq = kvm_cpu_get_interrupt (vcpu );
11426
- WARN_ON (irq < 0 );
11427
- vmcs12 -> vm_exit_intr_info = irq |
11428
- INTR_INFO_VALID_MASK | INTR_TYPE_EXT_INTR ;
11429
- }
11430
-
11431
- trace_kvm_nested_vmexit_inject (vmcs12 -> vm_exit_reason ,
11432
- vmcs12 -> exit_qualification ,
11433
- vmcs12 -> idt_vectoring_info_field ,
11434
- vmcs12 -> vm_exit_intr_info ,
11435
- vmcs12 -> vm_exit_intr_error_code ,
11436
- KVM_ISA_VMX );
11437
-
11438
11422
vm_entry_controls_reset_shadow (vmx );
11439
11423
vm_exit_controls_reset_shadow (vmx );
11440
11424
vmx_segment_cache_clear (vmx );
@@ -11443,8 +11427,6 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
11443
11427
if (VMCS02_POOL_SIZE == 0 )
11444
11428
nested_free_vmcs02 (vmx , vmx -> nested .current_vmptr );
11445
11429
11446
- load_vmcs12_host_state (vcpu , vmcs12 );
11447
-
11448
11430
/* Update any VMCS fields that might have changed while L2 ran */
11449
11431
vmcs_write32 (VM_EXIT_MSR_LOAD_COUNT , vmx -> msr_autoload .nr );
11450
11432
vmcs_write32 (VM_ENTRY_MSR_LOAD_COUNT , vmx -> msr_autoload .nr );
@@ -11493,23 +11475,57 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
11493
11475
*/
11494
11476
kvm_make_request (KVM_REQ_APIC_PAGE_RELOAD , vcpu );
11495
11477
11496
- if (unlikely (vmx -> fail )) {
11497
- /*
11498
- * After an early L2 VM-entry failure, we're now back
11499
- * in L1 which thinks it just finished a VMLAUNCH or
11500
- * VMRESUME instruction, so we need to set the failure
11501
- * flag and the VM-instruction error field of the VMCS
11502
- * accordingly.
11503
- */
11504
- vmx -> fail = 0 ;
11505
- nested_vmx_failValid (vcpu , vm_inst_error );
11506
- }
11507
-
11508
11478
if (enable_shadow_vmcs )
11509
11479
vmx -> nested .sync_shadow_vmcs = true;
11510
11480
11511
11481
/* in case we halted in L2 */
11512
11482
vcpu -> arch .mp_state = KVM_MP_STATE_RUNNABLE ;
11483
+
11484
+ if (likely (!vmx -> fail )) {
11485
+ /*
11486
+ * TODO: SDM says that with acknowledge interrupt on
11487
+ * exit, bit 31 of the VM-exit interrupt information
11488
+ * (valid interrupt) is always set to 1 on
11489
+ * EXIT_REASON_EXTERNAL_INTERRUPT, so we shouldn't
11490
+ * need kvm_cpu_has_interrupt(). See the commit
11491
+ * message for details.
11492
+ */
11493
+ if (nested_exit_intr_ack_set (vcpu ) &&
11494
+ exit_reason == EXIT_REASON_EXTERNAL_INTERRUPT &&
11495
+ kvm_cpu_has_interrupt (vcpu )) {
11496
+ int irq = kvm_cpu_get_interrupt (vcpu );
11497
+ WARN_ON (irq < 0 );
11498
+ vmcs12 -> vm_exit_intr_info = irq |
11499
+ INTR_INFO_VALID_MASK | INTR_TYPE_EXT_INTR ;
11500
+ }
11501
+
11502
+ trace_kvm_nested_vmexit_inject (vmcs12 -> vm_exit_reason ,
11503
+ vmcs12 -> exit_qualification ,
11504
+ vmcs12 -> idt_vectoring_info_field ,
11505
+ vmcs12 -> vm_exit_intr_info ,
11506
+ vmcs12 -> vm_exit_intr_error_code ,
11507
+ KVM_ISA_VMX );
11508
+
11509
+ load_vmcs12_host_state (vcpu , vmcs12 );
11510
+
11511
+ return ;
11512
+ }
11513
+
11514
+ /*
11515
+ * After an early L2 VM-entry failure, we're now back
11516
+ * in L1 which thinks it just finished a VMLAUNCH or
11517
+ * VMRESUME instruction, so we need to set the failure
11518
+ * flag and the VM-instruction error field of the VMCS
11519
+ * accordingly.
11520
+ */
11521
+ nested_vmx_failValid (vcpu , VMXERR_ENTRY_INVALID_CONTROL_FIELD );
11522
+ /*
11523
+ * The emulated instruction was already skipped in
11524
+ * nested_vmx_run, but the updated RIP was never
11525
+ * written back to the vmcs01.
11526
+ */
11527
+ skip_emulated_instruction (vcpu );
11528
+ vmx -> fail = 0 ;
11513
11529
}
11514
11530
11515
11531
/*
0 commit comments