riscv: prevent compressed instructions in alternatives
authorHeiko Stuebner <heiko@sntech.de>
Wed, 11 May 2022 19:29:15 +0000 (21:29 +0200)
committerPalmer Dabbelt <palmer@rivosinc.com>
Thu, 12 May 2022 04:36:32 +0000 (21:36 -0700)
Instructions are opportunistically compressed by the RISC-V assembler
when possible, but in alternatives-blocks both the old and new content
need to be the same size, so having the toolchain do somewhat random
optimizations will cause strange side-effects like
"attempt to move .org backwards" compile-time errors.

Already a simple "and" used in alternatives assembly will cause these
mismatched code sizes.

So prevent compressed instructions to be generated in alternatives-
code and use option-push and -pop to only limit this to the relevant
code blocks

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
Link: https://lore.kernel.org/r/20220511192921.2223629-7-heiko@sntech.de
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/include/asm/alternative-macros.h

index 8c2bbc7..e13b1f6 100644 (file)
        .popsection
        .subsection 1
 888 :
+       .option push
+       .option norvc
+       .option norelax
        \new_c
+       .option pop
 889 :
        .previous
        .org    . - (889b - 888b) + (887b - 886b)
 
 .macro __ALTERNATIVE_CFG old_c, new_c, vendor_id, errata_id, enable
 886 :
+       .option push
+       .option norvc
+       .option norelax
        \old_c
+       .option pop
 887 :
        ALT_NEW_CONTENT \vendor_id, \errata_id, \enable, \new_c
 .endm
 .macro __ALTERNATIVE_CFG_2 old_c, new_c_1, vendor_id_1, errata_id_1, enable_1, \
                                  new_c_2, vendor_id_2, errata_id_2, enable_2
 886 :
+       .option push
+       .option norvc
+       .option norelax
        \old_c
+       .option pop
 887 :
        ALT_NEW_CONTENT \vendor_id_1, \errata_id_1, \enable_1, \new_c_1
        ALT_NEW_CONTENT \vendor_id_2, \errata_id_2, \enable_2, \new_c_2
        ".popsection\n"                                                 \
        ".subsection 1\n"                                               \
        "888 :\n"                                                       \
+       ".option push\n"                                                \
+       ".option norvc\n"                                               \
+       ".option norelax\n"                                             \
        new_c "\n"                                                      \
+       ".option pop\n"                                                 \
        "889 :\n"                                                       \
        ".previous\n"                                                   \
        ".org   . - (887b - 886b) + (889b - 888b)\n"                    \
 
 #define __ALTERNATIVE_CFG(old_c, new_c, vendor_id, errata_id, enable)  \
        "886 :\n"                                                       \
+       ".option push\n"                                                \
+       ".option norvc\n"                                               \
+       ".option norelax\n"                                             \
        old_c "\n"                                                      \
+       ".option pop\n"                                                 \
        "887 :\n"                                                       \
        ALT_NEW_CONTENT(vendor_id, errata_id, enable, new_c)
 
                                   new_c_2, vendor_id_2, errata_id_2,   \
                                        enable_2)                       \
        "886 :\n"                                                       \
+       ".option push\n"                                                \
+       ".option norvc\n"                                               \
+       ".option norelax\n"                                             \
        old_c "\n"                                                      \
+       ".option pop\n"                                                 \
        "887 :\n"                                                       \
        ALT_NEW_CONTENT(vendor_id_1, errata_id_1, enable_1, new_c_1)    \
        ALT_NEW_CONTENT(vendor_id_2, errata_id_2, enable_2, new_c_2)