linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 00/52] CPU hotplug: Fix issues with callback registration
@ 2014-03-10 20:33 Srivatsa S. Bhat
  2014-03-10 20:34 ` [PATCH v3 01/52] CPU hotplug: Add lockdep annotations to get/put_online_cpus() Srivatsa S. Bhat
                   ` (53 more replies)
  0 siblings, 54 replies; 63+ messages in thread
From: Srivatsa S. Bhat @ 2014-03-10 20:33 UTC (permalink / raw)
  To: paulus, oleg, mingo, rjw, rusty, peterz, tglx, akpm
  Cc: linux-arch, ego, walken, linux, linux-pm, linux-kernel,
	linuxppc-dev, srivatsa.bhat, tj, paulmck

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 2 new APIs cpu_notifier_register_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_notifier_register_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_notifier_register_done();


In this patchset, patch 1 adds lockdep annotations to catch the above mentioned
deadlock scenario. Patch 2 introduces the new APIs and infrastructure necessary
for race-free callback registration. The remaining patches perform tree-wide
conversions (to use this model).

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

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


Changes from v2:
* Collected more Acks from subsystem maintainers.
* Updated the xen-balloon patch and got Ack from Boris Ostrovsky.


Gautham R. Shenoy (1):
      CPU hotplug: Add lockdep annotations to get/put_online_cpus()

Srivatsa S. Bhat (51):
      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, therm_throt.c: Remove unused therm_cpu_lock
      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      |   18 +---
 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/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                         |   36 +++++--
 include/linux/cpu.h                           |   47 ++++++++++
 include/linux/perf_event.h                    |   16 +++
 kernel/cpu.c                                  |   38 +++++++-
 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 ++++++++++++-------------
 51 files changed, 550 insertions(+), 226 deletions(-)


Regards,
Srivatsa S. Bhat
IBM Linux Technology Center

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

end of thread, other threads:[~2014-03-18 22:08 UTC | newest]

Thread overview: 63+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-10 20:33 [PATCH v3 00/52] CPU hotplug: Fix issues with callback registration Srivatsa S. Bhat
2014-03-10 20:34 ` [PATCH v3 01/52] CPU hotplug: Add lockdep annotations to get/put_online_cpus() Srivatsa S. Bhat
2014-03-10 20:34 ` [PATCH v3 02/52] CPU hotplug: Provide lockless versions of callback registration functions Srivatsa S. Bhat
2014-03-10 20:34 ` [PATCH v3 03/52] Doc/cpu-hotplug: Specify race-free way to register CPU hotplug callbacks Srivatsa S. Bhat
2014-03-10 20:34 ` [PATCH v3 04/52] CPU hotplug, perf: Fix CPU hotplug callback registration Srivatsa S. Bhat
2014-03-10 20:34 ` [PATCH v3 05/52] ia64, salinfo: Fix " Srivatsa S. Bhat
2014-03-10 20:34 ` [PATCH v3 06/52] ia64, palinfo: Fix CPU " Srivatsa S. Bhat
2014-03-10 20:34 ` [PATCH v3 07/52] ia64, topology: " Srivatsa S. Bhat
2014-03-10 20:35 ` [PATCH v3 08/52] ia64, err-inject: " Srivatsa S. Bhat
2014-03-10 20:35 ` [PATCH v3 09/52] arm, hw-breakpoint: " Srivatsa S. Bhat
2014-03-10 20:35 ` [PATCH v3 10/52] arm, kvm: " Srivatsa S. Bhat
2014-03-12 23:21   ` Christoffer Dall
2014-03-14  5:43     ` Srivatsa S. Bhat
2014-03-14 19:10       ` Christoffer Dall
2014-03-18 10:23         ` [UPDATED PATCH " Srivatsa S. Bhat
2014-03-18 22:08           ` Christoffer Dall
2014-03-10 20:35 ` [PATCH v3 11/52] s390, cacheinfo: " Srivatsa S. Bhat
2014-03-10 20:35 ` [PATCH v3 12/52] s390, smp: " Srivatsa S. Bhat
2014-03-10 20:36 ` [PATCH v3 13/52] sparc, sysfs: " Srivatsa S. Bhat
2014-03-10 20:36 ` [PATCH v3 14/52] powerpc, " Srivatsa S. Bhat
2014-03-10 20:36 ` [PATCH v3 15/52] x86, msr: " Srivatsa S. Bhat
2014-03-10 20:36 ` [PATCH v3 16/52] x86, cpuid: " Srivatsa S. Bhat
2014-03-10 20:36 ` [PATCH v3 17/52] x86, vsyscall: " Srivatsa S. Bhat
2014-03-10 20:36 ` [PATCH v3 18/52] x86, intel, uncore: " Srivatsa S. Bhat
2014-03-10 20:37 ` [PATCH v3 19/52] x86, mce: " Srivatsa S. Bhat
2014-03-10 20:37 ` [PATCH v3 20/52] x86, therm_throt.c: " Srivatsa S. Bhat
2014-03-10 20:37 ` [PATCH v3 21/52] x86, therm_throt.c: Remove unused therm_cpu_lock Srivatsa S. Bhat
2014-03-10 20:37 ` [PATCH v3 22/52] x86, amd, ibs: Fix CPU hotplug callback registration Srivatsa S. Bhat
2014-03-10 20:37 ` [PATCH v3 23/52] x86, intel, cacheinfo: " Srivatsa S. Bhat
2014-03-10 20:38 ` [PATCH v3 24/52] x86, intel, rapl: " Srivatsa S. Bhat
2014-03-10 20:38 ` [PATCH v3 25/52] x86, amd, uncore: " Srivatsa S. Bhat
2014-03-10 20:38 ` [PATCH v3 26/52] x86, hpet: " Srivatsa S. Bhat
2014-03-10 20:38 ` [PATCH v3 27/52] x86, pci, amd-bus: " Srivatsa S. Bhat
2014-03-10 20:38 ` [PATCH v3 28/52] x86, oprofile, nmi: " Srivatsa S. Bhat
2014-03-10 20:39 ` [PATCH v3 29/52] x86, kvm: " Srivatsa S. Bhat
2014-03-10 20:39 ` [PATCH v3 30/52] arm64, hw_breakpoint.c: " Srivatsa S. Bhat
2014-03-10 20:39 ` [PATCH v3 31/52] arm64, debug-monitors: " Srivatsa S. Bhat
2014-03-10 20:39 ` [PATCH v3 32/52] powercap, intel-rapl: " Srivatsa S. Bhat
2014-03-12 22:27   ` Jacob Pan
2014-03-10 20:39 ` [PATCH v3 33/52] scsi, bnx2i: " Srivatsa S. Bhat
2014-03-10 20:39 ` [PATCH v3 34/52] scsi, bnx2fc: " Srivatsa S. Bhat
2014-03-10 20:39 ` [PATCH v3 35/52] scsi, fcoe: " Srivatsa S. Bhat
2014-03-10 20:39 ` [PATCH v3 36/52] zsmalloc: " Srivatsa S. Bhat
2014-03-14  6:41   ` Minchan Kim
2014-03-10 20:40 ` [PATCH v3 37/52] acpi-cpufreq: " Srivatsa S. Bhat
2014-03-10 20:40 ` [PATCH v3 38/52] drivers/base/topology.c: " Srivatsa S. Bhat
2014-03-10 20:40 ` [PATCH v3 39/52] clocksource, dummy-timer: " Srivatsa S. Bhat
2014-03-10 20:40 ` [PATCH v3 40/52] intel-idle: " Srivatsa S. Bhat
2014-03-10 20:40 ` [PATCH v3 41/52] oprofile, nmi-timer: " Srivatsa S. Bhat
2014-03-10 20:40 ` [PATCH v3 42/52] octeon, watchdog: " Srivatsa S. Bhat
2014-03-10 20:40 ` [PATCH v3 43/52] thermal, x86-pkg-temp: " Srivatsa S. Bhat
2014-03-10 20:41 ` [PATCH v3 44/52] hwmon, coretemp: " Srivatsa S. Bhat
2014-03-10 20:41 ` [PATCH v3 45/52] hwmon, via-cputemp: " Srivatsa S. Bhat
2014-03-10 20:41 ` [PATCH v3 46/52] xen, balloon: " Srivatsa S. Bhat
2014-03-10 20:41 ` [PATCH v3 47/52] trace, ring-buffer: " Srivatsa S. Bhat
2014-03-10 20:42 ` [PATCH v3 48/52] profile: " Srivatsa S. Bhat
2014-03-10 20:42 ` [PATCH v3 49/52] mm, vmstat: " Srivatsa S. Bhat
2014-03-10 20:42 ` [PATCH v3 50/52] mm, zswap: " Srivatsa S. Bhat
2014-03-10 20:42 ` [PATCH v3 51/52] net/core/flow.c: " Srivatsa S. Bhat
2014-03-10 20:42 ` [PATCH v3 52/52] net/iucv/iucv.c: " Srivatsa S. Bhat
2014-03-11  0:31 ` [PATCH v3 00/52] CPU hotplug: Fix issues with " Rafael J. Wysocki
2014-03-11 22:07 ` Andrew Morton
2014-03-12 20:48   ` Srivatsa S. Bhat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).