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>
111 lines
1.8 KiB
C
111 lines
1.8 KiB
C
#ifndef __ASM_SH_FUTEX_IRQ_H
|
|
#define __ASM_SH_FUTEX_IRQ_H
|
|
|
|
#include <asm/system.h>
|
|
|
|
static inline int atomic_futex_op_xchg_set(int oparg, int __user *uaddr,
|
|
int *oldval)
|
|
{
|
|
unsigned long flags;
|
|
int ret;
|
|
|
|
local_irq_save(flags);
|
|
|
|
ret = get_user(*oldval, uaddr);
|
|
if (!ret)
|
|
ret = put_user(oparg, uaddr);
|
|
|
|
local_irq_restore(flags);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static inline int atomic_futex_op_xchg_add(int oparg, int __user *uaddr,
|
|
int *oldval)
|
|
{
|
|
unsigned long flags;
|
|
int ret;
|
|
|
|
local_irq_save(flags);
|
|
|
|
ret = get_user(*oldval, uaddr);
|
|
if (!ret)
|
|
ret = put_user(*oldval + oparg, uaddr);
|
|
|
|
local_irq_restore(flags);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static inline int atomic_futex_op_xchg_or(int oparg, int __user *uaddr,
|
|
int *oldval)
|
|
{
|
|
unsigned long flags;
|
|
int ret;
|
|
|
|
local_irq_save(flags);
|
|
|
|
ret = get_user(*oldval, uaddr);
|
|
if (!ret)
|
|
ret = put_user(*oldval | oparg, uaddr);
|
|
|
|
local_irq_restore(flags);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static inline int atomic_futex_op_xchg_and(int oparg, int __user *uaddr,
|
|
int *oldval)
|
|
{
|
|
unsigned long flags;
|
|
int ret;
|
|
|
|
local_irq_save(flags);
|
|
|
|
ret = get_user(*oldval, uaddr);
|
|
if (!ret)
|
|
ret = put_user(*oldval & oparg, uaddr);
|
|
|
|
local_irq_restore(flags);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static inline int atomic_futex_op_xchg_xor(int oparg, int __user *uaddr,
|
|
int *oldval)
|
|
{
|
|
unsigned long flags;
|
|
int ret;
|
|
|
|
local_irq_save(flags);
|
|
|
|
ret = get_user(*oldval, uaddr);
|
|
if (!ret)
|
|
ret = put_user(*oldval ^ oparg, uaddr);
|
|
|
|
local_irq_restore(flags);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static inline int atomic_futex_op_cmpxchg_inatomic(int *uval,
|
|
int __user *uaddr,
|
|
int oldval, int newval)
|
|
{
|
|
unsigned long flags;
|
|
int ret, prev = 0;
|
|
|
|
local_irq_save(flags);
|
|
|
|
ret = get_user(prev, uaddr);
|
|
if (!ret && oldval == prev)
|
|
ret = put_user(newval, uaddr);
|
|
|
|
local_irq_restore(flags);
|
|
|
|
*uval = prev;
|
|
return ret;
|
|
}
|
|
|
|
#endif /* __ASM_SH_FUTEX_IRQ_H */
|