Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1774796rdb; Mon, 8 Jan 2024 09:45:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGsM9OfXsaErX7Wt8+zamQuor4iDmk29hJ7OVgqYiGNRimKOtioynmghkZo41HT8rFgagWm X-Received: by 2002:a05:6402:14ca:b0:556:c796:7aaf with SMTP id f10-20020a05640214ca00b00556c7967aafmr2060720edx.58.1704735921276; Mon, 08 Jan 2024 09:45:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704735921; cv=none; d=google.com; s=arc-20160816; b=X4wSLML+R/cTv6591FETG17dpw38cKabHNtriahkT0/E6NA2SHFZzNLnXPhrauqmV4 jvQJxGy+wCwK/nB3xTGuqdJdMicejIDM/pscDfmyUEW5Mm+cixLhZUE7r2IFv3Lz2If2 xOvjmKTdY9Lm3zvI2gDOTgViTktY9WNlojJX5rx1gSYIYkkFqeKWJwIVdES8sJSt2g+t gJ2vmp8khIdfqJkWkwXxQxGSe/ZiieaWyRr2VugmQC1bGoshDaLCZS//5CvdIK9Fcsgx D53PfVCSakf9MRTo4loqnyMnlXBXjaEhvF9HREIVf/ZYkCKJ5Om0qZM1CcvxsblQz6Gx oV8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=CeET3LCD9y8mkzdt1n7zEREdExwaFpwQOr0tIUhzNgg=; fh=u8ZM6nX+vNiOuKgJ7/eBezNEE6mBdo6DLWKwoDleY0g=; b=OgNgbJ7T1pZce3GzvgZIT1F1fsBKbAEsyiu4sJxz3r610sceBE1GIucERkxW8Joy6Y FjxjZOxYh/279dn3jIVtFHljzf/SRELXMGK+qdBo7UTT09oZ3NiI3SKuzvp4mleR9qWv jIGt3FjEV9as3ZFo+GjLwF/o9tzEj+nxGytfhDnyqfEIqFbxeluqByy5N0H1CvgII16G qVeaPVOoM0nOhtCtk/hV+Lx7XiYanoWji4CC7m5V7GoNUKUwgwwZ7EMRmm8gPnhlfijz C98xKun9jpiJMitn5AEnYppTLVL1ZfUaS0hKhnyaT9Gt/oi4vJfYNfFCBRbfSApkHU95 gpGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1yff7LPS; spf=pass (google.com: domain of linux-kernel+bounces-19906-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19906-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dm23-20020a05640222d700b005533a15e27csi66063edb.88.2024.01.08.09.45.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 09:45:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19906-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=@google.com header.s=20230601 header.b=1yff7LPS; spf=pass (google.com: domain of linux-kernel+bounces-19906-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19906-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 9949D1F235FE for ; Mon, 8 Jan 2024 17:45:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4AC7855E55; Mon, 8 Jan 2024 17:38:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1yff7LPS" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1AB7E54F89 for ; Mon, 8 Jan 2024 17:38:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dbea293017dso2198859276.1 for ; Mon, 08 Jan 2024 09:38:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704735485; x=1705340285; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=CeET3LCD9y8mkzdt1n7zEREdExwaFpwQOr0tIUhzNgg=; b=1yff7LPSiX+Lx9usqzs3Ck7+fY59unWKCz9VwGMAY7w4RCgqBd4FImn/dqQmKvU5GY ajXMHZrEntZ51vVZxopVlZe5Q7R5obWH7o5C+BM9uQ1ZuKrymWuhumXUjrRIbFCErfk+ vZyPR3/rLP/6NslI9e0++PXoVzmWHLS4fW7gJUsqyyacTecmi3ia12nujaARyRYsgYbs nvuGZ42DA06RAFY4RxpQ6k7jABOgzdMbYP/2Kc3mryEg1QH07euEWRt572EnypLl1SMZ T3XYmgsHwFkvAIW5DaKtX4OJsfK8HtUMAH9WKsnCTL92s/38z2C2FTteRDltXZl8qyRZ WoxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704735485; x=1705340285; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CeET3LCD9y8mkzdt1n7zEREdExwaFpwQOr0tIUhzNgg=; b=nOhi+xTfMBKcJk62jKgsiIucO38TOWQF0PabqYi2+ZTIznP5Z52UL1ufXqzZzU3enO VDY7G+vMXMYG/OnvlG9NVG5LJ9nMg+cwl6TX0/8aG8WqOAsUlT84y3VrxW1rLZZBaPUd aAd/eHpw09eVxYY+rxus0NDd3AsisJivxZ+NotSpi+v9TwuqSaNbC3EcKYNth8ToGEti 6bgdQYN0DHrqJe1wgSwPB+0L/tAx7gQIsgNaV/ZApCou0RLSB9A0LERbZLuCeYAyqaHN Kd4PIJ9Tz2SAVfEz82V8iluPJQFtc2kBjEdnEMMxk32pbb0gdm2I1A+pNyKmX3rbsi5F 2MrA== X-Gm-Message-State: AOJu0Yyoq2rRSYaFTv2DqXh5XWWujqO+NrbwVP+eTDVingbX7LHDNq06 vPYou2zBKhiWm/5UynP5uK3Lf7MwvkpNddkLCg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:ba86:0:b0:dbe:9f60:c72f with SMTP id s6-20020a25ba86000000b00dbe9f60c72fmr1636784ybg.4.1704735485088; Mon, 08 Jan 2024 09:38:05 -0800 (PST) Date: Mon, 8 Jan 2024 09:38:03 -0800 In-Reply-To: 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> Message-ID: Subject: Re: [PATCH] KVM: x86: make KVM_REQ_NMI request iff NMI pending for vcpu From: Sean Christopherson To: Prasad Pandit Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Prasad Pandit Content-Type: text/plain; charset="us-ascii" On Mon, Jan 08, 2024, Prasad Pandit wrote: > 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...! This is on my list of things to grab for 6.8, I'm just waiting for various pull requests to fully land in order to simplify my branch management.