mirror of https://lore.kernel.org/lkml/
 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: [PATCHv3 06/10] KVM: x86: Save/restore all NMIs when multiple NMIs are pending
Date: Mon, 27 Feb 2023 09:23:56 +0530	[thread overview]
Message-ID: <20230227035400.1498-7-santosh.shukla@amd.com> (raw)
In-Reply-To: <20230227035400.1498-1-santosh.shukla@amd.com>

From: Sean Christopherson <seanjc@google.com>

Save all pending NMIs in KVM_GET_VCPU_EVENTS, and queue KVM_REQ_NMI if one
or more NMIs are pending after KVM_SET_VCPU_EVENTS in order to re-evaluate
pending NMIs with respect to NMI blocking.

KVM allows multiple NMIs to be pending in order to faithfully emulate bare
metal handling of simultaneous NMIs (on bare metal, truly simultaneous
NMIs are impossible, i.e. one will always arrive first and be consumed).
Support for simultaneous NMIs botched the save/restore though.  KVM only
saves one pending NMI, but allows userspace to restore 255 pending NMIs
as kvm_vcpu_events.nmi.pending is a u8, and KVM's internal state is stored
in an unsigned int.

Fixes: 7460fb4a3400 ("KVM: Fix simultaneous NMIs")
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Santosh Shukla <Santosh.Shukla@amd.com>
---
v3:
- There is checkpatch warning about the Fixes tag like below
 
 WARNING: Unknown commit id '7460fb4a3400', maybe rebased or not pulled?
 #19:
 Fixes: 7460fb4a3400 ("KVM: Fix simultaneous NMIs")

 total: 0 errors, 1 warnings, 20 lines checked

Although this patch is part of kernel v3.2 onwards


 arch/x86/kvm/x86.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 16590e094899..b22074f467e0 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5113,7 +5113,7 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu,
 	events->interrupt.shadow = static_call(kvm_x86_get_interrupt_shadow)(vcpu);
 
 	events->nmi.injected = vcpu->arch.nmi_injected;
-	events->nmi.pending = vcpu->arch.nmi_pending != 0;
+	events->nmi.pending = vcpu->arch.nmi_pending;
 	events->nmi.masked = static_call(kvm_x86_get_nmi_mask)(vcpu);
 
 	/* events->sipi_vector is never valid when reporting to user space */
@@ -5200,8 +5200,11 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
 						events->interrupt.shadow);
 
 	vcpu->arch.nmi_injected = events->nmi.injected;
-	if (events->flags & KVM_VCPUEVENT_VALID_NMI_PENDING)
+	if (events->flags & KVM_VCPUEVENT_VALID_NMI_PENDING) {
 		vcpu->arch.nmi_pending = events->nmi.pending;
+		if (vcpu->arch.nmi_pending)
+			kvm_make_request(KVM_REQ_NMI, vcpu);
+	}
 	static_call(kvm_x86_set_nmi_mask)(vcpu, events->nmi.masked);
 
 	if (events->flags & KVM_VCPUEVENT_VALID_SIPI_VECTOR &&
-- 
2.25.1


  parent reply	other threads:[~2023-02-27  3:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-27  3:53 [PATCHv3 00/10] SVM: virtual NMI Santosh Shukla
2023-02-27  3:53 ` [PATCHv3 01/10] KVM: nSVM: Disable intercept of VINTR if saved RFLAG.IF is 0 Santosh Shukla
2023-02-27  3:53 ` [PATCHv3 02/10] KVM: nSVM: Raise event on nested VM exit if L1 doesn't intercept IRQs Santosh Shukla
2023-02-27  3:53 ` [PATCHv3 03/10] KVM: SVM: add wrappers to enable/disable IRET interception Santosh Shukla
2023-02-27  3:53 ` [PATCHv3 04/10] KVM: x86: Raise an event request when processing NMIs if an NMI is pending Santosh Shukla
2023-02-27  3:53 ` [PATCHv3 05/10] KVM: x86: Tweak the code and comment related to handling concurrent NMIs Santosh Shukla
2023-02-27  3:53 ` Santosh Shukla [this message]
2023-02-27  3:53 ` [PATCHv3 07/10] x86/cpu: Add CPUID feature bit for VNMI Santosh Shukla
2023-02-27  3:53 ` [PATCHv3 08/10] KVM: SVM: Add VNMI bit definition Santosh Shukla
2023-02-27  3:53 ` [PATCHv3 09/10] KVM: x86: add support for delayed virtual NMI injection interface Santosh Shukla
2023-02-27  3:54 ` [PATCHv3 10/10] KVM: nSVM: implement support for nested VNMI Santosh Shukla
2023-02-27  4:47 ` [PATCHv3 00/10] SVM: virtual NMI 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=20230227035400.1498-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®