1/* SPDX-License-Identifier: GPL-2.0 */ 2/* 3 * __put_user functions. 4 * 5 * (C) Copyright 2005 Linus Torvalds 6 * (C) Copyright 2005 Andi Kleen 7 * (C) Copyright 2008 Glauber Costa 8 * 9 * These functions have a non-standard call interface 10 * to make them more efficient, especially as they 11 * return an error value in addition to the "real" 12 * return value. 13 */ 14#include <linux/linkage.h> 15#include <asm/thread_info.h> 16#include <asm/errno.h> 17#include <asm/asm.h> 18#include <asm/smap.h> 19#include <asm/export.h> 20 21 22/* 23 * __put_user_X 24 * 25 * Inputs: %eax[:%edx] contains the data 26 * %ecx contains the address 27 * 28 * Outputs: %ecx is error code (0 or -EFAULT) 29 * 30 * Clobbers: %ebx needed for task pointer 31 * 32 * These functions should not modify any other registers, 33 * as they get called from within inline assembly. 34 */ 35 36#ifdef CONFIG_X86_5LEVEL 37#define LOAD_TASK_SIZE_MINUS_N(n) \ 38 ALTERNATIVE __stringify(mov $((1 << 47) - 4096 - (n)),%rbx), \ 39 __stringify(mov $((1 << 56) - 4096 - (n)),%rbx), X86_FEATURE_LA57 40#else 41#define LOAD_TASK_SIZE_MINUS_N(n) \ 42 mov $(TASK_SIZE_MAX - (n)),%_ASM_BX 43#endif 44 45.text 46SYM_FUNC_START(__put_user_1) 47 LOAD_TASK_SIZE_MINUS_N(0) 48 cmp %_ASM_BX,%_ASM_CX 49 jae .Lbad_put_user 50SYM_INNER_LABEL(__put_user_nocheck_1, SYM_L_GLOBAL) 51 ENDBR 52 ASM_STAC 531: movb %al,(%_ASM_CX) 54 xor %ecx,%ecx 55 ASM_CLAC 56 RET 57SYM_FUNC_END(__put_user_1) 58EXPORT_SYMBOL(__put_user_1) 59EXPORT_SYMBOL(__put_user_nocheck_1) 60 61SYM_FUNC_START(__put_user_2) 62 LOAD_TASK_SIZE_MINUS_N(1) 63 cmp %_ASM_BX,%_ASM_CX 64 jae .Lbad_put_user 65SYM_INNER_LABEL(__put_user_nocheck_2, SYM_L_GLOBAL) 66 ENDBR 67 ASM_STAC 682: movw %ax,(%_ASM_CX) 69 xor %ecx,%ecx 70 ASM_CLAC 71 RET 72SYM_FUNC_END(__put_user_2) 73EXPORT_SYMBOL(__put_user_2) 74EXPORT_SYMBOL(__put_user_nocheck_2) 75 76SYM_FUNC_START(__put_user_4) 77 LOAD_TASK_SIZE_MINUS_N(3) 78 cmp %_ASM_BX,%_ASM_CX 79 jae .Lbad_put_user 80SYM_INNER_LABEL(__put_user_nocheck_4, SYM_L_GLOBAL) 81 ENDBR 82 ASM_STAC 833: movl %eax,(%_ASM_CX) 84 xor %ecx,%ecx 85 ASM_CLAC 86 RET 87SYM_FUNC_END(__put_user_4) 88EXPORT_SYMBOL(__put_user_4) 89EXPORT_SYMBOL(__put_user_nocheck_4) 90 91SYM_FUNC_START(__put_user_8) 92 LOAD_TASK_SIZE_MINUS_N(7) 93 cmp %_ASM_BX,%_ASM_CX 94 jae .Lbad_put_user 95SYM_INNER_LABEL(__put_user_nocheck_8, SYM_L_GLOBAL) 96 ENDBR 97 ASM_STAC 984: mov %_ASM_AX,(%_ASM_CX) 99#ifdef CONFIG_X86_32 1005: movl %edx,4(%_ASM_CX) 101#endif 102 xor %ecx,%ecx 103 ASM_CLAC 104 RET 105SYM_FUNC_END(__put_user_8) 106EXPORT_SYMBOL(__put_user_8) 107EXPORT_SYMBOL(__put_user_nocheck_8) 108 109SYM_CODE_START_LOCAL(.Lbad_put_user_clac) 110 ASM_CLAC 111.Lbad_put_user: 112 movl $-EFAULT,%ecx 113 RET 114SYM_CODE_END(.Lbad_put_user_clac) 115 116 _ASM_EXTABLE_UA(1b, .Lbad_put_user_clac) 117 _ASM_EXTABLE_UA(2b, .Lbad_put_user_clac) 118 _ASM_EXTABLE_UA(3b, .Lbad_put_user_clac) 119 _ASM_EXTABLE_UA(4b, .Lbad_put_user_clac) 120#ifdef CONFIG_X86_32 121 _ASM_EXTABLE_UA(5b, .Lbad_put_user_clac) 122#endif 123