Skip to content

Commit ea72229

Browse files
pratiksampatsmb49
authored andcommitted
cpufreq: powernv: Fix init_chip_info initialization in numa=off
BugLink: https://bugs.launchpad.net/bugs/1947781 commit f34ee9c upstream. In the numa=off kernel command-line configuration init_chip_info() loops around the number of chips and attempts to copy the cpumask of that node which is NULL for all iterations after the first chip. Hence, store the cpu mask for each chip instead of derving cpumask from node while populating the "chips" struct array and copy that to the chips[i].mask Fixes: 053819e ("cpufreq: powernv: Handle throttling due to Pmax capping at chip level") Cc: stable@vger.kernel.org # v4.3+ Reported-by: Shirisha Ganta <shirisha.ganta1@ibm.com> Signed-off-by: Pratik R. Sampat <psampat@linux.ibm.com> Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com> [mpe: Rename goto label to out_free_chip_cpu_mask] Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20210728120500.87549-2-psampat@linux.ibm.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Kamal Mostafa <kamal@canonical.com> Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
1 parent c769c62 commit ea72229

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

drivers/cpufreq/powernv-cpufreq.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#define MAX_PSTATE_SHIFT 32
3737
#define LPSTATE_SHIFT 48
3838
#define GPSTATE_SHIFT 56
39+
#define MAX_NR_CHIPS 32
3940

4041
#define MAX_RAMP_DOWN_TIME 5120
4142
/*
@@ -1051,35 +1052,46 @@ static int init_chip_info(void)
10511052
unsigned int *chip;
10521053
unsigned int cpu, i;
10531054
unsigned int prev_chip_id = UINT_MAX;
1055+
cpumask_t *chip_cpu_mask;
10541056
int ret = 0;
10551057

10561058
chip = kcalloc(num_possible_cpus(), sizeof(*chip), GFP_KERNEL);
10571059
if (!chip)
10581060
return -ENOMEM;
10591061

1062+
/* Allocate a chip cpu mask large enough to fit mask for all chips */
1063+
chip_cpu_mask = kcalloc(MAX_NR_CHIPS, sizeof(cpumask_t), GFP_KERNEL);
1064+
if (!chip_cpu_mask) {
1065+
ret = -ENOMEM;
1066+
goto free_and_return;
1067+
}
1068+
10601069
for_each_possible_cpu(cpu) {
10611070
unsigned int id = cpu_to_chip_id(cpu);
10621071

10631072
if (prev_chip_id != id) {
10641073
prev_chip_id = id;
10651074
chip[nr_chips++] = id;
10661075
}
1076+
cpumask_set_cpu(cpu, &chip_cpu_mask[nr_chips-1]);
10671077
}
10681078

10691079
chips = kcalloc(nr_chips, sizeof(struct chip), GFP_KERNEL);
10701080
if (!chips) {
10711081
ret = -ENOMEM;
1072-
goto free_and_return;
1082+
goto out_free_chip_cpu_mask;
10731083
}
10741084

10751085
for (i = 0; i < nr_chips; i++) {
10761086
chips[i].id = chip[i];
1077-
cpumask_copy(&chips[i].mask, cpumask_of_node(chip[i]));
1087+
cpumask_copy(&chips[i].mask, &chip_cpu_mask[i]);
10781088
INIT_WORK(&chips[i].throttle, powernv_cpufreq_work_fn);
10791089
for_each_cpu(cpu, &chips[i].mask)
10801090
per_cpu(chip_info, cpu) = &chips[i];
10811091
}
10821092

1093+
out_free_chip_cpu_mask:
1094+
kfree(chip_cpu_mask);
10831095
free_and_return:
10841096
kfree(chip);
10851097
return ret;

0 commit comments

Comments
 (0)