aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHeiko Carstens <heiko.carstens@de.ibm.com>2014-03-02 07:09:47 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-04-14 09:42:19 -0400
commitf26c70a452dc0507bf7d3d2c3158ee7808e14f1c (patch)
tree7626bda5305bd7c9013d48ef50d030ade70b4b70
parent47c4534a109e45700d1d1c8467c2b5a618212d81 (diff)
futex: Allow architectures to skip futex_atomic_cmpxchg_inatomic() test
commit 03b8c7b623c80af264c4c8d6111e5c6289933666 upstream. If an architecture has futex_atomic_cmpxchg_inatomic() implemented and there is no runtime check necessary, allow to skip the test within futex_init(). This allows to get rid of some code which would always give the same result, and also allows the compiler to optimize a couple of if statements away. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Finn Thain <fthain@telegraphics.com.au> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Link: http://lkml.kernel.org/r/20140302120947.GA3641@osiris Signed-off-by: Thomas Gleixner <tglx@linutronix.de> [geert: Backported to v3.10..v3.13] Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--arch/s390/Kconfig1
-rw-r--r--include/linux/futex.h4
-rw-r--r--init/Kconfig7
-rw-r--r--kernel/futex.c14
4 files changed, 24 insertions, 2 deletions
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 97dcbea97a1c..d8d6eeca56b0 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -116,6 +116,7 @@ config S390
116 select HAVE_FUNCTION_GRAPH_TRACER 116 select HAVE_FUNCTION_GRAPH_TRACER
117 select HAVE_FUNCTION_TRACER 117 select HAVE_FUNCTION_TRACER
118 select HAVE_FUNCTION_TRACE_MCOUNT_TEST 118 select HAVE_FUNCTION_TRACE_MCOUNT_TEST
119 select HAVE_FUTEX_CMPXCHG if FUTEX
119 select HAVE_KERNEL_BZIP2 120 select HAVE_KERNEL_BZIP2
120 select HAVE_KERNEL_GZIP 121 select HAVE_KERNEL_GZIP
121 select HAVE_KERNEL_LZMA 122 select HAVE_KERNEL_LZMA
diff --git a/include/linux/futex.h b/include/linux/futex.h
index b0d95cac826e..6435f46d6e13 100644
--- a/include/linux/futex.h
+++ b/include/linux/futex.h
@@ -55,7 +55,11 @@ union futex_key {
55#ifdef CONFIG_FUTEX 55#ifdef CONFIG_FUTEX
56extern void exit_robust_list(struct task_struct *curr); 56extern void exit_robust_list(struct task_struct *curr);
57extern void exit_pi_state_list(struct task_struct *curr); 57extern void exit_pi_state_list(struct task_struct *curr);
58#ifdef CONFIG_HAVE_FUTEX_CMPXCHG
59#define futex_cmpxchg_enabled 1
60#else
58extern int futex_cmpxchg_enabled; 61extern int futex_cmpxchg_enabled;
62#endif
59#else 63#else
60static inline void exit_robust_list(struct task_struct *curr) 64static inline void exit_robust_list(struct task_struct *curr)
61{ 65{
diff --git a/init/Kconfig b/init/Kconfig
index 2d9b83104dcf..5d6febaea56d 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1365,6 +1365,13 @@ config FUTEX
1365 support for "fast userspace mutexes". The resulting kernel may not 1365 support for "fast userspace mutexes". The resulting kernel may not
1366 run glibc-based applications correctly. 1366 run glibc-based applications correctly.
1367 1367
1368config HAVE_FUTEX_CMPXCHG
1369 bool
1370 help
1371 Architectures should select this if futex_atomic_cmpxchg_inatomic()
1372 is implemented and always working. This removes a couple of runtime
1373 checks.
1374
1368config EPOLL 1375config EPOLL
1369 bool "Enable eventpoll support" if EXPERT 1376 bool "Enable eventpoll support" if EXPERT
1370 default y 1377 default y
diff --git a/kernel/futex.c b/kernel/futex.c
index a283b3041072..3bc18bf48d0c 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -67,7 +67,9 @@
67 67
68#include "rtmutex_common.h" 68#include "rtmutex_common.h"
69 69
70#ifndef CONFIG_HAVE_FUTEX_CMPXCHG
70int __read_mostly futex_cmpxchg_enabled; 71int __read_mostly futex_cmpxchg_enabled;
72#endif
71 73
72#define FUTEX_HASHBITS (CONFIG_BASE_SMALL ? 4 : 8) 74#define FUTEX_HASHBITS (CONFIG_BASE_SMALL ? 4 : 8)
73 75
@@ -2729,10 +2731,10 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
2729 return do_futex(uaddr, op, val, tp, uaddr2, val2, val3); 2731 return do_futex(uaddr, op, val, tp, uaddr2, val2, val3);
2730} 2732}
2731 2733
2732static int __init futex_init(void) 2734static void __init futex_detect_cmpxchg(void)
2733{ 2735{
2736#ifndef CONFIG_HAVE_FUTEX_CMPXCHG
2734 u32 curval; 2737 u32 curval;
2735 int i;
2736 2738
2737 /* 2739 /*
2738 * This will fail and we want it. Some arch implementations do 2740 * This will fail and we want it. Some arch implementations do
@@ -2746,6 +2748,14 @@ static int __init futex_init(void)
2746 */ 2748 */
2747 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT) 2749 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
2748 futex_cmpxchg_enabled = 1; 2750 futex_cmpxchg_enabled = 1;
2751#endif
2752}
2753
2754static int __init futex_init(void)
2755{
2756 int i;
2757
2758 futex_detect_cmpxchg();
2749 2759
2750 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) { 2760 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
2751 plist_head_init(&futex_queues[i].chain); 2761 plist_head_init(&futex_queues[i].chain);