mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mikael Pettersson <mikpe@it.uu.se>
To: linux-kernel@vger.kernel.org
Cc: Lennert Buytenhek <buytenh@wantstofly.org>,
	mingo@redhat.com, rmk@arm.linux.org.uk, tglx@linutronix.de
Subject: [PATCH][RFC] unbreak generic futex_atomic_cmpxchg_inatomic() on UP
Date: Thu, 2 Aug 2007 01:00:21 +0200 (MEST)	[thread overview]
Message-ID: <200708012300.l71N0LRX008930@harpo.it.uu.se> (raw)

[Resend. I messed up the To: line the first time]

As has been reported recently by Lennert Buytenhek, robust futexes
are broken on ARM:

>If you're also running into glibc's tst-robust1 test suite test
>locking up your ARM machine, you're probably running into the fact
>that asm-arm/futex.h includes asm-generic/futex.h, and
>asm-generic/futex.h defines futex_atomic_cmpxchg_inatomic() to
>return -ENOSYS.  This causes handle_futex_death() to loop forever.

I can confirm this statement: building glibc-2.4 with NPTL on
ARM hangs the kernel when the test suite reaches tst-robust1.

The problem is that kernel/futex.c expects futex_atomic_cmpxchg_inatomic()
to return -EFAULT or the new value. It doesn't expect -ENOSYS at all, and
generally -ENOSYS causes the futex code to loop, hanging the kernel.

The higher-end archs (x86, sparc64, ppc64, etc) provide fully-functional
asm/futex.h implementations, but a number of archs (alpha, arm, arm26,
avr32, blackfin, cris, h8300, m32r, m68k, mk68knommu, sh64, sparc, um,
v850, and xtensa) use asm-generic/futex.h, which makes robust futexes
horribly broken on them. There have also been reports recently that PI
futexes are broken due to the generic futex_atomic_cmpxchg_inatomic()
just being an -ENOSYS stub.

The patch below implements the generic futex_atomic_cmpxchg_inatomic() in
terms of __copy_{from,to}_user_inatomic() and preempt_{disable,enable}().
It obviously doesn't support SMP, but UP-only support should go a long
way for users of the affected archs.

I'm using this patch now and it has allowed me to build and use glibc-2.4
with NPTL on ARM (glibc-2.4-11.src.rpm from FC5 + ARM fixes).
(Finally I can ditch LinuxThreads :->)

Comments?

/Mikael

--- linux-2.6.22/include/asm-generic/futex.h.~1~	2007-02-04 19:44:54.000000000 +0100
+++ linux-2.6.22/include/asm-generic/futex.h	2007-08-01 19:03:43.000000000 +0200
@@ -4,6 +4,7 @@
 #ifdef __KERNEL__
 
 #include <linux/futex.h>
+#include <linux/preempt.h>
 #include <asm/errno.h>
 #include <asm/uaccess.h>
 
@@ -52,7 +53,34 @@ futex_atomic_op_inuser (int encoded_op, 
 static inline int
 futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
 {
+#ifdef CONFIG_SMP
 	return -ENOSYS;
+#else
+	int curval, ret;
+
+	if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
+		return -EFAULT;
+
+	preempt_disable();
+
+	ret = -EFAULT;
+	if (__copy_from_user_inatomic(&curval, uaddr, sizeof(int)))
+		goto out;
+
+	ret = curval;
+	if (curval != oldval)
+		goto out;
+
+	ret = -EFAULT;
+	if (__copy_to_user_inatomic(uaddr, &newval, sizeof(int)))
+		goto out;
+
+	ret = newval;
+
+ out:
+	preempt_enable();
+	return ret;
+#endif
 }
 
 #endif

             reply	other threads:[~2007-08-01 23:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-01 23:00 Mikael Pettersson [this message]
2007-08-01 23:49 ` Lennert Buytenhek
2007-10-03 19:33 ` Riku Voipio
2007-08-02  0:06 Mikael Pettersson
2007-08-02  0:58 ` Lennert Buytenhek
2007-10-04  7:41 Mikael Pettersson
2007-10-04  8:07 ` Geert Uytterhoeven

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=200708012300.l71N0LRX008930@harpo.it.uu.se \
    --to=mikpe@it.uu.se \
    --cc=buytenh@wantstofly.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rmk@arm.linux.org.uk \
    --cc=tglx@linutronix.de \
    /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®