From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752735AbcD0NpT (ORCPT ); Wed, 27 Apr 2016 09:45:19 -0400 Received: from www.linutronix.de ([62.245.132.108]:52486 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752416AbcD0NpO (ORCPT ); Wed, 27 Apr 2016 09:45:14 -0400 Date: Wed, 27 Apr 2016 15:43:34 +0200 (CEST) From: Thomas Gleixner To: Rich Felker cc: linux-kernel@vger.kernel.org, Davidlohr Bueso , Ingo Molnar , Andrew Morton , Darren Hart , Mel Gorman , Sebastian Andrzej Siewior , "Kirill A. Shutemov" , Greg Ungerer , Geert Uytterhoeven , Yoshinori Sato Subject: Re: [PATCH] futex: fix shared futex operations on nommu In-Reply-To: <20160426010303.GA3706@brightrain.aerifal.cx> Message-ID: References: <20160426010303.GA3706@brightrain.aerifal.cx> User-Agent: Alpine 2.11 (DEB 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 25 Apr 2016, Rich Felker wrote: > The shared get_futex_key code does not work on nommu, but is not > needed anyway because it's impossible for a given backing to have > multiple distinct virtual addresses on nommu. Simply disable these > code paths by refraining from setting FLAG_SHARED when CONFIG_MMU is > not enabled. > > Signed-off-by: Rich Felker > --- > kernel/futex.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/kernel/futex.c b/kernel/futex.c > index a5d2e74..ed6f475 100644 > --- a/kernel/futex.c > +++ b/kernel/futex.c > @@ -3131,8 +3131,10 @@ long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout, > int cmd = op & FUTEX_CMD_MASK; > unsigned int flags = 0; > > +#ifdef CONFIG_MMU > if (!(op & FUTEX_PRIVATE_FLAG)) > flags |= FLAGS_SHARED; > +#endif Well, that's lame. The proper solution is to disable the code which is involved and let the compiler throw it away. Saves quite some text. Thanks, tglx 8<------------------- --- a/kernel/futex.c +++ b/kernel/futex.c @@ -179,7 +179,15 @@ int __read_mostly futex_cmpxchg_enabled; * Futex flags used to encode options to functions and preserve them across * restarts. */ -#define FLAGS_SHARED 0x01 +#ifdef CONFIG_MMU +# define FLAGS_SHARED 0x01 +#else +/* + * NOMMU does not have per process address space. Let the compiler optimize + * code away. + */ +# define FLAGS_SHARED 0x00 +#endif #define FLAGS_CLOCKRT 0x02 #define FLAGS_HAS_TIMEOUT 0x04 @@ -405,6 +413,16 @@ static void get_futex_key_refs(union fut if (!key->both.ptr) return; + /* + * On MMU less systems futexes are always "private" as there is no per + * process address space. We need the smp wmb nevertheless - yes, + * arch/blackfin has MMU less SMP ... + */ + if (!IS_ENABLED(CONFIG_MMU)) { + smp_mb(); /* explicit smp_mb(); (B) */ + return; + } + switch (key->both.offset & (FUT_OFF_INODE|FUT_OFF_MMSHARED)) { case FUT_OFF_INODE: ihold(key->shared.inode); /* implies smp_mb(); (B) */ @@ -436,6 +454,9 @@ static void drop_futex_key_refs(union fu return; } + if (!IS_ENABLED(CONFIG_MMU)) + return; + switch (key->both.offset & (FUT_OFF_INODE|FUT_OFF_MMSHARED)) { case FUT_OFF_INODE: iput(key->shared.inode);