1 /* SPDX-License-Identifier: GPL-2.0 */ 1 2 #ifndef _ASM_X86_FUTEX_H 3 #define _ASM_X86_FUTEX_H 4 5 #ifdef __KERNEL__ 6 7 #include <linux/futex.h> 8 #include <linux/uaccess.h> 9 10 #include <asm/asm.h> 11 #include <asm/errno.h> 12 #include <asm/processor.h> 13 #include <asm/smap.h> 14 15 #define unsafe_atomic_op1(insn, oval, uaddr, o 16 do { 17 int oldval = 0, ret; 18 asm volatile("1:\t" insn "\n" 19 "2:\n" 20 _ASM_EXTABLE_TYPE_REG(1b, 21 : "=r" (oldval), "=r" (re 22 : "" (oparg), "1" (0)); 23 if (ret) 24 goto label; 25 *oval = oldval; 26 } while(0) 27 28 29 #define unsafe_atomic_op2(insn, oval, uaddr, o 30 do { 31 int oldval = 0, ret, tem; 32 asm volatile("1:\tmovl %2, %0\n" 33 "2:\tmovl\t%0, %3\n" 34 "\t" insn "\n" 35 "3:\t" LOCK_PREFIX "cmpxc 36 "\tjnz\t2b\n" 37 "4:\n" 38 _ASM_EXTABLE_TYPE_REG(1b, 39 _ASM_EXTABLE_TYPE_REG(3b, 40 : "=&a" (oldval), "=&r" ( 41 "+m" (*uaddr), "=&r" (t 42 : "r" (oparg), "1" (0)); 43 if (ret) 44 goto label; 45 *oval = oldval; 46 } while(0) 47 48 static __always_inline int arch_futex_atomic_o 49 u32 __user *uaddr) 50 { 51 if (!user_access_begin(uaddr, sizeof(u 52 return -EFAULT; 53 54 switch (op) { 55 case FUTEX_OP_SET: 56 unsafe_atomic_op1("xchgl %0, % 57 break; 58 case FUTEX_OP_ADD: 59 unsafe_atomic_op1(LOCK_PREFIX 60 uaddr, opar 61 break; 62 case FUTEX_OP_OR: 63 unsafe_atomic_op2("orl %4, %3" 64 break; 65 case FUTEX_OP_ANDN: 66 unsafe_atomic_op2("andl %4, %3 67 break; 68 case FUTEX_OP_XOR: 69 unsafe_atomic_op2("xorl %4, %3 70 break; 71 default: 72 user_access_end(); 73 return -ENOSYS; 74 } 75 user_access_end(); 76 return 0; 77 Efault: 78 user_access_end(); 79 return -EFAULT; 80 } 81 82 static inline int futex_atomic_cmpxchg_inatomi 83 84 { 85 int ret = 0; 86 87 if (!user_access_begin(uaddr, sizeof(u 88 return -EFAULT; 89 asm volatile("\n" 90 "1:\t" LOCK_PREFIX "cmpxchgl % 91 "2:\n" 92 _ASM_EXTABLE_TYPE_REG(1b, 2b, 93 : "+r" (ret), "=a" (oldval), " 94 : "r" (newval), "1" (oldval) 95 : "memory" 96 ); 97 user_access_end(); 98 *uval = oldval; 99 return ret; 100 } 101 102 #endif 103 #endif /* _ASM_X86_FUTEX_H */ 104
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.