Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp90805pxb; Tue, 24 Aug 2021 21:11:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2wVubIhSUV4Nk7/We4NQr1MfFFStb4YXZsANar4yeVjKvg3jYWq8M9ZLTMM7Kn0cJV9k7 X-Received: by 2002:a17:906:3542:: with SMTP id s2mr44506690eja.379.1629864687469; Tue, 24 Aug 2021 21:11:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629864687; cv=none; d=google.com; s=arc-20160816; b=Fre4j4MBp6Ymi9y4Cs5bkUqbIwVDmzQNwFfK8yzxGFWq/wCya0jrWxbHN9I8YTLRv7 C3NaiwtaGs4uf+D08HeKPKmkvw/yUTYcwglWPzK6kw0L2CFu8gkN4//QCKcyYvEn6+WX 02FB80ts25T8q2bM/5fZ42e1Bpt0T9h9eT1d98OWpaN2dQ7kLAy646YylJ9g2uLmPqJs eKLEJQapDClyOGTiEXBLXVJ+U8HOUK3bVaMC9bs+nk8LcUW8PpAN4CyChPa/an3XT93/ WKZLEKVQXC+tzXzELaokgZDcpqneUg+EjdrG0xu5QQFGkWlkCsmyMuDw5NzWlwQqOfGO w6Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=NZoI/2t89xBZsKpePuesqEGL96FIMPFUNLVpR72Rozg=; b=Oh7RaX8yyDzKk/tx30ADF2/YYhNPQiFfpQ83DHdXK6BdGWZEMCcZbRxDtelvhINS/h z+eTybBYH91jbj7T2LaaZRO3hdciPFGWuIZ5w71UxP6cSVQkEWu3iZmZpc6JRoKvH42U qlRovHLA8+LNKnay77KtlCeWOWGk1NeMAKsR1IxJoagEsDvDuqBKhvtJS6hDmUuXAyBP CepqDtna/OEeBvIjpVJnEttgQ4ffJyXoosoB6qR4BQv+7jmuy8jkGwMdVM/9JNIPnPgb vFy38wE3eFUhJTluj7+on6efOngMGFYIUcyqIp2j8rxLW2qD40+I0uFKFluZAWWTFJHG ipsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EegF7oqb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gn41si11878993ejc.126.2021.08.24.21.11.04; Tue, 24 Aug 2021 21:11:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EegF7oqb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229631AbhHYEGn (ORCPT + 99 others); Wed, 25 Aug 2021 00:06:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229379AbhHYEGn (ORCPT ); Wed, 25 Aug 2021 00:06:43 -0400 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BBCCC061757; Tue, 24 Aug 2021 21:05:58 -0700 (PDT) Received: by mail-io1-xd32.google.com with SMTP id a21so29150136ioq.6; Tue, 24 Aug 2021 21:05:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NZoI/2t89xBZsKpePuesqEGL96FIMPFUNLVpR72Rozg=; b=EegF7oqbZkc2syS4cXBmSapTwbjI4P79ZFnOvmTcRGDf1kVVRrqdOELBgYukAMVcRF E5L0A65z7uT82650RwrmS3opolb9Z0mBUOg4LsgLiDhQldz++hVRAipq2bIJghRVUEHd wN+ZgZFdXl7G+cbp2HlnKij+sP9dWtX9h1sr6fh+Thp2l4oajwXETlk4CL3tjSQP95Kq JRg1F4lVdlrkiu7JvQ6zV4mvbwfrJinel9BV6bjsC9Wwo2t8Dtfov7YT27pmbBuQz/jf Hp0lXMS5ZggnkGmfhrAjIkOhfyJr3MU4MyRLSGqJ78LkVbcAv6TxYqsGfoRd66ksCdF9 w3mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NZoI/2t89xBZsKpePuesqEGL96FIMPFUNLVpR72Rozg=; b=e7BDFNsQjNKMBlkhlgs+E2MkH0GQtsfAKecuhwxinEiairYO5cTkEdsYGQYvs8PT3Y HnCV/aDiflBVJCKLWF25AyFe7qa6jvGekpEsXqQHJLBU1XqFa0aAzzEwhK3uJm8tcC7o AI4BIjnFKnOqaZRcnEa5ynpVeMsM/SWKPJafpELh65R1HbSkGOwHXksJQwoVHHAHj1F4 6mptRVpIdEbG7sfDck3EnIu3WgK77QdsdGUWlxxDU74jnjhPKNa8Y4c3WQ4xxkFID1zi /DMooDkcuq9+Xj26cTIGdzOP3etaSV7VOFoNy7NkDAlRLppH+xB+xpItk9Vs7oYYRLy0 0U0g== X-Gm-Message-State: AOAM530yZB4GoHFjq3K5kU2G7ZqUOcoSak80UdEZhX5iXF3ZibUEgJAY B+f4V3qc7E7yUoEsh4HkUFSSa60nwRIeeTfAdHY= X-Received: by 2002:a5d:96da:: with SMTP id r26mr34232231iol.47.1629864357564; Tue, 24 Aug 2021 21:05:57 -0700 (PDT) MIME-Version: 1.0 References: <20210821000501.375978-1-seanjc@google.com> <20210821000501.375978-3-seanjc@google.com> In-Reply-To: <20210821000501.375978-3-seanjc@google.com> From: Lai Jiangshan Date: Wed, 25 Aug 2021 12:05:45 +0800 Message-ID: Subject: Re: [PATCH 2/2] KVM: Guard cpusmask NULL check with CONFIG_CPUMASK_OFFSTACK To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, LKML , Venkatesh Srinivas , Vitaly Kuznetsov Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 21, 2021 at 8:09 AM Sean Christopherson wrote: > > Check for a NULL cpumask_var_t when kicking multiple vCPUs if and only if > cpumasks are configured to be allocated off-stack. This is a meaningless > optimization, e.g. avoids a TEST+Jcc and TEST+CMOV on x86, but more > importantly helps document that the NULL check is necessary even though > all callers pass in a local variable. > > No functional change intended. > > Signed-off-by: Sean Christopherson > --- > virt/kvm/kvm_main.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 786b914db98f..82c5280dd5ce 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -247,7 +247,7 @@ static void ack_flush(void *_completed) > > static inline bool kvm_kick_many_cpus(const struct cpumask *cpus, bool wait) > { > - if (unlikely(!cpus)) > + if (IS_ENABLED(CONFIG_CPUMASK_OFFSTACK) && unlikely(!cpus)) > cpus = cpu_online_mask; > > if (cpumask_empty(cpus)) > @@ -277,6 +277,14 @@ bool kvm_make_vcpus_request_mask(struct kvm *kvm, unsigned int req, > if (!(req & KVM_REQUEST_NO_WAKEUP) && kvm_vcpu_wake_up(vcpu)) > continue; > > + /* > + * tmp can be NULL if cpumasks are allocated off stack, as > + * allocation of the mask is deliberately not fatal and is > + * handled by falling back to kicking all online CPUs. > + */ > + if (IS_ENABLED(CONFIG_CPUMASK_OFFSTACK) && !tmp) > + continue; > + Hello, Sean I don't think it is a good idea to reinvent the cpumask_available(). You can rework the patch as the following code if cpumask_available() fits for you. Thanks Lai diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 3e67c93ca403..ca043ec7ed74 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -245,9 +245,11 @@ static void ack_flush(void *_completed) { } -static inline bool kvm_kick_many_cpus(const struct cpumask *cpus, bool wait) +static inline bool kvm_kick_many_cpus(cpumask_var_t tmp, bool wait) { - if (unlikely(!cpus)) + const struct cpumask *cpus = tmp; + + if (unlikely(!cpumask_available(tmp))) cpus = cpu_online_mask; if (cpumask_empty(cpus)) @@ -278,7 +280,7 @@ bool kvm_make_vcpus_request_mask(struct kvm *kvm, unsigned int req, if (!(req & KVM_REQUEST_NO_WAKEUP) && kvm_vcpu_wake_up(vcpu)) continue; - if (tmp != NULL && cpu != -1 && cpu != me && + if (cpumask_available(tmp) && cpu != -1 && cpu != me && kvm_request_needs_ipi(vcpu, req)) __cpumask_set_cpu(cpu, tmp); } > /* > * Note, the vCPU could get migrated to a different pCPU at any > * point after kvm_request_needs_ipi(), which could result in > @@ -288,7 +296,7 @@ bool kvm_make_vcpus_request_mask(struct kvm *kvm, unsigned int req, > * were reading SPTEs _before_ any changes were finalized. See > * kvm_vcpu_kick() for more details on handling requests. > */ > - if (tmp != NULL && kvm_request_needs_ipi(vcpu, req)) { > + if (kvm_request_needs_ipi(vcpu, req)) { > cpu = READ_ONCE(vcpu->cpu); > if (cpu != -1 && cpu != me) > __cpumask_set_cpu(cpu, tmp); > -- > 2.33.0.rc2.250.ged5fa647cd-goog >