Received: by 2002:ab2:604e:0:b0:1f4:60f3:cb4a with SMTP id a14csp14085lqm; Fri, 5 Apr 2024 07:32:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWELpwQLjwBa0S+vEjEsNSvWUHWO18uRknECwF4qxhVh09WMqB3Ehda1ydKhl+R5SEJKlTha6ZG/DbMzadSBiKulc9YSGKTY/l9/pUTIg== X-Google-Smtp-Source: AGHT+IF12wyNGf7dDPTh31xNBFSxXEuVH7s38bRBiCdqpo0OvM9pLVrrXfxfoEj5Elj5b6D3Qvzt X-Received: by 2002:a05:6358:d092:b0:183:8b61:eeaa with SMTP id jc18-20020a056358d09200b001838b61eeaamr2065244rwb.15.1712327526589; Fri, 05 Apr 2024 07:32:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712327526; cv=pass; d=google.com; s=arc-20160816; b=Doo+cwsOuCHHaR/bGYRWY04t5yyOC+Sonc7Dz3/tgWJ4MbxoQHGlyE4zWrLj9F3Nuy L/JeE5NCIW/Nm+rshmdyylSxNalR0rqrtEwbAHJZz1twasRnFu9wYyi2t0VjQPsml1Tc MFV1k5FosLpAPnQySDT5XsUkCb7mI5AbRXyw05lrYxcOr01/WPM1E2mIs5m+ouQL9BSq stq5/zBxIw71kVybTl6FdvlD/oRZRZ5k7LfuFoZrHOG7lhSeEZVXRK2uXugltP5Gkeg9 78U4C8Ynl5qgQ7J/sIQ3fLS2nDNPko1Iqg99fNg9cVjo6g1gtRdj53M/90gB0XkiqjTD oU7A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=HxLwATxS37R1yREB40MBO7AxAfbji66qpwNwLVNag+I=; fh=ylF/QGvPiJQU8U6Ny/oUD2h4Mq8j+cMbR8SM4xs1GPM=; b=VmXrxs4ADESFMehh7j7otEVNPiCMLgUksK/IZ74YoOtk0PmHaHpGaebLUckRlUKuMl XecJozyneiU/nNRAO5f6IwUoZAZ/VuRxd/wsfTxu+VRH+rMhG3zjJyysKIAJtlkyPIJs 6x57ww0Wt1aoD9ZA6pq4ZFKDuVUHlM5X2E6i/pqDGoNak6jF7otxQ8cNAqxvYRmt2kJl Xt3tXW5usowNwGXw2n6GYs9oY/0MAUXFtd/brq+M/8io+KpM+pNSxjYQQApcrxzZ39ST HbFszoUJ3PesU05x/5oMbDQhXst1lO1wBPr4EMVuyoEHiEIj7NFKL1c7B7JaKz9K2AnM KIVw==; 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-133162-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133162-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id w2-20020a631602000000b005dbe38b2cfdsi1455838pgl.494.2024.04.05.07.32.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 07:32:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-133162-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::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-133162-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133162-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 189AF2858D6 for ; Fri, 5 Apr 2024 14:32:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1708B16F918; Fri, 5 Apr 2024 14:30:58 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0464516F265; Fri, 5 Apr 2024 14:30:55 +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=1712327457; cv=none; b=FZm77f6kKtMRQifb6gbQeu4QBVC+dhVefvIDbEe8FiXaSeB/nPz2cnPezdGbXu2klsYf1IQnAawDm/K3imvGhHCvRkLe+HFg2zT/BV2FWibakf6Aj1f8XXjSdVNmjYRFEUWv3LHKklMhJBH622KK3voczaYD6eEIprr4Imk2khk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712327457; c=relaxed/simple; bh=YFwqn7103KaIEJsbClKdLm4y4hgjLT+JwR9D/hbmpUs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=TVAsaG9euEPfl5DypwzPBGi5Zxp0M2KjLVULd+3IPiNgthmfDmaqJxRTDGnFVZTkV6AM6ZezVorqUO/p3ZfebES/u24AOs7fUFGTSn4aR8T2f3w7QKGSQ54qahVIuailY/KFKctZ845EPgjgWGQG/j2bevNXYshdGdAzeRKv0SE= 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 22A4CFEC; Fri, 5 Apr 2024 07:31:26 -0700 (PDT) Received: from [10.57.54.111] (unknown [10.57.54.111]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7D3883F7B4; Fri, 5 Apr 2024 07:30:53 -0700 (PDT) Message-ID: <5ab9bd5b-87e9-4e09-af49-7f15b0cc48d5@arm.com> Date: Fri, 5 Apr 2024 15:30:51 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/9] perf/arm-cmn: Avoid explicit cpumask var allocation from stack Content-Language: en-GB To: Dawei Li , will@kernel.org, mark.rutland@arm.com Cc: 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 References: <20240402105610.1695644-1-dawei.li@shingroup.cn> <20240402105610.1695644-3-dawei.li@shingroup.cn> From: Robin Murphy In-Reply-To: <20240402105610.1695644-3-dawei.li@shingroup.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2024-04-02 11:56 am, 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. I think the temporary mask may simply be redundant anyway. It seems like I may have misunderstood, and cpumask_of_node() actually only covers online CPUs already. Thanks, Robin. > Signed-off-by: Dawei Li > --- > drivers/perf/arm-cmn.c | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) > > diff --git a/drivers/perf/arm-cmn.c b/drivers/perf/arm-cmn.c > index 7ef9c7e4836b..7278fd72d3da 100644 > --- a/drivers/perf/arm-cmn.c > +++ b/drivers/perf/arm-cmn.c > @@ -1949,21 +1949,26 @@ static int arm_cmn_pmu_offline_cpu(unsigned int cpu, struct hlist_node *cpuhp_no > { > struct arm_cmn *cmn; > unsigned int target; > + cpumask_var_t mask; > int node; > - cpumask_t mask; > > cmn = hlist_entry_safe(cpuhp_node, struct arm_cmn, cpuhp_node); > if (cpu != cmn->cpu) > return 0; > > + if (!alloc_cpumask_var(&mask, GFP_KERNEL)) > + return 0; > + > node = dev_to_node(cmn->dev); > - if (cpumask_and(&mask, cpumask_of_node(node), cpu_online_mask) && > - cpumask_andnot(&mask, &mask, cpumask_of(cpu))) > - target = cpumask_any(&mask); > + if (cpumask_and(mask, cpumask_of_node(node), cpu_online_mask) && > + cpumask_andnot(mask, mask, cpumask_of(cpu))) > + target = cpumask_any(mask); > else > target = cpumask_any_but(cpu_online_mask, cpu); > if (target < nr_cpu_ids) > arm_cmn_migrate(cmn, target); > + > + free_cpumask_var(mask); > return 0; > } >