[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20150616110855.GM3644@twins.programming.kicks-ass.net>
Date: Tue, 16 Jun 2015 13:08:55 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Oleg Nesterov <oleg@...hat.com>
Cc: "Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>, tj@...nel.org,
mingo@...hat.com, linux-kernel@...r.kernel.org, der.herr@...r.at,
dave@...olabs.net, torvalds@...ux-foundation.org,
josh@...htriplett.org
Subject: Re: ring_buffer_attach && cond_synchronize_rcu (Was: percpu-rwsem:
Optimize readers and reduce global impact)
On Sat, May 30, 2015 at 10:04:25PM +0200, Oleg Nesterov wrote:
> And. I tried to find other users of get_state/cond_sync. Found
> ring_buffer_attach() and it looks obviously buggy?
Urgh, indeed.
> 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?
Yes.
> Don't we need the patch below? (it also moves the ->rcu_pending check
> under "if (rb)", to make it more readable imo).
> --- x/kernel/events/core.c
> +++ x/kernel/events/core.c
> @@ -4310,20 +4310,20 @@ static void ring_buffer_attach(struct pe
> WARN_ON_ONCE(event->rcu_pending);
>
> spin_lock_irqsave(&old_rb->event_lock, flags);
> list_del_rcu(&event->rb_entry);
> spin_unlock_irqrestore(&old_rb->event_lock, flags);
>
> + 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);
Agreed.
--
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