2019-05-19 20:08:55 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2016-07-11 23:36:41 +08:00
|
|
|
/* Copyright 2002 Andi Kleen */
|
|
|
|
|
|
|
|
#include <linux/linkage.h>
|
|
|
|
#include <asm/errno.h>
|
|
|
|
#include <asm/cpufeatures.h>
|
2021-05-09 21:19:37 +08:00
|
|
|
#include <asm/alternative.h>
|
tools/headers: Synchronize kernel ABI headers
After the SPDX license tags were added a number of tooling headers got out of
sync with their kernel variants, generating lots of build warnings.
Sync them:
- tools/arch/x86/include/asm/disabled-features.h,
tools/arch/x86/include/asm/required-features.h,
tools/include/linux/hash.h:
Remove the SPDX tag where the kernel version does not have it.
- tools/include/asm-generic/bitops/__fls.h,
tools/include/asm-generic/bitops/arch_hweight.h,
tools/include/asm-generic/bitops/const_hweight.h,
tools/include/asm-generic/bitops/fls.h,
tools/include/asm-generic/bitops/fls64.h,
tools/include/uapi/asm-generic/ioctls.h,
tools/include/uapi/asm-generic/mman-common.h,
tools/include/uapi/sound/asound.h,
tools/include/uapi/linux/kvm.h,
tools/include/uapi/linux/perf_event.h,
tools/include/uapi/linux/sched.h,
tools/include/uapi/linux/vhost.h,
tools/include/uapi/sound/asound.h:
Add the SPDX tag of the respective kernel header.
- tools/include/uapi/linux/bpf_common.h,
tools/include/uapi/linux/fcntl.h,
tools/include/uapi/linux/hw_breakpoint.h,
tools/include/uapi/linux/mman.h,
tools/include/uapi/linux/stat.h,
Change the tag to the kernel header version:
-/* SPDX-License-Identifier: GPL-2.0 */
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
Also sync other header details:
- include/uapi/sound/asound.h:
Fix pointless end of line whitespace noise the header grew in this cycle.
- tools/arch/x86/lib/memcpy_64.S:
Sync the code and add tools/include/asm/export.h with dummy wrappers
to support building the kernel side code in a tooling header environment.
- tools/include/uapi/asm-generic/mman.h,
tools/include/uapi/linux/bpf.h:
Sync other details that don't impact tooling's use of the ABIs.
Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-11-03 19:18:37 +08:00
|
|
|
#include <asm/export.h>
|
2016-07-11 23:36:41 +08:00
|
|
|
|
2020-07-03 19:11:16 +08:00
|
|
|
.pushsection .noinstr.text, "ax"
|
|
|
|
|
2016-07-11 23:36:41 +08:00
|
|
|
/*
|
|
|
|
* We build a jump to memcpy_orig by default which gets NOPped out on
|
|
|
|
* the majority of x86 CPUs which set REP_GOOD. In addition, CPUs which
|
|
|
|
* have the enhanced REP MOVSB/STOSB feature (ERMS), change those NOPs
|
|
|
|
* to a jmp to memcpy_erms which does the REP; MOVSB mem copy.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* memcpy - Copy a memory block.
|
|
|
|
*
|
|
|
|
* Input:
|
|
|
|
* rdi destination
|
|
|
|
* rsi source
|
|
|
|
* rdx count
|
|
|
|
*
|
|
|
|
* Output:
|
|
|
|
* rax original destination
|
|
|
|
*/
|
2019-12-02 22:40:57 +08:00
|
|
|
SYM_FUNC_START_ALIAS(__memcpy)
|
2020-11-10 00:59:15 +08:00
|
|
|
SYM_FUNC_START_WEAK(memcpy)
|
2016-07-11 23:36:41 +08:00
|
|
|
ALTERNATIVE_2 "jmp memcpy_orig", "", X86_FEATURE_REP_GOOD, \
|
|
|
|
"jmp memcpy_erms", X86_FEATURE_ERMS
|
|
|
|
|
|
|
|
movq %rdi, %rax
|
|
|
|
movq %rdx, %rcx
|
|
|
|
shrq $3, %rcx
|
|
|
|
andl $7, %edx
|
|
|
|
rep movsq
|
|
|
|
movl %edx, %ecx
|
|
|
|
rep movsb
|
|
|
|
ret
|
2019-12-02 22:40:57 +08:00
|
|
|
SYM_FUNC_END(memcpy)
|
|
|
|
SYM_FUNC_END_ALIAS(__memcpy)
|
tools/headers: Synchronize kernel ABI headers
After the SPDX license tags were added a number of tooling headers got out of
sync with their kernel variants, generating lots of build warnings.
Sync them:
- tools/arch/x86/include/asm/disabled-features.h,
tools/arch/x86/include/asm/required-features.h,
tools/include/linux/hash.h:
Remove the SPDX tag where the kernel version does not have it.
- tools/include/asm-generic/bitops/__fls.h,
tools/include/asm-generic/bitops/arch_hweight.h,
tools/include/asm-generic/bitops/const_hweight.h,
tools/include/asm-generic/bitops/fls.h,
tools/include/asm-generic/bitops/fls64.h,
tools/include/uapi/asm-generic/ioctls.h,
tools/include/uapi/asm-generic/mman-common.h,
tools/include/uapi/sound/asound.h,
tools/include/uapi/linux/kvm.h,
tools/include/uapi/linux/perf_event.h,
tools/include/uapi/linux/sched.h,
tools/include/uapi/linux/vhost.h,
tools/include/uapi/sound/asound.h:
Add the SPDX tag of the respective kernel header.
- tools/include/uapi/linux/bpf_common.h,
tools/include/uapi/linux/fcntl.h,
tools/include/uapi/linux/hw_breakpoint.h,
tools/include/uapi/linux/mman.h,
tools/include/uapi/linux/stat.h,
Change the tag to the kernel header version:
-/* SPDX-License-Identifier: GPL-2.0 */
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
Also sync other header details:
- include/uapi/sound/asound.h:
Fix pointless end of line whitespace noise the header grew in this cycle.
- tools/arch/x86/lib/memcpy_64.S:
Sync the code and add tools/include/asm/export.h with dummy wrappers
to support building the kernel side code in a tooling header environment.
- tools/include/uapi/asm-generic/mman.h,
tools/include/uapi/linux/bpf.h:
Sync other details that don't impact tooling's use of the ABIs.
Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-11-03 19:18:37 +08:00
|
|
|
EXPORT_SYMBOL(memcpy)
|
|
|
|
EXPORT_SYMBOL(__memcpy)
|
2016-07-11 23:36:41 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* memcpy_erms() - enhanced fast string memcpy. This is faster and
|
|
|
|
* simpler than memcpy. Use memcpy_erms when possible.
|
|
|
|
*/
|
2020-11-10 00:59:15 +08:00
|
|
|
SYM_FUNC_START_LOCAL(memcpy_erms)
|
2016-07-11 23:36:41 +08:00
|
|
|
movq %rdi, %rax
|
|
|
|
movq %rdx, %rcx
|
|
|
|
rep movsb
|
|
|
|
ret
|
2019-12-02 22:40:57 +08:00
|
|
|
SYM_FUNC_END(memcpy_erms)
|
2016-07-11 23:36:41 +08:00
|
|
|
|
2020-11-10 00:59:15 +08:00
|
|
|
SYM_FUNC_START_LOCAL(memcpy_orig)
|
2016-07-11 23:36:41 +08:00
|
|
|
movq %rdi, %rax
|
|
|
|
|
|
|
|
cmpq $0x20, %rdx
|
|
|
|
jb .Lhandle_tail
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We check whether memory false dependence could occur,
|
|
|
|
* then jump to corresponding copy mode.
|
|
|
|
*/
|
|
|
|
cmp %dil, %sil
|
|
|
|
jl .Lcopy_backward
|
|
|
|
subq $0x20, %rdx
|
|
|
|
.Lcopy_forward_loop:
|
|
|
|
subq $0x20, %rdx
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Move in blocks of 4x8 bytes:
|
|
|
|
*/
|
|
|
|
movq 0*8(%rsi), %r8
|
|
|
|
movq 1*8(%rsi), %r9
|
|
|
|
movq 2*8(%rsi), %r10
|
|
|
|
movq 3*8(%rsi), %r11
|
|
|
|
leaq 4*8(%rsi), %rsi
|
|
|
|
|
|
|
|
movq %r8, 0*8(%rdi)
|
|
|
|
movq %r9, 1*8(%rdi)
|
|
|
|
movq %r10, 2*8(%rdi)
|
|
|
|
movq %r11, 3*8(%rdi)
|
|
|
|
leaq 4*8(%rdi), %rdi
|
|
|
|
jae .Lcopy_forward_loop
|
|
|
|
addl $0x20, %edx
|
|
|
|
jmp .Lhandle_tail
|
|
|
|
|
|
|
|
.Lcopy_backward:
|
|
|
|
/*
|
|
|
|
* Calculate copy position to tail.
|
|
|
|
*/
|
|
|
|
addq %rdx, %rsi
|
|
|
|
addq %rdx, %rdi
|
|
|
|
subq $0x20, %rdx
|
|
|
|
/*
|
|
|
|
* At most 3 ALU operations in one cycle,
|
|
|
|
* so append NOPS in the same 16 bytes trunk.
|
|
|
|
*/
|
|
|
|
.p2align 4
|
|
|
|
.Lcopy_backward_loop:
|
|
|
|
subq $0x20, %rdx
|
|
|
|
movq -1*8(%rsi), %r8
|
|
|
|
movq -2*8(%rsi), %r9
|
|
|
|
movq -3*8(%rsi), %r10
|
|
|
|
movq -4*8(%rsi), %r11
|
|
|
|
leaq -4*8(%rsi), %rsi
|
|
|
|
movq %r8, -1*8(%rdi)
|
|
|
|
movq %r9, -2*8(%rdi)
|
|
|
|
movq %r10, -3*8(%rdi)
|
|
|
|
movq %r11, -4*8(%rdi)
|
|
|
|
leaq -4*8(%rdi), %rdi
|
|
|
|
jae .Lcopy_backward_loop
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate copy position to head.
|
|
|
|
*/
|
|
|
|
addl $0x20, %edx
|
|
|
|
subq %rdx, %rsi
|
|
|
|
subq %rdx, %rdi
|
|
|
|
.Lhandle_tail:
|
|
|
|
cmpl $16, %edx
|
|
|
|
jb .Lless_16bytes
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Move data from 16 bytes to 31 bytes.
|
|
|
|
*/
|
|
|
|
movq 0*8(%rsi), %r8
|
|
|
|
movq 1*8(%rsi), %r9
|
|
|
|
movq -2*8(%rsi, %rdx), %r10
|
|
|
|
movq -1*8(%rsi, %rdx), %r11
|
|
|
|
movq %r8, 0*8(%rdi)
|
|
|
|
movq %r9, 1*8(%rdi)
|
|
|
|
movq %r10, -2*8(%rdi, %rdx)
|
|
|
|
movq %r11, -1*8(%rdi, %rdx)
|
|
|
|
retq
|
|
|
|
.p2align 4
|
|
|
|
.Lless_16bytes:
|
|
|
|
cmpl $8, %edx
|
|
|
|
jb .Lless_8bytes
|
|
|
|
/*
|
|
|
|
* Move data from 8 bytes to 15 bytes.
|
|
|
|
*/
|
|
|
|
movq 0*8(%rsi), %r8
|
|
|
|
movq -1*8(%rsi, %rdx), %r9
|
|
|
|
movq %r8, 0*8(%rdi)
|
|
|
|
movq %r9, -1*8(%rdi, %rdx)
|
|
|
|
retq
|
|
|
|
.p2align 4
|
|
|
|
.Lless_8bytes:
|
|
|
|
cmpl $4, %edx
|
|
|
|
jb .Lless_3bytes
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Move data from 4 bytes to 7 bytes.
|
|
|
|
*/
|
|
|
|
movl (%rsi), %ecx
|
|
|
|
movl -4(%rsi, %rdx), %r8d
|
|
|
|
movl %ecx, (%rdi)
|
|
|
|
movl %r8d, -4(%rdi, %rdx)
|
|
|
|
retq
|
|
|
|
.p2align 4
|
|
|
|
.Lless_3bytes:
|
|
|
|
subl $1, %edx
|
|
|
|
jb .Lend
|
|
|
|
/*
|
|
|
|
* Move data from 1 bytes to 3 bytes.
|
|
|
|
*/
|
|
|
|
movzbl (%rsi), %ecx
|
|
|
|
jz .Lstore_1byte
|
|
|
|
movzbq 1(%rsi), %r8
|
|
|
|
movzbq (%rsi, %rdx), %r9
|
|
|
|
movb %r8b, 1(%rdi)
|
|
|
|
movb %r9b, (%rdi, %rdx)
|
|
|
|
.Lstore_1byte:
|
|
|
|
movb %cl, (%rdi)
|
|
|
|
|
|
|
|
.Lend:
|
|
|
|
retq
|
2019-12-02 22:40:57 +08:00
|
|
|
SYM_FUNC_END(memcpy_orig)
|
2016-07-11 23:36:41 +08:00
|
|
|
|
2020-07-03 19:11:16 +08:00
|
|
|
.popsection
|