From: tip-bot for Oleg Nesterov <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: paulmck@linux.vnet.ibm.com, bp@alien8.de, brgerst@gmail.com,
mingo@kernel.org, luto@amacapital.net, hpa@zytor.com,
alexander.shishkin@linux.intel.com, oleg@redhat.com,
akpm@linux-foundation.org, peterz@infradead.org,
linux-kernel@vger.kernel.org, torvalds@linux-foundation.org,
dvlasenk@redhat.com, tglx@linutronix.de
Subject: [tip:perf/urgent] perf: Fix ring_buffer_attach() RCU sync, again
Date: Fri, 19 Jun 2015 10:57:42 -0700 [thread overview]
Message-ID: <tip-2f993cf093643b98477c421fa2b9a98dcc940323@git.kernel.org> (raw)
In-Reply-To: <20150530200425.GA15748@redhat.com>
Commit-ID: 2f993cf093643b98477c421fa2b9a98dcc940323
Gitweb: http://git.kernel.org/tip/2f993cf093643b98477c421fa2b9a98dcc940323
Author: Oleg Nesterov <oleg@redhat.com>
AuthorDate: Sat, 30 May 2015 22:04:25 +0200
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Fri, 19 Jun 2015 09:38:45 +0200
perf: Fix ring_buffer_attach() RCU sync, again
While looking for other users of get_state/cond_sync. I Found
ring_buffer_attach() and it looks obviously buggy?
Don't we need to ensure that we have "synchronize" _between_
list_del() and list_add() ?
IOW. Suppose that ring_buffer_attach() preempts right_after
get_state_synchronize_rcu() and gp completes before spin_lock().
In this case cond_synchronize_rcu() does nothing and we reuse
->rb_entry without waiting for gp in between?
It also moves the ->rcu_pending check under "if (rb)", to make it
more readable imo.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: dave@stgolabs.net
Cc: der.herr@hofr.at
Cc: josh@joshtriplett.org
Cc: tj@kernel.org
Fixes: b69cf53640da ("perf: Fix a race between ring_buffer_detach() and ring_buffer_attach()")
Link: http://lkml.kernel.org/r/20150530200425.GA15748@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
kernel/events/core.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index eddf1ed..0ceb386 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -4331,20 +4331,20 @@ static void ring_buffer_attach(struct perf_event *event,
WARN_ON_ONCE(event->rcu_pending);
old_rb = event->rb;
- event->rcu_batches = get_state_synchronize_rcu();
- event->rcu_pending = 1;
-
spin_lock_irqsave(&old_rb->event_lock, flags);
list_del_rcu(&event->rb_entry);
spin_unlock_irqrestore(&old_rb->event_lock, flags);
- }
- if (event->rcu_pending && rb) {
- cond_synchronize_rcu(event->rcu_batches);
- event->rcu_pending = 0;
+ event->rcu_batches = get_state_synchronize_rcu();
+ event->rcu_pending = 1;
}
if (rb) {
+ if (event->rcu_pending) {
+ cond_synchronize_rcu(event->rcu_batches);
+ event->rcu_pending = 0;
+ }
+
spin_lock_irqsave(&rb->event_lock, flags);
list_add_rcu(&event->rb_entry, &rb->event_list);
spin_unlock_irqrestore(&rb->event_lock, flags);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
Please read the FAQ at http://www.tux.org/lkml/
next prev parent reply other threads:[~2015-06-19 17:59 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-26 11:43 [RFC][PATCH 0/5] Optimize percpu-rwsem Peter Zijlstra
2015-05-26 11:43 ` [RFC][PATCH 1/5] rcu: Create rcu_sync infrastructure Peter Zijlstra
2015-05-30 16:58 ` Paul E. McKenney
2015-05-30 19:16 ` Oleg Nesterov
2015-05-30 19:25 ` Oleg Nesterov
2015-05-31 16:07 ` Paul E. McKenney
2015-05-26 11:43 ` [RFC][PATCH 2/5] rcusync: Introduce struct rcu_sync_ops Peter Zijlstra
2015-05-26 11:43 ` [RFC][PATCH 3/5] rcusync: Add the CONFIG_PROVE_RCU checks Peter Zijlstra
2015-05-26 11:44 ` [RFC][PATCH 4/5] rcusync: Introduce rcu_sync_dtor() Peter Zijlstra
2015-05-26 11:44 ` [RFC][PATCH 5/5] percpu-rwsem: Optimize readers and reduce global impact Peter Zijlstra
2015-05-29 19:45 ` Oleg Nesterov
2015-05-29 20:09 ` Oleg Nesterov
2015-05-29 20:41 ` Linus Torvalds
2015-05-30 20:49 ` Oleg Nesterov
2015-06-16 11:48 ` Peter Zijlstra
2015-05-30 17:18 ` Paul E. McKenney
2015-05-30 20:04 ` ring_buffer_attach && cond_synchronize_rcu (Was: percpu-rwsem: Optimize readers and reduce global impact) Oleg Nesterov
2015-06-16 11:08 ` Peter Zijlstra
2015-06-16 11:16 ` Peter Zijlstra
2015-06-16 19:03 ` Oleg Nesterov
2015-06-19 17:57 ` tip-bot for Oleg Nesterov [this message]
2015-05-26 18:12 ` [RFC][PATCH 0/5] Optimize percpu-rwsem Linus Torvalds
2015-05-26 18:34 ` Peter Zijlstra
2015-05-26 18:35 ` Tejun Heo
2015-05-26 18:42 ` Davidlohr Bueso
2015-05-26 21:57 ` Linus Torvalds
2015-05-27 9:28 ` Nicholas Mc Guire
2015-06-05 1:45 ` Al Viro
2015-06-05 21:08 ` Oleg Nesterov
2015-06-05 22:11 ` Al Viro
2015-06-05 23:36 ` Oleg Nesterov
2015-05-27 6:53 ` Peter Zijlstra
2015-05-26 18:57 ` Oleg Nesterov
2015-05-26 19:13 ` Oleg Nesterov
2015-05-26 19:29 ` Oleg Nesterov
2015-05-26 19:54 ` Davidlohr Bueso
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-2f993cf093643b98477c421fa2b9a98dcc940323@git.kernel.org \
--to=tipbot@zytor.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=bp@alien8.de \
--cc=brgerst@gmail.com \
--cc=dvlasenk@redhat.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.