All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/51] CPU hotplug: Fix issues with callback registration
@ 2014-02-05 22:04 Srivatsa S. Bhat
  2014-02-05 22:04 ` [PATCH 01/51] CPU hotplug: Provide lockless versions of callback registration functions Srivatsa S. Bhat
                   ` (52 more replies)
  0 siblings, 53 replies; 159+ messages in thread
From: Srivatsa S. Bhat @ 2014-02-05 22:04 UTC (permalink / raw)
  To: paulus, oleg, rusty, peterz, tglx, akpm
  Cc: mingo, paulmck, tj, walken, ego, linux, linux-kernel, srivatsa.bhat

Hi,

Many subsystems and drivers have the need to register CPU hotplug callbacks
from their init routines and also perform initialization for the CPUs that are
already online. But unfortunately there is no race-free way to achieve this
today.

For example, consider this piece of code:

	get_online_cpus();

	for_each_online_cpu(cpu)
		init_cpu(cpu);

	register_cpu_notifier(&foobar_cpu_notifier);

	put_online_cpus();

This is not safe because there is a possibility of an ABBA deadlock involving
the cpu_add_remove_lock and the cpu_hotplug.lock.

          CPU 0                                         CPU 1
          -----                                         -----

   Acquire cpu_hotplug.lock
   [via get_online_cpus()]

                                              CPU online/offline operation
                                              takes cpu_add_remove_lock
                                              [via cpu_maps_update_begin()]

   Try to acquire
   cpu_add_remove_lock
   [via register_cpu_notifier()]

                                              CPU online/offline operation
                                              tries to acquire cpu_hotplug.lock
                                              [via cpu_hotplug_begin()]

                            *** DEADLOCK! ***


Other combinations of callback registration also don't work correctly.
Examples:

	register_cpu_notifier(&foobar_cpu_notifier);

	get_online_cpus();

	for_each_online_cpu(cpu)
		init_cpu(cpu);

	put_online_cpus();

This can lead to double initialization if a hotplug operation occurs after
registering the notifier and before invoking get_online_cpus().

On the other hand, the following piece of code can miss hotplug events
altogether:

	get_online_cpus();

	for_each_online_cpu(cpu)
		init_cpu(cpu);

	put_online_cpus();
              ^
              |   Race window; Can miss hotplug events here
              v
	register_cpu_notifier(&foobar_cpu_notifier);


To solve these issues and provide a race-free method to register CPU hotplug
callbacks, this patchset introduces new variants of the callback registration
APIs that don't hold the cpu_add_remove_lock, and exports the
cpu_add_remove_lock via cpu_maps_update_begin/done() for use by various
subsystems. With this in place, the following code snippet will register a
hotplug callback as well as initialize already online CPUs without any race
conditions.

	cpu_maps_update_begin();

	for_each_online_cpu(cpu)
		init_cpu(cpu);

	/* This doesn't take the cpu_add_remove_lock */
	__register_cpu_notifier(&foobar_cpu_notifier);

	cpu_maps_update_done();


This patchset introduces this infrastructure in patch 1, and performs
tree-wide conversions (to use this model) in the remaining patches.

This patchset has been hosted in the below git tree. It applies cleanly on
v3.14-rc1.

git://github.com/srivatsabhat/linux.git cpuhp-registration-fixes-v1


Oleg, I have incorporated your fix for raid5 in this patchset, and modified
the patch a bit to handle the unregister_cpu_notifier() case as well. If you
are fine with that patch (patch 45), can you kindly provide your Signed-off-by
for that? Thank you!


 Oleg Nesterov (1):
      md, raid5: Fix CPU hotplug callback registration

 Srivatsa S. Bhat (50):
      CPU hotplug: Provide lockless versions of callback registration functions
      Doc/cpu-hotplug: Specify race-free way to register CPU hotplug callbacks
      CPU hotplug, perf: Fix CPU hotplug callback registration
      ia64, salinfo: Fix hotplug callback registration
      ia64, palinfo: Fix CPU hotplug callback registration
      ia64, topology: Fix CPU hotplug callback registration
      ia64, err-inject: Fix CPU hotplug callback registration
      arm, hw-breakpoint: Fix CPU hotplug callback registration
      arm, kvm: Fix CPU hotplug callback registration
      s390, cacheinfo: Fix CPU hotplug callback registration
      s390, smp: Fix CPU hotplug callback registration
      sparc, sysfs: Fix CPU hotplug callback registration
      powerpc, sysfs: Fix CPU hotplug callback registration
      x86, msr: Fix CPU hotplug callback registration
      x86, cpuid: Fix CPU hotplug callback registration
      x86, vsyscall: Fix CPU hotplug callback registration
      x86, intel, uncore: Fix CPU hotplug callback registration
      x86, mce: Fix CPU hotplug callback registration
      x86, therm_throt.c: Fix CPU hotplug callback registration
      x86, amd, ibs: Fix CPU hotplug callback registration
      x86, intel, cacheinfo: Fix CPU hotplug callback registration
      x86, intel, rapl: Fix CPU hotplug callback registration
      x86, amd, uncore: Fix CPU hotplug callback registration
      x86, hpet: Fix CPU hotplug callback registration
      x86, pci, amd-bus: Fix CPU hotplug callback registration
      x86, oprofile, nmi: Fix CPU hotplug callback registration
      x86, kvm: Fix CPU hotplug callback registration
      arm64, hw_breakpoint.c: Fix CPU hotplug callback registration
      arm64, debug-monitors: Fix CPU hotplug callback registration
      powercap, intel-rapl: Fix CPU hotplug callback registration
      scsi, bnx2i: Fix CPU hotplug callback registration
      scsi, bnx2fc: Fix CPU hotplug callback registration
      scsi, fcoe: Fix CPU hotplug callback registration
      zsmalloc: Fix CPU hotplug callback registration
      acpi-cpufreq: Fix CPU hotplug callback registration
      drivers/base/topology.c: Fix CPU hotplug callback registration
      clocksource, dummy-timer: Fix CPU hotplug callback registration
      intel-idle: Fix CPU hotplug callback registration
      oprofile, nmi-timer: Fix CPU hotplug callback registration
      octeon, watchdog: Fix CPU hotplug callback registration
      thermal, x86-pkg-temp: Fix CPU hotplug callback registration
      hwmon, coretemp: Fix CPU hotplug callback registration
      hwmon, via-cputemp: Fix CPU hotplug callback registration
      xen, balloon: Fix CPU hotplug callback registration
      trace, ring-buffer: Fix CPU hotplug callback registration
      profile: Fix CPU hotplug callback registration
      mm, vmstat: Fix CPU hotplug callback registration
      mm, zswap: Fix CPU hotplug callback registration
      net/core/flow.c: Fix CPU hotplug callback registration
      net/iucv/iucv.c: Fix CPU hotplug callback registration

 Documentation/cpu-hotplug.txt                 |   45 +++++++++
 arch/arm/kernel/hw_breakpoint.c               |    8 +-
 arch/arm/kvm/arm.c                            |    7 +
 arch/arm64/kernel/debug-monitors.c            |    6 +
 arch/arm64/kernel/hw_breakpoint.c             |    7 +
 arch/ia64/kernel/err_inject.c                 |   15 +++
 arch/ia64/kernel/palinfo.c                    |    6 +
 arch/ia64/kernel/salinfo.c                    |    6 +
 arch/ia64/kernel/topology.c                   |    6 +
 arch/powerpc/kernel/sysfs.c                   |    8 +-
 arch/s390/kernel/cache.c                      |    5 +
 arch/s390/kernel/smp.c                        |   13 ++-
 arch/sparc/kernel/sysfs.c                     |    6 +
 arch/x86/kernel/cpu/intel_cacheinfo.c         |   13 ++-
 arch/x86/kernel/cpu/mcheck/mce.c              |    8 +-
 arch/x86/kernel/cpu/mcheck/therm_throt.c      |    5 +
 arch/x86/kernel/cpu/perf_event_amd_ibs.c      |    6 +
 arch/x86/kernel/cpu/perf_event_amd_uncore.c   |    7 +
 arch/x86/kernel/cpu/perf_event_intel_rapl.c   |    9 +-
 arch/x86/kernel/cpu/perf_event_intel_uncore.c |    6 +
 arch/x86/kernel/cpuid.c                       |   15 ++-
 arch/x86/kernel/hpet.c                        |    4 +
 arch/x86/kernel/msr.c                         |   16 ++-
 arch/x86/kernel/vsyscall_64.c                 |    6 +
 arch/x86/kvm/x86.c                            |    7 +
 arch/x86/oprofile/nmi_int.c                   |   15 +++
 arch/x86/pci/amd_bus.c                        |    5 +
 drivers/base/topology.c                       |   12 ++
 drivers/clocksource/dummy_timer.c             |   11 ++
 drivers/cpufreq/acpi-cpufreq.c                |    7 +
 drivers/hwmon/coretemp.c                      |   14 +--
 drivers/hwmon/via-cputemp.c                   |   14 +--
 drivers/idle/intel_idle.c                     |   12 ++
 drivers/md/raid5.c                            |   90 +++++++++----------
 drivers/oprofile/nmi_timer_int.c              |   23 +++--
 drivers/powercap/intel_rapl.c                 |   10 ++
 drivers/scsi/bnx2fc/bnx2fc_fcoe.c             |   12 ++
 drivers/scsi/bnx2i/bnx2i_init.c               |   12 ++
 drivers/scsi/fcoe/fcoe.c                      |   15 +++
 drivers/thermal/x86_pkg_temp_thermal.c        |   14 +--
 drivers/watchdog/octeon-wdt-main.c            |   11 ++
 drivers/xen/balloon.c                         |   35 +++++--
 include/linux/cpu.h                           |   36 +++++++
 include/linux/perf_event.h                    |   16 +++
 kernel/cpu.c                                  |   20 ++++
 kernel/profile.c                              |   20 +++-
 kernel/trace/ring_buffer.c                    |   19 ++--
 mm/vmstat.c                                   |    6 +
 mm/zsmalloc.c                                 |   17 +++-
 mm/zswap.c                                    |    8 +-
 net/core/flow.c                               |    8 +-
 net/iucv/iucv.c                               |  121 ++++++++++++-------------
 52 files changed, 564 insertions(+), 259 deletions(-)


Regards,
Srivatsa S. Bhat
IBM Linux Technology Center


^ permalink raw reply	[flat|nested] 159+ messages in thread

end of thread, other threads:[~2014-02-14  6:47 UTC | newest]

Thread overview: 159+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-05 22:04 [PATCH 00/51] CPU hotplug: Fix issues with callback registration Srivatsa S. Bhat
2014-02-05 22:04 ` [PATCH 01/51] CPU hotplug: Provide lockless versions of callback registration functions Srivatsa S. Bhat
2014-02-06 18:41   ` Oleg Nesterov
2014-02-07 19:11     ` Gautham R Shenoy
2014-02-10  9:15       ` Srivatsa S. Bhat
2014-02-10 10:51         ` Gautham R Shenoy
2014-02-10 11:11           ` Srivatsa S. Bhat
2014-02-10 12:05             ` Gautham R Shenoy
2014-02-10 13:28               ` Srivatsa S. Bhat
2014-02-10 13:30           ` Srivatsa S. Bhat
2014-02-10 15:30           ` Oleg Nesterov
2014-02-10 17:27           ` Balbir Singh
2014-02-11  1:26   ` Toshi Kani
2014-02-11  9:27     ` Srivatsa S. Bhat
2014-02-11 16:33       ` Toshi Kani
2014-02-11 17:18         ` Gautham R Shenoy
2014-02-11 17:35           ` Toshi Kani
2014-02-11 19:20             ` Srivatsa S. Bhat
2014-02-11 20:51               ` Toshi Kani
2014-02-12  6:18                 ` Srivatsa S. Bhat
2014-02-13 10:56                   ` Srivatsa S. Bhat
2014-02-13 20:53                     ` Toshi Kani
2014-02-11 17:15       ` Oleg Nesterov
2014-02-11 19:08         ` Srivatsa S. Bhat
2014-02-13 17:44           ` Oleg Nesterov
2014-02-13 17:54             ` Srivatsa S. Bhat
2014-02-13 11:06     ` Gautham R Shenoy
2014-02-05 22:04 ` [PATCH 02/51] Doc/cpu-hotplug: Specify race-free way to register CPU hotplug callbacks Srivatsa S. Bhat
2014-02-05 22:05 ` [PATCH 03/51] CPU hotplug, perf: Fix CPU hotplug callback registration Srivatsa S. Bhat
2014-02-05 22:05 ` [PATCH 04/51] ia64, salinfo: Fix " Srivatsa S. Bhat
2014-02-05 22:17   ` Srivatsa S. Bhat
2014-02-05 22:05 ` [PATCH 05/51] ia64, palinfo: Fix CPU " Srivatsa S. Bhat
2014-02-05 22:17   ` Srivatsa S. Bhat
2014-02-05 22:05 ` [PATCH 06/51] ia64, topology: " Srivatsa S. Bhat
2014-02-05 22:17   ` Srivatsa S. Bhat
2014-02-05 22:05 ` [PATCH 07/51] ia64, err-inject: " Srivatsa S. Bhat
2014-02-05 22:17   ` Srivatsa S. Bhat
2014-02-05 22:06 ` [PATCH 08/51] arm, hw-breakpoint: " Srivatsa S. Bhat
2014-02-05 22:06   ` Srivatsa S. Bhat
2014-02-06 10:57   ` Will Deacon
2014-02-06 10:57     ` Will Deacon
2014-02-06 11:25     ` Srivatsa S. Bhat
2014-02-06 11:25       ` Srivatsa S. Bhat
2014-02-06 11:39       ` Will Deacon
2014-02-06 11:39         ` Will Deacon
2014-02-06 11:38         ` Srivatsa S. Bhat
2014-02-06 11:38           ` Srivatsa S. Bhat
2014-02-05 22:06 ` [PATCH 09/51] arm, kvm: " Srivatsa S. Bhat
2014-02-05 22:06   ` Srivatsa S. Bhat
2014-02-05 22:06 ` [PATCH 10/51] s390, cacheinfo: " Srivatsa S. Bhat
2014-02-05 22:06   ` Srivatsa S. Bhat
2014-02-05 22:06 ` [PATCH 11/51] s390, smp: " Srivatsa S. Bhat
2014-02-05 22:06   ` Srivatsa S. Bhat
2014-02-05 22:06 ` [PATCH 12/51] sparc, sysfs: " Srivatsa S. Bhat
2014-02-05 22:18   ` Srivatsa S. Bhat
2014-02-05 22:06 ` [PATCH 13/51] powerpc, " Srivatsa S. Bhat
2014-02-05 22:06   ` Srivatsa S. Bhat
2014-02-14  6:47   ` Madhavan Srinivasan
2014-02-14  6:47     ` Madhavan Srinivasan
2014-02-05 22:07 ` [PATCH 14/51] x86, msr: " Srivatsa S. Bhat
2014-02-05 22:07 ` [PATCH 15/51] x86, cpuid: " Srivatsa S. Bhat
2014-02-05 22:07 ` [PATCH 16/51] x86, vsyscall: " Srivatsa S. Bhat
2014-02-10 18:50   ` Gautham R Shenoy
2014-02-11  6:58     ` Srivatsa S. Bhat
2014-02-05 22:07 ` [PATCH 17/51] x86, intel, uncore: " Srivatsa S. Bhat
2014-02-05 22:07 ` [PATCH 18/51] x86, mce: " Srivatsa S. Bhat
2014-02-05 22:08 ` [PATCH 19/51] x86, therm_throt.c: " Srivatsa S. Bhat
2014-02-10 15:53   ` Oleg Nesterov
2014-02-10 17:29     ` Srivatsa S. Bhat
2014-02-10 18:04       ` Srivatsa S. Bhat
2014-02-05 22:08 ` [PATCH 20/51] x86, amd, ibs: " Srivatsa S. Bhat
2014-02-05 22:08 ` [PATCH 21/51] x86, intel, cacheinfo: " Srivatsa S. Bhat
2014-02-05 22:08 ` [PATCH 22/51] x86, intel, rapl: " Srivatsa S. Bhat
2014-02-05 22:08 ` [PATCH 23/51] x86, amd, uncore: " Srivatsa S. Bhat
2014-02-05 22:09 ` [PATCH 24/51] x86, hpet: " Srivatsa S. Bhat
2014-02-10 18:58   ` Gautham R Shenoy
2014-02-11  6:59     ` Srivatsa S. Bhat
2014-02-05 22:09 ` [PATCH 25/51] x86, pci, amd-bus: " Srivatsa S. Bhat
2014-02-05 22:09 ` [PATCH 26/51] x86, oprofile, nmi: " Srivatsa S. Bhat
2014-02-10 19:07   ` Gautham R Shenoy
2014-02-10 19:27     ` Gautham R Shenoy
2014-02-11  7:01       ` Srivatsa S. Bhat
2014-02-05 22:09 ` [PATCH 27/51] x86, kvm: " Srivatsa S. Bhat
2014-02-05 22:09 ` [PATCH 28/51] arm64, hw_breakpoint.c: " Srivatsa S. Bhat
2014-02-05 22:09   ` Srivatsa S. Bhat
2014-02-06 11:41   ` Will Deacon
2014-02-06 11:41     ` Will Deacon
2014-02-05 22:09 ` [PATCH 29/51] arm64, debug-monitors: " Srivatsa S. Bhat
2014-02-05 22:09   ` Srivatsa S. Bhat
2014-02-06 11:41   ` Will Deacon
2014-02-06 11:41     ` Will Deacon
2014-02-05 22:10 ` [PATCH 30/51] powercap, intel-rapl: " Srivatsa S. Bhat
2014-02-05 22:10 ` [PATCH 31/51] scsi, bnx2i: " Srivatsa S. Bhat
2014-02-05 22:10   ` Srivatsa S. Bhat
2014-02-05 22:10 ` [PATCH 32/51] scsi, bnx2fc: " Srivatsa S. Bhat
2014-02-05 22:10   ` Srivatsa S. Bhat
2014-02-05 22:10 ` [PATCH 33/51] scsi, fcoe: " Srivatsa S. Bhat
2014-02-05 22:10   ` Srivatsa S. Bhat
2014-02-05 22:10 ` [PATCH 34/51] zsmalloc: " Srivatsa S. Bhat
2014-02-05 22:10   ` Srivatsa S. Bhat
2014-02-05 22:10 ` [PATCH 35/51] acpi-cpufreq: " Srivatsa S. Bhat
2014-02-05 22:10   ` Srivatsa S. Bhat
2014-02-06 12:43   ` Rafael J. Wysocki
2014-02-06 16:05     ` Srivatsa S. Bhat
2014-02-07  4:09   ` Viresh Kumar
2014-02-05 22:11 ` [PATCH 36/51] drivers/base/topology.c: " Srivatsa S. Bhat
2014-02-05 22:11 ` [PATCH 37/51] clocksource, dummy-timer: " Srivatsa S. Bhat
2014-02-05 22:11 ` [PATCH 38/51] intel-idle: " Srivatsa S. Bhat
2014-02-05 22:11   ` Srivatsa S. Bhat
2014-02-06 12:43   ` Rafael J. Wysocki
2014-02-06 16:04     ` Srivatsa S. Bhat
2014-02-05 22:11 ` [PATCH 39/51] oprofile, nmi-timer: " Srivatsa S. Bhat
2014-02-05 22:11 ` [PATCH 40/51] octeon, watchdog: " Srivatsa S. Bhat
2014-02-05 22:11 ` [PATCH 41/51] thermal, x86-pkg-temp: " Srivatsa S. Bhat
2014-02-05 22:11   ` Srivatsa S. Bhat
2014-02-05 22:12 ` [PATCH 42/51] hwmon, coretemp: " Srivatsa S. Bhat
2014-02-05 22:24   ` [lm-sensors] " Srivatsa S. Bhat
2014-02-06  0:44   ` Guenter Roeck
2014-02-06  0:44     ` [lm-sensors] " Guenter Roeck
2014-02-06  1:25     ` Guenter Roeck
2014-02-06  1:25       ` [lm-sensors] " Guenter Roeck
2014-02-06 10:03       ` Srivatsa S. Bhat
2014-02-06 10:15         ` [lm-sensors] " Srivatsa S. Bhat
2014-02-05 22:12 ` [PATCH 43/51] hwmon, via-cputemp: " Srivatsa S. Bhat
2014-02-05 22:24   ` [lm-sensors] " Srivatsa S. Bhat
2014-02-06  0:44   ` Guenter Roeck
2014-02-06  0:44     ` [lm-sensors] " Guenter Roeck
2014-02-06  1:26     ` Guenter Roeck
2014-02-06  1:26       ` [lm-sensors] " Guenter Roeck
2014-02-05 22:12 ` [PATCH 44/51] xen, balloon: " Srivatsa S. Bhat
2014-02-05 22:12 ` Srivatsa S. Bhat
2014-02-05 22:12 ` [PATCH 45/51] md, raid5: " Srivatsa S. Bhat
2014-02-05 22:12   ` Srivatsa S. Bhat
2014-02-06  1:11   ` NeilBrown
2014-02-06 10:05     ` Srivatsa S. Bhat
2014-02-06 18:43       ` Oleg Nesterov
2014-02-05 22:12 ` [PATCH 46/51] trace, ring-buffer: " Srivatsa S. Bhat
2014-02-05 23:41   ` Steven Rostedt
2014-02-05 22:13 ` [PATCH 47/51] profile: " Srivatsa S. Bhat
2014-02-05 22:13 ` [PATCH 48/51] mm, vmstat: " Srivatsa S. Bhat
2014-02-05 22:13   ` Srivatsa S. Bhat
2014-02-06 15:35   ` Christoph Lameter
2014-02-06 15:35     ` Christoph Lameter
2014-02-07  2:52   ` Yasuaki Ishimatsu
2014-02-07  2:52     ` Yasuaki Ishimatsu
2014-02-05 22:13 ` [PATCH 49/51] mm, zswap: " Srivatsa S. Bhat
2014-02-05 22:13   ` Srivatsa S. Bhat
2014-02-05 22:13 ` [PATCH 50/51] net/core/flow.c: " Srivatsa S. Bhat
2014-02-07  4:39   ` David Miller
2014-02-07  5:19     ` David Miller
2014-02-05 22:13 ` [PATCH 51/51] net/iucv/iucv.c: " Srivatsa S. Bhat
2014-02-05 22:13   ` Srivatsa S. Bhat
2014-02-07  4:39   ` David Miller
2014-02-07  5:19     ` David Miller
2014-02-06  9:38 ` [PATCH 00/51] CPU hotplug: Fix issues with " Gautham R Shenoy
2014-02-06 11:04   ` Srivatsa S. Bhat
2014-02-06 11:08     ` Srivatsa S. Bhat
2014-02-06 12:14     ` Gautham R Shenoy
2014-02-06 16:09       ` Srivatsa S. Bhat

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.