b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | #ifndef _ASM_S390_FUTEX_H |
| 3 | #define _ASM_S390_FUTEX_H |
| 4 | |
| 5 | #include <linux/uaccess.h> |
| 6 | #include <linux/futex.h> |
| 7 | #include <asm/mmu_context.h> |
| 8 | #include <asm/errno.h> |
| 9 | |
| 10 | #define __futex_atomic_op(insn, ret, oldval, newval, uaddr, oparg) \ |
| 11 | asm volatile( \ |
| 12 | " sacf 256\n" \ |
| 13 | "0: l %1,0(%6)\n" \ |
| 14 | "1:"insn \ |
| 15 | "2: cs %1,%2,0(%6)\n" \ |
| 16 | "3: jl 1b\n" \ |
| 17 | " lhi %0,0\n" \ |
| 18 | "4: sacf 768\n" \ |
| 19 | EX_TABLE(0b,4b) EX_TABLE(1b,4b) \ |
| 20 | EX_TABLE(2b,4b) EX_TABLE(3b,4b) \ |
| 21 | : "=d" (ret), "=&d" (oldval), "=&d" (newval), \ |
| 22 | "=m" (*uaddr) \ |
| 23 | : "0" (-EFAULT), "d" (oparg), "a" (uaddr), \ |
| 24 | "m" (*uaddr) : "cc"); |
| 25 | |
| 26 | static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval, |
| 27 | u32 __user *uaddr) |
| 28 | { |
| 29 | int oldval = 0, newval, ret; |
| 30 | mm_segment_t old_fs; |
| 31 | |
| 32 | old_fs = enable_sacf_uaccess(); |
| 33 | pagefault_disable(); |
| 34 | switch (op) { |
| 35 | case FUTEX_OP_SET: |
| 36 | __futex_atomic_op("lr %2,%5\n", |
| 37 | ret, oldval, newval, uaddr, oparg); |
| 38 | break; |
| 39 | case FUTEX_OP_ADD: |
| 40 | __futex_atomic_op("lr %2,%1\nar %2,%5\n", |
| 41 | ret, oldval, newval, uaddr, oparg); |
| 42 | break; |
| 43 | case FUTEX_OP_OR: |
| 44 | __futex_atomic_op("lr %2,%1\nor %2,%5\n", |
| 45 | ret, oldval, newval, uaddr, oparg); |
| 46 | break; |
| 47 | case FUTEX_OP_ANDN: |
| 48 | __futex_atomic_op("lr %2,%1\nnr %2,%5\n", |
| 49 | ret, oldval, newval, uaddr, oparg); |
| 50 | break; |
| 51 | case FUTEX_OP_XOR: |
| 52 | __futex_atomic_op("lr %2,%1\nxr %2,%5\n", |
| 53 | ret, oldval, newval, uaddr, oparg); |
| 54 | break; |
| 55 | default: |
| 56 | ret = -ENOSYS; |
| 57 | } |
| 58 | pagefault_enable(); |
| 59 | disable_sacf_uaccess(old_fs); |
| 60 | |
| 61 | if (!ret) |
| 62 | *oval = oldval; |
| 63 | |
| 64 | return ret; |
| 65 | } |
| 66 | |
| 67 | static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, |
| 68 | u32 oldval, u32 newval) |
| 69 | { |
| 70 | mm_segment_t old_fs; |
| 71 | int ret; |
| 72 | |
| 73 | old_fs = enable_sacf_uaccess(); |
| 74 | asm volatile( |
| 75 | " sacf 256\n" |
| 76 | "0: cs %1,%4,0(%5)\n" |
| 77 | "1: la %0,0\n" |
| 78 | "2: sacf 768\n" |
| 79 | EX_TABLE(0b,2b) EX_TABLE(1b,2b) |
| 80 | : "=d" (ret), "+d" (oldval), "=m" (*uaddr) |
| 81 | : "0" (-EFAULT), "d" (newval), "a" (uaddr), "m" (*uaddr) |
| 82 | : "cc", "memory"); |
| 83 | disable_sacf_uaccess(old_fs); |
| 84 | *uval = oldval; |
| 85 | return ret; |
| 86 | } |
| 87 | |
| 88 | #endif /* _ASM_S390_FUTEX_H */ |