Revision e91467ecd1ef381377fd327c0ded922835ec52ab authored by Christian Borntraeger on 05 August 2006, 19:13:52 UTC, committed by Linus Torvalds on 06 August 2006, 15:57:46 UTC
This patch adds a barrier() in futex unqueue_me to avoid aliasing of two pointers. On my s390x system I saw the following oops: Unable to handle kernel pointer dereference at virtual kernel address 0000000000000000 Oops: 0004 [#1] CPU: 0 Not tainted Process mytool (pid: 13613, task: 000000003ecb6ac0, ksp: 00000000366bdbd8) Krnl PSW : 0704d00180000000 00000000003c9ac2 (_spin_lock+0xe/0x30) Krnl GPRS: 00000000ffffffff 000000003ecb6ac0 0000000000000000 0700000000000000 0000000000000000 0000000000000000 000001fe00002028 00000000000c091f 000001fe00002054 000001fe00002054 0000000000000000 00000000366bddc0 00000000005ef8c0 00000000003d00e8 0000000000144f91 00000000366bdcb8 Krnl Code: ba 4e 20 00 12 44 b9 16 00 3e a7 84 00 08 e3 e0 f0 88 00 04 Call Trace: ([<0000000000144f90>] unqueue_me+0x40/0xe4) [<0000000000145a0c>] do_futex+0x33c/0xc40 [<000000000014643e>] sys_futex+0x12e/0x144 [<000000000010bb00>] sysc_noemu+0x10/0x16 [<000002000003741c>] 0x2000003741c The code in question is: static int unqueue_me(struct futex_q *q) { int ret = 0; spinlock_t *lock_ptr; /* In the common case we don't take the spinlock, which is nice. */ retry: lock_ptr = q->lock_ptr; if (lock_ptr != 0) { spin_lock(lock_ptr); /* * q->lock_ptr can change between reading it and * spin_lock(), causing us to take the wrong lock. This * corrects the race condition. [...] and my compiler (gcc 4.1.0) makes the following out of it: 00000000000003c8 <unqueue_me>: 3c8: eb bf f0 70 00 24 stmg %r11,%r15,112(%r15) 3ce: c0 d0 00 00 00 00 larl %r13,3ce <unqueue_me+0x6> 3d0: R_390_PC32DBL .rodata+0x2a 3d4: a7 f1 1e 00 tml %r15,7680 3d8: a7 84 00 01 je 3da <unqueue_me+0x12> 3dc: b9 04 00 ef lgr %r14,%r15 3e0: a7 fb ff d0 aghi %r15,-48 3e4: b9 04 00 b2 lgr %r11,%r2 3e8: e3 e0 f0 98 00 24 stg %r14,152(%r15) 3ee: e3 c0 b0 28 00 04 lg %r12,40(%r11) /* write q->lock_ptr in r12 */ 3f4: b9 02 00 cc ltgr %r12,%r12 3f8: a7 84 00 4b je 48e <unqueue_me+0xc6> /* if r12 is zero then jump over the code.... */ 3fc: e3 20 b0 28 00 04 lg %r2,40(%r11) /* write q->lock_ptr in r2 */ 402: c0 e5 00 00 00 00 brasl %r14,402 <unqueue_me+0x3a> 404: R_390_PC32DBL _spin_lock+0x2 /* use r2 as parameter for spin_lock */ So the code becomes more or less: if (q->lock_ptr != 0) spin_lock(q->lock_ptr) instead of if (lock_ptr != 0) spin_lock(lock_ptr) Which caused the oops from above. After adding a barrier gcc creates code without this problem: [...] (the same) 3ee: e3 c0 b0 28 00 04 lg %r12,40(%r11) 3f4: b9 02 00 cc ltgr %r12,%r12 3f8: b9 04 00 2c lgr %r2,%r12 3fc: a7 84 00 48 je 48c <unqueue_me+0xc4> 400: c0 e5 00 00 00 00 brasl %r14,400 <unqueue_me+0x38> 402: R_390_PC32DBL _spin_lock+0x2 As a general note, this code of unqueue_me seems a bit fishy. The retry logic of unqueue_me only works if we can guarantee, that the original value of q->lock_ptr is always a spinlock (Otherwise we overwrite kernel memory). We know that q->lock_ptr can change. I dont know what happens with the original spinlock, as I am not an expert with the futex code. Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Rusty Russell <rusty@rustcorp.com.au> Acked-by: Ingo Molnar <mingo@redhat.com> Cc: Thomas Gleixner <tglx@timesys.com> Signed-off-by: Christian Borntraeger <borntrae@de.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 72f0b4e
File | Mode | Size |
---|---|---|
8253pit.h | -rw-r--r-- | 129 bytes |
Kbuild | -rw-r--r-- | 123 bytes |
a.out.h | -rw-r--r-- | 2.5 KB |
agp.h | -rw-r--r-- | 575 bytes |
agp_backend.h | -rw-r--r-- | 909 bytes |
atomic.h | -rw-r--r-- | 5.3 KB |
auxvec.h | -rw-r--r-- | 651 bytes |
barrier.h | -rw-r--r-- | 693 bytes |
bitops.h | -rw-r--r-- | 8.1 KB |
bug.h | -rw-r--r-- | 439 bytes |
bugs.h | -rw-r--r-- | 294 bytes |
byteorder.h | -rw-r--r-- | 1.3 KB |
cache.h | -rw-r--r-- | 542 bytes |
cacheflush.h | -rw-r--r-- | 2.5 KB |
checksum.h | -rw-r--r-- | 2.2 KB |
compiler.h | -rw-r--r-- | 3.7 KB |
console.h | -rw-r--r-- | 2.0 KB |
core_apecs.h | -rw-r--r-- | 16.9 KB |
core_cia.h | -rw-r--r-- | 15.4 KB |
core_irongate.h | -rw-r--r-- | 6.6 KB |
core_lca.h | -rw-r--r-- | 11.3 KB |
core_marvel.h | -rw-r--r-- | 9.1 KB |
core_mcpcia.h | -rw-r--r-- | 11.4 KB |
core_polaris.h | -rw-r--r-- | 2.9 KB |
core_t2.h | -rw-r--r-- | 19.6 KB |
core_titan.h | -rw-r--r-- | 11.2 KB |
core_tsunami.h | -rw-r--r-- | 8.4 KB |
core_wildfire.h | -rw-r--r-- | 8.4 KB |
cputime.h | -rw-r--r-- | 118 bytes |
current.h | -rw-r--r-- | 201 bytes |
delay.h | -rw-r--r-- | 225 bytes |
div64.h | -rw-r--r-- | 31 bytes |
dma-mapping.h | -rw-r--r-- | 2.6 KB |
dma.h | -rw-r--r-- | 12.3 KB |
elf.h | -rw-r--r-- | 5.7 KB |
emergency-restart.h | -rw-r--r-- | 149 bytes |
err_common.h | -rw-r--r-- | 3.2 KB |
err_ev6.h | -rw-r--r-- | 116 bytes |
err_ev7.h | -rw-r--r-- | 4.3 KB |
errno.h | -rw-r--r-- | 5.1 KB |
fcntl.h | -rw-r--r-- | 1.1 KB |
floppy.h | -rw-r--r-- | 3.2 KB |
fpu.h | -rw-r--r-- | 6.1 KB |
futex.h | -rw-r--r-- | 82 bytes |
gct.h | -rw-r--r-- | 1003 bytes |
gentrap.h | -rw-r--r-- | 1.4 KB |
hardirq.h | -rw-r--r-- | 828 bytes |
hw_irq.h | -rw-r--r-- | 216 bytes |
hwrpb.h | -rw-r--r-- | 6.9 KB |
ide.h | -rw-r--r-- | 1002 bytes |
io.h | -rw-r--r-- | 14.6 KB |
io_trivial.h | -rw-r--r-- | 2.9 KB |
ioctl.h | -rw-r--r-- | 2.2 KB |
ioctls.h | -rw-r--r-- | 3.6 KB |
ipcbuf.h | -rw-r--r-- | 575 bytes |
irq.h | -rw-r--r-- | 2.4 KB |
jensen.h | -rw-r--r-- | 8.3 KB |
kmap_types.h | -rw-r--r-- | 477 bytes |
linkage.h | -rw-r--r-- | 86 bytes |
local.h | -rw-r--r-- | 1.4 KB |
machvec.h | -rw-r--r-- | 3.5 KB |
mc146818rtc.h | -rw-r--r-- | 641 bytes |
md.h | -rw-r--r-- | 251 bytes |
mman.h | -rw-r--r-- | 2.3 KB |
mmu.h | -rw-r--r-- | 164 bytes |
mmu_context.h | -rw-r--r-- | 7.0 KB |
mmzone.h | -rw-r--r-- | 3.0 KB |
module.h | -rw-r--r-- | 448 bytes |
msgbuf.h | -rw-r--r-- | 859 bytes |
mutex.h | -rw-r--r-- | 308 bytes |
namei.h | -rw-r--r-- | 376 bytes |
page.h | -rw-r--r-- | 2.5 KB |
pal.h | -rw-r--r-- | 935 bytes |
param.h | -rw-r--r-- | 646 bytes |
parport.h | -rw-r--r-- | 517 bytes |
pci.h | -rw-r--r-- | 9.0 KB |
percpu.h | -rw-r--r-- | 114 bytes |
pgalloc.h | -rw-r--r-- | 1.5 KB |
pgtable.h | -rw-r--r-- | 13.3 KB |
poll.h | -rw-r--r-- | 473 bytes |
posix_types.h | -rw-r--r-- | 3.2 KB |
processor.h | -rw-r--r-- | 2.1 KB |
ptrace.h | -rw-r--r-- | 2.0 KB |
reg.h | -rw-r--r-- | 942 bytes |
regdef.h | -rw-r--r-- | 1004 bytes |
resource.h | -rw-r--r-- | 698 bytes |
rtc.h | -rw-r--r-- | 142 bytes |
rwsem.h | -rw-r--r-- | 5.6 KB |
scatterlist.h | -rw-r--r-- | 381 bytes |
sections.h | -rw-r--r-- | 128 bytes |
segment.h | -rw-r--r-- | 132 bytes |
semaphore.h | -rw-r--r-- | 3.1 KB |
sembuf.h | -rw-r--r-- | 607 bytes |
serial.h | -rw-r--r-- | 1006 bytes |
setup.h | -rw-r--r-- | 87 bytes |
sfp-machine.h | -rw-r--r-- | 2.9 KB |
shmbuf.h | -rw-r--r-- | 1.0 KB |
shmparam.h | -rw-r--r-- | 152 bytes |
sigcontext.h | -rw-r--r-- | 828 bytes |
siginfo.h | -rw-r--r-- | 169 bytes |
signal.h | -rw-r--r-- | 3.8 KB |
smp.h | -rw-r--r-- | 1.3 KB |
socket.h | -rw-r--r-- | 1.5 KB |
sockios.h | -rw-r--r-- | 385 bytes |
spinlock.h | -rw-r--r-- | 3.0 KB |
spinlock_types.h | -rw-r--r-- | 370 bytes |
stat.h | -rw-r--r-- | 1012 bytes |
statfs.h | -rw-r--r-- | 89 bytes |
string.h | -rw-r--r-- | 2.1 KB |
suspend.h | -rw-r--r-- | 107 bytes |
sysinfo.h | -rw-r--r-- | 857 bytes |
system.h | -rw-r--r-- | 16.8 KB |
termbits.h | -rw-r--r-- | 4.2 KB |
termios.h | -rw-r--r-- | 4.7 KB |
thread_info.h | -rw-r--r-- | 2.8 KB |
timex.h | -rw-r--r-- | 758 bytes |
tlb.h | -rw-r--r-- | 394 bytes |
tlbflush.h | -rw-r--r-- | 3.6 KB |
topology.h | -rw-r--r-- | 835 bytes |
types.h | -rw-r--r-- | 1.3 KB |
uaccess.h | -rw-r--r-- | 14.3 KB |
ucontext.h | -rw-r--r-- | 309 bytes |
unaligned.h | -rw-r--r-- | 100 bytes |
unistd.h | -rw-r--r-- | 19.9 KB |
user.h | -rw-r--r-- | 2.1 KB |
vga.h | -rw-r--r-- | 1.2 KB |
xor.h | -rw-r--r-- | 21.7 KB |
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...