android_kernel_xiaomi_sm8350/arch/arm/include/asm
Will Deacon 398aa66827 ARM: 6212/1: atomic ops: add memory constraints to inline asm
Currently, the 32-bit and 64-bit atomic operations on ARM do not
include memory constraints in the inline assembly blocks. In the
case of barrier-less operations [for example, atomic_add], this
means that the compiler may constant fold values which have actually
been modified by a call to an atomic operation.

This issue can be observed in the atomic64_test routine in
<kernel root>/lib/atomic64_test.c:

00000000 <test_atomic64>:
   0:	e1a0c00d 	mov	ip, sp
   4:	e92dd830 	push	{r4, r5, fp, ip, lr, pc}
   8:	e24cb004 	sub	fp, ip, #4
   c:	e24dd008 	sub	sp, sp, #8
  10:	e24b3014 	sub	r3, fp, #20
  14:	e30d000d 	movw	r0, #53261	; 0xd00d
  18:	e3011337 	movw	r1, #4919	; 0x1337
  1c:	e34c0001 	movt	r0, #49153	; 0xc001
  20:	e34a1aa3 	movt	r1, #43683	; 0xaaa3
  24:	e16300f8 	strd	r0, [r3, #-8]!
  28:	e30c0afe 	movw	r0, #51966	; 0xcafe
  2c:	e30b1eef 	movw	r1, #48879	; 0xbeef
  30:	e34d0eaf 	movt	r0, #57007	; 0xdeaf
  34:	e34d1ead 	movt	r1, #57005	; 0xdead
  38:	e1b34f9f 	ldrexd	r4, [r3]
  3c:	e1a34f90 	strexd	r4, r0, [r3]
  40:	e3340000 	teq	r4, #0
  44:	1afffffb 	bne	38 <test_atomic64+0x38>
  48:	e59f0004 	ldr	r0, [pc, #4]	; 54 <test_atomic64+0x54>
  4c:	e3a0101e 	mov	r1, #30
  50:	ebfffffe 	bl	0 <__bug>
  54:	00000000 	.word	0x00000000

The atomic64_set (0x38-0x44) writes to the atomic64_t, but the
compiler doesn't see this, assumes the test condition is always
false and generates an unconditional branch to __bug. The rest of the
test is optimised away.

This patch adds suitable memory constraints to the atomic operations on ARM
to ensure that the compiler is informed of the correct data hazards. We have
to use the "Qo" constraints to avoid hitting the GCC anomaly described at
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44492 , where the compiler
makes assumptions about the writeback in the addressing mode used by the
inline assembly. These constraints forbid the use of auto{inc,dec} addressing
modes, so it doesn't matter if we don't use the operand exactly once.

Cc: stable@kernel.org
Reviewed-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2010-07-09 11:29:35 +01:00
..
hardware Merge branches 'at91', 'bcmring', 'ep93xx', 'iop', 'misc', 'nomadik', 'omap', 'pxa', 'spear' and 'versatile' into devel 2010-05-17 11:53:39 +01:00
mach [ARM] pxa: fix incorrect gpio type in udc_pxa2xx.h 2010-06-13 23:55:12 +08:00
a.out-core.h
a.out.h
asm-offsets.h
assembler.h ARM: fix build error in arch/arm/kernel/process.c 2010-04-21 08:45:21 +01:00
atomic.h ARM: 6212/1: atomic ops: add memory constraints to inline asm 2010-07-09 11:29:35 +01:00
auxvec.h
bitops.h
bitsperlong.h
bug.h
bugs.h
byteorder.h
cache.h
cacheflush.h ARM: 6112/1: Use the Inner Shareable I-cache and BTB ops on ARMv7 SMP 2010-05-08 10:44:30 +01:00
cachetype.h
checksum.h
clkdev.h ARM: 6001/1: removing compilation warning comming from clkdev.h 2010-03-29 17:33:32 +01:00
cpu-multi32.h
cpu-single.h
cpu.h
cputime.h
cputype.h
current.h
delay.h
device.h
div64.h
dma-mapping.h dma-mapping: arm: use generic pci_set_dma_mask and pci_set_consistent_dma_mask 2010-03-12 15:52:42 -08:00
dma.h
domain.h
ecard.h
elf.h arch/arm/include/asm/elf.h: forward-declare the task-struct 2010-05-01 11:33:00 +01:00
emergency-restart.h
entry-macro-vic2.S
errno.h
fb.h
fcntl.h
fiq.h
fixmap.h
flat.h
floppy.h
fpstate.h
ftrace.h
futex.h ARM: fix build error in arch/arm/kernel/process.c 2010-04-21 08:45:21 +01:00
glue.h
gpio.h
hardirq.h ARM: 6138/1: Add support for 10 hardirq bits 2010-05-20 23:51:07 +01:00
highmem.h ARM: 6007/1: fix highmem with VIPT cache and DMA 2010-04-14 11:11:27 +01:00
hw_irq.h
hwcap.h
ide.h
io.h
ioctl.h
ioctls.h ARM: 6092/1: atmel_serial: support for RS485 communications 2010-05-04 16:59:11 +01:00
ipcbuf.h
irq_regs.h
irq.h ARM: 6000/1: removing compilation warning comming from <asm/irq.h> 2010-03-29 17:33:31 +01:00
irqflags.h
Kbuild
kdebug.h
kexec.h
kgdb.h
kmap_types.h kdb: core for kgdb back end (2 of 2) 2010-05-20 21:04:21 -05:00
kprobes.h
leds.h
limits.h
linkage.h
local.h
localtimer.h
locks.h
mach-types.h
mc146818rtc.h
memory.h ARM: 5928/1: Change type of VMALLOC_END to unsigned long. 2010-02-15 21:40:33 +00:00
mman.h
mmu_context.h
mmu.h
mmzone.h
module.h
msgbuf.h
mtd-xip.h
mutex.h
nwflash.h
outercache.h ARM: 5994/1: ARM: Add outer_cache_fns.sync function pointer (2/4) 2010-03-25 21:13:49 +00:00
page-nommu.h
page.h
param.h
parport.h
pci.h ARM: 6058/1: Add support for PCI domains 2010-04-22 21:38:11 +01:00
percpu.h
perf_event.h ARM: 6071/1: perf-events: allow modules to query the number of hardware counters 2010-05-17 11:53:58 +01:00
pgalloc.h
pgtable-hwdef.h
pgtable-nommu.h ARM: 5988/1: pgprot_dmacoherent() for non-mmu builds 2010-03-13 10:48:22 +00:00
pgtable.h ARM: Optionally allow ARMv6 to use 'normal, bufferable' memory for DMA 2010-05-17 11:52:11 +01:00
pmu.h ARM: 6064/1: pmu: register IRQs at runtime 2010-05-17 11:53:57 +01:00
poll.h
posix_types.h
proc-fns.h
processor.h ARM: 6194/1: change definition of cpu_relax() for ARM11MPCore 2010-07-01 10:13:52 +01:00
procinfo.h
ptrace.h arm: use generic ptrace_resume code 2010-03-12 15:52:38 -08:00
resource.h
scatterlist.h asm-generic: remove ARCH_HAS_SG_CHAIN in scatterlist.h 2010-05-27 09:12:54 -07:00
sections.h
segment.h
sembuf.h
serial.h
setup.h
shmbuf.h
shmparam.h
sigcontext.h
siginfo.h
signal.h
sizes.h
smp_plat.h
smp_scu.h
smp_twd.h ARM: 6125/1: ARM TWD: move TWD registers to common header 2010-05-12 11:18:13 +01:00
smp.h ARM: rename mach_cpu_disable() to platform_cpu_disable() 2010-05-15 15:03:51 +01:00
socket.h
sockios.h
sparsemem.h
spinlock_types.h
spinlock.h
stacktrace.h
stat.h
statfs.h
string.h
swab.h
system.h Merge branch 'devel-stable' into devel 2010-05-17 17:24:04 +01:00
tcm.h
termbits.h
termios.h
therm.h
thread_info.h add descriptive comment for TIF_MEMDIE task flag declaration. 2010-05-14 11:13:27 +02:00
thread_notify.h
timex.h
tlb.h
tlbflush.h ARM: 6112/1: Use the Inner Shareable I-cache and BTB ops on ARMv7 SMP 2010-05-08 10:44:30 +01:00
topology.h
traps.h
types.h
uaccess.h ARM: fix build error in arch/arm/kernel/process.c 2010-04-21 08:45:21 +01:00
ucontext.h ARM: 6051/1: VFP: preserve the HW context when calling signal handlers 2010-04-14 11:11:30 +01:00
unaligned.h
unified.h
unistd.h Add generic sys_ipc wrapper 2010-03-12 15:52:32 -08:00
unwind.h
user.h ARM: 6051/1: VFP: preserve the HW context when calling signal handlers 2010-04-14 11:11:30 +01:00
vfp.h
vfpmacros.h
vga.h
xor.h