s390/alternatives: Convert runtime sanity check into compile time check
authorHeiko Carstens <hca@linux.ibm.com>
Mon, 13 May 2024 10:16:20 +0000 (12:16 +0200)
committerAlexander Gordeev <agordeev@linux.ibm.com>
Tue, 14 May 2024 18:21:23 +0000 (20:21 +0200)
__apply_alternatives() contains a runtime check which verifies that the
size of the to be patched code area is even. Convert this to a compile time
check using a similar ".org" trick, which is already used to verify that
old and new code areas have the same size.

Reviewed-by: Sven Schnelle <svens@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
arch/s390/include/asm/alternative-asm.h
arch/s390/include/asm/alternative.h
arch/s390/kernel/alternative.c

index 7db046596b93e81e1b45a0e2537f602556747d39..608f6287ca9ccab697a9c75452875539cd79a8fd 100644 (file)
@@ -15,6 +15,7 @@
        .long   \alt_start - .
        .word   \feature
        .byte   \orig_end - \orig_start
+       .org    . - ( \orig_end - \orig_start ) & 1
        .org    . - ( \orig_end - \orig_start ) + ( \alt_end - \alt_start )
        .org    . - ( \alt_end - \alt_start ) + ( \orig_end - \orig_start )
 .endm
index 904dd049f954767e4c5812358d6d403884638008..dd93b92c3ab69ad285a8a87407f814fa3d60f11e 100644 (file)
@@ -53,6 +53,7 @@ void apply_alternatives(struct alt_instr *start, struct alt_instr *end);
        "\t.long " b_altinstr(num)"b - .\n"     /* alt instruction */   \
        "\t.word " __stringify(facility) "\n"   /* facility bit    */   \
        "\t.byte " oldinstr_len "\n"            /* instruction len */   \
+       "\t.org . - (" oldinstr_len ") & 1\n"                           \
        "\t.org . - (" oldinstr_len ") + (" altinstr_len(num) ")\n"     \
        "\t.org . - (" altinstr_len(num) ") + (" oldinstr_len ")\n"
 
index e7bca29f9c3485bead01a70b6935f3f9041b7f8e..1ac5f707dd70500e568354631e1193b259721828 100644 (file)
@@ -33,13 +33,6 @@ static void __init_or_module __apply_alternatives(struct alt_instr *start,
 
                if (!__test_facility(a->facility, alt_stfle_fac_list))
                        continue;
-
-               if (unlikely(a->instrlen % 2)) {
-                       WARN_ONCE(1, "cpu alternatives instructions length is "
-                                    "odd, skipping patching\n");
-                       continue;
-               }
-
                s390_kernel_write(instr, replacement, a->instrlen);
        }
 }