public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Cathy Avery <cavery@redhat.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, pbonzini@redhat.com
Cc: vkuznets@redhat.com, wei.huang2@amd.com
Subject: [PATCH 2/2] KVM: x86: check_nested_events if there is an injectable NMI
Date: Tue, 14 Apr 2020 16:11:07 -0400	[thread overview]
Message-ID: <20200414201107.22952-3-cavery@redhat.com> (raw)
In-Reply-To: <20200414201107.22952-1-cavery@redhat.com>

With NMI intercept moved to check_nested_events there is a race
condition where vcpu->arch.nmi_pending is set late causing
the execution of check_nested_events to not setup correctly
for nested.exit_required. A second call to check_nested_events
allows the injectable nmi to be detected in time in order to
require immediate exit from L2 to L1.

Signed-off-by: Cathy Avery <cavery@redhat.com>
---
 arch/x86/kvm/x86.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 027dfd278a97..ecfafcd93536 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -7734,10 +7734,17 @@ static int inject_pending_event(struct kvm_vcpu *vcpu)
 		vcpu->arch.smi_pending = false;
 		++vcpu->arch.smi_count;
 		enter_smm(vcpu);
-	} else 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 (vcpu->arch.nmi_pending) {
+		if (is_guest_mode(vcpu) && kvm_x86_ops.check_nested_events) {
+			r = kvm_x86_ops.check_nested_events(vcpu);
+			if (r != 0)
+				return r;
+		}
+		if (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
-- 
2.20.1


  parent reply	other threads:[~2020-04-14 20:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-14 20:11 [PATCH 0/2] KVM: SVM: Implement check_nested_events for NMI Cathy Avery
2020-04-14 20:11 ` [PATCH 1/2] " Cathy Avery
2020-04-14 20:11 ` Cathy Avery [this message]
2020-04-23 14:42   ` [PATCH 2/2] KVM: x86: check_nested_events if there is an injectable NMI Sean Christopherson
2020-04-23 15:10     ` Paolo Bonzini
2020-04-23 15:35       ` Sean Christopherson
2020-04-23 15:43         ` Paolo Bonzini
2020-04-23 18:32           ` Paolo Bonzini
2020-04-23 15:36     ` Cathy Avery
2020-04-23 15:45       ` Paolo Bonzini
2020-04-23 18:33         ` Sean Christopherson
2020-04-23 18:47           ` Paolo Bonzini
2020-04-15  9:49 ` [PATCH 0/2] KVM: SVM: Implement check_nested_events for NMI Vitaly Kuznetsov
2020-04-15 12:45   ` Paolo Bonzini
2020-04-23 13:43 ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200414201107.22952-3-cavery@redhat.com \
    --to=cavery@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=vkuznets@redhat.com \
    --cc=wei.huang2@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox