KVM: x86: Save/restore all NMIs when multiple NMIs are pending
authorSean Christopherson <seanjc@google.com>
Mon, 27 Feb 2023 08:40:12 +0000 (14:10 +0530)
committerSean Christopherson <seanjc@google.com>
Wed, 22 Mar 2023 19:34:34 +0000 (12:34 -0700)
commitab2ee212a57bf136b896a47ce37da38a1fdbdc36
tree6ad64b7860b6d8cc8b81047ebbc19dc0773a39d3
parent400fee8c9b2df61721de8103a4054247bea79fd0
KVM: x86: Save/restore all NMIs when multiple NMIs are pending

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: Santosh Shukla <Santosh.Shukla@amd.com>
Link: https://lore.kernel.org/r/20230227084016.3368-8-santosh.shukla@amd.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/x86.c