Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1166321
| Path | csiph.com!aioe.org!bofh.it!news.nic.it!robomod |
|---|---|
| From | Oleg Nesterov <oleg@redhat.com> |
| Newsgroups | linux.kernel |
| Subject | Re: ring_buffer_attach && cond_synchronize_rcu (Was: percpu-rwsem: Optimize readers and reduce global impact) |
| Date | Tue, 16 Jun 2015 21:10:02 +0200 |
| Message-ID | <pC4pc-32i-15@gated-at.bofh.it> (permalink) |
| References | <pum9z-3Vw-3@gated-at.bofh.it> <pum9z-3Vw-1@gated-at.bofh.it> <pvSAp-169-1@gated-at.bofh.it> <pvVeV-52X-5@gated-at.bofh.it> <pBWUF-xl-5@gated-at.bofh.it> <pBX4l-Iz-7@gated-at.bofh.it> |
| X-Original-To | Peter Zijlstra <peterz@infradead.org> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Disposition | inline |
| User-Agent | Mutt/1.5.18 (2008-05-17) |
| X-Scanned-By | MIMEDefang 2.68 on 10.5.11.23 |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 85 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>, tj@kernel.org, mingo@redhat.com, linux-kernel@vger.kernel.org, der.herr@hofr.at, dave@stgolabs.net, torvalds@linux-foundation.org, josh@joshtriplett.org |
| X-Original-Date | Tue, 16 Jun 2015 21:03:51 +0200 |
| X-Original-Message-ID | <20150616190351.GA28724@redhat.com> |
| X-Original-References | <20150526114356.609107918@infradead.org> <20150526120215.042527659@infradead.org> <20150530171806.GB14999@linux.vnet.ibm.com> <20150530200425.GA15748@redhat.com> <20150616110855.GM3644@twins.programming.kicks-ass.net> <20150616111620.GC18673@twins.programming.kicks-ass.net> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | aioe.org linux.kernel:1166321 |
Show key headers only | View raw
On 06/16, Peter Zijlstra wrote:
>
>
> I made that the below.
>
> Are you OK with the Changelog edits and the added SoB ?
Of course,
Thanks Peter!
Oleg.
> ---
> Subject: perf: Fix ring_buffer_attach() RCU sync, again.
> From: Oleg Nesterov <oleg@redhat.com>
> Date: Sat, 30 May 2015 22:04:25 +0200
>
> 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.
>
> Cc: tj@kernel.org
> Cc: mingo@redhat.com
> Cc: der.herr@hofr.at
> Cc: dave@stgolabs.net
> Cc: torvalds@linux-foundation.org
> Cc: josh@joshtriplett.org
> Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Fixes: b69cf53640da ("perf: Fix a race between ring_buffer_detach() and ring_buffer_attach()")
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Link: http://lkml.kernel.org/r/20150530200425.GA15748@redhat.com
> ---
> kernel/events/core.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -4307,20 +4307,20 @@ static void ring_buffer_attach(struct pe
> 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
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next | Find similar | Unroll thread
Re: ring_buffer_attach && cond_synchronize_rcu (Was: percpu-rwsem: Optimize readers and reduce global impact) Oleg Nesterov <oleg@redhat.com> - 2015-06-16 21:10 +0200
csiph-web