1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2012 ARM Ltd.
8 #include <linux/futex.h>
9 #include <linux/uaccess.h>
11 #include <asm/errno.h>
13 #define FUTEX_MAX_LOOPS 128 /* What's the largest number you can think of? */
15 #define __futex_atomic_op(insn, ret, oldval, uaddr, tmp, oparg) \
17 unsigned int loops = FUTEX_MAX_LOOPS; \
19 uaccess_enable_privileged(); \
21 " prfm pstl1strm, %2\n" \
24 "2: stlxr %w0, %w3, %2\n" \
26 " sub %w4, %w4, %w0\n" \
31 " .pushsection .fixup,\"ax\"\n" \
36 _ASM_EXTABLE(1b, 4b) \
37 _ASM_EXTABLE(2b, 4b) \
38 : "=&r" (ret), "=&r" (oldval), "+Q" (*uaddr), "=&r" (tmp), \
40 : "r" (oparg), "Ir" (-EFAULT), "Ir" (-EAGAIN) \
42 uaccess_disable_privileged(); \
46 arch_futex_atomic_op_inuser(int op
, int oparg
, int *oval
, u32 __user
*_uaddr
)
48 int oldval
= 0, ret
, tmp
;
49 u32 __user
*uaddr
= __uaccess_mask_ptr(_uaddr
);
51 if (!access_ok(_uaddr
, sizeof(u32
)))
56 __futex_atomic_op("mov %w3, %w5",
57 ret
, oldval
, uaddr
, tmp
, oparg
);
60 __futex_atomic_op("add %w3, %w1, %w5",
61 ret
, oldval
, uaddr
, tmp
, oparg
);
64 __futex_atomic_op("orr %w3, %w1, %w5",
65 ret
, oldval
, uaddr
, tmp
, oparg
);
68 __futex_atomic_op("and %w3, %w1, %w5",
69 ret
, oldval
, uaddr
, tmp
, ~oparg
);
72 __futex_atomic_op("eor %w3, %w1, %w5",
73 ret
, oldval
, uaddr
, tmp
, oparg
);
86 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*_uaddr
,
87 u32 oldval
, u32 newval
)
90 unsigned int loops
= FUTEX_MAX_LOOPS
;
94 if (!access_ok(_uaddr
, sizeof(u32
)))
97 uaddr
= __uaccess_mask_ptr(_uaddr
);
98 uaccess_enable_privileged();
99 asm volatile("// futex_atomic_cmpxchg_inatomic\n"
100 " prfm pstl1strm, %2\n"
102 " sub %w3, %w1, %w5\n"
104 "2: stlxr %w3, %w6, %2\n"
106 " sub %w4, %w4, %w3\n"
112 " .pushsection .fixup,\"ax\"\n"
118 : "+r" (ret
), "=&r" (val
), "+Q" (*uaddr
), "=&r" (tmp
), "+r" (loops
)
119 : "r" (oldval
), "r" (newval
), "Ir" (-EFAULT
), "Ir" (-EAGAIN
)
121 uaccess_disable_privileged();
129 #endif /* __ASM_FUTEX_H */