Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1996741lqz; Tue, 2 Apr 2024 04:25:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVLQuE/mg6CNnr0Pn5MaXoLwdVCqsn5zw5KxVHKftEzctIrnCWZw4p+vplDUFovBwR/GgAxuRqx47eeoP/X9WyWEYnk946Sh4lp3fiHyQ== X-Google-Smtp-Source: AGHT+IEkXZxDBERp3A4Uu/bXVXTWtow21WWCfA2KSFJjD+g1LrowttYC1af47TAzV1K/12RvuSAy X-Received: by 2002:a05:6a20:3d05:b0:1a7:19f:2c3a with SMTP id y5-20020a056a203d0500b001a7019f2c3amr14559567pzi.7.1712057102751; Tue, 02 Apr 2024 04:25:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712057102; cv=pass; d=google.com; s=arc-20160816; b=GekvshPZp+HvxeZME39PbvQbj770T/jiBy9DWRNiEsaVh4sDorOsE5p3ZBTTPfinuG RZsvzu859hNl4opVOuS0L6fzub23uIywhC21QnTUt1nE7qOLu+Wf+VM1LfJBH/h3btVA Lm61NyJy8rV9o1Sjl5tplnMfJr2/yEuhg6bQC5tgV1u0HRqzLy++yDUzTDF14HY1+XWR Fe+haDqE0WRMbjU1MF4aw1tBI/+WWse34qOhnNut4rgWdu6liZA8kcHP4iOBYtKv/0J8 GZ33aw9z6UpnPDhlhlPkqVrAj7qdskaOwayfVwBQQ106PMGykDEHMUifM/1kOG4YsXmJ 2oEw== 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=UCSeec+GjegXhO/v5aN1+xE+ykhJyKeUcIm/rRBZHUk=; fh=OvZr5JdCTmRwQbONTItcif7O2QSbk2WSQlYCKZQBTyg=; b=VvijjIFLL32xFds6Nl6Gu6iaMeax+uhXX/GHxt86HiRRzD3n0nHNA0KfeZSaBrrhpH rVUEz7f7nRNRC28CduGwbD4y1d2/orLU7DjsCYBUT4lmLq3GOWm2kqIlLFeYlsjQ51KT TWrKyoW4YY4Asr5JnoL9+36gPTFjvqMrfNEgDhSz1nVI+DVtKGmWBwjVErNWLP/8zBG3 OlLIpG8APDHb/nzUcYg/Spu3L0XX/oic6SugMDEwS3GkjBOWzlCmpU5dygAHOGuPE2KW wnaoUl0HiDktXip7S5RaqsXZ2QGPDUfcZMzMYcldVskDfdMZTlPJcfMEoDuJc21svIy/ C6Ag==; 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-127823-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127823-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id q7-20020a056a00084700b006eb43bc0fbesi4172763pfk.51.2024.04.02.04.25.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 04:25:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-127823-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::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-127823-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127823-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id CE535B25373 for ; Tue, 2 Apr 2024 11:07:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ACC5F60DFB; Tue, 2 Apr 2024 11:07:03 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0A8758AC3; Tue, 2 Apr 2024 11:07:00 +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=1712056023; cv=none; b=XYjh5YTwHUa3XdqIPeZqmqrYh/X9ktCqaj8yrsrknWWSnZOVufZGna0f7r9U42N3UBSgJbS4pQX36rMCsEDLsPYiJEPdSbk+b8Ix3X9uESV32Q29AeNyvUtmbmhqCMo0P0kuuiBT8Jkpzw6cm7Xm5fqiD3GiQytS2MsIY3kgk28= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712056023; c=relaxed/simple; bh=gLAAunGWwvRJHGizwYjm8QzkWNHBiV97BX0ZTwmQaiM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=C6GEtouFP4XWdW3rVjGpVzTrpiKU2ERoJxEIgmZtp+mYCs0G8uXjL/0PtD4qLh4oqa3zLKp9MfTLhsjQ7CLS4Yp/nT7jLLgHlwi2oEuCYh2jFhIkgOK7nfZX/iXUy1loeXLpZ1WhMqaQwsjxfUBSOwPiRG/u2ngJl/oWHOZlyJo= 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 F3879FEC; Tue, 2 Apr 2024 04:07:31 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.18.33]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 26E383F766; Tue, 2 Apr 2024 04:06:58 -0700 (PDT) Date: Tue, 2 Apr 2024 12:06:52 +0100 From: Mark Rutland To: Dawei Li Cc: will@kernel.org, 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 1/9] perf/alibaba_uncore_drw: Avoid explicit cpumask var allocation from stack Message-ID: References: <20240402105610.1695644-1-dawei.li@shingroup.cn> <20240402105610.1695644-2-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: <20240402105610.1695644-2-dawei.li@shingroup.cn> On Tue, Apr 02, 2024 at 06:56:02PM +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. > > Use *cpumask_var API(s) to address it. > > Signed-off-by: Dawei Li > --- > drivers/perf/alibaba_uncore_drw_pmu.c | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) > > diff --git a/drivers/perf/alibaba_uncore_drw_pmu.c b/drivers/perf/alibaba_uncore_drw_pmu.c > index a9277dcf90ce..251f0a2dee84 100644 > --- a/drivers/perf/alibaba_uncore_drw_pmu.c > +++ b/drivers/perf/alibaba_uncore_drw_pmu.c > @@ -743,25 +743,28 @@ static void ali_drw_pmu_remove(struct platform_device *pdev) > > static int ali_drw_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node) > { > + cpumask_var_t node_online_cpus; > struct ali_drw_pmu_irq *irq; > struct ali_drw_pmu *drw_pmu; > unsigned int target; > int ret; > - cpumask_t node_online_cpus; > > irq = hlist_entry_safe(node, struct ali_drw_pmu_irq, node); > if (cpu != irq->cpu) > return 0; > > - ret = cpumask_and(&node_online_cpus, > + if (!alloc_cpumask_var(&node_online_cpus, GFP_KERNEL)) > + return 0; NAK. This error path leaves things in an incorrect state and this approach does not make sense. Please allocate the cpumasks when we allocate the PMU. Then we can reasonably fail to probe the PMU if we don't have enough memory, and the masks will definitely be accessible in gotplug paths. The same comment applies to the whole series. Mark. > + > + ret = cpumask_and(node_online_cpus, > cpumask_of_node(cpu_to_node(cpu)), cpu_online_mask); > if (ret) > - target = cpumask_any_but(&node_online_cpus, cpu); > + target = cpumask_any_but(node_online_cpus, cpu); > else > target = cpumask_any_but(cpu_online_mask, cpu); > > if (target >= nr_cpu_ids) > - return 0; > + goto __free_cpumask; > > /* We're only reading, but this isn't the place to be involving RCU */ > mutex_lock(&ali_drw_pmu_irqs_lock); > @@ -772,6 +775,8 @@ static int ali_drw_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node) > WARN_ON(irq_set_affinity_hint(irq->irq_num, cpumask_of(target))); > irq->cpu = target; > > +__free_cpumask: > + free_cpumask_var(node_online_cpus); > return 0; > } > > -- > 2.27.0 >