Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6984399rdb; Tue, 2 Jan 2024 23:54:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IFYeH9tda/eH4I9yl9TOyb62V9o69k0Q8W3A/1mQeJ51dVvXX/WxKceH6YQIWiUz2D+FUXC X-Received: by 2002:a17:906:fd8c:b0:a28:a409:c1bf with SMTP id xa12-20020a170906fd8c00b00a28a409c1bfmr86496ejb.164.1704268444765; Tue, 02 Jan 2024 23:54:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704268444; cv=none; d=google.com; s=arc-20160816; b=O56869fl7QVU+LRFXRg2OFkfXAYvLyV7Sm2SWpPZEAnseEK/i/olLkFhwsdcYGQB1V e0jO+KLNDvsCT9syrOgShWfmA5/aLLGwvifEnyfFJVp/JHLUiHAwkzBPpf/tLOzHwbR3 LlaQSaeDlRXzLobTwpAkt+dCAEvuOTkZWtyy5iqzOUPn4ZZKKKTOyBsrc6R1jzTix0ZQ Cdr1FvIF6AK83WxlvKVBdbS4v4kX4E9TRCW+GN39TSvSpzImIpyjdqV8XgQEdUQqfpFM i7wFOfYPVp1VxLqinMf2knt0AEvbuoAgKN4Ro6MlqHnEs7sj6xL/Pqvcet578R/Lv+DX qFmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=SWQQWalLqDTi/rVwra4T6IuCV/dWGZrTeD1nxNtIarw=; fh=CNGLvKgnJ/tn5tJ88P6/TRQDxjB46s7X2Db5IsUhtRU=; b=MGS89/Jf7fv84wQx4Zm62ia+Z/fc/z05iVSElEKsR9C7cPDILvjh3Y8xDIpY4HpFlW t0XPD03XWn0pfh5+WP5pSG/HSq2xJrpbopaNZ1TxG4I1ildb5lhe6mbA9w1U7J5z6GOW FptyyUjh/Hq4xTC/KjxmF0jV2XjGYovDcYfUHM2ZxS+7Ww1Qm4F376wB+LS+lLp40raH Zp4TyTesgbB12jUJa9Tx6Ki0mCo/NvOwQ2y8R6bvXvIBJOCIfViZ21UVc5ZZsgBB4fEk nTN99/UqR+ulIDq9JiDTJ73drQzux05DpXorwj9br1dcNGhAf/EYucGAmVyrr+7240DG 24zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SXjitsMC; spf=pass (google.com: domain of linux-kernel+bounces-15250-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15250-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id fv14-20020a170907508e00b00a276dc72065si4723226ejc.376.2024.01.02.23.54.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 23:54:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15250-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SXjitsMC; spf=pass (google.com: domain of linux-kernel+bounces-15250-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15250-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 7F16B1F228FB for ; Wed, 3 Jan 2024 07:54:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 321291804F; Wed, 3 Jan 2024 07:53:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SXjitsMC" X-Original-To: linux-kernel@vger.kernel.org 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 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: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 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=[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()") 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 = 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