Skip to content

Commit eda6c45

Browse files
anjutsudhakargregkh
authored andcommitted
powerpc/perf: Fix kfree memory allocated for nest pmus
commit 110df8b upstream. imc_common_cpuhp_mem_free() is the common function for all IMC (In-memory Collection counters) domains to unregister cpuhotplug callback and free memory. Since kfree of memory allocated for nest-imc (per_nest_pmu_arr) is in the common code, all domains (core/nest/thread) can do the kfree in the failure case. This could potentially create a call trace as shown below, where core(/thread/nest) imc pmu initialization fails and in the failure path imc_common_cpuhp_mem_free() free the memory(per_nest_pmu_arr), which is allocated by successfully registered nest units. The call trace is generated in a scenario where core-imc initialization is made to fail and a cpuhotplug is performed in a p9 system. During cpuhotplug ppc_nest_imc_cpu_offline() tries to access per_nest_pmu_arr, which is already freed by core-imc. NIP [c000000000cb6a94] mutex_lock+0x34/0x90 LR [c000000000cb6a88] mutex_lock+0x28/0x90 Call Trace: mutex_lock+0x28/0x90 (unreliable) perf_pmu_migrate_context+0x90/0x3a0 ppc_nest_imc_cpu_offline+0x190/0x1f0 cpuhp_invoke_callback+0x160/0x820 cpuhp_thread_fun+0x1bc/0x270 smpboot_thread_fn+0x250/0x290 kthread+0x1a8/0x1b0 ret_from_kernel_thread+0x5c/0x74 To address this scenario do the kfree(per_nest_pmu_arr) only in case of nest-imc initialization failure, and when there is no other nest units registered. Fixes: 73ce9ae ("powerpc/perf: Fix IMC_MAX_PMU macro") Signed-off-by: Anju T Sudhakar <[email protected]> Reviewed-by: Madhavan Srinivasan <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Cc: Andrew Donnellan <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 80da94a commit eda6c45

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

arch/powerpc/perf/imc-pmu.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,7 @@ static void imc_common_cpuhp_mem_free(struct imc_pmu *pmu_ptr)
11891189
if (nest_pmus == 1) {
11901190
cpuhp_remove_state(CPUHP_AP_PERF_POWERPC_NEST_IMC_ONLINE);
11911191
kfree(nest_imc_refc);
1192+
kfree(per_nest_pmu_arr);
11921193
}
11931194

11941195
if (nest_pmus > 0)
@@ -1213,7 +1214,6 @@ static void imc_common_cpuhp_mem_free(struct imc_pmu *pmu_ptr)
12131214
kfree(pmu_ptr->attr_groups[IMC_EVENT_ATTR]->attrs);
12141215
kfree(pmu_ptr->attr_groups[IMC_EVENT_ATTR]);
12151216
kfree(pmu_ptr);
1216-
kfree(per_nest_pmu_arr);
12171217
return;
12181218
}
12191219

@@ -1327,6 +1327,8 @@ int init_imc_pmu(struct device_node *parent, struct imc_pmu *pmu_ptr, int pmu_id
13271327
ret = nest_pmu_cpumask_init();
13281328
if (ret) {
13291329
mutex_unlock(&nest_init_lock);
1330+
kfree(nest_imc_refc);
1331+
kfree(per_nest_pmu_arr);
13301332
goto err_free;
13311333
}
13321334
}

0 commit comments

Comments
 (0)