Re: [PATCH 02/28] KVM: x86: enable event window in inject_pending_event

From: Paolo Bonzini
Date: Fri May 29 2020 - 04:48:09 EST


On 29/05/20 04:16, Krish Sadhukhan wrote:
>
> On 5/26/20 10:22 AM, Paolo Bonzini wrote:
>> In case an interrupt arrives after nested.check_events but before the
>> call to kvm_cpu_has_injectable_intr, we could end up enabling the
>> interrupt
>> window even if the interrupt is actually going to be a vmexit. This is
>> useless rather than harmful, but it really complicates reasoning about
>> SVM's handling of the VINTR intercept. We'd like to never bother with
>> the VINTR intercept if V_INTR_MASKING=1 && INTERCEPT_INTR=1, because in
>> that case there is no interrupt window and we can just exit the nested
>> guest whenever we want.
>>
>> As a first step, this patch moves the opening of the interrupt
>> window inside inject_pending_event. This consolidates the check for
>> pending interrupt/NMI/SMI in one place, removing the repeated call to
>> kvm_cpu_has_injectable_intr.
>>
>> The main functional change here is that re-injection of still-pending
>> events will also use req_immediate_exit instead of using interrupt-window
>> intercepts.
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
>> ---
>> Â arch/x86/include/asm/kvm_host.h |ÂÂ 8 +--
>> Â arch/x86/kvm/svm/svm.cÂÂÂÂÂÂÂÂÂ |Â 24 +++----
>> Â arch/x86/kvm/vmx/vmx.cÂÂÂÂÂÂÂÂÂ |Â 20 +++---
>> Â arch/x86/kvm/x86.cÂÂÂÂÂÂÂÂÂÂÂÂÂ | 112 +++++++++++++++++---------------
>> Â 4 files changed, 87 insertions(+), 77 deletions(-)
>>
>> diff --git a/arch/x86/include/asm/kvm_host.h
>> b/arch/x86/include/asm/kvm_host.h
>> index db261da578f3..7707bd4b0593 100644
>> --- a/arch/x86/include/asm/kvm_host.h
>> +++ b/arch/x86/include/asm/kvm_host.h
>> @@ -1136,8 +1136,8 @@ struct kvm_x86_ops {
>> ÂÂÂÂÂ void (*set_nmi)(struct kvm_vcpu *vcpu);
>> ÂÂÂÂÂ void (*queue_exception)(struct kvm_vcpu *vcpu);
>> ÂÂÂÂÂ void (*cancel_injection)(struct kvm_vcpu *vcpu);
>> -ÂÂÂ bool (*interrupt_allowed)(struct kvm_vcpu *vcpu, bool
>> for_injection);
>> -ÂÂÂ bool (*nmi_allowed)(struct kvm_vcpu *vcpu, bool for_injection);
>> +ÂÂÂ int (*interrupt_allowed)(struct kvm_vcpu *vcpu, bool for_injection);
>> +ÂÂÂ int (*nmi_allowed)(struct kvm_vcpu *vcpu, bool for_injection);
>> ÂÂÂÂÂ bool (*get_nmi_mask)(struct kvm_vcpu *vcpu);
>> ÂÂÂÂÂ void (*set_nmi_mask)(struct kvm_vcpu *vcpu, bool masked);
>> ÂÂÂÂÂ void (*enable_nmi_window)(struct kvm_vcpu *vcpu);
>> @@ -1234,10 +1234,10 @@ struct kvm_x86_ops {
>> Â ÂÂÂÂÂ void (*setup_mce)(struct kvm_vcpu *vcpu);
>> Â -ÂÂÂ bool (*smi_allowed)(struct kvm_vcpu *vcpu, bool for_injection);
>> +ÂÂÂ int (*smi_allowed)(struct kvm_vcpu *vcpu, bool for_injection);
>> ÂÂÂÂÂ int (*pre_enter_smm)(struct kvm_vcpu *vcpu, char *smstate);
>> ÂÂÂÂÂ int (*pre_leave_smm)(struct kvm_vcpu *vcpu, const char *smstate);
>> -ÂÂÂ int (*enable_smi_window)(struct kvm_vcpu *vcpu);
>> +ÂÂÂ void (*enable_smi_window)(struct kvm_vcpu *vcpu);
>> Â ÂÂÂÂÂ int (*mem_enc_op)(struct kvm *kvm, void __user *argp);
>> ÂÂÂÂÂ int (*mem_enc_reg_region)(struct kvm *kvm, struct kvm_enc_region
>> *argp);
>> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
>> index 9987f6fe9d88..9ac9963405b5 100644
>> --- a/arch/x86/kvm/svm/svm.c
>> +++ b/arch/x86/kvm/svm/svm.c
>> @@ -3053,15 +3053,15 @@ bool svm_nmi_blocked(struct kvm_vcpu *vcpu)
>> ÂÂÂÂÂ return ret;
>> Â }
>> Â -static bool svm_nmi_allowed(struct kvm_vcpu *vcpu, bool for_injection)
>> +static int svm_nmi_allowed(struct kvm_vcpu *vcpu, bool for_injection)
>> Â {
>> ÂÂÂÂÂ struct vcpu_svm *svm = to_svm(vcpu);
>> ÂÂÂÂÂ if (svm->nested.nested_run_pending)
>> -ÂÂÂÂÂÂÂ return false;
>> +ÂÂÂÂÂÂÂ return -EBUSY;
>> Â ÂÂÂÂÂ /* An NMI must not be injected into L2 if it's supposed to
>> VM-Exit. */
>> ÂÂÂÂÂ if (for_injection && is_guest_mode(vcpu) &&
>> nested_exit_on_nmi(svm))
>> -ÂÂÂÂÂÂÂ return false;
>> +ÂÂÂÂÂÂÂ return -EBUSY;
>> Â ÂÂÂÂÂ return !svm_nmi_blocked(vcpu);
>> Â }
>> @@ -3112,18 +3112,18 @@ bool svm_interrupt_blocked(struct kvm_vcpu *vcpu)
>> ÂÂÂÂÂ return (vmcb->control.int_state & SVM_INTERRUPT_SHADOW_MASK);
>> Â }
>> Â -static bool svm_interrupt_allowed(struct kvm_vcpu *vcpu, bool
>> for_injection)
>> +static int svm_interrupt_allowed(struct kvm_vcpu *vcpu, bool
>> for_injection)
>> Â {
>> ÂÂÂÂÂ struct vcpu_svm *svm = to_svm(vcpu);
>> ÂÂÂÂÂ if (svm->nested.nested_run_pending)
>> -ÂÂÂÂÂÂÂ return false;
>> +ÂÂÂÂÂÂÂ return -EBUSY;
>> Â ÂÂÂÂÂ /*
>> ÂÂÂÂÂÂ * An IRQ must not be injected into L2 if it's supposed to VM-Exit,
>> ÂÂÂÂÂÂ * e.g. if the IRQ arrived asynchronously after checking nested
>> events.
>> ÂÂÂÂÂÂ */
>> ÂÂÂÂÂ if (for_injection && is_guest_mode(vcpu) &&
>> nested_exit_on_intr(svm))
>> -ÂÂÂÂÂÂÂ return false;
>> +ÂÂÂÂÂÂÂ return -EBUSY;
>> Â ÂÂÂÂÂ return !svm_interrupt_blocked(vcpu);
>> Â }
>> @@ -3793,15 +3793,15 @@ bool svm_smi_blocked(struct kvm_vcpu *vcpu)
>> ÂÂÂÂÂ return is_smm(vcpu);
>> Â }
>> Â -static bool svm_smi_allowed(struct kvm_vcpu *vcpu, bool for_injection)
>> +static int svm_smi_allowed(struct kvm_vcpu *vcpu, bool for_injection)
>> Â {
>> ÂÂÂÂÂ struct vcpu_svm *svm = to_svm(vcpu);
>> ÂÂÂÂÂ if (svm->nested.nested_run_pending)
>> -ÂÂÂÂÂÂÂ return false;
>> +ÂÂÂÂÂÂÂ return -EBUSY;
>> Â ÂÂÂÂÂ /* An SMI must not be injected into L2 if it's supposed to
>> VM-Exit. */
>> ÂÂÂÂÂ if (for_injection && is_guest_mode(vcpu) &&
>> nested_exit_on_smi(svm))
>> -ÂÂÂÂÂÂÂ return false;
>> +ÂÂÂÂÂÂÂ return -EBUSY;
>> Â ÂÂÂÂÂ return !svm_smi_blocked(vcpu);
>> Â }
>> @@ -3848,7 +3848,7 @@ static int svm_pre_leave_smm(struct kvm_vcpu
>> *vcpu, const char *smstate)
>> ÂÂÂÂÂ return 0;
>> Â }
>> Â -static int enable_smi_window(struct kvm_vcpu *vcpu)
>> +static void enable_smi_window(struct kvm_vcpu *vcpu)
>> Â {
>> ÂÂÂÂÂ struct vcpu_svm *svm = to_svm(vcpu);
>> Â @@ -3856,9 +3856,9 @@ static int enable_smi_window(struct kvm_vcpu
>> *vcpu)
>> ÂÂÂÂÂÂÂÂÂ if (vgif_enabled(svm))
>> ÂÂÂÂÂÂÂÂÂÂÂÂÂ set_intercept(svm, INTERCEPT_STGI);
>> ÂÂÂÂÂÂÂÂÂ /* STGI will cause a vm exit */
>> -ÂÂÂÂÂÂÂ return 1;
>> +ÂÂÂ } else {
>> + /* We must be in SMM; RSM will cause a vmexit anyway. */
>> ÂÂÂÂÂ }
>> -ÂÂÂ return 0;
>> Â }
>> Â Â static bool svm_need_emulation_on_page_fault(struct kvm_vcpu *vcpu)
>> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
>> index 55712dd86baf..aedc46407b1f 100644
>> --- a/arch/x86/kvm/vmx/vmx.c
>> +++ b/arch/x86/kvm/vmx/vmx.c
>> @@ -4552,14 +4552,14 @@ bool vmx_nmi_blocked(struct kvm_vcpu *vcpu)
>> ÂÂÂÂÂÂÂÂÂÂ GUEST_INTR_STATE_NMI));
>> Â }
>> Â -static bool vmx_nmi_allowed(struct kvm_vcpu *vcpu, bool for_injection)
>> +static int vmx_nmi_allowed(struct kvm_vcpu *vcpu, bool for_injection)
>> Â {
>> ÂÂÂÂÂ if (to_vmx(vcpu)->nested.nested_run_pending)
>> -ÂÂÂÂÂÂÂ return false;
>> +ÂÂÂÂÂÂÂ return -EBUSY;
>> Â ÂÂÂÂÂ /* An NMI must not be injected into L2 if it's supposed to
>> VM-Exit. */
>> ÂÂÂÂÂ if (for_injection && is_guest_mode(vcpu) &&
>> nested_exit_on_nmi(vcpu))
>> -ÂÂÂÂÂÂÂ return false;
>> +ÂÂÂÂÂÂÂ return -EBUSY;
>> Â ÂÂÂÂÂ return !vmx_nmi_blocked(vcpu);
>> Â }
>> @@ -4574,17 +4574,17 @@ bool vmx_interrupt_blocked(struct kvm_vcpu *vcpu)
>> ÂÂÂÂÂÂÂÂÂ (GUEST_INTR_STATE_STI | GUEST_INTR_STATE_MOV_SS));
>> Â }
>> Â -static bool vmx_interrupt_allowed(struct kvm_vcpu *vcpu, bool
>> for_injection)
>> +static int vmx_interrupt_allowed(struct kvm_vcpu *vcpu, bool
>> for_injection)
>> Â {
>> ÂÂÂÂÂ if (to_vmx(vcpu)->nested.nested_run_pending)
>> -ÂÂÂÂÂÂÂ return false;
>> +ÂÂÂÂÂÂÂ return -EBUSY;
>> Â ÂÂÂÂÂÂÂÂ /*
>> ÂÂÂÂÂÂÂÂÂ * An IRQ must not be injected into L2 if it's supposed to
>> VM-Exit,
>> ÂÂÂÂÂÂÂÂÂ * e.g. if the IRQ arrived asynchronously after checking
>> nested events.
>> ÂÂÂÂÂÂÂÂÂ */
>> ÂÂÂÂÂ if (for_injection && is_guest_mode(vcpu) &&
>> nested_exit_on_intr(vcpu))
>> -ÂÂÂÂÂÂÂ return false;
>> +ÂÂÂÂÂÂÂ return -EBUSY;
>> Â ÂÂÂÂÂ return !vmx_interrupt_blocked(vcpu);
>> Â }
>> @@ -7755,11 +7755,11 @@ static void vmx_setup_mce(struct kvm_vcpu *vcpu)
>> ÂÂÂÂÂÂÂÂÂÂÂÂÂ ~FEAT_CTL_LMCE_ENABLED;
>> Â }
>> Â -static bool vmx_smi_allowed(struct kvm_vcpu *vcpu, bool for_injection)
>> +static int vmx_smi_allowed(struct kvm_vcpu *vcpu, bool for_injection)
>> Â {
>> ÂÂÂÂÂ /* we need a nested vmexit to enter SMM, postpone if run is
>> pending */
>> ÂÂÂÂÂ if (to_vmx(vcpu)->nested.nested_run_pending)
>> -ÂÂÂÂÂÂÂ return false;
>> +ÂÂÂÂÂÂÂ return -EBUSY;
>> ÂÂÂÂÂ return !is_smm(vcpu);
>> Â }
>> Â @@ -7797,9 +7797,9 @@ static int vmx_pre_leave_smm(struct kvm_vcpu
>> *vcpu, const char *smstate)
>> ÂÂÂÂÂ return 0;
>> Â }
>> Â -static int enable_smi_window(struct kvm_vcpu *vcpu)
>> +static void enable_smi_window(struct kvm_vcpu *vcpu)
>> Â {
>> -ÂÂÂ return 0;
>> + /* RSM will cause a vmexit anyway. */
>> Â }
>> Â Â static bool vmx_need_emulation_on_page_fault(struct kvm_vcpu *vcpu)
>> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>> index 064a7ea0e671..192238841cac 100644
>> --- a/arch/x86/kvm/x86.c
>> +++ b/arch/x86/kvm/x86.c
>> @@ -7710,7 +7710,7 @@ static void update_cr8_intercept(struct kvm_vcpu
>> *vcpu)
>> ÂÂÂÂÂ kvm_x86_ops.update_cr8_intercept(vcpu, tpr, max_irr);
>> Â }
>> Â -static int inject_pending_event(struct kvm_vcpu *vcpu)
>> +static void inject_pending_event(struct kvm_vcpu *vcpu, bool
>> *req_immediate_exit)
>
>
> Now that this function also opens the interrupt window instead of
> injecting an event, does it makes sense to change its name to something
> like process_pending_event() ?
>
>> Â {
>> ÂÂÂÂÂ int r;
>> ÂÂÂÂÂ bool can_inject = true;
>> @@ -7756,8 +7756,8 @@ static int inject_pending_event(struct kvm_vcpu
>> *vcpu)
>> ÂÂÂÂÂÂ */
>> ÂÂÂÂÂ if (is_guest_mode(vcpu)) {
>> ÂÂÂÂÂÂÂÂÂ r = kvm_x86_ops.nested_ops->check_events(vcpu);
>> -ÂÂÂÂÂÂÂ if (r != 0)
>> -ÂÂÂÂÂÂÂÂÂÂÂ return r;
>> +ÂÂÂÂÂÂÂ if (r < 0)
>> +ÂÂÂÂÂÂÂÂÂÂÂ goto busy;
>> ÂÂÂÂÂ }
>> Â ÂÂÂÂÂ /* try to inject new event if pending */
>> @@ -7795,27 +7795,64 @@ static int inject_pending_event(struct
>> kvm_vcpu *vcpu)
>> ÂÂÂÂÂÂÂÂÂ can_inject = false;
>> ÂÂÂÂÂ }
>> Â -ÂÂÂ /* Finish re-injection before considering new events */
>> -ÂÂÂ if (!can_inject)
>> -ÂÂÂÂÂÂÂ return 0;
>> +ÂÂÂ /*
>> +ÂÂÂÂ * Finally, either inject the event or enable window-open exits.
>> +ÂÂÂÂ * If an event is pending but cannot be injected right now (for
>> +ÂÂÂÂ * example if it just arrived and we have to inject it as a
>> + * vmexit), then we request an immediate exit. This is indicated
>> +ÂÂÂÂ * by a -EBUSY return value from kvm_x86_ops.*_allowed.
>> +ÂÂÂÂ */
>> +ÂÂÂ if (vcpu->arch.smi_pending) {
>> +ÂÂÂÂÂÂÂ r = can_inject ? kvm_x86_ops.smi_allowed(vcpu, true) : -EBUSY;
>> +ÂÂÂÂÂÂÂ if (r < 0)
>> +ÂÂÂÂÂÂÂÂÂÂÂ goto busy;
>> +ÂÂÂÂÂÂÂ if (r) {
>> +ÂÂÂÂÂÂÂÂÂÂÂ vcpu->arch.smi_pending = false;
>> +ÂÂÂÂÂÂÂÂÂÂÂ ++vcpu->arch.smi_count;
>> +ÂÂÂÂÂÂÂÂÂÂÂ enter_smm(vcpu);
>> +ÂÂÂÂÂÂÂÂÂÂÂ can_inject = false;
>> +ÂÂÂÂÂÂÂ } else {
>> +ÂÂÂÂÂÂÂÂÂÂÂ kvm_x86_ops.enable_smi_window(vcpu);
>> +ÂÂÂÂÂÂÂ }
>> +ÂÂÂ }
>> Â -ÂÂÂ if (vcpu->arch.smi_pending &&
>> -ÂÂÂÂÂÂÂ kvm_x86_ops.smi_allowed(vcpu, true)) {
>> -ÂÂÂÂÂÂÂ vcpu->arch.smi_pending = false;
>> -ÂÂÂÂÂÂÂ ++vcpu->arch.smi_count;
>> -ÂÂÂÂÂÂÂ enter_smm(vcpu);
>> -ÂÂÂ } else if (vcpu->arch.nmi_pending &&
>> -ÂÂÂÂÂÂÂÂÂÂ kvm_x86_ops.nmi_allowed(vcpu, true)) {
>> -ÂÂÂÂÂÂÂ --vcpu->arch.nmi_pending;
>> -ÂÂÂÂÂÂÂ vcpu->arch.nmi_injected = true;
>> -ÂÂÂÂÂÂÂ kvm_x86_ops.set_nmi(vcpu);
>> -ÂÂÂ } else if (kvm_cpu_has_injectable_intr(vcpu) &&
>> -ÂÂÂÂÂÂÂÂÂÂ kvm_x86_ops.interrupt_allowed(vcpu, true)) {
>> -ÂÂÂÂÂÂÂ kvm_queue_interrupt(vcpu, kvm_cpu_get_interrupt(vcpu), false);
>> -ÂÂÂÂÂÂÂ kvm_x86_ops.set_irq(vcpu);
>> +ÂÂÂ if (vcpu->arch.nmi_pending) {
>> +ÂÂÂÂÂÂÂ r = can_inject ? kvm_x86_ops.nmi_allowed(vcpu, true) : -EBUSY;
>> +ÂÂÂÂÂÂÂ if (r < 0)
>> +ÂÂÂÂÂÂÂÂÂÂÂ goto busy;
>> +ÂÂÂÂÂÂÂ if (r) {
>> +ÂÂÂÂÂÂÂÂÂÂÂ --vcpu->arch.nmi_pending;
>> +ÂÂÂÂÂÂÂÂÂÂÂ vcpu->arch.nmi_injected = true;
>> +ÂÂÂÂÂÂÂÂÂÂÂ kvm_x86_ops.set_nmi(vcpu);
>> +ÂÂÂÂÂÂÂÂÂÂÂ can_inject = false;
>> +ÂÂÂÂÂÂÂ } else {
>> +ÂÂÂÂÂÂÂÂÂÂÂ kvm_x86_ops.enable_nmi_window(vcpu);
>> +ÂÂÂÂÂÂÂ }
>> ÂÂÂÂÂ }
>> Â -ÂÂÂ return 0;
>> +ÂÂÂ if (kvm_cpu_has_injectable_intr(vcpu)) {
>> +ÂÂÂÂÂÂÂ r = can_inject ? kvm_x86_ops.interrupt_allowed(vcpu, true) :
>> -EBUSY;
>> +ÂÂÂÂÂÂÂ if (r < 0)
>> +ÂÂÂÂÂÂÂÂÂÂÂ goto busy;
>> +ÂÂÂÂÂÂÂ if (r) {
>> +ÂÂÂÂÂÂÂÂÂÂÂ kvm_queue_interrupt(vcpu, kvm_cpu_get_interrupt(vcpu),
>> false);
>> +ÂÂÂÂÂÂÂÂÂÂÂ kvm_x86_ops.set_irq(vcpu);
>> +ÂÂÂÂÂÂÂ } else {
>> +ÂÂÂÂÂÂÂÂÂÂÂ kvm_x86_ops.enable_irq_window(vcpu);
>> +ÂÂÂÂÂÂÂ }
>> +ÂÂÂ }
>> +
>> +ÂÂÂ if (is_guest_mode(vcpu) &&
>> +ÂÂÂÂÂÂÂ kvm_x86_ops.nested_ops->hv_timer_pending &&
>> +ÂÂÂÂÂÂÂ kvm_x86_ops.nested_ops->hv_timer_pending(vcpu))
>> +ÂÂÂÂÂÂÂ *req_immediate_exit = true;
>
>
> Nit:Â May be we can use goto for consistency ?
>
>> +
>> +ÂÂÂ WARN_ON(vcpu->arch.exception.pending);
>> +ÂÂÂ return;
>> +
>> +busy:
>> +ÂÂÂ *req_immediate_exit = true;
>> +ÂÂÂ return;
>> Â }
>> Â Â static void process_nmi(struct kvm_vcpu *vcpu)
>> @@ -8353,36 +8390,9 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
>> ÂÂÂÂÂÂÂÂÂÂÂÂÂ goto out;
>> ÂÂÂÂÂÂÂÂÂ }
>> Â -ÂÂÂÂÂÂÂ if (inject_pending_event(vcpu) != 0)
>> -ÂÂÂÂÂÂÂÂÂÂÂ req_immediate_exit = true;
>> -ÂÂÂÂÂÂÂ else {
>> -ÂÂÂÂÂÂÂÂÂÂÂ /* Enable SMI/NMI/IRQ window open exits if needed.
>> -ÂÂÂÂÂÂÂÂÂÂÂÂ *
>> -ÂÂÂÂÂÂÂÂÂÂÂÂ * SMIs have three cases:
>> -ÂÂÂÂÂÂÂÂÂÂÂÂ * 1) They can be nested, and then there is nothing to
>> -ÂÂÂÂÂÂÂÂÂÂÂÂ *ÂÂÂ do here because RSM will cause a vmexit anyway.
>> -ÂÂÂÂÂÂÂÂÂÂÂÂ * 2) There is an ISA-specific reason why SMI cannot be
>> -ÂÂÂÂÂÂÂÂÂÂÂÂ *ÂÂÂ injected, and the moment when this changes can be
>> -ÂÂÂÂÂÂÂÂÂÂÂÂ *ÂÂÂ intercepted.
>> -ÂÂÂÂÂÂÂÂÂÂÂÂ * 3) Or the SMI can be pending because
>> -ÂÂÂÂÂÂÂÂÂÂÂÂ *ÂÂÂ inject_pending_event has completed the injection
>> -ÂÂÂÂÂÂÂÂÂÂÂÂ *ÂÂÂ of an IRQ or NMI from the previous vmexit, and
>> -ÂÂÂÂÂÂÂÂÂÂÂÂ *ÂÂÂ then we request an immediate exit to inject the
>> -ÂÂÂÂÂÂÂÂÂÂÂÂ *ÂÂÂ SMI.
>> -ÂÂÂÂÂÂÂÂÂÂÂÂ */
>> -ÂÂÂÂÂÂÂÂÂÂÂ if (vcpu->arch.smi_pending && !is_smm(vcpu))
>> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (!kvm_x86_ops.enable_smi_window(vcpu))
>> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ req_immediate_exit = true;
>> -ÂÂÂÂÂÂÂÂÂÂÂ if (vcpu->arch.nmi_pending)
>> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ kvm_x86_ops.enable_nmi_window(vcpu);
>> -ÂÂÂÂÂÂÂÂÂÂÂ if (kvm_cpu_has_injectable_intr(vcpu) || req_int_win)
>> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ kvm_x86_ops.enable_irq_window(vcpu);
>> -ÂÂÂÂÂÂÂÂÂÂÂ if (is_guest_mode(vcpu) &&
>> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ kvm_x86_ops.nested_ops->hv_timer_pending &&
>> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ kvm_x86_ops.nested_ops->hv_timer_pending(vcpu))
>> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ req_immediate_exit = true;
>> -ÂÂÂÂÂÂÂÂÂÂÂ WARN_ON(vcpu->arch.exception.pending);
>> -ÂÂÂÂÂÂÂ }
>> +ÂÂÂÂÂÂÂ inject_pending_event(vcpu, &req_immediate_exit);
>> +ÂÂÂÂÂÂÂ if (req_int_win)
>> +ÂÂÂÂÂÂÂÂÂÂÂ kvm_x86_ops.enable_irq_window(vcpu);
>
>
> Passing req_int_win to inject_pending_event and opening the window
> inside there will probably look logically better since this action is
> taken inside it.

This is a special case for the userspace irqchip case;
inject_pending_event is enabling the IRQ window in response to a pending
event while this is not. But your right that I should rename
inject_pending_event to handle_pending_event.

Also, I'm thinking of dropping support for kernel_irqchip=off
completely, in that unless you do KVM_CREATE_IRQCHIP you won't be able
to inject interrupts at all.

Paolo