aboutsummaryrefslogtreecommitdiffstats
path: root/arch/alpha
diff options
context:
space:
mode:
authorMichel Lespinasse <walken@google.com>2011-03-10 21:48:51 -0500
committerThomas Gleixner <tglx@linutronix.de>2011-03-11 06:23:08 -0500
commit37a9d912b24f96a0591773e6e6c3642991ae5a70 (patch)
tree5c4d5b9a52e2c533269e589115afbd25b6c8534b /arch/alpha
parent522d7decc0370070448a8c28982c8dfd8970489e (diff)
futex: Sanitize cmpxchg_futex_value_locked API
The cmpxchg_futex_value_locked API was funny in that it returned either the original, user-exposed futex value OR an error code such as -EFAULT. This was confusing at best, and could be a source of livelocks in places that retry the cmpxchg_futex_value_locked after trying to fix the issue by running fault_in_user_writeable(). This change makes the cmpxchg_futex_value_locked API more similar to the get_futex_value_locked one, returning an error code and updating the original value through a reference argument. Signed-off-by: Michel Lespinasse <walken@google.com> Acked-by: Chris Metcalf <cmetcalf@tilera.com> [tile] Acked-by: Tony Luck <tony.luck@intel.com> [ia64] Acked-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Michal Simek <monstr@monstr.eu> [microblaze] Acked-by: David Howells <dhowells@redhat.com> [frv] Cc: Darren Hart <darren@dvhart.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Matt Turner <mattst88@gmail.com> Cc: Russell King <linux@arm.linux.org.uk> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: "James E.J. Bottomley" <jejb@parisc-linux.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Paul Mundt <lethal@linux-sh.org> Cc: "David S. Miller" <davem@davemloft.net> Cc: Linus Torvalds <torvalds@linux-foundation.org> LKML-Reference: <20110311024851.GC26122@google.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'arch/alpha')
-rw-r--r--arch/alpha/include/asm/futex.h22
1 files changed, 12 insertions, 10 deletions
diff --git a/arch/alpha/include/asm/futex.h b/arch/alpha/include/asm/futex.h
index 945de222ab91..c4e5c2850cce 100644
--- a/arch/alpha/include/asm/futex.h
+++ b/arch/alpha/include/asm/futex.h
@@ -81,21 +81,22 @@ static inline int futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
81} 81}
82 82
83static inline int 83static inline int
84futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval) 84futex_atomic_cmpxchg_inatomic(int *uval, int __user *uaddr,
85 int oldval, int newval)
85{ 86{
86 int prev, cmp; 87 int ret = 0, prev, cmp;
87 88
88 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int))) 89 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
89 return -EFAULT; 90 return -EFAULT;
90 91
91 __asm__ __volatile__ ( 92 __asm__ __volatile__ (
92 __ASM_SMP_MB 93 __ASM_SMP_MB
93 "1: ldl_l %0,0(%2)\n" 94 "1: ldl_l %1,0(%3)\n"
94 " cmpeq %0,%3,%1\n" 95 " cmpeq %1,%4,%2\n"
95 " beq %1,3f\n" 96 " beq %2,3f\n"
96 " mov %4,%1\n" 97 " mov %5,%2\n"
97 "2: stl_c %1,0(%2)\n" 98 "2: stl_c %2,0(%3)\n"
98 " beq %1,4f\n" 99 " beq %2,4f\n"
99 "3: .subsection 2\n" 100 "3: .subsection 2\n"
100 "4: br 1b\n" 101 "4: br 1b\n"
101 " .previous\n" 102 " .previous\n"
@@ -105,11 +106,12 @@ futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
105 " .long 2b-.\n" 106 " .long 2b-.\n"
106 " lda $31,3b-2b(%0)\n" 107 " lda $31,3b-2b(%0)\n"
107 " .previous\n" 108 " .previous\n"
108 : "=&r"(prev), "=&r"(cmp) 109 : "+r"(ret), "=&r"(prev), "=&r"(cmp)
109 : "r"(uaddr), "r"((long)oldval), "r"(newval) 110 : "r"(uaddr), "r"((long)oldval), "r"(newval)
110 : "memory"); 111 : "memory");
111 112
112 return prev; 113 *uval = prev;
114 return ret;
113} 115}
114 116
115#endif /* __KERNEL__ */ 117#endif /* __KERNEL__ */