stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Mike Galbraith <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: tglx@linutronix.de, bp@alien8.de, efault@gmx.de,
	rruslich@cisco.com, gregkh@linuxfoundation.org, hpa@zytor.com,
	bigeasy@linutronix.de, stable@vger.kernel.org,
	anna-maria@linutronix.de, linux-kernel@vger.kernel.org,
	akpm@linux-foundation.org, torvalds@linux-foundation.org,
	jslaby@suse.cz, nix.or.die@gmail.com, mingo@kernel.org
Subject: [tip:timers/urgent] tick/broadcast: Prevent deadlock on tick_broadcast_lock
Date: Mon, 13 Feb 2017 00:52:14 -0800	[thread overview]
Message-ID: <tip-202461e2f3c15dbfb05825d29ace0d20cdf55fa4@git.kernel.org> (raw)
In-Reply-To: <1486953115.5912.4.camel@gmx.de>

Commit-ID:  202461e2f3c15dbfb05825d29ace0d20cdf55fa4
Gitweb:     http://git.kernel.org/tip/202461e2f3c15dbfb05825d29ace0d20cdf55fa4
Author:     Mike Galbraith <efault@gmx.de>
AuthorDate: Mon, 13 Feb 2017 03:31:55 +0100
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Mon, 13 Feb 2017 09:49:31 +0100

tick/broadcast: Prevent deadlock on tick_broadcast_lock

tick_broadcast_lock is taken from interrupt context, but the following call
chain takes the lock without disabling interrupts:

[   12.703736]  _raw_spin_lock+0x3b/0x50
[   12.703738]  tick_broadcast_control+0x5a/0x1a0
[   12.703742]  intel_idle_cpu_online+0x22/0x100
[   12.703744]  cpuhp_invoke_callback+0x245/0x9d0
[   12.703752]  cpuhp_thread_fun+0x52/0x110
[   12.703754]  smpboot_thread_fn+0x276/0x320

So the following deadlock can happen:

   lock(tick_broadcast_lock);
   <Interrupt>
      lock(tick_broadcast_lock);

intel_idle_cpu_online() is the only place which violates the calling
convention of tick_broadcast_control(). This was caused by the removal of
the smp function call in course of the cpu hotplug rework.

Instead of slapping local_irq_disable/enable() at the call site, we can
relax the calling convention and handle it in the core code, which makes
the whole machinery more robust.

Fixes: 29d7bbada98e ("intel_idle: Remove superfluous SMP fuction call")
Reported-by: Gabriel C <nix.or.die@gmail.com>
Signed-off-by: Mike Galbraith <efault@gmx.de>
Cc: Ruslan Ruslichenko <rruslich@cisco.com>
Cc: Jiri Slaby <jslaby@suse.cz>
Cc: Greg KH <gregkh@linuxfoundation.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: lwn@lwn.net
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Anna-Maria Gleixner <anna-maria@linutronix.de>
Cc: Sebastian Siewior <bigeasy@linutronix.de>
Cc: stable <stable@vger.kernel.org>
Link: http://lkml.kernel.org/r/1486953115.5912.4.camel@gmx.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

---
 kernel/time/tick-broadcast.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
index 3109204..17ac99b 100644
--- a/kernel/time/tick-broadcast.c
+++ b/kernel/time/tick-broadcast.c
@@ -347,17 +347,16 @@ static void tick_handle_periodic_broadcast(struct clock_event_device *dev)
  *
  * Called when the system enters a state where affected tick devices
  * might stop. Note: TICK_BROADCAST_FORCE cannot be undone.
- *
- * Called with interrupts disabled, so clockevents_lock is not
- * required here because the local clock event device cannot go away
- * under us.
  */
 void tick_broadcast_control(enum tick_broadcast_mode mode)
 {
 	struct clock_event_device *bc, *dev;
 	struct tick_device *td;
 	int cpu, bc_stopped;
+	unsigned long flags;
 
+	/* Protects also the local clockevent device. */
+	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
 	td = this_cpu_ptr(&tick_cpu_device);
 	dev = td->evtdev;
 
@@ -365,12 +364,11 @@ void tick_broadcast_control(enum tick_broadcast_mode mode)
 	 * Is the device not affected by the powerstate ?
 	 */
 	if (!dev || !(dev->features & CLOCK_EVT_FEAT_C3STOP))
-		return;
+		goto out;
 
 	if (!tick_device_is_functional(dev))
-		return;
+		goto out;
 
-	raw_spin_lock(&tick_broadcast_lock);
 	cpu = smp_processor_id();
 	bc = tick_broadcast_device.evtdev;
 	bc_stopped = cpumask_empty(tick_broadcast_mask);
@@ -420,7 +418,8 @@ void tick_broadcast_control(enum tick_broadcast_mode mode)
 				tick_broadcast_setup_oneshot(bc);
 		}
 	}
-	raw_spin_unlock(&tick_broadcast_lock);
+out:
+	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
 EXPORT_SYMBOL_GPL(tick_broadcast_control);
 

  parent reply	other threads:[~2017-02-13  8:53 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-26  7:48 Linux 4.9.6 Greg KH
2017-01-26  7:48 ` Greg KH
2017-02-06 17:30 ` Linux 4.9.6 ( Restore IO-APIC irq_chip retrigger callback , breaks my box ) Gabriel C
2017-02-06 17:41   ` Greg KH
2017-02-06 19:05     ` Ruslan Ruslichenko -X (rruslich - GLOBALLOGIC INC at Cisco)
2017-02-06 20:38       ` Gabriel C
2017-02-06 23:06   ` Linus Torvalds
2017-02-07 20:46     ` Thomas Gleixner
2017-02-07 21:25       ` Thomas Gleixner
2017-02-10 23:17         ` Gabriel C
2017-02-11  1:42           ` Gabriel C
2017-02-11  8:26           ` Thomas Gleixner
2017-02-11 13:09             ` Gabriel C
2017-02-11 14:21               ` Borislav Petkov
2017-02-11 20:58                 ` Gabriel C
2017-02-11 21:32                   ` Borislav Petkov
2017-02-12 20:21                     ` Gabriel C
2017-02-12 21:12                       ` Borislav Petkov
2017-02-12 22:21                         ` Gabriel C
2017-02-13  0:38                           ` Borislav Petkov
2017-02-13  1:26                             ` Gabriel C
2017-02-13  2:31                               ` Mike Galbraith
     [not found]                                 ` <CA+55aFzC33RgUDbb-tn9+ANJtD_R2+FzjJihnT_kGk-h+nTD1Q@mail.gmail.com>
2017-02-13  5:48                                   ` Gabriel C
2017-02-13 14:05                                     ` Thomas Gleixner
2017-02-13 14:16                                       ` Thomas Gleixner
2017-02-13 20:24                                         ` Gabriel C
2017-02-13 18:35                                     ` Linus Torvalds
2017-02-13 19:33                                       ` Thomas Gleixner
2017-02-13 20:12                                         ` Linus Torvalds
2017-02-13 20:18                                           ` Thomas Gleixner
2017-02-13 20:22                                           ` Steven Rostedt
2017-02-13 20:43                                           ` Borislav Petkov
2017-02-13 20:59                                             ` Thomas Gleixner
2017-02-13 21:42                                               ` Gabriel C
2017-02-14  0:04                                                 ` Gabriel C
2017-02-13 21:33                                             ` Linus Torvalds
2017-02-13 21:35                                               ` Thomas Gleixner
2017-02-13 21:42                                                 ` Thomas Gleixner
2017-02-13 21:44                                                 ` Linus Torvalds
2017-02-14  8:15                                                   ` Thomas Gleixner
2017-02-14 14:49                                                     ` Thomas Gleixner
2017-02-14 14:55                                                       ` Greg Kroah-Hartman
2017-02-14 15:11                                                         ` Thomas Gleixner
2017-02-14 16:45                                                       ` Thomas Gleixner
2017-02-15  2:17                                                         ` Gabriel C
2017-02-15  8:46                                                           ` Thomas Gleixner
2017-02-13  8:47                                 ` Thomas Gleixner
2017-02-13  8:52                                 ` tip-bot for Mike Galbraith [this message]
2017-02-13 10:28                               ` Borislav Petkov
2017-02-07 21:24     ` Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-202461e2f3c15dbfb05825d29ace0d20cdf55fa4@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=akpm@linux-foundation.org \
    --cc=anna-maria@linutronix.de \
    --cc=bigeasy@linutronix.de \
    --cc=bp@alien8.de \
    --cc=efault@gmx.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=hpa@zytor.com \
    --cc=jslaby@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=nix.or.die@gmail.com \
    --cc=rruslich@cisco.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).