[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.DEB.2.11.1511042025160.4032@nanos>
Date: Wed, 4 Nov 2015 20:35:00 +0100 (CET)
From: Thomas Gleixner <tglx@...utronix.de>
To: Tejun Heo <tj@...nel.org>
cc: Chris Worley <chris.worley@...marydata.com>,
linux-kernel@...r.kernel.org, bfields@...ldses.org,
Michael Skralivetsky <michael.skralivetsky@...marydata.com>,
Trond Myklebust <trond.myklebust@...marydata.com>,
Shaohua Li <shli@...com>,
Jeff Layton <jlayton@...chiereds.net>, kernel-team@...com
Subject: Re: [PATCH] timer: add_timer_on() should perform proper migration
Tejun,
On Wed, 4 Nov 2015, Tejun Heo wrote:
> Regardless of the previous CPU a timer was on, add_timer_on()
> currently simply sets timer->flags to the new CPU. As the caller must
> be seeing the timer as idle, this is locally fine, but the timer
> leaving the old base while unlocked can lead to race conditions as
> follows.
nice detective work. This has been there forever. I really wonder why
nobody ever triggered this before.
@stable:
The patch does only apply to kernels >= 4.2. Backport for older
kernels is below.
Thanks,
tglx
----------->
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -966,13 +966,26 @@ EXPORT_SYMBOL(add_timer);
*/
void add_timer_on(struct timer_list *timer, int cpu)
{
- struct tvec_base *base = per_cpu(tvec_bases, cpu);
+ struct tvec_base *new_base = per_cpu(tvec_bases, cpu);
+ struct tvec_base *base;
unsigned long flags;
timer_stats_timer_set_start_info(timer);
BUG_ON(timer_pending(timer) || !timer->function);
- spin_lock_irqsave(&base->lock, flags);
- timer_set_base(timer, base);
+
+ /*
+ * If @timer was on a different CPU, it should be migrated with the
+ * old base locked to prevent other operations proceeding with the
+ * wrong base locked. See lock_timer_base().
+ */
+ base = lock_timer_base(timer, &flags);
+ if (base != new_base) {
+ timer_set_base(timer, NULL);
+ spin_unlock(&base->lock);
+ base = new_base;
+ spin_lock(&base->lock);
+ timer_set_base(timer, base);
+ }
debug_activate(timer, timer->expires);
internal_add_timer(base, timer);
spin_unlock_irqrestore(&base->lock, flags);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists