linux-stable/arch/x86
Peter Zijlstra 8b71aa1a3b perf/x86/intel: Delay memory deallocation until x86_pmu_dead_cpu()
commit 602cae04c4 upstream.

intel_pmu_cpu_prepare() allocated memory for ->shared_regs among other
members of struct cpu_hw_events. This memory is released in
intel_pmu_cpu_dying() which is wrong. The counterpart of the
intel_pmu_cpu_prepare() callback is x86_pmu_dead_cpu().

Otherwise if the CPU fails on the UP path between CPUHP_PERF_X86_PREPARE
and CPUHP_AP_PERF_X86_STARTING then it won't release the memory but
allocate new memory on the next attempt to online the CPU (leaking the
old memory).
Also, if the CPU down path fails between CPUHP_AP_PERF_X86_STARTING and
CPUHP_PERF_X86_PREPARE then the CPU will go back online but never
allocate the memory that was released in x86_pmu_dying_cpu().

Make the memory allocation/free symmetrical in regard to the CPU hotplug
notifier by moving the deallocation to intel_pmu_cpu_dead().

This started in commit:

   a7e3ed1e47 ("perf: Add support for supplementary event registers").

In principle the bug was introduced in v2.6.39 (!), but it will almost
certainly not backport cleanly across the big CPU hotplug rewrite between v4.7-v4.15...

[ bigeasy: Added patch description. ]
[ mingo: Added backporting guidance. ]

Reported-by: He Zhe <zhe.he@windriver.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> # With developer hat on
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> # With maintainer hat on
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: acme@kernel.org
Cc: bp@alien8.de
Cc: hpa@zytor.com
Cc: jolsa@kernel.org
Cc: kan.liang@linux.intel.com
Cc: namhyung@kernel.org
Cc: <stable@vger.kernel.org>
Fixes: a7e3ed1e47 ("perf: Add support for supplementary event registers").
Link: https://lkml.kernel.org/r/20181219165350.6s3jvyxbibpvlhtq@linutronix.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>
[ He Zhe: Fixes conflict caused by missing disable_counter_freeze which is
 introduced since v4.20 af3bdb991a. ]
Signed-off-by: He Zhe <zhe.he@windriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-02-12 19:47:26 +01:00
..
boot x86/efi: Allocate e820 buffer before calling efi_exit_boot_service 2018-12-13 09:16:22 +01:00
configs
crypto crypto: aesni - don't use GFP_ATOMIC allocation if the request doesn't cross a page in gcm 2018-11-13 11:08:45 -08:00
entry x86/entry/64/compat: Fix stack switching for XEN PV 2019-01-31 08:14:39 +01:00
events perf/x86/intel: Delay memory deallocation until x86_pmu_dead_cpu() 2019-02-12 19:47:26 +01:00
hyperv x86/hyper-v: rename ipi_arg_{ex,non_ex} structures 2018-09-20 00:51:42 +02:00
ia32
include x86/fpu: Add might_fault() to user_insn() 2019-02-12 19:47:04 +01:00
kernel x86/MCE: Initialize mce.bank in the case of a fatal error in mce_no_way_out() 2019-02-12 19:47:26 +01:00
kvm cpu/hotplug: Fix "SMT disabled by BIOS" detection for KVM 2019-02-12 19:47:25 +01:00
lib x86/kaslr: Fix incorrect i8254 outb() parameters 2019-01-31 08:14:39 +01:00
math-emu
mm x86/dump_pagetables: Fix LDT remap address marker 2019-01-13 09:50:58 +01:00
net bpf, x32: Fix regression caused by commit 24dea04767 2018-07-26 02:51:12 +02:00
oprofile
pci x86/PCI: Fix Broadcom CNB20LE unintended sign extension (redux) 2019-02-12 19:46:58 +01:00
platform x86/earlyprintk/efi: Fix infinite loop on some screen widths 2018-12-21 14:15:14 +01:00
power Power management updates for 4.19-rc1 2018-08-14 13:12:24 -07:00
purgatory kbuild: move bin2c back to scripts/ from scripts/basic/ 2018-07-18 01:18:05 +09:00
ras
realmode
tools x86/relocs: Add __end_rodata_aligned to S_REL 2018-08-09 20:42:07 +02:00
um um: Drop own definition of PTRACE_SYSEMU/_SINGLESTEP 2018-11-21 09:19:16 +01:00
video
xen xen: Fix x86 sched_clock() interface for xen 2019-01-22 21:40:32 +01:00
.gitignore
Kbuild
Kconfig x86/Kconfig: Select SCHED_SMT if SMP enabled 2018-12-05 19:32:02 +01:00
Kconfig.cpu
Kconfig.debug Kconfig: consolidate the "Kernel hacking" menu 2018-08-02 08:06:48 +09:00
Makefile x86/build: Fix compiler support check for CONFIG_RETPOLINE 2018-12-19 19:19:54 +01:00
Makefile.um kbuild: rename LDFLAGS to KBUILD_LDFLAGS 2018-08-24 08:22:08 +09:00
Makefile_32.cpu