All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] KVM: x86: Inject pending interrupt even if pending nmi exist
@ 2016-03-24  5:17 Yuki Shibuya
  2016-03-24 11:14 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Yuki Shibuya @ 2016-03-24  5:17 UTC (permalink / raw)
  To: pbonzini; +Cc: kvm, Radim Krčmář, Jan Kiszka, Nobuo Yoshida

Non maskable interrupts (NMI) are preferred to interrupts in current
implementation. If a NMI is pending and NMI is blocked by the result
of nmi_allowed(), pending interrupt is not injected and
enable_irq_window() is not executed, even if interrupts injection is
allowed.

In old kernel (e.g. 2.6.32), schedule() is often called in NMI context.
In this case, interrupts are needed to execute iret that intends end
of NMI. The flag of blocking new NMI is not cleared until the guest
execute the iret, and interrupts are blocked by pending NMI. Due to
this, iret can't be invoked in the guest, and the guest is starved
until block is cleared by some events (e.g. canceling injection).

This patch injects pending interrupts, when it's allowed, even if NMI
is blocked. And, If an interrupts is pending after executing
inject_pending_event(), enable_irq_window() is executed regardless of
NMI pending counter.

Signed-off-by: Yuki Shibuya <shibuya.yk@ncos.nec.co.jp>
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
---
 arch/x86/kvm/x86.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 7236bd3..d4fd555 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -6087,12 +6087,10 @@ static int inject_pending_event(struct kvm_vcpu *vcpu, bool req_int_win)
 	}
 
 	/* try to inject new event if pending */
-	if (vcpu->arch.nmi_pending) {
-		if (kvm_x86_ops->nmi_allowed(vcpu)) {
-			--vcpu->arch.nmi_pending;
-			vcpu->arch.nmi_injected = true;
-			kvm_x86_ops->set_nmi(vcpu);
-		}
+	if (vcpu->arch.nmi_pending && kvm_x86_ops->nmi_allowed(vcpu)) {
+		--vcpu->arch.nmi_pending;
+		vcpu->arch.nmi_injected = true;
+		kvm_x86_ops->set_nmi(vcpu);
 	} else if (kvm_cpu_has_injectable_intr(vcpu)) {
 		/*
 		 * Because interrupts can be injected asynchronously, we are
@@ -6561,10 +6559,12 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
 		if (inject_pending_event(vcpu, req_int_win) != 0)
 			req_immediate_exit = true;
 		/* enable NMI/IRQ window open exits if needed */
-		else if (vcpu->arch.nmi_pending)
-			kvm_x86_ops->enable_nmi_window(vcpu);
-		else if (kvm_cpu_has_injectable_intr(vcpu) || req_int_win)
-			kvm_x86_ops->enable_irq_window(vcpu);
+		else {
+			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 (kvm_lapic_enabled(vcpu)) {
 			update_cr8_intercept(vcpu);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] KVM: x86: Inject pending interrupt even if pending nmi exist
  2016-03-24  5:17 [PATCH v3] KVM: x86: Inject pending interrupt even if pending nmi exist Yuki Shibuya
@ 2016-03-24 11:14 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2016-03-24 11:14 UTC (permalink / raw)
  To: Yuki Shibuya; +Cc: kvm, Radim Krčmář, Jan Kiszka, Nobuo Yoshida



On 24/03/2016 06:17, Yuki Shibuya wrote:
> Non maskable interrupts (NMI) are preferred to interrupts in current
> implementation. If a NMI is pending and NMI is blocked by the result
> of nmi_allowed(), pending interrupt is not injected and
> enable_irq_window() is not executed, even if interrupts injection is
> allowed.
> 
> In old kernel (e.g. 2.6.32), schedule() is often called in NMI context.
> In this case, interrupts are needed to execute iret that intends end
> of NMI. The flag of blocking new NMI is not cleared until the guest
> execute the iret, and interrupts are blocked by pending NMI. Due to
> this, iret can't be invoked in the guest, and the guest is starved
> until block is cleared by some events (e.g. canceling injection).
> 
> This patch injects pending interrupts, when it's allowed, even if NMI
> is blocked. And, If an interrupts is pending after executing
> inject_pending_event(), enable_irq_window() is executed regardless of
> NMI pending counter.
> 
> Signed-off-by: Yuki Shibuya <shibuya.yk@ncos.nec.co.jp>
> Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  arch/x86/kvm/x86.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 7236bd3..d4fd555 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -6087,12 +6087,10 @@ static int inject_pending_event(struct kvm_vcpu *vcpu, bool req_int_win)
>  	}
>  
>  	/* try to inject new event if pending */
> -	if (vcpu->arch.nmi_pending) {
> -		if (kvm_x86_ops->nmi_allowed(vcpu)) {
> -			--vcpu->arch.nmi_pending;
> -			vcpu->arch.nmi_injected = true;
> -			kvm_x86_ops->set_nmi(vcpu);
> -		}
> +	if (vcpu->arch.nmi_pending && kvm_x86_ops->nmi_allowed(vcpu)) {
> +		--vcpu->arch.nmi_pending;
> +		vcpu->arch.nmi_injected = true;
> +		kvm_x86_ops->set_nmi(vcpu);
>  	} else if (kvm_cpu_has_injectable_intr(vcpu)) {
>  		/*
>  		 * Because interrupts can be injected asynchronously, we are
> @@ -6561,10 +6559,12 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
>  		if (inject_pending_event(vcpu, req_int_win) != 0)
>  			req_immediate_exit = true;
>  		/* enable NMI/IRQ window open exits if needed */
> -		else if (vcpu->arch.nmi_pending)
> -			kvm_x86_ops->enable_nmi_window(vcpu);
> -		else if (kvm_cpu_has_injectable_intr(vcpu) || req_int_win)
> -			kvm_x86_ops->enable_irq_window(vcpu);
> +		else {
> +			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 (kvm_lapic_enabled(vcpu)) {
>  			update_cr8_intercept(vcpu);
> 

Thanks, queued for 4.6 and stable.

Paolo

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-03-24 11:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-24  5:17 [PATCH v3] KVM: x86: Inject pending interrupt even if pending nmi exist Yuki Shibuya
2016-03-24 11:14 ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.