1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright 2008 Vitaly Mayatskikh <vmayatsk@redhat.com>
4 * Copyright 2002 Andi Kleen, SuSE Labs.
6 * Functions to copy from and to user space.
9 #include <linux/export.h>
10 #include <linux/linkage.h>
11 #include <asm/cpufeatures.h>
12 #include <asm/alternative.h>
16 * rep_movs_alternative - memory copy with exception handling.
17 * This version is for CPUs that don't have FSRM (Fast Short Rep Movs)
25 * rcx uncopied bytes or 0 if successful.
27 * NOTE! The calling convention is very intentionally the same as
28 * for 'rep movs', so that we can rewrite the function call with
29 * just a plain 'rep movs' on machines that have FSRM. But to make
30 * it simpler for us, we can clobber rsi/rdi and rax freely.
32 SYM_FUNC_START(rep_movs_alternative)
52 _ASM_EXTABLE_UA( 0b, .Lexit)
53 _ASM_EXTABLE_UA( 1b, .Lexit)
67 _ASM_EXTABLE_UA( 2b, .Lcopy_user_tail)
68 _ASM_EXTABLE_UA( 3b, .Lcopy_user_tail)
71 0: ALTERNATIVE "jmp .Llarge_movsq", "rep movsb", X86_FEATURE_ERMS
74 _ASM_EXTABLE_UA( 0b, 1b)
86 1: leaq (%rax,%rcx,8),%rcx
89 _ASM_EXTABLE_UA( 0b, 1b)
90 SYM_FUNC_END(rep_movs_alternative)
91 EXPORT_SYMBOL(rep_movs_alternative)