From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757397AbcKXR7l (ORCPT ); Thu, 24 Nov 2016 12:59:41 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:37968 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753737AbcKXR7k (ORCPT ); Thu, 24 Nov 2016 12:59:40 -0500 Date: Thu, 24 Nov 2016 18:56:53 +0100 (CET) From: Thomas Gleixner To: Peter Zijlstra cc: mingo@kernel.org, juri.lelli@arm.com, rostedt@goodmis.org, xlpang@redhat.com, bigeasy@linutronix.de, linux-kernel@vger.kernel.org, mathieu.desnoyers@efficios.com, jdesfossez@efficios.com, bristot@redhat.com Subject: Re: [RFC][PATCH 4/4] futex: Rewrite FUTEX_UNLOCK_PI In-Reply-To: <20161124165241.GF3174@twins.programming.kicks-ass.net> Message-ID: References: <20161003091234.879763059@infradead.org> <20161003091847.704255067@infradead.org> <20161007112143.GJ3117@twins.programming.kicks-ass.net> <20161008165540.GI3568@worktop.programming.kicks-ass.net> <20161021122735.GA3117@twins.programming.kicks-ass.net> <20161123192005.GA3107@twins.programming.kicks-ass.net> <20161124165241.GF3174@twins.programming.kicks-ass.net> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 24 Nov 2016, Peter Zijlstra wrote: > On Wed, Nov 23, 2016 at 08:20:05PM +0100, Peter Zijlstra wrote: > > > + if (oldowner == &init_task && uval != 0) { > > > + raw_spin_lock(&pi_state->owner->pi_lock); > > > + list_del_init(&pi_state->list); > > > + raw_spin_unlock(&pi_state->owner->pi_lock); > > > + pi_state->owner = NULL; > > > + return -EAGAIN; > > > > @@ -2679,6 +2690,10 @@ static int futex_lock_pi(u32 __user *uad > > > > > > out_put_key: > > > put_futex_key(&q.key); > > > + > > > + if (ret == -EAGAIN) > > > + goto retry; > > > + > > > > And this is far too clever and really needs a comment. So the crucial > > point is that this is after unqueue_me_pi(), which drops the pi_state > > and loops back to lookup the pi_state again, which, hopefully, has now > > been completely destroyed -- and therefore we hit the regular > > attach_to_pi_owner() path, fixing up our 'funny' state. > > > > I'm stumped on REQUEUE_PI.. this relies on attach_to_pi_owner() and You mean LOCK_PI, right? > fixup_owner() being in the same function. But this is not the case for > requeue. WAIT_REQUEUE has the fixup, as its return path finds it has > acquired the outer pi-futex (uaddr2), but the lookup_pi_state() stuff is > done by CMP_REQUEUE, which does the actual transfer of the waiters from > inner futex (uaddr1) to outer futex (uaddr2). Correct. WAIT_REQUEUE puts the futex on the inner (uaddr1) and then gets moved to the outer. From there it's the same thing as LOCK_PI. > Maybe I can restructure things a bit, I think CMP_REQUEUE would also > know who actually acquired the outer-futex, but I have to think more on > this and the brain is pretty fried... That is irrelevant at requeue time and the owner can change up to the point where the waiter is really woken by a UNLOCK_PI. Thanks, tglx