blob: 6a4f43c2d9e6d6eea725f5141eb98d9b12935b48 [file] [log] [blame]
Vitaly Mayatskikhad2fc2c2008-07-02 15:53:13 +02001/*
2 * Copyright 2008 Vitaly Mayatskikh <vmayatsk@redhat.com>
3 * Copyright 2002 Andi Kleen, SuSE Labs.
Andi Kleen0812a572007-02-13 13:26:19 +01004 * Subject to the GNU Public License v2.
5 *
6 * Functions to copy from and to user space.
7 */
8
9#include <linux/linkage.h>
10#include <asm/dwarf2.h>
11
12#define FIX_ALIGNMENT 1
13
14#include <asm/current.h>
15#include <asm/asm-offsets.h>
16#include <asm/thread_info.h>
H. Peter Anvin0d8559f2012-04-20 12:19:51 -070017#include <asm/asm.h>
H. Peter Anvin63bcff22012-09-21 12:43:12 -070018#include <asm/smap.h>
Andi Kleen0812a572007-02-13 13:26:19 +010019
Vitaly Mayatskikhad2fc2c2008-07-02 15:53:13 +020020 .macro ALIGN_DESTINATION
Andi Kleen0812a572007-02-13 13:26:19 +010021#ifdef FIX_ALIGNMENT
22 /* check for bad alignment of destination */
23 movl %edi,%ecx
24 andl $7,%ecx
Vitaly Mayatskikhad2fc2c2008-07-02 15:53:13 +020025 jz 102f /* already aligned */
26 subl $8,%ecx
27 negl %ecx
28 subl %ecx,%edx
29100: movb (%rsi),%al
30101: movb %al,(%rdi)
Andi Kleen0812a572007-02-13 13:26:19 +010031 incq %rsi
32 incq %rdi
33 decl %ecx
Vitaly Mayatskikhad2fc2c2008-07-02 15:53:13 +020034 jnz 100b
35102:
36 .section .fixup,"ax"
Vitaly Mayatskikhafd962a2008-07-30 13:30:14 +020037103: addl %ecx,%edx /* ecx is zerorest also */
Vitaly Mayatskikhad2fc2c2008-07-02 15:53:13 +020038 jmp copy_user_handle_tail
Andi Kleen0812a572007-02-13 13:26:19 +010039 .previous
40
H. Peter Anvin0d8559f2012-04-20 12:19:51 -070041 _ASM_EXTABLE(100b,103b)
42 _ASM_EXTABLE(101b,103b)
Vitaly Mayatskikhad2fc2c2008-07-02 15:53:13 +020043#endif
44 .endm
Andi Kleen0812a572007-02-13 13:26:19 +010045
Vitaly Mayatskikhad2fc2c2008-07-02 15:53:13 +020046/*
47 * copy_user_nocache - Uncached memory copy with exception handling
48 * This will force destination/source out of cache for more performance.
49 */
50ENTRY(__copy_user_nocache)
51 CFI_STARTPROC
H. Peter Anvin63bcff22012-09-21 12:43:12 -070052 ASM_STAC
Vitaly Mayatskikhad2fc2c2008-07-02 15:53:13 +020053 cmpl $8,%edx
54 jb 20f /* less then 8 bytes, go to byte copy loop */
55 ALIGN_DESTINATION
56 movl %edx,%ecx
57 andl $63,%edx
58 shrl $6,%ecx
59 jz 17f
601: movq (%rsi),%r8
612: movq 1*8(%rsi),%r9
623: movq 2*8(%rsi),%r10
634: movq 3*8(%rsi),%r11
645: movnti %r8,(%rdi)
656: movnti %r9,1*8(%rdi)
667: movnti %r10,2*8(%rdi)
678: movnti %r11,3*8(%rdi)
689: movq 4*8(%rsi),%r8
6910: movq 5*8(%rsi),%r9
7011: movq 6*8(%rsi),%r10
7112: movq 7*8(%rsi),%r11
7213: movnti %r8,4*8(%rdi)
7314: movnti %r9,5*8(%rdi)
7415: movnti %r10,6*8(%rdi)
7516: movnti %r11,7*8(%rdi)
76 leaq 64(%rsi),%rsi
77 leaq 64(%rdi),%rdi
78 decl %ecx
79 jnz 1b
8017: movl %edx,%ecx
Andi Kleen0812a572007-02-13 13:26:19 +010081 andl $7,%edx
Vitaly Mayatskikhad2fc2c2008-07-02 15:53:13 +020082 shrl $3,%ecx
83 jz 20f
8418: movq (%rsi),%r8
8519: movnti %r8,(%rdi)
86 leaq 8(%rsi),%rsi
87 leaq 8(%rdi),%rdi
88 decl %ecx
89 jnz 18b
9020: andl %edx,%edx
91 jz 23f
92 movl %edx,%ecx
9321: movb (%rsi),%al
9422: movb %al,(%rdi)
95 incq %rsi
96 incq %rdi
97 decl %ecx
98 jnz 21b
9923: xorl %eax,%eax
H. Peter Anvin63bcff22012-09-21 12:43:12 -0700100 ASM_CLAC
Vitaly Mayatskikhad2fc2c2008-07-02 15:53:13 +0200101 sfence
102 ret
103
104 .section .fixup,"ax"
10530: shll $6,%ecx
Andi Kleen0812a572007-02-13 13:26:19 +0100106 addl %ecx,%edx
Vitaly Mayatskikhad2fc2c2008-07-02 15:53:13 +0200107 jmp 60f
Jeremy Fitzhardinge27cb0a72008-07-10 12:52:52 -070010840: lea (%rdx,%rcx,8),%rdx
Vitaly Mayatskikhad2fc2c2008-07-02 15:53:13 +0200109 jmp 60f
11050: movl %ecx,%edx
11160: sfence
Vitaly Mayatskikhad2fc2c2008-07-02 15:53:13 +0200112 jmp copy_user_handle_tail
113 .previous
114
H. Peter Anvin0d8559f2012-04-20 12:19:51 -0700115 _ASM_EXTABLE(1b,30b)
116 _ASM_EXTABLE(2b,30b)
117 _ASM_EXTABLE(3b,30b)
118 _ASM_EXTABLE(4b,30b)
119 _ASM_EXTABLE(5b,30b)
120 _ASM_EXTABLE(6b,30b)
121 _ASM_EXTABLE(7b,30b)
122 _ASM_EXTABLE(8b,30b)
123 _ASM_EXTABLE(9b,30b)
124 _ASM_EXTABLE(10b,30b)
125 _ASM_EXTABLE(11b,30b)
126 _ASM_EXTABLE(12b,30b)
127 _ASM_EXTABLE(13b,30b)
128 _ASM_EXTABLE(14b,30b)
129 _ASM_EXTABLE(15b,30b)
130 _ASM_EXTABLE(16b,30b)
131 _ASM_EXTABLE(18b,40b)
132 _ASM_EXTABLE(19b,40b)
133 _ASM_EXTABLE(21b,50b)
134 _ASM_EXTABLE(22b,50b)
Andi Kleen0812a572007-02-13 13:26:19 +0100135 CFI_ENDPROC
136ENDPROC(__copy_user_nocache)