2013-11-18 11:46:43 +07:00
|
|
|
/*
|
|
|
|
* Atomic futex routines
|
|
|
|
*
|
|
|
|
* Based on the PowerPC implementataion
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 TangoTec Ltd.
|
|
|
|
*
|
|
|
|
* Baruch Siach <baruch@tkos.co.il>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ASM_XTENSA_FUTEX_H
|
|
|
|
#define _ASM_XTENSA_FUTEX_H
|
|
|
|
|
|
|
|
#include <linux/futex.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
|
2018-12-21 08:18:12 +07:00
|
|
|
#if XCHAL_HAVE_EXCLUSIVE
|
|
|
|
#define __futex_atomic_op(insn, ret, old, uaddr, arg) \
|
|
|
|
__asm__ __volatile( \
|
|
|
|
"1: l32ex %[oldval], %[addr]\n" \
|
|
|
|
insn "\n" \
|
|
|
|
"2: s32ex %[newval], %[addr]\n" \
|
|
|
|
" getex %[newval]\n" \
|
|
|
|
" beqz %[newval], 1b\n" \
|
|
|
|
" movi %[newval], 0\n" \
|
|
|
|
"3:\n" \
|
|
|
|
" .section .fixup,\"ax\"\n" \
|
|
|
|
" .align 4\n" \
|
|
|
|
" .literal_position\n" \
|
|
|
|
"5: movi %[oldval], 3b\n" \
|
|
|
|
" movi %[newval], %[fault]\n" \
|
|
|
|
" jx %[oldval]\n" \
|
|
|
|
" .previous\n" \
|
|
|
|
" .section __ex_table,\"a\"\n" \
|
|
|
|
" .long 1b, 5b, 2b, 5b\n" \
|
|
|
|
" .previous\n" \
|
|
|
|
: [oldval] "=&r" (old), [newval] "=&r" (ret) \
|
|
|
|
: [addr] "r" (uaddr), [oparg] "r" (arg), \
|
|
|
|
[fault] "I" (-EFAULT) \
|
|
|
|
: "memory")
|
|
|
|
#elif XCHAL_HAVE_S32C1I
|
2019-05-07 02:02:26 +07:00
|
|
|
#define __futex_atomic_op(insn, ret, old, uaddr, arg) \
|
2013-11-18 11:46:43 +07:00
|
|
|
__asm__ __volatile( \
|
2019-05-07 02:02:26 +07:00
|
|
|
"1: l32i %[oldval], %[addr], 0\n" \
|
2013-11-18 11:46:43 +07:00
|
|
|
insn "\n" \
|
2019-05-07 02:02:26 +07:00
|
|
|
" wsr %[oldval], scompare1\n" \
|
|
|
|
"2: s32c1i %[newval], %[addr], 0\n" \
|
|
|
|
" bne %[newval], %[oldval], 1b\n" \
|
|
|
|
" movi %[newval], 0\n" \
|
2013-11-18 11:46:43 +07:00
|
|
|
"3:\n" \
|
|
|
|
" .section .fixup,\"ax\"\n" \
|
|
|
|
" .align 4\n" \
|
2018-12-06 03:48:19 +07:00
|
|
|
" .literal_position\n" \
|
2019-05-07 02:02:26 +07:00
|
|
|
"5: movi %[oldval], 3b\n" \
|
|
|
|
" movi %[newval], %[fault]\n" \
|
|
|
|
" jx %[oldval]\n" \
|
2013-11-18 11:46:43 +07:00
|
|
|
" .previous\n" \
|
|
|
|
" .section __ex_table,\"a\"\n" \
|
2019-05-07 02:02:26 +07:00
|
|
|
" .long 1b, 5b, 2b, 5b\n" \
|
2013-11-18 11:46:43 +07:00
|
|
|
" .previous\n" \
|
2019-05-07 02:02:26 +07:00
|
|
|
: [oldval] "=&r" (old), [newval] "=&r" (ret) \
|
|
|
|
: [addr] "r" (uaddr), [oparg] "r" (arg), \
|
|
|
|
[fault] "I" (-EFAULT) \
|
2013-11-18 11:46:43 +07:00
|
|
|
: "memory")
|
2018-12-21 08:18:12 +07:00
|
|
|
#endif
|
2013-11-18 11:46:43 +07:00
|
|
|
|
2017-08-24 14:31:05 +07:00
|
|
|
static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval,
|
|
|
|
u32 __user *uaddr)
|
2013-11-18 11:46:43 +07:00
|
|
|
{
|
2018-12-21 08:18:12 +07:00
|
|
|
#if XCHAL_HAVE_S32C1I || XCHAL_HAVE_EXCLUSIVE
|
2013-11-18 11:46:43 +07:00
|
|
|
int oldval = 0, ret;
|
|
|
|
|
|
|
|
pagefault_disable();
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
case FUTEX_OP_SET:
|
2019-05-07 02:02:26 +07:00
|
|
|
__futex_atomic_op("mov %[newval], %[oparg]",
|
|
|
|
ret, oldval, uaddr, oparg);
|
2013-11-18 11:46:43 +07:00
|
|
|
break;
|
|
|
|
case FUTEX_OP_ADD:
|
2019-05-07 02:02:26 +07:00
|
|
|
__futex_atomic_op("add %[newval], %[oldval], %[oparg]",
|
|
|
|
ret, oldval, uaddr, oparg);
|
2013-11-18 11:46:43 +07:00
|
|
|
break;
|
|
|
|
case FUTEX_OP_OR:
|
2019-05-07 02:02:26 +07:00
|
|
|
__futex_atomic_op("or %[newval], %[oldval], %[oparg]",
|
|
|
|
ret, oldval, uaddr, oparg);
|
2013-11-18 11:46:43 +07:00
|
|
|
break;
|
|
|
|
case FUTEX_OP_ANDN:
|
2019-05-07 02:02:26 +07:00
|
|
|
__futex_atomic_op("and %[newval], %[oldval], %[oparg]",
|
|
|
|
ret, oldval, uaddr, ~oparg);
|
2013-11-18 11:46:43 +07:00
|
|
|
break;
|
|
|
|
case FUTEX_OP_XOR:
|
2019-05-07 02:02:26 +07:00
|
|
|
__futex_atomic_op("xor %[newval], %[oldval], %[oparg]",
|
|
|
|
ret, oldval, uaddr, oparg);
|
2013-11-18 11:46:43 +07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
pagefault_enable();
|
|
|
|
|
2017-08-24 14:31:05 +07:00
|
|
|
if (!ret)
|
|
|
|
*oval = oldval;
|
2013-11-18 11:46:43 +07:00
|
|
|
|
2017-08-24 14:31:05 +07:00
|
|
|
return ret;
|
2019-05-07 02:02:26 +07:00
|
|
|
#else
|
|
|
|
return -ENOSYS;
|
|
|
|
#endif
|
2013-11-18 11:46:43 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
|
|
|
|
u32 oldval, u32 newval)
|
|
|
|
{
|
2018-12-21 08:18:12 +07:00
|
|
|
#if XCHAL_HAVE_S32C1I || XCHAL_HAVE_EXCLUSIVE
|
2019-05-07 02:02:26 +07:00
|
|
|
unsigned long tmp;
|
2013-11-18 11:46:43 +07:00
|
|
|
int ret = 0;
|
|
|
|
|
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 09:57:57 +07:00
|
|
|
if (!access_ok(uaddr, sizeof(u32)))
|
2013-11-18 11:46:43 +07:00
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
__asm__ __volatile__ (
|
|
|
|
" # futex_atomic_cmpxchg_inatomic\n"
|
2018-12-21 08:18:12 +07:00
|
|
|
#if XCHAL_HAVE_EXCLUSIVE
|
|
|
|
"1: l32ex %[tmp], %[addr]\n"
|
|
|
|
" s32i %[tmp], %[uval], 0\n"
|
|
|
|
" bne %[tmp], %[oldval], 2f\n"
|
|
|
|
" mov %[tmp], %[newval]\n"
|
|
|
|
"3: s32ex %[tmp], %[addr]\n"
|
|
|
|
" getex %[tmp]\n"
|
|
|
|
" beqz %[tmp], 1b\n"
|
|
|
|
#elif XCHAL_HAVE_S32C1I
|
2019-05-07 02:02:26 +07:00
|
|
|
" wsr %[oldval], scompare1\n"
|
|
|
|
"1: s32c1i %[newval], %[addr], 0\n"
|
|
|
|
" s32i %[newval], %[uval], 0\n"
|
2018-12-21 08:18:12 +07:00
|
|
|
#endif
|
2018-01-06 05:27:58 +07:00
|
|
|
"2:\n"
|
2013-11-18 11:46:43 +07:00
|
|
|
" .section .fixup,\"ax\"\n"
|
|
|
|
" .align 4\n"
|
2018-12-06 03:48:19 +07:00
|
|
|
" .literal_position\n"
|
2019-05-07 02:02:26 +07:00
|
|
|
"4: movi %[tmp], 2b\n"
|
|
|
|
" movi %[ret], %[fault]\n"
|
|
|
|
" jx %[tmp]\n"
|
2013-11-18 11:46:43 +07:00
|
|
|
" .previous\n"
|
|
|
|
" .section __ex_table,\"a\"\n"
|
2019-05-07 02:02:26 +07:00
|
|
|
" .long 1b, 4b\n"
|
2018-12-21 08:18:12 +07:00
|
|
|
#if XCHAL_HAVE_EXCLUSIVE
|
|
|
|
" .long 3b, 4b\n"
|
|
|
|
#endif
|
2013-11-18 11:46:43 +07:00
|
|
|
" .previous\n"
|
2019-05-07 02:02:26 +07:00
|
|
|
: [ret] "+r" (ret), [newval] "+r" (newval), [tmp] "=&r" (tmp)
|
|
|
|
: [addr] "r" (uaddr), [oldval] "r" (oldval), [uval] "r" (uval),
|
|
|
|
[fault] "I" (-EFAULT)
|
2013-11-18 11:46:43 +07:00
|
|
|
: "memory");
|
|
|
|
|
|
|
|
return ret;
|
2019-05-07 02:02:26 +07:00
|
|
|
#else
|
|
|
|
return -ENOSYS;
|
|
|
|
#endif
|
2013-11-18 11:46:43 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _ASM_XTENSA_FUTEX_H */
|