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
|
|
|
|
Remove 'type' argument from access_ok() function
Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
of the user address range verification function since we got rid of the
old racy i386-only code to walk page tables by hand.
It existed because the original 80386 would not honor the write protect
bit when in kernel mode, so you had to do COW by hand before doing any
user access. But we haven't supported that in a long time, and these
days the 'type' argument is a purely historical artifact.
A discussion about extending 'user_access_begin()' to do the range
checking resulted this patch, because there is no way we're going to
move the old VERIFY_xyz interface to that model. And it's best done at
the end of the merge window when I've done most of my merges, so let's
just get this done once and for all.
This patch was mostly done with a sed-script, with manual fix-ups for
the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.
There were a couple of notable cases:
- csky still had the old "verify_area()" name as an alias.
- the iter_iov code had magical hardcoded knowledge of the actual
values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
really used it)
- microblaze used the type argument for a debug printout
but other than those oddities this should be a total no-op patch.
I tried to fix up all architectures, did fairly extensive grepping for
access_ok() uses, and the changes are trivial, but I may have missed
something. Any missed conversion should be trivially fixable, though.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-04 10:57:57 +08:00
|
|
|
if (!access_ok(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
|