From nobody Fri Dec 26 17:19:27 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE67C1802F for ; Wed, 3 Jan 2024 07:53:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SXjitsMC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704268433; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=SWQQWalLqDTi/rVwra4T6IuCV/dWGZrTeD1nxNtIarw=; b=SXjitsMCnzPfIKv60VKnvGS7KJn1M3UNDmlii7ZpN9sYYmfnGzrnZehWYag80VrtcvJE0v DqA0n4Uv1BLaApI+E0Bm+OliOCs/qIGBtPfzV7Tavgcj+iAY4c9HL61IaCShaklwJ9+27x 8PhlZbjmbKPiusPyXyHTNl0sjZFIBns= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-64-qB21hdV7MgeY4gGnoxEWzA-1; Wed, 03 Jan 2024 02:53:51 -0500 X-MC-Unique: qB21hdV7MgeY4gGnoxEWzA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 78DA9101A555; Wed, 3 Jan 2024 07:53:51 +0000 (UTC) Received: from kaapi.redhat.com (unknown [10.74.16.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9DEA5492BE6; Wed, 3 Jan 2024 07:53:49 +0000 (UTC) From: Prasad Pandit To: Sean Christopherson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Prasad Pandit Subject: [PATCH] KVM: x86: make KVM_REQ_NMI request iff NMI pending for vcpu Date: Wed, 3 Jan 2024 13:23:43 +0530 Message-ID: <20240103075343.549293-1-ppandit@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 Content-Type: text/plain; charset="utf-8" From: Prasad Pandit 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=3D[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 p= rocess_nmi()") Signed-off-by: Prasad Pandit --- arch/x86/kvm/x86.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 1a3aaa7dafae..468870450b8b 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5405,7 +5405,8 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct = kvm_vcpu *vcpu, if (events->flags & KVM_VCPUEVENT_VALID_NMI_PENDING) { vcpu->arch.nmi_pending =3D 0; atomic_set(&vcpu->arch.nmi_queued, events->nmi.pending); - kvm_make_request(KVM_REQ_NMI, vcpu); + if (events->nmi.pending) + kvm_make_request(KVM_REQ_NMI, vcpu); } static_call(kvm_x86_set_nmi_mask)(vcpu, events->nmi.masked); -- 2.43.0