ARM: assembler: introduce bl_r macro
authorArd Biesheuvel <ardb@kernel.org>
Tue, 5 Oct 2021 07:15:35 +0000 (09:15 +0200)
committerArd Biesheuvel <ardb@kernel.org>
Fri, 3 Dec 2021 14:11:31 +0000 (15:11 +0100)
Add a bl_r macro that abstract the difference between the ways indirect
calls are performed on older and newer ARM architecture revisions.

The main difference is to prefer blx instructions over explicit LR
assignments when possible, as these tend to confuse the prediction logic
in out-of-order cores when speculating across a function return.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Tested-by: Keith Packard <keithpac@amazon.com>
Tested-by: Marc Zyngier <maz@kernel.org>
Tested-by: Vladimir Murzin <vladimir.murzin@arm.com> # ARMv7M
arch/arm/include/asm/assembler.h

index 7d23d4b..870bfae 100644 (file)
@@ -624,4 +624,19 @@ THUMB(     orr     \reg , \reg , #PSR_T_BIT        )
        .endif
        .endm
 
+       /*
+        * bl_r - branch and link to register
+        *
+        * @dst: target to branch to
+        * @c: conditional opcode suffix
+        */
+       .macro          bl_r, dst:req, c
+       .if             __LINUX_ARM_ARCH__ < 6
+       mov\c           lr, pc
+       mov\c           pc, \dst
+       .else
+       blx\c           \dst
+       .endif
+       .endm
+
 #endif /* __ASM_ASSEMBLER_H__ */