linux-stable/arch
Anju T Sudhakar eda6c45adc powerpc/perf: Fix kfree memory allocated for nest pmus
commit 110df8bd3e 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: 73ce9aec65 ("powerpc/perf: Fix IMC_MAX_PMU macro")
Signed-off-by: Anju T Sudhakar <anju@linux.vnet.ibm.com>
Reviewed-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Cc: Andrew Donnellan <ajd@linux.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-11-20 17:59:26 +01:00
..
alpha alpha: Fix Eiger NR_IRQS to 128 2019-02-20 10:20:53 +01:00
arc ARC: hide unused function unw_hdr_alloc 2019-07-21 09:04:41 +02:00
arm ARM: dts: dra7: Disable USB metastability workaround for USB2 2019-11-12 19:18:28 +01:00
arm64 arm64: Do not mask out PTE_RDONLY in pte_same() 2019-11-12 19:18:05 +01:00
blackfin
c6x
cris
frv
h8300 h8300: use cc-cross-prefix instead of hardcoding h8300-unknown-linux- 2019-04-05 22:31:25 +02:00
hexagon
ia64 ia64:unwind: fix double free for mod->arch.init_unw_table 2019-10-05 12:47:48 +02:00
m32r
m68k m68k: Add -ffreestanding to CFLAGS 2019-03-23 14:35:21 +01:00
metag
microblaze
mips MIPS: BCM63XX: fix switch core reset on BCM6368 2019-11-20 17:59:24 +01:00
mn10300
nios2
openrisc
parisc parisc: Fix vmap memory leak in ioremap()/iounmap() 2019-10-29 09:17:40 +01:00
powerpc powerpc/perf: Fix kfree memory allocated for nest pmus 2019-11-20 17:59:26 +01:00
s390 kvm: Convert kvm_lock to a mutex 2019-11-12 19:19:05 +01:00
score
sh sh: kernel: hw_breakpoint: Fix missing break in switch statement 2019-08-25 10:50:01 +02:00
sparc bpf: get rid of pure_initcall dependency to enable jits 2019-08-25 10:50:02 +02:00
tile
um um: Silence lockdep complaint about mmap_sem 2019-07-31 07:28:53 +02:00
unicore32
x86 KVM: x86: introduce is_pae_paging 2019-11-20 17:59:23 +01:00
xtensa xtensa: drop EXPORT_SYMBOL for outs*/ins* 2019-10-29 09:17:40 +01:00
.gitignore
Kconfig