Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 188D3C61DA7 for ; Sat, 28 Jan 2023 01:10:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229832AbjA1BKN (ORCPT ); Fri, 27 Jan 2023 20:10:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229883AbjA1BKK (ORCPT ); Fri, 27 Jan 2023 20:10:10 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3BCE783E6 for ; Fri, 27 Jan 2023 17:09:27 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id rm7-20020a17090b3ec700b0022c05558d22so6275652pjb.5 for ; Fri, 27 Jan 2023 17:09:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=BvDAtcWxpw0OO9CIbwxN2UD8Ft4Fj6lH34EVPxrgfKI=; b=s2HEceqQte7E79aunBrwqCeshew83p+7aDGZJpBTU9d3SEvowWG1QvkqukX5MGJc0N 7GxvnRV2Lx8I0XEcnLSHabBKqJrOsrU7l5sjossB4RhNHui1n79vUqHdeUSkP+6VJXaV XFLzeQVK6CFCTI4FAN2N0ZkhXHY+JinRNQg+VxEgvBvmu7pjU2Jxb8f4vob6ywSY9Se9 wbWwa1IFuRJqKt5V84quH+FScywvcrWi0iED+OWBsWwAv8Mt+ZMXMMCNNXTba2fq8Hv/ 1FrJmPyhTi3tuAF5K+lshEUsArssDdeWLN6Y3P2hjCAex0ZcHxEs9pCLKwcsQuzg24mW yKCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=BvDAtcWxpw0OO9CIbwxN2UD8Ft4Fj6lH34EVPxrgfKI=; b=qVTCvnMp/kR3c19wt59DQUOep/BBdMa3tkj/DcfUTXaqnMdJD3rKJNeU7JeGwuv5hN HBx2r23mpm7phU4NOoYwS6H1zODeyrdzuIhE0Mr3LHT2XiVYMLASAB4R0b9iCI/1d/qZ YfynlEjaKCqLfYbefcT6x+8WASvVtRrIdpaqizG73K/3q0DCx6ADLMoFWXXmjj3Mgk+/ tsNfw77i0rbpVrHusLQvMSOn7wir/PFsYTczhjWdOzM9WcohPUlIKkQda9e09x7NLMD5 cqp8NhXRk5ETR9S3KJbj84ovGQN8gUq88zkdgBstUZ0cSsWzNRuron6zVwdrVtFTudCw rQhg== X-Gm-Message-State: AO0yUKX2oI4OUoMfE5F5jf15hSac2s5duy2AIhcvq/VijU6VRQYGPNA7 JWKP5Wye/OfsCeSi14yYpEWCmw== X-Google-Smtp-Source: AK7set9V1nbyj5JVvia8fyiXGTwoku2mOKuKfBs6aPc6BS5JnYNaBgvYF5vFd/2yoJGtQtix32pXIg== X-Received: by 2002:a17:902:d70a:b0:193:256d:8afe with SMTP id w10-20020a170902d70a00b00193256d8afemr208955ply.2.1674868167288; Fri, 27 Jan 2023 17:09:27 -0800 (PST) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id u8-20020a170902e5c800b00194bf875ed8sm3453070plf.139.2023.01.27.17.09.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 17:09:26 -0800 (PST) Date: Sat, 28 Jan 2023 01:09:23 +0000 From: Sean Christopherson To: Maxim Levitsky Cc: kvm@vger.kernel.org, Sandipan Das , Paolo Bonzini , Jim Mattson , Peter Zijlstra , Dave Hansen , Borislav Petkov , Pawan Gupta , Thomas Gleixner , Ingo Molnar , Josh Poimboeuf , Daniel Sneddon , Jiaxi Chen , Babu Moger , linux-kernel@vger.kernel.org, Jing Liu , Wyes Karny , x86@kernel.org, "H. Peter Anvin" Subject: Re: [PATCH v2 07/11] KVM: x86: add a delayed hardware NMI injection interface Message-ID: References: <20221129193717.513824-1-mlevitsk@redhat.com> <20221129193717.513824-8-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221129193717.513824-8-mlevitsk@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 29, 2022, Maxim Levitsky wrote: > This patch adds two new vendor callbacks: No "this patch" please, just say what it does. > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index 684a5519812fb2..46993ce61c92db 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -871,8 +871,13 @@ struct kvm_vcpu_arch { > u64 tsc_scaling_ratio; /* current scaling ratio */ > > atomic_t nmi_queued; /* unprocessed asynchronous NMIs */ > - unsigned nmi_pending; /* NMI queued after currently running handler */ > + > + unsigned int nmi_pending; /* > + * NMI queued after currently running handler > + * (not including a hardware pending NMI (e.g vNMI)) > + */ Put the block comment above. I'd say collapse all of the comments about NMIs into a single big block comment. > bool nmi_injected; /* Trying to inject an NMI this entry */ > + > bool smi_pending; /* SMI queued after currently running handler */ > u8 handling_intr_from_guest; > > @@ -10015,13 +10022,34 @@ static void process_nmi(struct kvm_vcpu *vcpu) > * Otherwise, allow two (and we'll inject the first one immediately). > */ > if (static_call(kvm_x86_get_nmi_mask)(vcpu) || vcpu->arch.nmi_injected) > - limit = 1; > + limit--; > + > + /* Also if there is already a NMI hardware queued to be injected, > + * decrease the limit again > + */ /* * Block comment ... */ > + if (static_call(kvm_x86_get_hw_nmi_pending)(vcpu)) I'd prefer "is_hw_nmi_pending()" over "get", even if it means not pairing with "set". Though I think that's a good thing since they aren't perfect pairs. > + limit--; > > - vcpu->arch.nmi_pending += atomic_xchg(&vcpu->arch.nmi_queued, 0); > + if (limit <= 0) > + return; > + > + /* Attempt to use hardware NMI queueing */ > + if (static_call(kvm_x86_set_hw_nmi_pending)(vcpu)) { > + limit--; > + nmi_to_queue--; > + } > + > + vcpu->arch.nmi_pending += nmi_to_queue; > vcpu->arch.nmi_pending = min(vcpu->arch.nmi_pending, limit); > kvm_make_request(KVM_REQ_EVENT, vcpu); > } > > +/* Return total number of NMIs pending injection to the VM */ > +int kvm_get_total_nmi_pending(struct kvm_vcpu *vcpu) > +{ > + return vcpu->arch.nmi_pending + static_call(kvm_x86_get_hw_nmi_pending)(vcpu); Nothing cares about the total count, this can just be; bool kvm_is_nmi_pending(struct kvm_vcpu *vcpu) { return vcpu->arch.nmi_pending || static_call(kvm_x86_is_hw_nmi_pending)(vcpu); } > +} > + > void kvm_make_scan_ioapic_request_mask(struct kvm *kvm, > unsigned long *vcpu_bitmap) > { > -- > 2.26.3 >