From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpbg153.qq.com (smtpbg153.qq.com [13.245.218.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD62A7FBA6; Tue, 2 Apr 2024 10:58:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.245.218.24 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712055489; cv=none; b=gzKMaAw0QJd3lGH2LyboCN5amErxMEgCnU1rbMK3avYBpJD8S6udpdoRW2lEYOe4ZIQkoHfiifJ7HAtTmpOaMuYpWDlp1xzvVWko953/k44nTMNHjlt2dwqU1oqv+6pRgT6d9pPACnWw4KmY+zGsyqgi36/jiYAvrEYzObY3AIs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712055489; c=relaxed/simple; bh=kBhgbN7veyPdJiucyzUm36iOG/7FCi2+n/Y5GolQDQY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Dk+Z19Ey0hETxsgeBESk//ZODA2S9O9C4QezuqRMMDf8/1YNZOWpWifvrXVEQI7MzHLqpWtJisOhNddCt1vhsQlbFW1TdxvZpOZZZZPh/fu+G29/nYnybJVTWb0td4lC7yb9V6xYV55x3uA8XXE7G5+y+7dBnZZUJgmtdl+oSYE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn; spf=pass smtp.mailfrom=shingroup.cn; arc=none smtp.client-ip=13.245.218.24 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shingroup.cn X-QQ-mid: bizesmtpsz6t1712055425t71idd1 X-QQ-Originating-IP: Un3ri6CHwwLui5oq45tA1OXYdCgmI9pohTO0oH1tBU0= Received: from localhost ( [112.0.147.175]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 02 Apr 2024 18:57:04 +0800 (CST) X-QQ-SSF: 01400000000000704000000A0000000 X-QQ-FEAT: RrZlkntZBfktBWsBF1E+TH5J6loXlgQ3eAU19WtoMF7qdeTVjXhPDBscmPite 2ovkkkqxI68M8HuFvipOvq8mq8IkFWrgg2ZajQUXeWRV5BA082MjJ5B+wQph7d+l9ItO8fj w/NCUcTAB6KgKgiJPO6LHkOzxog1FYAU128tjeKLiTgx0siyjehIhTkYX2Pm7Do1ivTfOVK DULIAgFBMAhH+hs8n4SqOqt9Rdh3SglT/1fTStlTmizTpxY2HnRf5J3Fivl2pSJtW7rF6PZ +GA+jzuMwnhLZJE9FEZe9nPipczqaLWRJHm8HH7yCT7b3QL7HMrwY1y3NJQOmgLUkIUqXTz EZ6PJaWFU8Snde9TL/2V8e0Tunk9dWY+nmtkc+LnLoTrcbIeYWWBqA4X96M+eXHwElKRTs7 x+JeeYCYIy95lDu7H5qvLw== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 6688925915623200332 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 4/9] perf/arm_dsu: Avoid explicit cpumask var allocation from stack Date: Tue, 2 Apr 2024 18:56:05 +0800 Message-Id: <20240402105610.1695644-5-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> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpsz:shingroup.cn:qybglogicsvrgz:qybglogicsvrgz5a-1 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/arm_dsu_pmu.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/perf/arm_dsu_pmu.c b/drivers/perf/arm_dsu_pmu.c index bae3ca37f846..87efdca05807 100644 --- a/drivers/perf/arm_dsu_pmu.c +++ b/drivers/perf/arm_dsu_pmu.c @@ -230,13 +230,21 @@ static const struct attribute_group *dsu_pmu_attr_groups[] = { NULL, }; -static int dsu_pmu_get_online_cpu_any_but(struct dsu_pmu *dsu_pmu, int cpu) +static unsigned int dsu_pmu_get_online_cpu_any_but(struct dsu_pmu *dsu_pmu, int cpu) { - struct cpumask online_supported; + cpumask_var_t online_supported; + unsigned int ret; - cpumask_and(&online_supported, - &dsu_pmu->associated_cpus, cpu_online_mask); - return cpumask_any_but(&online_supported, cpu); + if (!alloc_cpumask_var(&online_supported, GFP_KERNEL)) + return -ENOMEM; + + cpumask_and(online_supported, + &dsu_pmu->associated_cpus, cpu_online_mask); + ret = cpumask_any_but(&online_supported, cpu); + + free_cpumask_var(online_supported); + + return ret; } static inline bool dsu_pmu_counter_valid(struct dsu_pmu *dsu_pmu, u32 idx) -- 2.27.0 From mboxrd@z Thu Jan 1 00:00:00 1970 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 50719C6FD1F for ; Tue, 2 Apr 2024 10:58:14 +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=6NheISdqD0O0ZbP84CADWHBOU+IUp2N4+Una/OpOgfQ=; b=dJyt7gcA9oltfm cVg1iuC+WWKmEW/S9txfUOZYkw56PMb6Mh9iKnBZ4gGclmNJhwSyeA65Ye0rtzxv+VzFosSFjquR1 xc3IVwcBxv8tGTKoyYnCzha2iWPXV3pWsZcxFL020chfC6bmI+63dNJrCuBxuY7TYmwU04PJvu6j8 xyn7VMHay3naQM+Wreyip6608L5BzH2+dUcu5dh6m1N+QAsRfg0+p8aVVPblqHZ9BdlorFIszi5yc 4gtjTWRNZQ8EGc8vyDBNs4aQlhUyR2XYnEZ1SW8ilb0yXMzMp0pLEeRmzFseLAa1nxwnLNrYFih83 WWrUVwE5V8IGL9Vsvoeg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rrbq4-0000000Al4Z-0rtj; Tue, 02 Apr 2024 10:58:00 +0000 Received: from bg1.exmail.qq.com ([114.132.73.137]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rrbpz-0000000Al0e-3myJ for linux-arm-kernel@lists.infradead.org; Tue, 02 Apr 2024 10:57:58 +0000 X-QQ-mid: bizesmtpsz6t1712055425t71idd1 X-QQ-Originating-IP: Un3ri6CHwwLui5oq45tA1OXYdCgmI9pohTO0oH1tBU0= Received: from localhost ( [112.0.147.175]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 02 Apr 2024 18:57:04 +0800 (CST) X-QQ-SSF: 01400000000000704000000A0000000 X-QQ-FEAT: RrZlkntZBfktBWsBF1E+TH5J6loXlgQ3eAU19WtoMF7qdeTVjXhPDBscmPite 2ovkkkqxI68M8HuFvipOvq8mq8IkFWrgg2ZajQUXeWRV5BA082MjJ5B+wQph7d+l9ItO8fj w/NCUcTAB6KgKgiJPO6LHkOzxog1FYAU128tjeKLiTgx0siyjehIhTkYX2Pm7Do1ivTfOVK DULIAgFBMAhH+hs8n4SqOqt9Rdh3SglT/1fTStlTmizTpxY2HnRf5J3Fivl2pSJtW7rF6PZ +GA+jzuMwnhLZJE9FEZe9nPipczqaLWRJHm8HH7yCT7b3QL7HMrwY1y3NJQOmgLUkIUqXTz EZ6PJaWFU8Snde9TL/2V8e0Tunk9dWY+nmtkc+LnLoTrcbIeYWWBqA4X96M+eXHwElKRTs7 x+JeeYCYIy95lDu7H5qvLw== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 6688925915623200332 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 4/9] perf/arm_dsu: Avoid explicit cpumask var allocation from stack Date: Tue, 2 Apr 2024 18:56:05 +0800 Message-Id: <20240402105610.1695644-5-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_035756_319566_E68E4810 X-CRM114-Status: GOOD ( 10.75 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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/arm_dsu_pmu.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/perf/arm_dsu_pmu.c b/drivers/perf/arm_dsu_pmu.c index bae3ca37f846..87efdca05807 100644 --- a/drivers/perf/arm_dsu_pmu.c +++ b/drivers/perf/arm_dsu_pmu.c @@ -230,13 +230,21 @@ static const struct attribute_group *dsu_pmu_attr_groups[] = { NULL, }; -static int dsu_pmu_get_online_cpu_any_but(struct dsu_pmu *dsu_pmu, int cpu) +static unsigned int dsu_pmu_get_online_cpu_any_but(struct dsu_pmu *dsu_pmu, int cpu) { - struct cpumask online_supported; + cpumask_var_t online_supported; + unsigned int ret; - cpumask_and(&online_supported, - &dsu_pmu->associated_cpus, cpu_online_mask); - return cpumask_any_but(&online_supported, cpu); + if (!alloc_cpumask_var(&online_supported, GFP_KERNEL)) + return -ENOMEM; + + cpumask_and(online_supported, + &dsu_pmu->associated_cpus, cpu_online_mask); + ret = cpumask_any_but(&online_supported, cpu); + + free_cpumask_var(online_supported); + + return ret; } static inline bool dsu_pmu_counter_valid(struct dsu_pmu *dsu_pmu, u32 idx) -- 2.27.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel