From: Frederic Weisbecker <fweisbec@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Andrew Morton <akpm@linux-foundation.org>,
Steven Rostedt <rostedt@goodmis.org>,
Paul Gortmaker <paul.gortmaker@windriver.com>
Subject: [RFC PATCH 1/9] irq_work: Fix racy check on work pending flag
Date: Mon, 29 Oct 2012 14:28:08 +0100 [thread overview]
Message-ID: <1351517296-9173-2-git-send-email-fweisbec@gmail.com> (raw)
In-Reply-To: <1351517296-9173-1-git-send-email-fweisbec@gmail.com>
Context requirements on irq work claim are not entirely
clear. But it appears that we can try to claim a work that
may be already claimed by another CPU.
If so then the early check on IRQ_WORK_PENDING in
irq_work_claim() is racy because another CPU may be
changing the flags concurrently and we have nothing
to synchronize against that. So the value we deal with
may be stale for a while already.
To fix this, start with our best wish as the initial
value for the work flags and feed cmpxchg with it. But
only do the check against IRQ_WORK_PENDING flag with the
cmpxchg result.
Nonetheless, if the work is not pending but our best wish
was wrong, restart with the old value returned by cmpxchg.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Paul Gortmaker <paul.gortmaker@windriver.com>
---
kernel/irq_work.c | 17 ++++++++++++-----
1 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/kernel/irq_work.c b/kernel/irq_work.c
index 1588e3b..679c13e 100644
--- a/kernel/irq_work.c
+++ b/kernel/irq_work.c
@@ -34,15 +34,22 @@ static DEFINE_PER_CPU(struct llist_head, irq_work_list);
*/
static bool irq_work_claim(struct irq_work *work)
{
- unsigned long flags, nflags;
+ unsigned long flags, oflags, nflags;
+ /*
+ * Can't check IRQ_WORK_PENDING bit right now because the work
+ * can be running on another CPU and we are not sync with its
+ * changes to work flags. Only cmpxchg can reliably check for us.
+ */
+ flags = work->flags & ~IRQ_WORK_PENDING;
for (;;) {
- flags = work->flags;
- if (flags & IRQ_WORK_PENDING)
- return false;
nflags = flags | IRQ_WORK_FLAGS;
- if (cmpxchg(&work->flags, flags, nflags) == flags)
+ oflags = cmpxchg(&work->flags, flags, nflags);
+ if (oflags == flags)
break;
+ if (oflags & IRQ_WORK_PENDING)
+ return false;
+ flags = oflags;
cpu_relax();
}
--
1.7.5.4
next prev parent reply other threads:[~2012-10-29 13:28 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-29 13:28 [RFC PATCH 0/9] printk: Make it usable on nohz CPUs v3 Frederic Weisbecker
2012-10-29 13:28 ` Frederic Weisbecker [this message]
2012-10-29 13:47 ` [RFC PATCH 1/9] irq_work: Fix racy check on work pending flag Steven Rostedt
2012-10-29 19:18 ` Frederic Weisbecker
2012-10-29 13:28 ` [RFC PATCH 2/9] irq_work: Remove CONFIG_HAVE_IRQ_WORK Frederic Weisbecker
2012-10-29 13:28 ` [RFC PATCH 3/9] irq_work: Move irq_work_raise() declaration/default definition to arch headers Frederic Weisbecker
2012-10-29 13:52 ` Steven Rostedt
2012-10-29 18:37 ` Frederic Weisbecker
2012-10-29 13:28 ` [RFC PATCH 4/9] irq_work: Let the arch tell us about self-IPI support Frederic Weisbecker
2012-10-29 13:56 ` Steven Rostedt
2012-10-29 20:58 ` Frederic Weisbecker
2012-10-29 13:28 ` [RFC PATCH 5/9] x86: Implement arch_irq_work_has_ipi() Frederic Weisbecker
2012-10-29 13:28 ` [RFC PATCH 6/9] nohz: Add API to check tick state Frederic Weisbecker
2012-10-29 13:28 ` [RFC PATCH 7/9] irq_work: Make self-IPIs optable Frederic Weisbecker
2012-10-29 14:28 ` Steven Rostedt
2012-11-06 14:24 ` Frederic Weisbecker
2012-10-29 13:28 ` [RFC PATCH 8/9] irq_work: Handle queuing without IPI support in dyntick idle mode Frederic Weisbecker
2012-10-29 13:28 ` [RFC PATCH 9/9] printk: Wake up klogd using irq_work Frederic Weisbecker
2012-10-29 14:37 ` Steven Rostedt
2012-10-29 21:04 ` Frederic Weisbecker
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=1351517296-9173-2-git-send-email-fweisbec@gmail.com \
--to=fweisbec@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=paul.gortmaker@windriver.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.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
Powered by JetHome