Skip to content
Browse files

CPU hotplug, debug: detect imbalance between get_online_cpus() and pu…


The synchronization between CPU hotplug readers and writers is achieved
by means of refcounting, safeguarded by the cpu_hotplug.lock.

get_online_cpus() increments the refcount, whereas put_online_cpus()
decrements it.  If we ever hit an imbalance between the two, we end up
compromising the guarantees of the hotplug synchronization i.e, for
example, an extra call to put_online_cpus() can end up allowing a
hotplug reader to execute concurrently with a hotplug writer.

So, add a WARN_ON() in put_online_cpus() to detect such cases where the
refcount can go negative, and also attempt to fix it up, so that we can
continue to run.

Signed-off-by: Srivatsa S. Bhat <>
Reviewed-by: Yasuaki Ishimatsu <>
Cc: Jiri Kosina <>
Cc: Thomas Gleixner <>
Cc: Ingo Molnar <>
Cc: Peter Zijlstra <>
Signed-off-by: Andrew Morton <>
Signed-off-by: Linus Torvalds <>
  • Loading branch information...
1 parent 7ac57a8 commit 075663d19885eb3738fd2d7dbdb8947e12563b68 Srivatsa S. Bhat committed with Oct 8, 2012
Showing with 4 additions and 0 deletions.
  1. +4 −0 kernel/cpu.c
4 kernel/cpu.c
@@ -80,6 +80,10 @@ void put_online_cpus(void)
if (cpu_hotplug.active_writer == current)
+ if (WARN_ON(!cpu_hotplug.refcount))
+ cpu_hotplug.refcount++; /* try to fix things up */
if (!--cpu_hotplug.refcount && unlikely(cpu_hotplug.active_writer))

0 comments on commit 075663d

Please sign in to comment.
Something went wrong with that request. Please try again.