From: tip-bot for Salman Qazi <sqazi@google.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@redhat.com,
peterz@infradead.org, sqazi@google.com, tglx@linutronix.de
Subject: [tip:timers/urgent] hrtimer: Preserve timer state in remove_hrtimer()
Date: Thu, 14 Oct 2010 11:34:31 GMT [thread overview]
Message-ID: <tip-f13d4f979c518119bba5439dd2364d76d31dcd3f@git.kernel.org> (raw)
In-Reply-To: <20101012142351.8485.21823.stgit@dungbeetle.mtv.corp.google.com>
Commit-ID: f13d4f979c518119bba5439dd2364d76d31dcd3f
Gitweb: http://git.kernel.org/tip/f13d4f979c518119bba5439dd2364d76d31dcd3f
Author: Salman Qazi <sqazi@google.com>
AuthorDate: Tue, 12 Oct 2010 07:25:19 -0700
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Thu, 14 Oct 2010 13:29:59 +0200
hrtimer: Preserve timer state in remove_hrtimer()
The race is described as follows:
CPU X CPU Y
remove_hrtimer
// state & QUEUED == 0
timer->state = CALLBACK
unlock timer base
timer->f(n) //very long
hrtimer_start
lock timer base
remove_hrtimer // no effect
hrtimer_enqueue
timer->state = CALLBACK |
QUEUED
unlock timer base
hrtimer_start
lock timer base
remove_hrtimer
mode = INACTIVE
// CALLBACK bit lost!
switch_hrtimer_base
CALLBACK bit not set:
timer->base
changes to a
different CPU.
lock this CPU's timer base
The bug was introduced with commit ca109491f (hrtimer: removing all ur
callback modes) in 2.6.29
[ tglx: Feed new state via local variable and add a comment. ]
Signed-off-by: Salman Qazi <sqazi@google.com>
Cc: akpm@linux-foundation.org
Cc: Peter Zijlstra <peterz@infradead.org>
LKML-Reference: <20101012142351.8485.21823.stgit@dungbeetle.mtv.corp.google.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@kernel.org
---
kernel/hrtimer.c | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
index 1decafb..72206cf 100644
--- a/kernel/hrtimer.c
+++ b/kernel/hrtimer.c
@@ -931,6 +931,7 @@ static inline int
remove_hrtimer(struct hrtimer *timer, struct hrtimer_clock_base *base)
{
if (hrtimer_is_queued(timer)) {
+ unsigned long state;
int reprogram;
/*
@@ -944,8 +945,13 @@ remove_hrtimer(struct hrtimer *timer, struct hrtimer_clock_base *base)
debug_deactivate(timer);
timer_stats_hrtimer_clear_start_info(timer);
reprogram = base->cpu_base == &__get_cpu_var(hrtimer_bases);
- __remove_hrtimer(timer, base, HRTIMER_STATE_INACTIVE,
- reprogram);
+ /*
+ * We must preserve the CALLBACK state flag here,
+ * otherwise we could move the timer base in
+ * switch_hrtimer_base.
+ */
+ state = timer->state & HRTIMER_STATE_CALLBACK;
+ __remove_hrtimer(timer, base, state, reprogram);
return 1;
}
return 0;
@@ -1231,6 +1237,9 @@ static void __run_hrtimer(struct hrtimer *timer, ktime_t *now)
BUG_ON(timer->state != HRTIMER_STATE_CALLBACK);
enqueue_hrtimer(timer, base);
}
+
+ WARN_ON_ONCE(!(timer->state & HRTIMER_STATE_CALLBACK));
+
timer->state &= ~HRTIMER_STATE_CALLBACK;
}
next prev parent reply other threads:[~2010-10-14 11:35 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-08 2:33 [PATCH] Fix a complex race in hrtimer code Salman Qazi
2010-10-08 18:01 ` Salman Qazi
2010-10-11 22:43 ` Andrew Morton
2010-10-11 23:18 ` Salman Qazi
2010-10-11 23:23 ` Andrew Morton
2010-10-11 23:43 ` Salman Qazi
2010-10-12 0:02 ` Salman Qazi
2010-10-12 8:49 ` Thomas Gleixner
2010-10-12 14:25 ` Salman Qazi
2010-10-14 11:34 ` tip-bot for Salman Qazi [this message]
2010-10-14 13:23 ` [tip:timers/urgent] hrtimer: Preserve timer state in remove_hrtimer() Peter Zijlstra
2010-10-14 13:34 ` Thomas Gleixner
2010-10-12 14:28 ` [PATCH] Fix a complex race in hrtimer code Salman Qazi
2010-10-12 16:54 ` Thomas Gleixner
2010-10-12 17:38 ` Salman Qazi
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-f13d4f979c518119bba5439dd2364d76d31dcd3f@git.kernel.org \
--to=sqazi@google.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/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
all inboxes | Powered by JetHome®