aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/include
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/powerpc/include
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/powerpc/include')
-rw-r--r--arch/powerpc/include/asm/futex.h20
1 files changed, 11 insertions, 9 deletions
diff --git a/arch/powerpc/include/asm/futex.h b/arch/powerpc/include/asm/futex.h
index 7c589ef81fb0..631e8da60064 100644
--- a/arch/powerpc/include/asm/futex.h
+++ b/arch/powerpc/include/asm/futex.h
@@ -82,35 +82,37 @@ static inline int futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
82} 82}
83 83
84static inline int 84static inline int
85futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval) 85futex_atomic_cmpxchg_inatomic(int *uval, int __user *uaddr,
86 int oldval, int newval)
86{ 87{
87 int prev; 88 int ret = 0, prev;
88 89
89 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int))) 90 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
90 return -EFAULT; 91 return -EFAULT;
91 92
92 __asm__ __volatile__ ( 93 __asm__ __volatile__ (
93 PPC_RELEASE_BARRIER 94 PPC_RELEASE_BARRIER
94"1: lwarx %0,0,%2 # futex_atomic_cmpxchg_inatomic\n\ 95"1: lwarx %1,0,%3 # futex_atomic_cmpxchg_inatomic\n\
95 cmpw 0,%0,%3\n\ 96 cmpw 0,%1,%4\n\
96 bne- 3f\n" 97 bne- 3f\n"
97 PPC405_ERR77(0,%2) 98 PPC405_ERR77(0,%3)
98"2: stwcx. %4,0,%2\n\ 99"2: stwcx. %5,0,%3\n\
99 bne- 1b\n" 100 bne- 1b\n"
100 PPC_ACQUIRE_BARRIER 101 PPC_ACQUIRE_BARRIER
101"3: .section .fixup,\"ax\"\n\ 102"3: .section .fixup,\"ax\"\n\
1024: li %0,%5\n\ 1034: li %0,%6\n\
103 b 3b\n\ 104 b 3b\n\
104 .previous\n\ 105 .previous\n\
105 .section __ex_table,\"a\"\n\ 106 .section __ex_table,\"a\"\n\
106 .align 3\n\ 107 .align 3\n\
107 " PPC_LONG "1b,4b,2b,4b\n\ 108 " PPC_LONG "1b,4b,2b,4b\n\
108 .previous" \ 109 .previous" \
109 : "=&r" (prev), "+m" (*uaddr) 110 : "+r" (ret), "=&r" (prev), "+m" (*uaddr)
110 : "r" (uaddr), "r" (oldval), "r" (newval), "i" (-EFAULT) 111 : "r" (uaddr), "r" (oldval), "r" (newval), "i" (-EFAULT)
111 : "cc", "memory"); 112 : "cc", "memory");
112 113
113 return prev; 114 *uval = prev;
115 return ret;
114} 116}
115 117
116#endif /* __KERNEL__ */ 118#endif /* __KERNEL__ */