]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
KVM: x86: make KVM_REQ_NMI request iff NMI pending for vcpu
authorPrasad Pandit <pjp@fedoraproject.org>
Wed, 3 Jan 2024 07:53:43 +0000 (13:23 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 23 Feb 2024 08:25:10 +0000 (09:25 +0100)
commiteea9b2e0d22211b3413606519b34ca4ea4dad9f0
tree84aff3bd1d81eed6fa2d0031e75bbca40160afe1
parentb2479ab426cef7ab79a13005650eff956223ced2
KVM: x86: make KVM_REQ_NMI request iff NMI pending for vcpu

commit 6231c9e1a9f35b535c66709aa8a6eda40dbc4132 upstream.

kvm_vcpu_ioctl_x86_set_vcpu_events() routine makes 'KVM_REQ_NMI'
request for a vcpu even when its 'events->nmi.pending' is zero.
Ex:
    qemu_thread_start
     kvm_vcpu_thread_fn
      qemu_wait_io_event
       qemu_wait_io_event_common
        process_queued_cpu_work
         do_kvm_cpu_synchronize_post_init/_reset
          kvm_arch_put_registers
           kvm_put_vcpu_events (cpu, level=[2|3])

This leads vCPU threads in QEMU to constantly acquire & release the
global mutex lock, delaying the guest boot due to lock contention.
Add check to make KVM_REQ_NMI request only if vcpu has NMI pending.

Fixes: bdedff263132 ("KVM: x86: Route pending NMIs from userspace through process_nmi()")
Cc: stable@vger.kernel.org
Signed-off-by: Prasad Pandit <pjp@fedoraproject.org>
Link: https://lore.kernel.org/r/20240103075343.549293-1-ppandit@redhat.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kvm/x86.c