]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/boot: Remove semicolon from "rep" prefixes
authorUros Bizjak <ubizjak@gmail.com>
Fri, 18 Apr 2025 07:13:50 +0000 (09:13 +0200)
committerIngo Molnar <mingo@kernel.org>
Fri, 18 Apr 2025 07:32:57 +0000 (09:32 +0200)
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
arch/x86/boot/bioscall.S
arch/x86/boot/boot.h
arch/x86/boot/compressed/string.c
arch/x86/boot/copy.S
arch/x86/boot/header.S
arch/x86/boot/string.c
arch/x86/boot/video.c

index aa9b9645758433b088eeb579a9553b693dfa381a..cf4a6155714e14363d96ae8b6aea0ae954ec0b16 100644 (file)
@@ -32,7 +32,7 @@ intcall:
        movw    %dx, %si
        movw    %sp, %di
        movw    $11, %cx
-       rep; movsl
+       rep movsl
 
        /* Pop full state from the stack */
        popal
@@ -67,7 +67,7 @@ intcall:
        jz      4f
        movw    %sp, %si
        movw    $11, %cx
-       rep; movsl
+       rep movsl
 4:     addw    $44, %sp
 
        /* Restore state and return */
index 38f17a1e1e367f5d554f62bcf2959c9c28634a63..f3771a6373c76c37bbe16babe945226e96028bc1 100644 (file)
@@ -155,14 +155,14 @@ static inline void wrgs32(u32 v, addr_t addr)
 static inline bool memcmp_fs(const void *s1, addr_t s2, size_t len)
 {
        bool diff;
-       asm volatile("fs; repe; cmpsb" CC_SET(nz)
+       asm volatile("fs repe cmpsb" CC_SET(nz)
                     : CC_OUT(nz) (diff), "+D" (s1), "+S" (s2), "+c" (len));
        return diff;
 }
 static inline bool memcmp_gs(const void *s1, addr_t s2, size_t len)
 {
        bool diff;
-       asm volatile("gs; repe; cmpsb" CC_SET(nz)
+       asm volatile("gs repe cmpsb" CC_SET(nz)
                     : CC_OUT(nz) (diff), "+D" (s1), "+S" (s2), "+c" (len));
        return diff;
 }
index 81fc1eaa32299064376f8f56a8692cc1e0218005..9af19d9614cba567f7a8c87aefdf2b8b1e19bc6a 100644 (file)
@@ -15,9 +15,9 @@ static void *____memcpy(void *dest, const void *src, size_t n)
 {
        int d0, d1, d2;
        asm volatile(
-               "rep movsl\n\t"
+               "rep movsl\n\t"
                "movl %4,%%ecx\n\t"
-               "rep ; movsb\n\t"
+               "rep movsb"
                : "=&c" (d0), "=&D" (d1), "=&S" (d2)
                : "0" (n >> 2), "g" (n & 3), "1" (dest), "2" (src)
                : "memory");
@@ -29,9 +29,9 @@ static void *____memcpy(void *dest, const void *src, size_t n)
 {
        long d0, d1, d2;
        asm volatile(
-               "rep movsq\n\t"
+               "rep movsq\n\t"
                "movq %4,%%rcx\n\t"
-               "rep ; movsb\n\t"
+               "rep movsb"
                : "=&c" (d0), "=&D" (d1), "=&S" (d2)
                : "0" (n >> 3), "g" (n & 7), "1" (dest), "2" (src)
                : "memory");
index 6afd05e819d26831d739bb6c6aba27f4ba0c2137..3973a67cd04e415db30b4c08e4bc9889c6bc8c0e 100644 (file)
@@ -22,10 +22,10 @@ SYM_FUNC_START_NOALIGN(memcpy)
        movw    %dx, %si
        pushw   %cx
        shrw    $2, %cx
-       rep; movsl
+       rep movsl
        popw    %cx
        andw    $3, %cx
-       rep; movsb
+       rep movsb
        popw    %di
        popw    %si
        retl
@@ -38,10 +38,10 @@ SYM_FUNC_START_NOALIGN(memset)
        imull   $0x01010101,%eax
        pushw   %cx
        shrw    $2, %cx
-       rep; stosl
+       rep stosl
        popw    %cx
        andw    $3, %cx
-       rep; stosb
+       rep stosb
        popw    %di
        retl
 SYM_FUNC_END(memset)
index b5c79f43359bcde2c4c3c5ed796e8780f7979774..9cb91421b4e410efa118d682a93c16fa2573745a 100644 (file)
@@ -585,7 +585,7 @@ start_of_setup:
        xorl    %eax, %eax
        subw    %di, %cx
        shrw    $2, %cx
-       rep; stosl
+       rep stosl
 
 # Jump to C code (should not return)
        calll   main
index 84f7a883ce1e82c075687d9bceb527a380d3192e..f35369bb14c5141ea8079a14f81d838e1797161d 100644 (file)
@@ -32,7 +32,7 @@
 int memcmp(const void *s1, const void *s2, size_t len)
 {
        bool diff;
-       asm("repe; cmpsb" CC_SET(nz)
+       asm("repe cmpsb" CC_SET(nz)
            : CC_OUT(nz) (diff), "+D" (s1), "+S" (s2), "+c" (len));
        return diff;
 }
index f2e96905b3fe2165426529d362fcf8cbbde68bc9..0641c8c46aee2f6dab29d66b741bd1be21f0d685 100644 (file)
@@ -292,7 +292,7 @@ static void restore_screen(void)
                             "shrw %%cx ; "
                             "jnc 1f ; "
                             "stosw \n\t"
-                            "1: rep;stosl ; "
+                            "1: rep stosl ; "
                             "popw %%es"
                             : "+D" (dst), "+c" (npad)
                             : "bdS" (video_segment),