Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/boot: Remove semicolon from "rep" prefixes

Minimum version of binutils required to compile the kernel is 2.25.
This version correctly handles the "rep" prefixes, so it is possible
to remove the semicolon, which was used to support ancient versions
of GNU as.

Due to the semicolon, the compiler considers "rep; insn" (or its
alternate "rep\n\tinsn" form) as two separate instructions. Removing
the semicolon makes asm length calculations more accurate, consequently
making scheduling and inlining decisions of the compiler more accurate.

Removing the semicolon also enables assembler checks involving "rep"
prefixes. Trying to assemble e.g. "rep addl %eax, %ebx" results in:

Error: invalid instruction `add' after `rep'

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Martin Mares <mj@ucw.cz>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20250418071437.4144391-1-ubizjak@gmail.com

authored by

Uros Bizjak and committed by
Ingo Molnar
0dcc5147 498cb872

+15 -15
+2 -2
arch/x86/boot/bioscall.S
··· 32 32 movw %dx, %si 33 33 movw %sp, %di 34 34 movw $11, %cx 35 - rep; movsl 35 + rep movsl 36 36 37 37 /* Pop full state from the stack */ 38 38 popal ··· 67 67 jz 4f 68 68 movw %sp, %si 69 69 movw $11, %cx 70 - rep; movsl 70 + rep movsl 71 71 4: addw $44, %sp 72 72 73 73 /* Restore state and return */
+2 -2
arch/x86/boot/boot.h
··· 155 155 static inline bool memcmp_fs(const void *s1, addr_t s2, size_t len) 156 156 { 157 157 bool diff; 158 - asm volatile("fs; repe; cmpsb" CC_SET(nz) 158 + asm volatile("fs repe cmpsb" CC_SET(nz) 159 159 : CC_OUT(nz) (diff), "+D" (s1), "+S" (s2), "+c" (len)); 160 160 return diff; 161 161 } 162 162 static inline bool memcmp_gs(const void *s1, addr_t s2, size_t len) 163 163 { 164 164 bool diff; 165 - asm volatile("gs; repe; cmpsb" CC_SET(nz) 165 + asm volatile("gs repe cmpsb" CC_SET(nz) 166 166 : CC_OUT(nz) (diff), "+D" (s1), "+S" (s2), "+c" (len)); 167 167 return diff; 168 168 }
+4 -4
arch/x86/boot/compressed/string.c
··· 15 15 { 16 16 int d0, d1, d2; 17 17 asm volatile( 18 - "rep ; movsl\n\t" 18 + "rep movsl\n\t" 19 19 "movl %4,%%ecx\n\t" 20 - "rep ; movsb\n\t" 20 + "rep movsb" 21 21 : "=&c" (d0), "=&D" (d1), "=&S" (d2) 22 22 : "0" (n >> 2), "g" (n & 3), "1" (dest), "2" (src) 23 23 : "memory"); ··· 29 29 { 30 30 long d0, d1, d2; 31 31 asm volatile( 32 - "rep ; movsq\n\t" 32 + "rep movsq\n\t" 33 33 "movq %4,%%rcx\n\t" 34 - "rep ; movsb\n\t" 34 + "rep movsb" 35 35 : "=&c" (d0), "=&D" (d1), "=&S" (d2) 36 36 : "0" (n >> 3), "g" (n & 7), "1" (dest), "2" (src) 37 37 : "memory");
+4 -4
arch/x86/boot/copy.S
··· 22 22 movw %dx, %si 23 23 pushw %cx 24 24 shrw $2, %cx 25 - rep; movsl 25 + rep movsl 26 26 popw %cx 27 27 andw $3, %cx 28 - rep; movsb 28 + rep movsb 29 29 popw %di 30 30 popw %si 31 31 retl ··· 38 38 imull $0x01010101,%eax 39 39 pushw %cx 40 40 shrw $2, %cx 41 - rep; stosl 41 + rep stosl 42 42 popw %cx 43 43 andw $3, %cx 44 - rep; stosb 44 + rep stosb 45 45 popw %di 46 46 retl 47 47 SYM_FUNC_END(memset)
+1 -1
arch/x86/boot/header.S
··· 585 585 xorl %eax, %eax 586 586 subw %di, %cx 587 587 shrw $2, %cx 588 - rep; stosl 588 + rep stosl 589 589 590 590 # Jump to C code (should not return) 591 591 calll main
+1 -1
arch/x86/boot/string.c
··· 32 32 int memcmp(const void *s1, const void *s2, size_t len) 33 33 { 34 34 bool diff; 35 - asm("repe; cmpsb" CC_SET(nz) 35 + asm("repe cmpsb" CC_SET(nz) 36 36 : CC_OUT(nz) (diff), "+D" (s1), "+S" (s2), "+c" (len)); 37 37 return diff; 38 38 }
+1 -1
arch/x86/boot/video.c
··· 292 292 "shrw %%cx ; " 293 293 "jnc 1f ; " 294 294 "stosw \n\t" 295 - "1: rep;stosl ; " 295 + "1: rep stosl ; " 296 296 "popw %%es" 297 297 : "+D" (dst), "+c" (npad) 298 298 : "bdS" (video_segment),