All of lore.kernel.org
 help / color / mirror / Atom feed
From: Santosh Shukla <santosh.shukla@amd.com>
To: <kvm@vger.kernel.org>, <seanjc@google.com>
Cc: <pbonzini@redhat.com>, <jmattson@google.com>, <joro@8bytes.org>,
	<linux-kernel@vger.kernel.org>, <mail@maciej.szmigiero.name>,
	<mlevitsk@redhat.com>, <thomas.lendacky@amd.com>,
	<vkuznets@redhat.com>
Subject: [PATCHv4 06/11] KVM: x86: Tweak the code and comment related to handling concurrent NMIs
Date: Mon, 27 Feb 2023 14:10:11 +0530	[thread overview]
Message-ID: <20230227084016.3368-7-santosh.shukla@amd.com> (raw)
In-Reply-To: <20230227084016.3368-1-santosh.shukla@amd.com>

From: Sean Christopherson <seanjc@google.com>

Tweak the code and comment that deals with concurrent NMIs to explicitly
call out that x86 allows exactly one pending NMI, but that KVM needs to
temporarily allow two pending NMIs in order to workaround the fact that
the target vCPU cannot immediately recognize an incoming NMI, unlike bare
metal.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Santosh Shukla <Santosh.Shukla@amd.com>
---
v3:
https://lore.kernel.org/all/Y9mtGV+q0P2U9+M1@google.com/
from Sean comment.

 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 1cd9cadc82af..16590e094899 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -10136,15 +10136,22 @@ static int kvm_check_and_inject_events(struct kvm_vcpu *vcpu,
 
 static void process_nmi(struct kvm_vcpu *vcpu)
 {
-	unsigned limit = 2;
+	unsigned int limit;
 
 	/*
-	 * x86 is limited to one NMI running, and one NMI pending after it.
-	 * If an NMI is already in progress, limit further NMIs to just one.
-	 * Otherwise, allow two (and we'll inject the first one immediately).
+	 * x86 is limited to one NMI pending, but because KVM can't react to
+	 * incoming NMIs as quickly as bare metal, e.g. if the vCPU is
+	 * scheduled out, KVM needs to play nice with two queued NMIs showing
+	 * up at the same time.  To handle this scenario, allow two NMIs to be
+	 * (temporarily) pending so long as NMIs are not blocked and KVM is not
+	 * waiting for a previous NMI injection to complete (which effectively
+	 * blocks NMIs).  KVM will immediately inject one of the two NMIs, and
+	 * will request an NMI window to handle the second NMI.
 	 */
 	if (static_call(kvm_x86_get_nmi_mask)(vcpu) || vcpu->arch.nmi_injected)
 		limit = 1;
+	else
+		limit = 2;
 
 	vcpu->arch.nmi_pending += atomic_xchg(&vcpu->arch.nmi_queued, 0);
 	vcpu->arch.nmi_pending = min(vcpu->arch.nmi_pending, limit);
-- 
2.25.1


  parent reply	other threads:[~2023-02-27  8:53 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-27  8:40 [PATCHv4 00/11] SVM: virtual NMI Santosh Shukla
2023-02-27  8:40 ` [PATCHv4 01/11] KVM: nSVM: Don't sync vmcb02 V_IRQ back to vmcb12 if KVM (L0) is intercepting VINTR Santosh Shukla
2023-02-27  8:40 ` [PATCHv4 02/11] KVM: nSVM: Disable intercept of VINTR if saved RFLAG.IF is 0 Santosh Shukla
2023-02-27  8:40 ` [PATCHv4 03/11] KVM: nSVM: Raise event on nested VM exit if L1 doesn't intercept IRQs Santosh Shukla
2023-02-27  8:40 ` [PATCHv4 04/11] KVM: SVM: add wrappers to enable/disable IRET interception Santosh Shukla
2023-02-27  8:40 ` [PATCHv4 05/11] KVM: x86: Raise an event request when processing NMIs if an NMI is pending Santosh Shukla
2023-02-27  8:40 ` Santosh Shukla [this message]
2023-02-27  8:40 ` [PATCHv4 07/11] KVM: x86: Save/restore all NMIs when multiple NMIs are pending Santosh Shukla
2023-02-27  8:40 ` [PATCHv4 08/11] x86/cpu: Add CPUID feature bit for VNMI Santosh Shukla
2023-03-22 19:07   ` Sean Christopherson
2023-02-27  8:40 ` [PATCHv4 09/11] KVM: SVM: Add VNMI bit definition Santosh Shukla
2023-03-23  0:54   ` Sean Christopherson
2023-02-27  8:40 ` [PATCHv4 10/11] KVM: x86: add support for delayed virtual NMI injection interface Santosh Shukla
2023-03-23  0:49   ` Sean Christopherson
2023-02-27  8:40 ` [PATCHv4 11/11] KVM: nSVM: implement support for nested VNMI Santosh Shukla
2023-03-23  0:50   ` Sean Christopherson
2023-03-10  9:19 ` [PATCHv4 00/11] SVM: virtual NMI Santosh Shukla
2023-03-10 17:02   ` Sean Christopherson
2023-03-23  0:57 ` Sean Christopherson
2023-03-23  1:14   ` Sean Christopherson
2023-03-23 22:53 ` Sean Christopherson
2023-03-24  8:25   ` Santosh Shukla

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=20230227084016.3368-7-santosh.shukla@amd.com \
    --to=santosh.shukla@amd.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mail@maciej.szmigiero.name \
    --cc=mlevitsk@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=thomas.lendacky@amd.com \
    --cc=vkuznets@redhat.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 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.