1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_ARM_FUTEX_H
3 #define _ASM_ARM_FUTEX_H
7 #include <linux/futex.h>
8 #include <linux/uaccess.h>
11 #define __futex_atomic_ex_table(err_reg) \
13 " .pushsection __ex_table,\"a\"\n" \
15 " .long 1b, 4f, 2b, 4f\n" \
17 " .pushsection .text.fixup,\"ax\"\n" \
19 "4: mov %0, " err_reg "\n" \
25 #define __futex_atomic_op(insn, ret, oldval, tmp, uaddr, oparg) \
27 unsigned int __ua_flags; \
30 __ua_flags = uaccess_save_and_enable(); \
31 __asm__ __volatile__( \
32 "1: ldrex %1, [%3]\n" \
34 "2: strex %2, %0, [%3]\n" \
38 __futex_atomic_ex_table("%5") \
39 : "=&r" (ret), "=&r" (oldval), "=&r" (tmp) \
40 : "r" (uaddr), "r" (oparg), "Ir" (-EFAULT) \
42 uaccess_restore(__ua_flags); \
46 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
,
47 u32 oldval
, u32 newval
)
49 unsigned int __ua_flags
;
53 if (!access_ok(uaddr
, sizeof(u32
)))
57 /* Prefetching cannot fault */
59 __ua_flags
= uaccess_save_and_enable();
60 __asm__
__volatile__("@futex_atomic_cmpxchg_inatomic\n"
63 " ite eq @ explicit IT needed for the 2b label\n"
64 "2: strexeq %0, %3, [%4]\n"
68 __futex_atomic_ex_table("%5")
69 : "=&r" (ret
), "=&r" (val
)
70 : "r" (oldval
), "r" (newval
), "r" (uaddr
), "Ir" (-EFAULT
)
72 uaccess_restore(__ua_flags
);
79 #else /* !SMP, we can work around lack of atomic ops by disabling preemption */
81 #include <linux/preempt.h>
82 #include <asm/domain.h>
84 #define __futex_atomic_op(insn, ret, oldval, tmp, uaddr, oparg) \
86 unsigned int __ua_flags = uaccess_save_and_enable(); \
87 __asm__ __volatile__( \
88 "1: " TUSER(ldr) " %1, [%3]\n" \
90 "2: " TUSER(str) " %0, [%3]\n" \
92 __futex_atomic_ex_table("%5") \
93 : "=&r" (ret), "=&r" (oldval), "=&r" (tmp) \
94 : "r" (uaddr), "r" (oparg), "Ir" (-EFAULT) \
96 uaccess_restore(__ua_flags); \
100 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
,
101 u32 oldval
, u32 newval
)
103 unsigned int __ua_flags
;
107 if (!access_ok(uaddr
, sizeof(u32
)))
111 __ua_flags
= uaccess_save_and_enable();
112 __asm__
__volatile__("@futex_atomic_cmpxchg_inatomic\n"
114 "1: " TUSER(ldr
) " %1, [%4]\n"
116 " it eq @ explicit IT needed for the 2b label\n"
117 "2: " TUSERCOND(str
, eq
) " %3, [%4]\n"
118 __futex_atomic_ex_table("%5")
119 : "+r" (ret
), "=&r" (val
)
120 : "r" (oldval
), "r" (newval
), "r" (uaddr
), "Ir" (-EFAULT
)
122 uaccess_restore(__ua_flags
);
133 arch_futex_atomic_op_inuser(int op
, int oparg
, int *oval
, u32 __user
*uaddr
)
135 int oldval
= 0, ret
, tmp
;
137 if (!access_ok(uaddr
, sizeof(u32
)))
146 __futex_atomic_op("mov %0, %4", ret
, oldval
, tmp
, uaddr
, oparg
);
149 __futex_atomic_op("add %0, %1, %4", ret
, oldval
, tmp
, uaddr
, oparg
);
152 __futex_atomic_op("orr %0, %1, %4", ret
, oldval
, tmp
, uaddr
, oparg
);
155 __futex_atomic_op("and %0, %1, %4", ret
, oldval
, tmp
, uaddr
, ~oparg
);
158 __futex_atomic_op("eor %0, %1, %4", ret
, oldval
, tmp
, uaddr
, oparg
);
169 * Store unconditionally. If ret != 0 the extra store is the least
170 * of the worries but GCC cannot figure out that __futex_atomic_op()
171 * is either setting ret to -EFAULT or storing the old value in
172 * oldval which results in a uninitialized warning at the call site.
179 #endif /* __KERNEL__ */
180 #endif /* _ASM_ARM_FUTEX_H */