linux/arch
Christian Ruppert 79e5f05edc ARC: Add implicit compiler barrier to raw_local_irq* functions
ARC irqsave/restore macros were missing the compiler barrier, causing a
stale load in irq-enabled region be used in irq-safe region, despite
being changed, because the register holding the value was still live.

The problem manifested as random crashes in timer code when stress
testing ARCLinux (3.9-rc3) on a !SMP && !PREEMPT_COUNT

Here's the exact sequence which caused this:
 (0). tv1[x] <----> t1 <---> t2
 (1). mod_timer(t1) interrupted after it calls timer_pending()
 (2). mod_timer(t2) completes
 (3). mod_timer(t1) resumes but messes up the list
 (4). __runt_timers( ) uses bogus timer_list entry / crashes in
      timer->function

Essentially mod_timer() was racing against itself and while the spinlock
serialized the tv1[] timer link list, timer_pending() called outside the
spinlock, cached timer link list element in a register.
With low register pressure (and a deep register file), lack of barrier
in raw_local_irqsave() as well as preempt_disable (!PREEMPT_COUNT
version), there was nothing to force gcc to reload across the spinlock,
causing a stale value in reg be used for link list manipulation - ensuing
a corruption.

ARcompact disassembly which shows the culprit generated code:

mod_timer:
    push_s blink
    mov_s r13,r0	# timer, timer
..
    ###### timer_pending( )
    ld_s r3,[r13]       # <------ <variable>.entry.next LOADED
    brne r3, 0, @.L163

.L163:
..
    ###### spin_lock_irq( )
    lr  r5, [status32]  # flags
    bic r4, r5, 6       # temp, flags,
    and.f 0, r5, 6      # flags,
    flag.nz r4

    ###### detach_if_pending( ) begins

    tst_s r3,r3  <--------------
			# timer_pending( ) checks timer->entry.next
                        # r3 is NOT reloaded by gcc, using stale value
    beq.d @.L169
    mov.eq r0,0

    #####  detach_timer( ): __list_del( )

    ld r4,[r13,4]    	# <variable>.entry.prev, D.31439
    st r4,[r3,4]     	# <variable>.prev, D.31439
    st r3,[r4]       	# <variable>.next, D.30246

We initially tried to fix this by adding barrier() to preempt_* macros
for !PREEMPT_COUNT but Linus clarified that it was anything but wrong.
http://www.spinics.net/lists/kernel/msg1512709.html

[vgupta: updated commitlog]

Reported-by/Signed-off-by: Christian Ruppert <christian.ruppert@abilis.com>
Cc: Christian Ruppert <christian.ruppert@abilis.com>
Cc: Pierrick Hascoet <pierrick.hascoet@abilis.com>
Debugged-by/Signed-off-by: Vineet Gupta <vgupta@synopsys.com>

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-04-08 16:10:26 -07:00
..
alpha alpha: irq: remove deprecated use of IRQF_DISABLED 2013-04-07 12:59:30 -07:00
arc ARC: Add implicit compiler barrier to raw_local_irq* functions 2013-04-08 16:10:26 -07:00
arm Merge branch 'fixes' of git://git.linaro.org/people/rmk/linux-arm 2013-04-03 16:15:17 -07:00
arm64 Fix IS_ENABLED() usage typo (missing CONFIG_ prefix). 2013-03-28 13:45:49 -07:00
avr32 Select VIRT_TO_BUS directly where needed 2013-03-12 11:16:40 -07:00
blackfin Select VIRT_TO_BUS directly where needed 2013-03-12 11:16:40 -07:00
c6x
cris Select VIRT_TO_BUS directly where needed 2013-03-12 11:16:40 -07:00
frv Select VIRT_TO_BUS directly where needed 2013-03-12 11:16:40 -07:00
h8300 Select VIRT_TO_BUS directly where needed 2013-03-12 11:16:40 -07:00
hexagon
ia64 ia64 idle: delete stale (*idle)() function pointer 2013-03-29 11:12:25 -07:00
m32r UAPI: fix endianness conditionals in M32R's asm/stat.h 2013-03-13 15:21:49 -07:00
m68k Select VIRT_TO_BUS directly where needed 2013-03-12 11:16:40 -07:00
metag
microblaze Select VIRT_TO_BUS directly where needed 2013-03-12 11:16:40 -07:00
mips Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/ralf/upstream-linus 2013-04-05 12:23:12 -07:00
mn10300 Select VIRT_TO_BUS directly where needed 2013-03-12 11:16:40 -07:00
openrisc openrisc: remove HAVE_VIRT_TO_BUS 2013-03-13 06:12:39 +01:00
parisc Select VIRT_TO_BUS directly where needed 2013-03-12 11:16:40 -07:00
powerpc powerpc: define the conditions where the ePAPR idle hcall can be supported 2013-03-26 08:47:27 +11:00
s390 s390/mm: provide emtpy check_pgt_cache() function 2013-04-02 08:53:11 +02:00
score Select VIRT_TO_BUS directly where needed 2013-03-12 11:16:40 -07:00
sh
sparc Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc 2013-03-19 14:47:11 -07:00
tile Merge branch 'stable' of git://git.kernel.org/pub/scm/linux/kernel/git/cmetcalf/linux-tile 2013-04-01 08:17:09 -07:00
um um: Use tty_port in SIGWINCH handler 2013-03-11 10:08:04 +01:00
unicore32 Select VIRT_TO_BUS directly where needed 2013-03-12 11:16:40 -07:00
x86 Merge git://git.kernel.org/pub/scm/virt/kvm/kvm 2013-04-07 13:01:25 -07:00
xtensa Select VIRT_TO_BUS directly where needed 2013-03-12 11:16:40 -07:00
.gitignore
Kconfig Select VIRT_TO_BUS directly where needed 2013-03-12 11:16:40 -07:00