Skip to content

Commit 02041b3

Browse files
jpoimboePeter Zijlstra
authored andcommitted
x86/uaccess: Don't jump between functions
For unwinding sanity, a function shouldn't jump to the middle of another function. Move the short string user copy code out to a separate non-function code snippet. Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/9519e4853148b765e047967708f2b61e56c93186.1649718562.git.jpoimboe@redhat.com
1 parent b2d229d commit 02041b3

File tree

1 file changed

+52
-35
lines changed

1 file changed

+52
-35
lines changed

arch/x86/lib/copy_user_64.S

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@
5353
SYM_FUNC_START(copy_user_generic_unrolled)
5454
ASM_STAC
5555
cmpl $8,%edx
56-
jb 20f /* less then 8 bytes, go to byte copy loop */
56+
jb .Lcopy_user_short_string_bytes
5757
ALIGN_DESTINATION
5858
movl %edx,%ecx
5959
andl $63,%edx
6060
shrl $6,%ecx
61-
jz .L_copy_short_string
61+
jz copy_user_short_string
6262
1: movq (%rsi),%r8
6363
2: movq 1*8(%rsi),%r9
6464
3: movq 2*8(%rsi),%r10
@@ -79,37 +79,11 @@ SYM_FUNC_START(copy_user_generic_unrolled)
7979
leaq 64(%rdi),%rdi
8080
decl %ecx
8181
jnz 1b
82-
.L_copy_short_string:
83-
movl %edx,%ecx
84-
andl $7,%edx
85-
shrl $3,%ecx
86-
jz 20f
87-
18: movq (%rsi),%r8
88-
19: movq %r8,(%rdi)
89-
leaq 8(%rsi),%rsi
90-
leaq 8(%rdi),%rdi
91-
decl %ecx
92-
jnz 18b
93-
20: andl %edx,%edx
94-
jz 23f
95-
movl %edx,%ecx
96-
21: movb (%rsi),%al
97-
22: movb %al,(%rdi)
98-
incq %rsi
99-
incq %rdi
100-
decl %ecx
101-
jnz 21b
102-
23: xor %eax,%eax
103-
ASM_CLAC
104-
RET
82+
jmp copy_user_short_string
10583

10684
30: shll $6,%ecx
10785
addl %ecx,%edx
108-
jmp 60f
109-
40: leal (%rdx,%rcx,8),%edx
110-
jmp 60f
111-
50: movl %ecx,%edx
112-
60: jmp .Lcopy_user_handle_tail /* ecx is zerorest also */
86+
jmp .Lcopy_user_handle_tail
11387

11488
_ASM_EXTABLE_CPY(1b, 30b)
11589
_ASM_EXTABLE_CPY(2b, 30b)
@@ -127,10 +101,6 @@ SYM_FUNC_START(copy_user_generic_unrolled)
127101
_ASM_EXTABLE_CPY(14b, 30b)
128102
_ASM_EXTABLE_CPY(15b, 30b)
129103
_ASM_EXTABLE_CPY(16b, 30b)
130-
_ASM_EXTABLE_CPY(18b, 40b)
131-
_ASM_EXTABLE_CPY(19b, 40b)
132-
_ASM_EXTABLE_CPY(21b, 50b)
133-
_ASM_EXTABLE_CPY(22b, 50b)
134104
SYM_FUNC_END(copy_user_generic_unrolled)
135105
EXPORT_SYMBOL(copy_user_generic_unrolled)
136106

@@ -191,7 +161,7 @@ EXPORT_SYMBOL(copy_user_generic_string)
191161
SYM_FUNC_START(copy_user_enhanced_fast_string)
192162
ASM_STAC
193163
/* CPUs without FSRM should avoid rep movsb for short copies */
194-
ALTERNATIVE "cmpl $64, %edx; jb .L_copy_short_string", "", X86_FEATURE_FSRM
164+
ALTERNATIVE "cmpl $64, %edx; jb copy_user_short_string", "", X86_FEATURE_FSRM
195165
movl %edx,%ecx
196166
1: rep movsb
197167
xorl %eax,%eax
@@ -243,6 +213,53 @@ SYM_CODE_START_LOCAL(.Lcopy_user_handle_tail)
243213

244214
SYM_CODE_END(.Lcopy_user_handle_tail)
245215

216+
/*
217+
* Finish memcpy of less than 64 bytes. #AC should already be set.
218+
*
219+
* Input:
220+
* rdi destination
221+
* rsi source
222+
* rdx count (< 64)
223+
*
224+
* Output:
225+
* eax uncopied bytes or 0 if successful.
226+
*/
227+
SYM_CODE_START_LOCAL(copy_user_short_string)
228+
movl %edx,%ecx
229+
andl $7,%edx
230+
shrl $3,%ecx
231+
jz .Lcopy_user_short_string_bytes
232+
18: movq (%rsi),%r8
233+
19: movq %r8,(%rdi)
234+
leaq 8(%rsi),%rsi
235+
leaq 8(%rdi),%rdi
236+
decl %ecx
237+
jnz 18b
238+
.Lcopy_user_short_string_bytes:
239+
andl %edx,%edx
240+
jz 23f
241+
movl %edx,%ecx
242+
21: movb (%rsi),%al
243+
22: movb %al,(%rdi)
244+
incq %rsi
245+
incq %rdi
246+
decl %ecx
247+
jnz 21b
248+
23: xor %eax,%eax
249+
ASM_CLAC
250+
RET
251+
252+
40: leal (%rdx,%rcx,8),%edx
253+
jmp 60f
254+
50: movl %ecx,%edx /* ecx is zerorest also */
255+
60: jmp .Lcopy_user_handle_tail
256+
257+
_ASM_EXTABLE_CPY(18b, 40b)
258+
_ASM_EXTABLE_CPY(19b, 40b)
259+
_ASM_EXTABLE_CPY(21b, 50b)
260+
_ASM_EXTABLE_CPY(22b, 50b)
261+
SYM_CODE_END(copy_user_short_string)
262+
246263
/*
247264
* copy_user_nocache - Uncached memory copy with exception handling
248265
* This will force destination out of cache for more performance.

0 commit comments

Comments
 (0)