linux/arch/arc
Vineet Gupta 80f420842f ARC: Make ARC bitops "safer" (add anti-optimization)
ARCompact/ARCv2 ISA provide that any instructions which deals with
bitpos/count operand ASL, LSL, BSET, BCLR, BMSK .... will only consider
lower 5 bits. i.e. auto-clamp the pos to 0-31.

ARC Linux bitops exploited this fact by NOT explicitly masking out upper
bits for @nr operand in general, saving a bunch of AND/BMSK instructions
in generated code around bitops.

While this micro-optimization has worked well over years it is NOT safe
as shifting a number with a value, greater than native size is
"undefined" per "C" spec.

So as it turns outm EZChip ran into this eventually, in their massive
muti-core SMP build with 64 cpus. There was a test_bit() inside a loop
from 63 to 0 and gcc was weirdly optimizing away the first iteration
(so it was really adhering to standard by implementing undefined behaviour
vs. removing all the iterations which were phony i.e. (1 << [63..32])

| for i = 63 to 0
|    X = ( 1 << i )
|    if X == 0
|       continue

So fix the code to do the explicit masking at the expense of generating
additional instructions. Fortunately, this can be mitigated to a large
extent as gcc has SHIFT_COUNT_TRUNCATED which allows combiner to fold
masking into shift operation itself. It is currently not enabled in ARC
gcc backend, but could be done after a bit of testing.

Fixes STAR 9000866918 ("unsafe "undefined behavior" code in kernel")

Reported-by: Noam Camus <noamc@ezchip.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
2015-07-09 17:36:32 +05:30
..
boot ARCv2: [axs103] bump CPU frequency from 75 to 90 MHZ 2015-07-09 17:36:31 +05:30
configs ARCv2: [vdk] dts files and defconfig for HS38 VDK 2015-06-25 06:00:21 +05:30
include ARC: Make ARC bitops "safer" (add anti-optimization) 2015-07-09 17:36:32 +05:30
kernel ARCv2: intc: IDU: Fix potential race in installing a chained IRQ handler 2015-07-06 11:09:06 +05:30
lib
mm ARC: Don't memzero twice in dma_alloc_coherent for __GFP_ZERO 2015-07-06 11:09:01 +05:30
oprofile
plat-axs10x ARCv2: [vdk] dts files and defconfig for HS38 VDK 2015-06-25 06:00:21 +05:30
plat-sim ARCv2: [nsim*hs*] Support simulation platforms for HS38x cores 2015-06-25 06:00:19 +05:30
plat-tb10x
Kbuild
Kconfig ARC: Kconfig: better way to disable ARC_HAS_LLSC for ARC_CPU_750D 2015-07-06 10:12:39 +05:30
Kconfig.debug
Makefile ARC: Override toplevel default -O2 with -O3 2015-07-06 11:09:00 +05:30