WSL2-Linux-Kernel/arch/x86/oprofile
Srivatsa S. Bhat 76902e3d9c x86, oprofile, nmi: Fix CPU hotplug callback registration
Subsystems that want to register CPU hotplug callbacks, as well as perform
initialization for the CPUs that are already online, often do it as shown
below:

	get_online_cpus();

	for_each_online_cpu(cpu)
		init_cpu(cpu);

	register_cpu_notifier(&foobar_cpu_notifier);

	put_online_cpus();

This is wrong, since it is prone to ABBA deadlocks involving the
cpu_add_remove_lock and the cpu_hotplug.lock (when running concurrently
with CPU hotplug operations).

Instead, the correct and race-free way of performing the callback
registration is:

	cpu_notifier_register_begin();

	for_each_online_cpu(cpu)
		init_cpu(cpu);

	/* Note the use of the double underscored version of the API */
	__register_cpu_notifier(&foobar_cpu_notifier);

	cpu_notifier_register_done();

Fix the oprofile code in x86 by using this latter form of callback
registration. But retain the calls to get/put_online_cpus(), since they are
used in other places as well, to protect the variables 'nmi_enabled' and
'ctr_running'. Strictly speaking, this is not necessary since
cpu_notifier_register_begin/done() provide a stronger synchronization
with CPU hotplug than get/put_online_cpus(). However, let's retain the
calls to get/put_online_cpus() to be consistent with the other call-sites.

By nesting get/put_online_cpus() *inside* cpu_notifier_register_begin/done(),
we avoid the ABBA deadlock possibility mentioned above.

Cc: Robert Richter <rric@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2014-03-20 13:43:43 +01:00
..
Makefile oprofile, x86: Reimplement nmi timer mode using perf event 2011-11-04 16:27:18 +01:00
backtrace.c perf: Fix arch_perf_out_copy_user default 2013-11-06 12:34:25 +01:00
init.c oprofile, x86: Reimplement nmi timer mode using perf event 2011-11-04 16:27:18 +01:00
nmi_int.c x86, oprofile, nmi: Fix CPU hotplug callback registration 2014-03-20 13:43:43 +01:00
op_counter.h oprofile, x86: Allow setting EDGE/INV/CMASK for counter events 2011-03-24 18:45:44 +01:00
op_model_amd.c oprofilefs_create_...() do not need superblock argument 2013-09-03 22:52:48 -04:00
op_model_p4.c
op_model_ppro.c oprofile, x86: Fix overflow and warning (commit 1d12d35) 2011-08-16 23:51:00 +02:00
op_x86_model.h perf, x86: Implement IBS initialization 2011-10-10 06:57:16 +02:00