Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ia64, palinfo: 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 palinfo code in ia64 by using this latter form of callback
registration.

Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Srivatsa S. Bhat and committed by
Rafael J. Wysocki
9f37bca9 eff722b0

+5 -1
+5 -1
arch/ia64/kernel/palinfo.c
··· 996 996 if (!palinfo_dir) 997 997 return -ENOMEM; 998 998 999 + cpu_notifier_register_begin(); 1000 + 999 1001 /* Create palinfo dirs in /proc for all online cpus */ 1000 1002 for_each_online_cpu(i) { 1001 1003 create_palinfo_proc_entries(i); 1002 1004 } 1003 1005 1004 1006 /* Register for future delivery via notify registration */ 1005 - register_hotcpu_notifier(&palinfo_cpu_notifier); 1007 + __register_hotcpu_notifier(&palinfo_cpu_notifier); 1008 + 1009 + cpu_notifier_register_done(); 1006 1010 1007 1011 return 0; 1008 1012 }