Skip to content

Commit 7401056

Browse files
sudeep-hollaolofj
authored andcommitted
drivers/firmware: psci_checker: stash and use topology_core_cpumask for hotplug tests
Commit 7f9545a ("arm64: smp: remove cpu and numa topology information when hotplugging out CPU") updates the cpu topology when the CPU is hotplugged out. However the PSCI checker code uses the topology_core_cpumask pointers for some of the cpu hotplug testing. Since the pointer to the core_cpumask of the first CPU in the group is used, which when that CPU itself is hotpugged out is just set to itself, the testing terminates after that particular CPU is tested out. But the intention of this tests is to cover all the CPU in the group. In order to support that, we need to stash the topology_core_cpumask before the start of the test and use that value instead of pointer to a cpumask which will be updated on CPU hotplug. Fixes: 7f9545a ("arm64: smp: remove cpu and numa topology information when hotplugging out CPU") Reported-by: Geert Uytterhoeven <geert@linux-m68k.org> Tested-by: Geert Uytterhoeven <geert+renesas@glider.be> Cc: Mark Rutland <mark.rutland@arm.com> Acked-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com> Signed-off-by: Olof Johansson <olof@lixom.net>
1 parent 1ca8c0a commit 7401056

1 file changed

Lines changed: 49 additions & 34 deletions

File tree

‎drivers/firmware/psci_checker.c‎

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,6 @@ static int psci_ops_check(void)
7777
return 0;
7878
}
7979

80-
static int find_cpu_groups(const struct cpumask *cpus,
81-
const struct cpumask **cpu_groups)
82-
{
83-
unsigned int nb = 0;
84-
cpumask_var_t tmp;
85-
86-
if (!alloc_cpumask_var(&tmp, GFP_KERNEL))
87-
return -ENOMEM;
88-
cpumask_copy(tmp, cpus);
89-
90-
while (!cpumask_empty(tmp)) {
91-
const struct cpumask *cpu_group =
92-
topology_core_cpumask(cpumask_any(tmp));
93-
94-
cpu_groups[nb++] = cpu_group;
95-
cpumask_andnot(tmp, tmp, cpu_group);
96-
}
97-
98-
free_cpumask_var(tmp);
99-
return nb;
100-
}
101-
10280
/*
10381
* offlined_cpus is a temporary array but passing it as an argument avoids
10482
* multiple allocations.
@@ -166,29 +144,66 @@ static unsigned int down_and_up_cpus(const struct cpumask *cpus,
166144
return err;
167145
}
168146

147+
static void free_cpu_groups(int num, cpumask_var_t **pcpu_groups)
148+
{
149+
int i;
150+
cpumask_var_t *cpu_groups = *pcpu_groups;
151+
152+
for (i = 0; i < num; ++i)
153+
free_cpumask_var(cpu_groups[i]);
154+
kfree(cpu_groups);
155+
}
156+
157+
static int alloc_init_cpu_groups(cpumask_var_t **pcpu_groups)
158+
{
159+
int num_groups = 0;
160+
cpumask_var_t tmp, *cpu_groups;
161+
162+
if (!alloc_cpumask_var(&tmp, GFP_KERNEL))
163+
return -ENOMEM;
164+
165+
cpu_groups = kcalloc(nb_available_cpus, sizeof(cpu_groups),
166+
GFP_KERNEL);
167+
if (!cpu_groups)
168+
return -ENOMEM;
169+
170+
cpumask_copy(tmp, cpu_online_mask);
171+
172+
while (!cpumask_empty(tmp)) {
173+
const struct cpumask *cpu_group =
174+
topology_core_cpumask(cpumask_any(tmp));
175+
176+
if (!alloc_cpumask_var(&cpu_groups[num_groups], GFP_KERNEL)) {
177+
free_cpu_groups(num_groups, &cpu_groups);
178+
return -ENOMEM;
179+
}
180+
cpumask_copy(cpu_groups[num_groups++], cpu_group);
181+
cpumask_andnot(tmp, tmp, cpu_group);
182+
}
183+
184+
free_cpumask_var(tmp);
185+
*pcpu_groups = cpu_groups;
186+
187+
return num_groups;
188+
}
189+
169190
static int hotplug_tests(void)
170191
{
171-
int err;
172-
cpumask_var_t offlined_cpus;
173-
int i, nb_cpu_group;
174-
const struct cpumask **cpu_groups;
192+
int i, nb_cpu_group, err = -ENOMEM;
193+
cpumask_var_t offlined_cpus, *cpu_groups;
175194
char *page_buf;
176195

177-
err = -ENOMEM;
178196
if (!alloc_cpumask_var(&offlined_cpus, GFP_KERNEL))
179197
return err;
180-
/* We may have up to nb_available_cpus cpu_groups. */
181-
cpu_groups = kmalloc_array(nb_available_cpus, sizeof(*cpu_groups),
182-
GFP_KERNEL);
183-
if (!cpu_groups)
198+
199+
nb_cpu_group = alloc_init_cpu_groups(&cpu_groups);
200+
if (nb_cpu_group < 0)
184201
goto out_free_cpus;
185202
page_buf = (char *)__get_free_page(GFP_KERNEL);
186203
if (!page_buf)
187204
goto out_free_cpu_groups;
188205

189206
err = 0;
190-
nb_cpu_group = find_cpu_groups(cpu_online_mask, cpu_groups);
191-
192207
/*
193208
* Of course the last CPU cannot be powered down and cpu_down() should
194209
* refuse doing that.
@@ -212,7 +227,7 @@ static int hotplug_tests(void)
212227

213228
free_page((unsigned long)page_buf);
214229
out_free_cpu_groups:
215-
kfree(cpu_groups);
230+
free_cpu_groups(nb_cpu_group, &cpu_groups);
216231
out_free_cpus:
217232
free_cpumask_var(offlined_cpus);
218233
return err;

0 commit comments

Comments
 (0)