From patchwork Tue Apr 2 10:56:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dawei Li X-Patchwork-Id: 13613752 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 14F87CD1284 for ; Tue, 2 Apr 2024 10:59:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=88bCkhqTilr222tcDwc+lpma/1oVrEKCZ5uDnQh0WWU=; b=WXx0LYJAuKohkr +gauZa3ot7Dl0ARv85BtmW/vd7FPonCj54rddP5qSLIAwo9LOW1DG6Yvp1gHOtYF75MR48+lWXTAQ Klz+6S50S2JlvUkTUzxQgbukwD4EiF9nWTNqoN0X0B/qGRHBUyZT2MjU6Z9To7A+Ew4FdndPJGd04 1MK4gltCmzLHrpFyAB+bbjCq86DEG3L+UCDuqo1TNoOAhmZ4t2Ao5XCm2Prbhhyy+bC6xh9qhTEj4 mM7gUmVPt4+JbT6eMfDnfQjWb1pk2qlY+lwcDxQQENUSF+N37syiEJjoId1Fe1dokMVVAy1buiWc5 3KelAapMD8Ox4zk6iDXA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rrbqq-0000000Alh0-2AdW; Tue, 02 Apr 2024 10:58:48 +0000 Received: from bg1.exmail.qq.com ([114.132.74.132]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rrbqk-0000000AlZx-1C9M for linux-arm-kernel@lists.infradead.org; Tue, 02 Apr 2024 10:58:46 +0000 X-QQ-mid: bizesmtpsz7t1712055482t8hhr29 X-QQ-Originating-IP: AIcr+JMMiHNAe9ivs3l6hnjCuJ93m5xNH9hw9O48loQ= Received: from localhost ( [112.0.147.175]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 02 Apr 2024 18:58:00 +0800 (CST) X-QQ-SSF: 01400000000000704000000A0000000 X-QQ-FEAT: 3M0okmaRx3jDSki7LRBGbMl6eVjhJrP7hy+2d57Zwz9+hkzPLSG00e+1ByNRJ xCUqV/VaOH9XPhyMNY6fXwGTZkOUIOF7FwM9vxUNJTyzeHF+BJ7JjtJ443q4nZzWvAFRe89 5q6ewnYehc0YZfYalerNRGY19Re1KFcJ7z2BrSuBDEWvqVKiYyr9CNnhDeTfnKq142ZVAHv 4C9u0f5MohXsc3rTyWoYZlXRKC7yJWlyqUJgSxEN5ardzQSwc7WjJ3VtJhXemJzTDWqbQRW 6yCjzYBZrAzM1dAY6tOfZLAeBxOAc6O+3d4Y6rB6KRcldI1/Kr9C4a6CtRV9ABWwdGc57D5 Wihf/pxeEVr5f4qy20Gqh7kF2Ekt1q9Pkg3Ke/b+VumTe+eyU93WGAXd8BBtzTbChLjA4b9 +bVJTMCVliEvQxnRyGxyWA== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 17135480200508921622 From: Dawei Li To: 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, Dawei Li Subject: [PATCH 9/9] perf/thunder_x2: Avoid explicit cpumask var allocation from stack Date: Tue, 2 Apr 2024 18:56:10 +0800 Message-Id: <20240402105610.1695644-10-dawei.li@shingroup.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240402105610.1695644-1-dawei.li@shingroup.cn> References: <20240402105610.1695644-1-dawei.li@shingroup.cn> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpsz:shingroup.cn:qybglogicsvrgz:qybglogicsvrgz5a-1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240402_035842_996261_F1F07E76 X-CRM114-Status: GOOD ( 11.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/thunderx2_pmu.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/perf/thunderx2_pmu.c b/drivers/perf/thunderx2_pmu.c index e16d10c763de..8a02a4533b32 100644 --- a/drivers/perf/thunderx2_pmu.c +++ b/drivers/perf/thunderx2_pmu.c @@ -932,9 +932,9 @@ static int tx2_uncore_pmu_online_cpu(unsigned int cpu, static int tx2_uncore_pmu_offline_cpu(unsigned int cpu, struct hlist_node *hpnode) { - int new_cpu; + cpumask_var_t cpu_online_mask_temp; struct tx2_uncore_pmu *tx2_pmu; - struct cpumask cpu_online_mask_temp; + int new_cpu; tx2_pmu = hlist_entry_safe(hpnode, struct tx2_uncore_pmu, hpnode); @@ -945,17 +945,21 @@ static int tx2_uncore_pmu_offline_cpu(unsigned int cpu, if (tx2_pmu->hrtimer_callback) hrtimer_cancel(&tx2_pmu->hrtimer); - cpumask_copy(&cpu_online_mask_temp, cpu_online_mask); - cpumask_clear_cpu(cpu, &cpu_online_mask_temp); - new_cpu = cpumask_any_and( - cpumask_of_node(tx2_pmu->node), - &cpu_online_mask_temp); + if (!alloc_cpumask_var(&cpu_online_mask_temp, GFP_KERNEL)) + return 0; + + cpumask_copy(cpu_online_mask_temp, cpu_online_mask); + cpumask_clear_cpu(cpu, cpu_online_mask_temp); + new_cpu = cpumask_any_and(cpumask_of_node(tx2_pmu->node), + cpu_online_mask_temp); tx2_pmu->cpu = new_cpu; if (new_cpu >= nr_cpu_ids) - return 0; + goto __free_cpumask; perf_pmu_migrate_context(&tx2_pmu->pmu, cpu, new_cpu); +__free_cpumask: + free_cpumask_var(cpu_online_mask_temp); return 0; }