Received: by 2002:a05:7208:208b:b0:81:d631:dc8 with SMTP id y11csp228142rby; Wed, 3 Apr 2024 07:35:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU0yg0SA7Sg7GXvUIvejKZ/8YDC1Xx+pHFFAFx6vZ5sDcj2uobBv2KKYLB/OGL+hrZgqBGqzk3OwY+tlMIJgSSwyRAa8mOCHdSVvucfWQ== X-Google-Smtp-Source: AGHT+IFSYSE0UPphrB0cG66JrKrCQXbTioRH7fny/+lIregeXgMnaSuhEN2blXLfvZI98Obn+jVR X-Received: by 2002:ac8:5886:0:b0:434:342e:2c0c with SMTP id t6-20020ac85886000000b00434342e2c0cmr3739629qta.9.1712154925955; Wed, 03 Apr 2024 07:35:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712154925; cv=pass; d=google.com; s=arc-20160816; b=gw/fq2Odb/cXEbSUmFfSXcjqjGJvtRsJAlW6v8m4cioaoPcr6tPPZnZ6lZeIVZZhRj WBkG0j0VYVGUaXcyLFA5+lviNq5iCMnwOQiXC8KNpTUPHmkU3nxgC+bmhdSjPCKRVX0B 0Df9Dmh5KOiRCxTAZp9PgujsgnAAaPDoTPrHF/8E7GTVbCqCLbk9/eZkSOgBpU0RbmZf TOSSNNwHlURL71/Zne8p532UyVxSFJnyTqkV/M/KdKQE9mJgQQGz3yp5wFNJxLr4RjZk wQeH44R2gQUA+cDOMhwdA7degm98XpzOCDHSlFOy4wrx1S6EN4dS+mZvOY36RcvnKKXw jonw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=OIKFPsyOzCIuH4XcWSPIB4HiD06Qkif/244AZs4cvzo=; fh=qsOUwQFvo38RhuS3PDiTiyDKNDaJOiHjgqt/S0c+5B0=; b=esCH+a1HcisWLGFECEz35Z3hNr9tQsXXMvRdWJvoNhyXIkelEvWlTCSQ88gKKoDiBE jXmzjJUVg9EabZrA1+wCOxWFAoIMVgugDs7XFcY11Hej8MBWapHrpVeXYJ9QAHYWVig0 hTVHXi1QQG3qhap4SL1Z3eDDnpo6nLtat9bke+P7yn2nOj61JEm/DzgGsWw+lSNy9eso YxhlEKXj1bI3txTocnyfYZOlldMt1cxljPCg3JHEGgLfEbPlbipOxttV9wGP524XuJm0 3LNLANJEcvbBqKap5LYdPhPxjrs1woQzZ720XyKpkZysjpEG4VgvbLX28q6kMRL/uol1 ZXFw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-129974-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129974-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d13-20020ac85acd000000b0043433eac4a8si3998788qtd.515.2024.04.03.07.35.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 07:35:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-129974-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-129974-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129974-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B0B971C2601C for ; Wed, 3 Apr 2024 14:35:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1A93F58AD4; Wed, 3 Apr 2024 14:35:19 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7B3D057875; Wed, 3 Apr 2024 14:35:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712154918; cv=none; b=Iep7MKxu1rbwd046w7zYJ7dPkP6tcaiIMf+vuLIvK6Q4TtnrNfKnU585SAoZC4OMkcfhfmBNHICugJP2uCbXZ80MSwl2hMxcweHtUXAQcJcqNEhw+1GCS+qWGKuXJp4cOKyFaRKQQliNmwtYmGPQ8ooT3mLJMz/J0ZXZAOJQCgg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712154918; c=relaxed/simple; bh=RTGore1mMiwZPaN2GqgBvhB6ZDNGVsnEsd/hvDoQcBw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dMVg58PGodaGKA8mz6u46tOfn++p+8TBdIta4AKxkY5kmS1PnakTxylQgL7C11bUZFZxvsPpDYDrBRodsY3MxBpSRhoHwWoQyYU3JdZezXinX1VgkZgdGDHcIjnn+4LU6riq17r9xISTU8ZOB6465ct0vvceyEhsYrOOhf9tt1c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D1B3D1007; Wed, 3 Apr 2024 07:35:46 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.16.212]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8A9943F7B4; Wed, 3 Apr 2024 07:35:13 -0700 (PDT) Date: Wed, 3 Apr 2024 15:35:10 +0100 From: Mark Rutland To: Dawei Li Cc: will@kernel.org, yury.norov@gmail.com, linux@rasmusvillemoes.dk, xueshuai@linux.alibaba.com, renyu.zj@linux.alibaba.com, yangyicong@hisilicon.com, jonathan.cameron@huawei.com, andersson@kernel.org, konrad.dybcio@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: Re: [PATCH v2 07/10] perf/hisi_pcie: Avoid placing cpumask var on stack Message-ID: References: <20240403125109.2054881-1-dawei.li@shingroup.cn> <20240403125109.2054881-8-dawei.li@shingroup.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240403125109.2054881-8-dawei.li@shingroup.cn> On Wed, Apr 03, 2024 at 08:51:06PM +0800, Dawei Li wrote: > For CONFIG_CPUMASK_OFFSTACK=y kernel, explicit allocation of cpumask > variable on stack is not recommended since it can cause potential stack > overflow. > > Instead, kernel code should always use *cpumask_var API(s) to allocate > cpumask var in config-neutral way, leaving allocation strategy to > CONFIG_CPUMASK_OFFSTACK. > > But dynamic allocation in cpuhp's teardown callback is somewhat problematic > for if allocation fails(which is unlikely but still possible): > - If -ENOMEM is returned to caller, kernel crashes for non-bringup > teardown; > - If callback pretends nothing happened and returns 0 to caller, it may > trap system into an in-consisitent/compromised state; > > Use newly-introduced cpumask_any_and_but() to address all issues above. > It eliminates usage of temporary cpumask var in generic way, no matter how > the cpumask var is allocated. > > Suggested-by: Mark Rutland > Signed-off-by: Dawei Li The logic looks good to me, but I'd like the commit message updated the same as per my comment on patch 2. With that commit message: Reviewed-by: Mark Rutland Mark. > --- > drivers/perf/hisilicon/hisi_pcie_pmu.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/drivers/perf/hisilicon/hisi_pcie_pmu.c b/drivers/perf/hisilicon/hisi_pcie_pmu.c > index 5d1f0e9fdb08..06b192cc31d5 100644 > --- a/drivers/perf/hisilicon/hisi_pcie_pmu.c > +++ b/drivers/perf/hisilicon/hisi_pcie_pmu.c > @@ -673,7 +673,6 @@ static int hisi_pcie_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node) > { > struct hisi_pcie_pmu *pcie_pmu = hlist_entry_safe(node, struct hisi_pcie_pmu, node); > unsigned int target; > - cpumask_t mask; > int numa_node; > > /* Nothing to do if this CPU doesn't own the PMU */ > @@ -684,10 +683,10 @@ static int hisi_pcie_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node) > > /* Choose a local CPU from all online cpus. */ > numa_node = dev_to_node(&pcie_pmu->pdev->dev); > - if (cpumask_and(&mask, cpumask_of_node(numa_node), cpu_online_mask) && > - cpumask_andnot(&mask, &mask, cpumask_of(cpu))) > - target = cpumask_any(&mask); > - else > + > + target = cpumask_any_and_but(cpumask_of_node(numa_node), > + cpu_online_mask, cpu); > + if (target >= nr_cpu_ids) > target = cpumask_any_but(cpu_online_mask, cpu); > > if (target >= nr_cpu_ids) { > -- > 2.27.0 >