Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1546666rdb; Mon, 8 Jan 2024 02:47:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IGGp8gjSLZNbBoiK+Vjge4b6IOiXHjtZzLp9juc02H6aQUBTd1eTDIUYDcH2UnFySrqZ5BW X-Received: by 2002:a17:906:b184:b0:a26:9ec0:e35 with SMTP id w4-20020a170906b18400b00a269ec00e35mr1341361ejy.135.1704710836100; Mon, 08 Jan 2024 02:47:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704710836; cv=none; d=google.com; s=arc-20160816; b=Ki5BhxlxYW2vS42f1pTLw36m37DrgV8ai8xuk+dQPkhZRPfiLoQzQYgR9NxvsqYqn8 Z58NYg2dXYpOr8B1k6AotxfIQLqYmBquq61cKWvjQJrgsjK6t7eE8JwtcPtJDv7UWTN6 SxizOiQOxWI8LslnUSE6It7Vf7l8eYfKUlRFOoj7PbWfvnJ2tSZPuQv8t8ZvcvpxKdzK cFA8eBkV9v0bb5FUWwoXuW6qA/Fhxs9DLILq/HUdxvZPbpkPhPNY4ermSD7Au6Tvwtwn N/GTOVmGRwjge7dfkJBGcu9aa6i1fWreE8hG/QnsoojAiHwYaCrfEvA4SSpti6BeGrRD 2hcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=KkVC+mvoxuSAncS71/24Hr1464TinqZdTby20Br9LBs=; fh=CNGLvKgnJ/tn5tJ88P6/TRQDxjB46s7X2Db5IsUhtRU=; b=0vARudsJXgzH6K0BFyMoWJO4aZCb3RQyRQdwY1Rq56OJK70rhQ8G1/QvFBj14eQ6v3 xjNIDhTi+f0oFP3WYokUvLk3URkklXm2td7Xw2S0iT58fZTmRVdWGFY6dFkl8XcsDziy CvaKGtBx5JCaPOrVjpFuZtZ+/s4tSY+Rryn5xeFJysakeI2TS7nmvTmiezQ8M9CN7NeC Sx+gYzS6IjeaE6zFnX98PvVY1761ulTBbmqrwgsd4lmUoNf/PPcfja0BMB+2WzdthRPE b+tdL5GIQvcqgB4Yc45xdF4PIPlQRjME3eSM8dJgfxvL5drUbZP3JyXOx6qq6NqE91v9 uv0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AHaEXqrL; spf=pass (google.com: domain of linux-kernel+bounces-19353-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19353-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v2-20020a17090606c200b00a27873a068fsi3104522ejb.30.2024.01.08.02.47.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 02:47:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19353-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AHaEXqrL; spf=pass (google.com: domain of linux-kernel+bounces-19353-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19353-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 D21411F22411 for ; Mon, 8 Jan 2024 10:47:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6A54E2942F; Mon, 8 Jan 2024 10:46:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="AHaEXqrL" 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 2F26C28E25 for ; Mon, 8 Jan 2024 10:46:05 +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=1704710765; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=KkVC+mvoxuSAncS71/24Hr1464TinqZdTby20Br9LBs=; b=AHaEXqrLCB5EhVKw+harz40HHfcgHxPcq7eDpFjii548y3MA8SFMRTCcdFF9LAg843rPsN SGprROUTCRYL6FeVrTkwWuwZmEYZ1Tsc2lInwheedl1P/tUSgSSEwL4ok5cnHgRAFukHy6 bH7oKtqn6TjF7/+JjuRDHDVTptylGZI= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-182-DhmFpjpwMkahJnS2v2P_5A-1; Mon, 08 Jan 2024 05:46:03 -0500 X-MC-Unique: DhmFpjpwMkahJnS2v2P_5A-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-33770774fe4so119720f8f.3 for ; Mon, 08 Jan 2024 02:46:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704710762; x=1705315562; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KkVC+mvoxuSAncS71/24Hr1464TinqZdTby20Br9LBs=; b=vHAAyCifIpFl7CPUJK9T0YqHX4UUkBvtVCFKXuwuQgHSQUwT4wBt3w+9nta/o5Xe1+ 2oZ88JFNEVot/I/+wYH1/veM5Y/moh6Gyh9lCB70B9eX7eEbrYdICrdPh0N5fVbmVGO8 XEmeOv+Qy2B4d0e28lFDyqcJp8A9e7q+H+w3AAH2cwn2s5xY3KY9cDme9hto4SwtQQfu vS7YLoVqhmF7lvSeXJyqe3qNCu3qX8TKaiHbmotPnUrbW8ojVgsfFlAr+WM6khzVPqkJ qSn8BaqI6CqF4T5VNRAwJ+t7Nbw/55m7c+oYV4XCHSsQWEJWgkiakDzhpuwMDP5uFzI+ TtnA== X-Gm-Message-State: AOJu0YzFTDQy/YG+GHhlkcQMZXrgsu+qDu6RAjyPuALk7sn3qMKJ5nJG 6Fjx2YY/DYlfutxQKVMham4KlwDVBweox2wPgUUTGFiRQTtXrgYHyXrDgH8Jz7J1MeW2lgW305j L+HiRGJf1vWybgRY9hsSNIF6f3hFRLHAFPrUTPYtyooHqf9d2 X-Received: by 2002:a5d:6b8a:0:b0:337:554a:1663 with SMTP id n10-20020a5d6b8a000000b00337554a1663mr2007855wrx.44.1704710762303; Mon, 08 Jan 2024 02:46:02 -0800 (PST) X-Received: by 2002:a5d:6b8a:0:b0:337:554a:1663 with SMTP id n10-20020a5d6b8a000000b00337554a1663mr2007850wrx.44.1704710762007; Mon, 08 Jan 2024 02:46:02 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240103075343.549293-1-ppandit@redhat.com> In-Reply-To: <20240103075343.549293-1-ppandit@redhat.com> From: Prasad Pandit Date: Mon, 8 Jan 2024 16:15:45 +0530 Message-ID: Subject: Re: [PATCH] KVM: x86: make KVM_REQ_NMI request iff NMI pending for vcpu To: Sean Christopherson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Prasad Pandit Content-Type: text/plain; charset="UTF-8" On Wed, 3 Jan 2024 at 13:24, Prasad Pandit wrote: > 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 Ping...! --- - Prasad