Skip to content

Commit e47e717

Browse files
Paolo Abenigregkh
authored andcommitted
x86/uaccess: Optimize copy_user_enhanced_fast_string() for short strings
commit 236222d39347e0e486010f10c1493e83dbbdfba8 upstream. According to the Intel datasheet, the REP MOVSB instruction exposes a pretty heavy setup cost (50 ticks), which hurts short string copy operations. This change tries to avoid this cost by calling the explicit loop available in the unrolled code for strings shorter than 64 bytes. The 64 bytes cutoff value is arbitrary from the code logic point of view - it has been selected based on measurements, as the largest value that still ensures a measurable gain. Micro benchmarks of the __copy_from_user() function with lengths in the [0-63] range show this performance gain (shorter the string, larger the gain): - in the [55%-4%] range on Intel Xeon(R) CPU E5-2690 v4 - in the [72%-9%] range on Intel Core i7-4810MQ Other tested CPUs - namely Intel Atom S1260 and AMD Opteron 8216 - show no difference, because they do not expose the ERMS feature bit. Signed-off-by: Paolo Abeni <pabeni@redhat.com> Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Cc: Alan Cox <gnomes@lxorguk.ukuu.org.uk> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Hannes Frederic Sowa <hannes@stressinduktion.org> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Kees Cook <keescook@chromium.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/4533a1d101fd460f80e21329a34928fad521c1d4.1498744345.git.pabeni@redhat.com [ Clarified the changelog. ] Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mel Gorman <mgorman@techsingularity.net>
1 parent 0214a8c commit e47e717

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

arch/x86/lib/copy_user_64.S

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ ENTRY(copy_user_generic_unrolled)
8080
movl %edx,%ecx
8181
andl $63,%edx
8282
shrl $6,%ecx
83-
jz 17f
83+
jz .L_copy_short_string
8484
1: movq (%rsi),%r8
8585
2: movq 1*8(%rsi),%r9
8686
3: movq 2*8(%rsi),%r10
@@ -101,7 +101,8 @@ ENTRY(copy_user_generic_unrolled)
101101
leaq 64(%rdi),%rdi
102102
decl %ecx
103103
jnz 1b
104-
17: movl %edx,%ecx
104+
.L_copy_short_string:
105+
movl %edx,%ecx
105106
andl $7,%edx
106107
shrl $3,%ecx
107108
jz 20f
@@ -215,6 +216,8 @@ ENDPROC(copy_user_generic_string)
215216
*/
216217
ENTRY(copy_user_enhanced_fast_string)
217218
ASM_STAC
219+
cmpl $64,%edx
220+
jb .L_copy_short_string /* less then 64 bytes, avoid the costly 'rep' */
218221
movl %edx,%ecx
219222
1: rep
220223
movsb

0 commit comments

Comments
 (0)