mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Rich Felker <dalias@libc.org>
Cc: linux-kernel@vger.kernel.org, Davidlohr Bueso <dave@stgolabs.net>,
	Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Darren Hart <dvhart@linux.intel.com>,
	Mel Gorman <mgorman@suse.de>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	Greg Ungerer <gerg@uclinux.org>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Yoshinori Sato <ysato@users.sourceforge.jp>
Subject: Re: [PATCH] futex: fix shared futex operations on nommu
Date: Wed, 27 Apr 2016 15:43:34 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.11.1604271526580.3941@nanos> (raw)
In-Reply-To: <20160426010303.GA3706@brightrain.aerifal.cx>

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 <dalias@libc.org>
> ---
>  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);

      parent reply	other threads:[~2016-04-27 13:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-26  1:03 Rich Felker
2016-04-26  9:55 ` Sebastian Andrzej Siewior
2016-04-26 15:53   ` Rich Felker
2016-04-26 16:11     ` Sebastian Andrzej Siewior
2016-04-26 16:27       ` Rich Felker
2016-04-26 22:27         ` Andrew Morton
2016-04-26 22:31           ` Rich Felker
2016-04-27 13:43 ` Thomas Gleixner [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.11.1604271526580.3941@nanos \
    --to=tglx@linutronix.de \
    --cc=akpm@linux-foundation.org \
    --cc=bigeasy@linutronix.de \
    --cc=dalias@libc.org \
    --cc=dave@stgolabs.net \
    --cc=dvhart@linux.intel.com \
    --cc=geert@linux-m68k.org \
    --cc=gerg@uclinux.org \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@kernel.org \
    --cc=ysato@users.sourceforge.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®