2013-01-18 17:42:22 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* Vineetg: August 2010: From Android kernel work
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ASM_FUTEX_H
|
|
|
|
#define _ASM_FUTEX_H
|
|
|
|
|
|
|
|
#include <linux/futex.h>
|
|
|
|
#include <linux/preempt.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <asm/errno.h>
|
|
|
|
|
2015-06-25 16:16:57 +08:00
|
|
|
#ifdef CONFIG_ARC_HAS_LLSC
|
|
|
|
|
|
|
|
#define __futex_atomic_op(insn, ret, oldval, uaddr, oparg)\
|
|
|
|
\
|
2015-08-05 21:40:02 +08:00
|
|
|
smp_mb(); \
|
2015-06-25 16:16:57 +08:00
|
|
|
__asm__ __volatile__( \
|
|
|
|
"1: llock %1, [%2] \n" \
|
|
|
|
insn "\n" \
|
|
|
|
"2: scond %0, [%2] \n" \
|
|
|
|
" bnz 1b \n" \
|
|
|
|
" mov %0, 0 \n" \
|
|
|
|
"3: \n" \
|
|
|
|
" .section .fixup,\"ax\" \n" \
|
|
|
|
" .align 4 \n" \
|
|
|
|
"4: mov %0, %4 \n" \
|
2015-08-12 22:23:32 +08:00
|
|
|
" j 3b \n" \
|
2015-06-25 16:16:57 +08:00
|
|
|
" .previous \n" \
|
|
|
|
" .section __ex_table,\"a\" \n" \
|
|
|
|
" .align 4 \n" \
|
|
|
|
" .word 1b, 4b \n" \
|
|
|
|
" .word 2b, 4b \n" \
|
|
|
|
" .previous \n" \
|
|
|
|
\
|
|
|
|
: "=&r" (ret), "=&r" (oldval) \
|
|
|
|
: "r" (uaddr), "r" (oparg), "ir" (-EFAULT) \
|
2015-08-05 21:40:02 +08:00
|
|
|
: "cc", "memory"); \
|
|
|
|
smp_mb() \
|
2015-06-25 16:16:57 +08:00
|
|
|
|
|
|
|
#else /* !CONFIG_ARC_HAS_LLSC */
|
|
|
|
|
2013-01-18 17:42:22 +08:00
|
|
|
#define __futex_atomic_op(insn, ret, oldval, uaddr, oparg)\
|
|
|
|
\
|
2015-08-05 21:40:02 +08:00
|
|
|
smp_mb(); \
|
2013-01-18 17:42:22 +08:00
|
|
|
__asm__ __volatile__( \
|
2015-06-25 16:16:57 +08:00
|
|
|
"1: ld %1, [%2] \n" \
|
2013-01-18 17:42:22 +08:00
|
|
|
insn "\n" \
|
2015-06-25 16:16:57 +08:00
|
|
|
"2: st %0, [%2] \n" \
|
2013-01-18 17:42:22 +08:00
|
|
|
" mov %0, 0 \n" \
|
|
|
|
"3: \n" \
|
|
|
|
" .section .fixup,\"ax\" \n" \
|
|
|
|
" .align 4 \n" \
|
|
|
|
"4: mov %0, %4 \n" \
|
2015-08-12 22:23:32 +08:00
|
|
|
" j 3b \n" \
|
2013-01-18 17:42:22 +08:00
|
|
|
" .previous \n" \
|
|
|
|
" .section __ex_table,\"a\" \n" \
|
|
|
|
" .align 4 \n" \
|
|
|
|
" .word 1b, 4b \n" \
|
|
|
|
" .word 2b, 4b \n" \
|
|
|
|
" .previous \n" \
|
|
|
|
\
|
|
|
|
: "=&r" (ret), "=&r" (oldval) \
|
|
|
|
: "r" (uaddr), "r" (oparg), "ir" (-EFAULT) \
|
2015-08-05 21:40:02 +08:00
|
|
|
: "cc", "memory"); \
|
|
|
|
smp_mb() \
|
2013-01-18 17:42:22 +08:00
|
|
|
|
2015-06-25 16:16:57 +08:00
|
|
|
#endif
|
|
|
|
|
2017-08-24 15:31:05 +08:00
|
|
|
static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval,
|
|
|
|
u32 __user *uaddr)
|
2013-01-18 17:42:22 +08:00
|
|
|
{
|
|
|
|
int oldval = 0, ret;
|
|
|
|
|
2015-08-06 21:41:06 +08:00
|
|
|
#ifndef CONFIG_ARC_HAS_LLSC
|
|
|
|
preempt_disable(); /* to guarantee atomic r-m-w of futex op */
|
|
|
|
#endif
|
2015-05-11 23:52:17 +08:00
|
|
|
pagefault_disable();
|
2013-01-18 17:42:22 +08:00
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
case FUTEX_OP_SET:
|
|
|
|
__futex_atomic_op("mov %0, %3", ret, oldval, uaddr, oparg);
|
|
|
|
break;
|
|
|
|
case FUTEX_OP_ADD:
|
2015-08-05 21:53:34 +08:00
|
|
|
/* oldval = *uaddr; *uaddr += oparg ; ret = *uaddr */
|
2013-01-18 17:42:22 +08:00
|
|
|
__futex_atomic_op("add %0, %1, %3", ret, oldval, uaddr, oparg);
|
|
|
|
break;
|
|
|
|
case FUTEX_OP_OR:
|
|
|
|
__futex_atomic_op("or %0, %1, %3", ret, oldval, uaddr, oparg);
|
|
|
|
break;
|
|
|
|
case FUTEX_OP_ANDN:
|
|
|
|
__futex_atomic_op("bic %0, %1, %3", ret, oldval, uaddr, oparg);
|
|
|
|
break;
|
|
|
|
case FUTEX_OP_XOR:
|
|
|
|
__futex_atomic_op("xor %0, %1, %3", ret, oldval, uaddr, oparg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2015-05-11 23:52:17 +08:00
|
|
|
pagefault_enable();
|
2015-08-06 21:41:06 +08:00
|
|
|
#ifndef CONFIG_ARC_HAS_LLSC
|
|
|
|
preempt_enable();
|
|
|
|
#endif
|
2013-01-18 17:42:22 +08:00
|
|
|
|
2017-08-24 15:31:05 +08:00
|
|
|
if (!ret)
|
|
|
|
*oval = oldval;
|
|
|
|
|
2013-01-18 17:42:22 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-05 21:40:02 +08:00
|
|
|
/*
|
|
|
|
* cmpxchg of futex (pagefaults disabled by caller)
|
2015-08-06 19:33:17 +08:00
|
|
|
* Return 0 for success, -EFAULT otherwise
|
2013-01-18 17:42:22 +08:00
|
|
|
*/
|
|
|
|
static inline int
|
2015-08-05 21:53:34 +08:00
|
|
|
futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, u32 expval,
|
|
|
|
u32 newval)
|
2013-01-18 17:42:22 +08:00
|
|
|
{
|
2015-08-06 19:33:17 +08:00
|
|
|
int ret = 0;
|
2015-08-05 21:53:34 +08:00
|
|
|
u32 existval;
|
2013-01-18 17:42:22 +08:00
|
|
|
|
2015-08-05 21:53:34 +08:00
|
|
|
if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
|
2013-01-18 17:42:22 +08:00
|
|
|
return -EFAULT;
|
|
|
|
|
2015-08-06 21:41:06 +08:00
|
|
|
#ifndef CONFIG_ARC_HAS_LLSC
|
|
|
|
preempt_disable(); /* to guarantee atomic r-m-w of futex op */
|
|
|
|
#endif
|
2015-08-05 21:40:02 +08:00
|
|
|
smp_mb();
|
2013-01-18 17:42:22 +08:00
|
|
|
|
|
|
|
__asm__ __volatile__(
|
2015-06-25 16:16:57 +08:00
|
|
|
#ifdef CONFIG_ARC_HAS_LLSC
|
2015-08-06 19:33:17 +08:00
|
|
|
"1: llock %1, [%4] \n"
|
|
|
|
" brne %1, %2, 3f \n"
|
|
|
|
"2: scond %3, [%4] \n"
|
2015-06-25 16:16:57 +08:00
|
|
|
" bnz 1b \n"
|
|
|
|
#else
|
2015-08-06 19:33:17 +08:00
|
|
|
"1: ld %1, [%4] \n"
|
|
|
|
" brne %1, %2, 3f \n"
|
|
|
|
"2: st %3, [%4] \n"
|
2015-06-25 16:16:57 +08:00
|
|
|
#endif
|
2013-01-18 17:42:22 +08:00
|
|
|
"3: \n"
|
|
|
|
" .section .fixup,\"ax\" \n"
|
2015-08-06 19:33:17 +08:00
|
|
|
"4: mov %0, %5 \n"
|
2015-08-12 22:23:32 +08:00
|
|
|
" j 3b \n"
|
2013-01-18 17:42:22 +08:00
|
|
|
" .previous \n"
|
|
|
|
" .section __ex_table,\"a\" \n"
|
|
|
|
" .align 4 \n"
|
|
|
|
" .word 1b, 4b \n"
|
|
|
|
" .word 2b, 4b \n"
|
|
|
|
" .previous\n"
|
2015-08-06 19:33:17 +08:00
|
|
|
: "+&r"(ret), "=&r"(existval)
|
2015-08-05 21:53:34 +08:00
|
|
|
: "r"(expval), "r"(newval), "r"(uaddr), "ir"(-EFAULT)
|
2013-01-18 17:42:22 +08:00
|
|
|
: "cc", "memory");
|
|
|
|
|
2015-08-05 21:40:02 +08:00
|
|
|
smp_mb();
|
2013-01-18 17:42:22 +08:00
|
|
|
|
2015-08-06 21:41:06 +08:00
|
|
|
#ifndef CONFIG_ARC_HAS_LLSC
|
|
|
|
preempt_enable();
|
|
|
|
#endif
|
2015-08-05 21:53:34 +08:00
|
|
|
*uval = existval;
|
2015-08-06 19:33:17 +08:00
|
|
|
return ret;
|
2013-01-18 17:42:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|