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

Configure Feed

Select the types of activity you want to include in your feed.

ARM: 8550/1: protect idiv patching against undefined gcc behavior

It was reported that a kernel with CONFIG_ARM_PATCH_IDIV=y stopped
booting when compiled with the upcoming gcc 6. Turns out that turning
a function address into a writable array is undefined and gcc 6 decided
it was OK to omit the store to the first word of the function while
still preserving the store to the second word.

Even though gcc 6 is now fixed to behave more coherently, it is a
mystery that gcc 4 and gcc 5 actually produce wanted code in the kernel.
And in fact the reduced test case to illustrate the issue does indeed
break with gcc < 6 as well.

In any case, let's guard the kernel against undefined compiler behavior
by hiding the nature of the array location as suggested by gcc
developers.

Reference: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70128

Signed-off-by: Nicolas Pitre <nico@linaro.org>
Reported-by: Marcin Juszkiewicz <mjuszkiewicz@redhat.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: stable@vger.kernel.org # v4.5
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>

authored by

Nicolas Pitre and committed by
Russell King
208fae5c f2335a2a

+2
+2
arch/arm/kernel/setup.c
··· 430 430 pr_info("CPU: div instructions available: patching division code\n"); 431 431 432 432 fn_addr = ((uintptr_t)&__aeabi_uidiv) & ~1; 433 + asm ("" : "+g" (fn_addr)); 433 434 ((u32 *)fn_addr)[0] = udiv_instruction(); 434 435 ((u32 *)fn_addr)[1] = bx_lr_instruction(); 435 436 flush_icache_range(fn_addr, fn_addr + 8); 436 437 437 438 fn_addr = ((uintptr_t)&__aeabi_idiv) & ~1; 439 + asm ("" : "+g" (fn_addr)); 438 440 ((u32 *)fn_addr)[0] = sdiv_instruction(); 439 441 ((u32 *)fn_addr)[1] = bx_lr_instruction(); 440 442 flush_icache_range(fn_addr, fn_addr + 8);