diff options
author | Guilherme G. Piccoli <gpiccoli@linux.vnet.ibm.com> | 2017-10-19 15:41:33 -0400 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2017-10-25 06:41:13 -0400 |
commit | 0b167f11085a34281349f395d200052b61a7e221 (patch) | |
tree | 323931d5300107fae8ed66a354f3051b6b0b3131 | |
parent | 0d8ba16278ec30a262d931875018abee332f926f (diff) |
powerpc/perf: Fix IMC allocation routine
When setting nr_cpus=1, we observed a crash in IMC code during boot
due to a missing allocation: basically, IMC code is taking the number
of threads into account in imc_mem_init() and if we manually set
nr_cpus for a value that is not multiple of the number of threads per
core, an integer division in that function will discard the decimal
portion, leading IMC to not allocate one mem_info struct. This causes
a NULL pointer dereference later, on is_core_imc_mem_inited().
This patch just rounds that division up, fixing the bug.
Signed-off-by: Guilherme G. Piccoli <gpiccoli@linux.vnet.ibm.com>
Acked-by: Anju T Sudhakar <anju@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
-rw-r--r-- | arch/powerpc/perf/imc-pmu.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c index 88126245881b..92ae5de0bbac 100644 --- a/arch/powerpc/perf/imc-pmu.c +++ b/arch/powerpc/perf/imc-pmu.c | |||
@@ -1104,7 +1104,7 @@ static int init_nest_pmu_ref(void) | |||
1104 | 1104 | ||
1105 | static void cleanup_all_core_imc_memory(void) | 1105 | static void cleanup_all_core_imc_memory(void) |
1106 | { | 1106 | { |
1107 | int i, nr_cores = num_present_cpus() / threads_per_core; | 1107 | int i, nr_cores = DIV_ROUND_UP(num_present_cpus(), threads_per_core); |
1108 | struct imc_mem_info *ptr = core_imc_pmu->mem_info; | 1108 | struct imc_mem_info *ptr = core_imc_pmu->mem_info; |
1109 | int size = core_imc_pmu->counter_mem_size; | 1109 | int size = core_imc_pmu->counter_mem_size; |
1110 | 1110 | ||
@@ -1212,7 +1212,7 @@ static int imc_mem_init(struct imc_pmu *pmu_ptr, struct device_node *parent, | |||
1212 | if (!pmu_ptr->pmu.name) | 1212 | if (!pmu_ptr->pmu.name) |
1213 | return -ENOMEM; | 1213 | return -ENOMEM; |
1214 | 1214 | ||
1215 | nr_cores = num_present_cpus() / threads_per_core; | 1215 | nr_cores = DIV_ROUND_UP(num_present_cpus(), threads_per_core); |
1216 | pmu_ptr->mem_info = kcalloc(nr_cores, sizeof(struct imc_mem_info), | 1216 | pmu_ptr->mem_info = kcalloc(nr_cores, sizeof(struct imc_mem_info), |
1217 | GFP_KERNEL); | 1217 | GFP_KERNEL); |
1218 | 1218 | ||