From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933636AbcKXQw4 (ORCPT ); Thu, 24 Nov 2016 11:52:56 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:35975 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932584AbcKXQwy (ORCPT ); Thu, 24 Nov 2016 11:52:54 -0500 Date: Thu, 24 Nov 2016 17:52:41 +0100 From: Peter Zijlstra To: Thomas Gleixner 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 Message-ID: <20161124165241.GF3174@twins.programming.kicks-ass.net> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161123192005.GA3107@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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). 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...