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

ARM: 9390/2: lib: Annotate loop delay instructions for CFI

When we annotate the loop delay code with SYM_TYPED_FUNC_START()
a function prototype signature will be emitted into the object
file above each site called from C, and the delay loop code is
using "fallthroughs" from the different assembly callbacks. This
will not work as the execution flow will run into the prototype
signatures.

Rewrite the code to use explicit branches to the other code
segments and annotate the code using SYM_TYPED_FUNC_START().

Tested on the ARM Versatile which uses the calibrated loop delay.

Tested-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Sami Tolvanen <samitolvanen@google.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>

authored by

Linus Walleij and committed by
Russell King (Oracle)
7339fb11 393999fa

+10 -6
+10 -6
arch/arm/lib/delay-loop.S
··· 5 5 * Copyright (C) 1995, 1996 Russell King 6 6 */ 7 7 #include <linux/linkage.h> 8 + #include <linux/cfi_types.h> 8 9 #include <asm/assembler.h> 9 10 #include <asm/delay.h> 10 11 ··· 25 24 * HZ <= 1000 26 25 */ 27 26 28 - ENTRY(__loop_udelay) 27 + SYM_TYPED_FUNC_START(__loop_udelay) 29 28 ldr r2, .LC1 30 29 mul r0, r2, r0 @ r0 = delay_us * UDELAY_MULT 31 - ENTRY(__loop_const_udelay) @ 0 <= r0 <= 0xfffffaf0 30 + b __loop_const_udelay 31 + SYM_FUNC_END(__loop_udelay) 32 + 33 + SYM_TYPED_FUNC_START(__loop_const_udelay) @ 0 <= r0 <= 0xfffffaf0 32 34 ldr r2, .LC0 33 35 ldr r2, [r2] 34 36 umull r1, r0, r2, r0 @ r0-r1 = r0 * loops_per_jiffy 35 37 adds r1, r1, #0xffffffff @ rounding up ... 36 38 adcs r0, r0, r0 @ and right shift by 31 37 39 reteq lr 40 + b __loop_delay 41 + SYM_FUNC_END(__loop_const_udelay) 38 42 39 43 .align 3 40 44 41 45 @ Delay routine 42 - ENTRY(__loop_delay) 46 + SYM_TYPED_FUNC_START(__loop_delay) 43 47 subs r0, r0, #1 44 48 #if 0 45 49 retls lr ··· 64 58 #endif 65 59 bhi __loop_delay 66 60 ret lr 67 - ENDPROC(__loop_udelay) 68 - ENDPROC(__loop_const_udelay) 69 - ENDPROC(__loop_delay) 61 + SYM_FUNC_END(__loop_delay)