[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240402105610.1695644-5-dawei.li@shingroup.cn>
Date: Tue, 2 Apr 2024 18:56:05 +0800
From: Dawei Li <dawei.li@...ngroup.cn>
To: will@...nel.org,
mark.rutland@....com
Cc: xueshuai@...ux.alibaba.com,
renyu.zj@...ux.alibaba.com,
yangyicong@...ilicon.com,
jonathan.cameron@...wei.com,
andersson@...nel.org,
konrad.dybcio@...aro.org,
linux-arm-kernel@...ts.infradead.org,
linux-kernel@...r.kernel.org,
linux-arm-msm@...r.kernel.org,
Dawei Li <dawei.li@...ngroup.cn>
Subject: [PATCH 4/9] perf/arm_dsu: Avoid explicit cpumask var allocation from stack
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 <dawei.li@...ngroup.cn>
---
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
Powered by blists - more mailing lists