blob: 0ea344c5ea439c6d323425e95fd1c44aaaa0414d [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/* 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 *
Olivier Deprez157378f2022-04-04 15:47:50 +020028 * Outputs: %ecx is error code (0 or -EFAULT)
29 *
30 * Clobbers: %ebx needed for task pointer
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000031 *
32 * These functions should not modify any other registers,
33 * as they get called from within inline assembly.
34 */
35
Olivier Deprez157378f2022-04-04 15:47:50 +020036#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
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000044
45.text
Olivier Deprez157378f2022-04-04 15:47:50 +020046SYM_FUNC_START(__put_user_1)
47 LOAD_TASK_SIZE_MINUS_N(0)
48 cmp %_ASM_BX,%_ASM_CX
David Brazdil0f672f62019-12-10 10:32:29 +000049 jae .Lbad_put_user
Olivier Deprez157378f2022-04-04 15:47:50 +020050SYM_INNER_LABEL(__put_user_nocheck_1, SYM_L_GLOBAL)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000051 ASM_STAC
521: movb %al,(%_ASM_CX)
Olivier Deprez157378f2022-04-04 15:47:50 +020053 xor %ecx,%ecx
David Brazdil0f672f62019-12-10 10:32:29 +000054 ASM_CLAC
55 ret
Olivier Deprez157378f2022-04-04 15:47:50 +020056SYM_FUNC_END(__put_user_1)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000057EXPORT_SYMBOL(__put_user_1)
Olivier Deprez157378f2022-04-04 15:47:50 +020058EXPORT_SYMBOL(__put_user_nocheck_1)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000059
Olivier Deprez157378f2022-04-04 15:47:50 +020060SYM_FUNC_START(__put_user_2)
61 LOAD_TASK_SIZE_MINUS_N(1)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000062 cmp %_ASM_BX,%_ASM_CX
David Brazdil0f672f62019-12-10 10:32:29 +000063 jae .Lbad_put_user
Olivier Deprez157378f2022-04-04 15:47:50 +020064SYM_INNER_LABEL(__put_user_nocheck_2, SYM_L_GLOBAL)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000065 ASM_STAC
662: movw %ax,(%_ASM_CX)
Olivier Deprez157378f2022-04-04 15:47:50 +020067 xor %ecx,%ecx
David Brazdil0f672f62019-12-10 10:32:29 +000068 ASM_CLAC
69 ret
Olivier Deprez157378f2022-04-04 15:47:50 +020070SYM_FUNC_END(__put_user_2)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000071EXPORT_SYMBOL(__put_user_2)
Olivier Deprez157378f2022-04-04 15:47:50 +020072EXPORT_SYMBOL(__put_user_nocheck_2)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000073
Olivier Deprez157378f2022-04-04 15:47:50 +020074SYM_FUNC_START(__put_user_4)
75 LOAD_TASK_SIZE_MINUS_N(3)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000076 cmp %_ASM_BX,%_ASM_CX
David Brazdil0f672f62019-12-10 10:32:29 +000077 jae .Lbad_put_user
Olivier Deprez157378f2022-04-04 15:47:50 +020078SYM_INNER_LABEL(__put_user_nocheck_4, SYM_L_GLOBAL)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000079 ASM_STAC
803: movl %eax,(%_ASM_CX)
Olivier Deprez157378f2022-04-04 15:47:50 +020081 xor %ecx,%ecx
David Brazdil0f672f62019-12-10 10:32:29 +000082 ASM_CLAC
83 ret
Olivier Deprez157378f2022-04-04 15:47:50 +020084SYM_FUNC_END(__put_user_4)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000085EXPORT_SYMBOL(__put_user_4)
Olivier Deprez157378f2022-04-04 15:47:50 +020086EXPORT_SYMBOL(__put_user_nocheck_4)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000087
Olivier Deprez157378f2022-04-04 15:47:50 +020088SYM_FUNC_START(__put_user_8)
89 LOAD_TASK_SIZE_MINUS_N(7)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000090 cmp %_ASM_BX,%_ASM_CX
David Brazdil0f672f62019-12-10 10:32:29 +000091 jae .Lbad_put_user
Olivier Deprez157378f2022-04-04 15:47:50 +020092SYM_INNER_LABEL(__put_user_nocheck_8, SYM_L_GLOBAL)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000093 ASM_STAC
944: mov %_ASM_AX,(%_ASM_CX)
95#ifdef CONFIG_X86_32
965: movl %edx,4(%_ASM_CX)
97#endif
Olivier Deprez157378f2022-04-04 15:47:50 +020098 xor %ecx,%ecx
David Brazdil0f672f62019-12-10 10:32:29 +000099 ASM_CLAC
100 RET
Olivier Deprez157378f2022-04-04 15:47:50 +0200101SYM_FUNC_END(__put_user_8)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000102EXPORT_SYMBOL(__put_user_8)
Olivier Deprez157378f2022-04-04 15:47:50 +0200103EXPORT_SYMBOL(__put_user_nocheck_8)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000104
Olivier Deprez157378f2022-04-04 15:47:50 +0200105SYM_CODE_START_LOCAL(.Lbad_put_user_clac)
David Brazdil0f672f62019-12-10 10:32:29 +0000106 ASM_CLAC
107.Lbad_put_user:
Olivier Deprez157378f2022-04-04 15:47:50 +0200108 movl $-EFAULT,%ecx
David Brazdil0f672f62019-12-10 10:32:29 +0000109 RET
Olivier Deprez157378f2022-04-04 15:47:50 +0200110SYM_CODE_END(.Lbad_put_user_clac)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000111
David Brazdil0f672f62019-12-10 10:32:29 +0000112 _ASM_EXTABLE_UA(1b, .Lbad_put_user_clac)
113 _ASM_EXTABLE_UA(2b, .Lbad_put_user_clac)
114 _ASM_EXTABLE_UA(3b, .Lbad_put_user_clac)
115 _ASM_EXTABLE_UA(4b, .Lbad_put_user_clac)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000116#ifdef CONFIG_X86_32
David Brazdil0f672f62019-12-10 10:32:29 +0000117 _ASM_EXTABLE_UA(5b, .Lbad_put_user_clac)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000118#endif