@@ -3442,7 +3442,7 @@ static int nested_vmx_write_pml_buffer(struct kvm_vcpu *vcpu, gpa_t gpa)
3442
3442
if (!nested_cpu_has_pml (vmcs12 ))
3443
3443
return 0 ;
3444
3444
3445
- if (vmcs12 -> guest_pml_index >= PML_ENTITY_NUM ) {
3445
+ if (vmcs12 -> guest_pml_index >= PML_LOG_NR_ENTRIES ) {
3446
3446
vmx -> nested .pml_full = true;
3447
3447
return 1 ;
3448
3448
}
@@ -3481,14 +3481,6 @@ static int nested_vmx_check_permission(struct kvm_vcpu *vcpu)
3481
3481
return 1 ;
3482
3482
}
3483
3483
3484
- static u8 vmx_has_apicv_interrupt (struct kvm_vcpu * vcpu )
3485
- {
3486
- u8 rvi = vmx_get_rvi ();
3487
- u8 vppr = kvm_lapic_get_reg (vcpu -> arch .apic , APIC_PROCPRI );
3488
-
3489
- return ((rvi & 0xf0 ) > (vppr & 0xf0 ));
3490
- }
3491
-
3492
3484
static void load_vmcs12_host_state (struct kvm_vcpu * vcpu ,
3493
3485
struct vmcs12 * vmcs12 );
3494
3486
@@ -3508,7 +3500,6 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu,
3508
3500
struct vcpu_vmx * vmx = to_vmx (vcpu );
3509
3501
struct vmcs12 * vmcs12 = get_vmcs12 (vcpu );
3510
3502
enum vm_entry_failure_code entry_failure_code ;
3511
- bool evaluate_pending_interrupts ;
3512
3503
union vmx_exit_reason exit_reason = {
3513
3504
.basic = EXIT_REASON_INVALID_STATE ,
3514
3505
.failed_vmentry = 1 ,
@@ -3527,13 +3518,6 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu,
3527
3518
3528
3519
kvm_service_local_tlb_flush_requests (vcpu );
3529
3520
3530
- evaluate_pending_interrupts = exec_controls_get (vmx ) &
3531
- (CPU_BASED_INTR_WINDOW_EXITING | CPU_BASED_NMI_WINDOW_EXITING );
3532
- if (likely (!evaluate_pending_interrupts ) && kvm_vcpu_apicv_active (vcpu ))
3533
- evaluate_pending_interrupts |= vmx_has_apicv_interrupt (vcpu );
3534
- if (!evaluate_pending_interrupts )
3535
- evaluate_pending_interrupts |= kvm_apic_has_pending_init_or_sipi (vcpu );
3536
-
3537
3521
if (!vmx -> nested .nested_run_pending ||
3538
3522
!(vmcs12 -> vm_entry_controls & VM_ENTRY_LOAD_DEBUG_CONTROLS ))
3539
3523
vmx -> nested .pre_vmenter_debugctl = vmcs_read64 (GUEST_IA32_DEBUGCTL );
@@ -3616,9 +3600,13 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu,
3616
3600
* Re-evaluate pending events if L1 had a pending IRQ/NMI/INIT/SIPI
3617
3601
* when it executed VMLAUNCH/VMRESUME, as entering non-root mode can
3618
3602
* effectively unblock various events, e.g. INIT/SIPI cause VM-Exit
3619
- * unconditionally.
3603
+ * unconditionally. Take care to pull data from vmcs01 as appropriate,
3604
+ * e.g. when checking for interrupt windows, as vmcs02 is now loaded.
3620
3605
*/
3621
- if (unlikely (evaluate_pending_interrupts ))
3606
+ if ((__exec_controls_get (& vmx -> vmcs01 ) & (CPU_BASED_INTR_WINDOW_EXITING |
3607
+ CPU_BASED_NMI_WINDOW_EXITING )) ||
3608
+ kvm_apic_has_pending_init_or_sipi (vcpu ) ||
3609
+ kvm_apic_has_interrupt (vcpu ))
3622
3610
kvm_make_request (KVM_REQ_EVENT , vcpu );
3623
3611
3624
3612
/*
@@ -3751,14 +3739,6 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch)
3751
3739
if (unlikely (status != NVMX_VMENTRY_SUCCESS ))
3752
3740
goto vmentry_failed ;
3753
3741
3754
- /* Emulate processing of posted interrupts on VM-Enter. */
3755
- if (nested_cpu_has_posted_intr (vmcs12 ) &&
3756
- kvm_apic_has_interrupt (vcpu ) == vmx -> nested .posted_intr_nv ) {
3757
- vmx -> nested .pi_pending = true;
3758
- kvm_make_request (KVM_REQ_EVENT , vcpu );
3759
- kvm_apic_clear_irr (vcpu , vmx -> nested .posted_intr_nv );
3760
- }
3761
-
3762
3742
/* Hide L1D cache contents from the nested guest. */
3763
3743
vmx -> vcpu .arch .l1tf_flush_l1d = true;
3764
3744
@@ -4220,13 +4200,25 @@ static int vmx_check_nested_events(struct kvm_vcpu *vcpu)
4220
4200
*/
4221
4201
bool block_nested_exceptions = vmx -> nested .nested_run_pending ;
4222
4202
/*
4223
- * New events (not exceptions) are only recognized at instruction
4203
+ * Events that don't require injection, i.e. that are virtualized by
4204
+ * hardware, aren't blocked by a pending VM-Enter as KVM doesn't need
4205
+ * to regain control in order to deliver the event, and hardware will
4206
+ * handle event ordering, e.g. with respect to injected exceptions.
4207
+ *
4208
+ * But, new events (not exceptions) are only recognized at instruction
4224
4209
* boundaries. If an event needs reinjection, then KVM is handling a
4225
- * VM-Exit that occurred _during_ instruction execution; new events are
4226
- * blocked until the instruction completes.
4210
+ * VM-Exit that occurred _during_ instruction execution; new events,
4211
+ * irrespective of whether or not they're injected, are blocked until
4212
+ * the instruction completes.
4213
+ */
4214
+ bool block_non_injected_events = kvm_event_needs_reinjection (vcpu );
4215
+ /*
4216
+ * Inject events are blocked by nested VM-Enter, as KVM is responsible
4217
+ * for managing priority between concurrent events, i.e. KVM needs to
4218
+ * wait until after VM-Enter completes to deliver injected events.
4227
4219
*/
4228
4220
bool block_nested_events = block_nested_exceptions ||
4229
- kvm_event_needs_reinjection ( vcpu ) ;
4221
+ block_non_injected_events ;
4230
4222
4231
4223
if (lapic_in_kernel (vcpu ) &&
4232
4224
test_bit (KVM_APIC_INIT , & apic -> pending_events )) {
@@ -4338,18 +4330,26 @@ static int vmx_check_nested_events(struct kvm_vcpu *vcpu)
4338
4330
if (kvm_cpu_has_interrupt (vcpu ) && !vmx_interrupt_blocked (vcpu )) {
4339
4331
int irq ;
4340
4332
4341
- if (block_nested_events )
4342
- return - EBUSY ;
4343
- if (!nested_exit_on_intr (vcpu ))
4333
+ if (!nested_exit_on_intr (vcpu )) {
4334
+ if (block_nested_events )
4335
+ return - EBUSY ;
4336
+
4344
4337
goto no_vmexit ;
4338
+ }
4345
4339
4346
4340
if (!nested_exit_intr_ack_set (vcpu )) {
4341
+ if (block_nested_events )
4342
+ return - EBUSY ;
4343
+
4347
4344
nested_vmx_vmexit (vcpu , EXIT_REASON_EXTERNAL_INTERRUPT , 0 , 0 );
4348
4345
return 0 ;
4349
4346
}
4350
4347
4351
4348
irq = kvm_cpu_get_extint (vcpu );
4352
4349
if (irq != -1 ) {
4350
+ if (block_nested_events )
4351
+ return - EBUSY ;
4352
+
4353
4353
nested_vmx_vmexit (vcpu , EXIT_REASON_EXTERNAL_INTERRUPT ,
4354
4354
INTR_INFO_VALID_MASK | INTR_TYPE_EXT_INTR | irq , 0 );
4355
4355
return 0 ;
@@ -4368,11 +4368,22 @@ static int vmx_check_nested_events(struct kvm_vcpu *vcpu)
4368
4368
* and enabling posted interrupts requires ACK-on-exit.
4369
4369
*/
4370
4370
if (irq == vmx -> nested .posted_intr_nv ) {
4371
+ /*
4372
+ * Nested posted interrupts are delivered via RVI, i.e.
4373
+ * aren't injected by KVM, and so can be queued even if
4374
+ * manual event injection is disallowed.
4375
+ */
4376
+ if (block_non_injected_events )
4377
+ return - EBUSY ;
4378
+
4371
4379
vmx -> nested .pi_pending = true;
4372
4380
kvm_apic_clear_irr (vcpu , irq );
4373
4381
goto no_vmexit ;
4374
4382
}
4375
4383
4384
+ if (block_nested_events )
4385
+ return - EBUSY ;
4386
+
4376
4387
nested_vmx_vmexit (vcpu , EXIT_REASON_EXTERNAL_INTERRUPT ,
4377
4388
INTR_INFO_VALID_MASK | INTR_TYPE_EXT_INTR | irq , 0 );
4378
4389
@@ -5050,6 +5061,11 @@ void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 vm_exit_reason,
5050
5061
kvm_make_request (KVM_REQ_APICV_UPDATE , vcpu );
5051
5062
}
5052
5063
5064
+ if (vmx -> nested .update_vmcs01_hwapic_isr ) {
5065
+ vmx -> nested .update_vmcs01_hwapic_isr = false;
5066
+ kvm_apic_update_hwapic_isr (vcpu );
5067
+ }
5068
+
5053
5069
if ((vm_exit_reason != -1 ) &&
5054
5070
(enable_shadow_vmcs || nested_vmx_is_evmptr12_valid (vmx )))
5055
5071
vmx -> nested .need_vmcs12_to_shadow_sync = true;
0 commit comments