1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #include <linux/linkage.h>
4 #include <asm/export.h>
7 * Most CPUs support enhanced REP MOVSB/STOSB instructions. It is
8 * recommended to use this when possible and we do use them by default.
9 * If enhanced REP MOVSB/STOSB is not available, try to use fast string.
10 * Otherwise, use original.
17 SYM_FUNC_START(clear_page_rep)
22 SYM_FUNC_END(clear_page_rep)
23 EXPORT_SYMBOL_GPL(clear_page_rep)
25 SYM_FUNC_START(clear_page_orig)
31 #define PUT(x) movq %rax,x*8(%rdi)
44 SYM_FUNC_END(clear_page_orig)
45 EXPORT_SYMBOL_GPL(clear_page_orig)
47 SYM_FUNC_START(clear_page_erms)
52 SYM_FUNC_END(clear_page_erms)
53 EXPORT_SYMBOL_GPL(clear_page_erms)
56 * Default clear user-space.
62 * rcx: uncleared bytes or 0 if successful.
64 SYM_FUNC_START(clear_user_original)
66 * Copy only the lower 32 bits of size as that is enough to handle the rest bytes,
67 * i.e., no need for a 'q' suffix and thus a REX prefix.
85 # now do the rest bytes
94 * %rax still needs to be cleared in the exception case because this function is called
95 * from inline asm and the compiler expects %rax to be zero when exiting the inline asm,
96 * in case it might reuse it somewhere.
102 # convert remaining qwords back into bytes to return to caller
112 _ASM_EXTABLE_UA(.Lqwords, .Lqwords_exception)
113 _ASM_EXTABLE_UA(.Lbytes, .Lbytes_exception)
114 SYM_FUNC_END(clear_user_original)
115 EXPORT_SYMBOL(clear_user_original)
118 * Alternative clear user-space when CPU feature X86_FEATURE_REP_GOOD is
125 * rcx: uncleared bytes or 0 if successful.
127 SYM_FUNC_START(clear_user_rep_good)
128 # call the original thing for less than a cacheline
130 jb clear_user_original
133 # copy lower 32-bits for rest bytes
136 jz .Lrep_good_rest_bytes
141 .Lrep_good_rest_bytes:
150 # see .Lexit comment above
154 .Lrep_good_qwords_exception:
155 # convert remaining qwords back into bytes to return to caller
161 _ASM_EXTABLE_UA(.Lrep_good_qwords, .Lrep_good_qwords_exception)
162 _ASM_EXTABLE_UA(.Lrep_good_bytes, .Lrep_good_exit)
163 SYM_FUNC_END(clear_user_rep_good)
164 EXPORT_SYMBOL(clear_user_rep_good)
167 * Alternative clear user-space when CPU feature X86_FEATURE_ERMS is present.
173 * rcx: uncleared bytes or 0 if successful.
176 SYM_FUNC_START(clear_user_erms)
177 # call the original thing for less than a cacheline
179 jb clear_user_original
188 _ASM_EXTABLE_UA(.Lerms_bytes, .Lerms_exit)
189 SYM_FUNC_END(clear_user_erms)
190 EXPORT_SYMBOL(clear_user_erms)