Skip to content

Commit

Permalink
CPU hotplug, debug: detect imbalance between get_online_cpus() and pu…
Browse files Browse the repository at this point in the history
…t_online_cpus()

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 <srivatsa.bhat@linux.vnet.ibm.com>
Reviewed-by: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Srivatsa S. Bhat authored and torvalds committed Oct 9, 2012
1 parent 7ac57a8 commit 075663d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions kernel/cpu.c
Expand Up @@ -80,6 +80,10 @@ void put_online_cpus(void)
if (cpu_hotplug.active_writer == current) if (cpu_hotplug.active_writer == current)
return; return;
mutex_lock(&cpu_hotplug.lock); mutex_lock(&cpu_hotplug.lock);

if (WARN_ON(!cpu_hotplug.refcount))
cpu_hotplug.refcount++; /* try to fix things up */

if (!--cpu_hotplug.refcount && unlikely(cpu_hotplug.active_writer)) if (!--cpu_hotplug.refcount && unlikely(cpu_hotplug.active_writer))
wake_up_process(cpu_hotplug.active_writer); wake_up_process(cpu_hotplug.active_writer);
mutex_unlock(&cpu_hotplug.lock); mutex_unlock(&cpu_hotplug.lock);
Expand Down

0 comments on commit 075663d

Please sign in to comment.