• Peter Zijlstra's avatar
    locking/qspinlock: Fix spin_unlock_wait() some more · 2c610022
    Peter Zijlstra authored
    While this prior commit:
    
      54cf809b ("locking,qspinlock: Fix spin_is_locked() and spin_unlock_wait()")
    
    ... fixes spin_is_locked() and spin_unlock_wait() for the usage
    in ipc/sem and netfilter, it does not in fact work right for the
    usage in task_work and futex.
    
    So while the 2 locks crossed problem:
    
    	spin_lock(A)		spin_lock(B)
    	if (!spin_is_locked(B)) spin_unlock_wait(A)
    	  foo()			foo();
    
    ... works with the smp_mb() injected by both spin_is_locked() and
    spin_unlock_wait(), this is not sufficient for:
    
    	flag = 1;
    	smp_mb();		spin_lock()
    	spin_unlock_wait()	if (!flag)
    				  // add to lockless list
    	// iterate lockless list
    
    ... because in this scenario, the store from spin_lock() can be delayed
    past the load of flag, uncrossing the variables and loosing the
    guarantee.
    
    This patch reworks spin_is_locked() and spin_unlock_wait() to work in
    both cases by exploiting the observation that while the lock byte
    store can be delayed, the contender must have registered itself
    visibly in other state contained in the word.
    
    It also allows for architectures to override both functions, as PPC
    and ARM64 have an additional issue for which we currently have no
    generic solution.
    Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Boqun Feng <boqun.feng@gmail.com>
    Cc: Davidlohr Bueso <dave@stgolabs.net>
    Cc: Giovanni Gherdovich <ggherdovich@suse.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Pan Xinhui <xinhui.pan@linux.vnet.ibm.com>
    Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Waiman Long <waiman.long@hpe.com>
    Cc: Will Deacon <will.deacon@arm.com>
    Cc: stable@vger.kernel.org # v4.2 and later
    Fixes: 54cf809b ("locking,qspinlock: Fix spin_is_locked() and spin_unlock_wait()")
    Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
    2c610022
Name
Last commit
Last update
..
bitops Loading commit data...
4level-fixup.h Loading commit data...
Kbuild.asm Loading commit data...
asm-offsets.h Loading commit data...
atomic-long.h Loading commit data...
atomic.h Loading commit data...
atomic64.h Loading commit data...
audit_change_attr.h Loading commit data...
audit_dir_write.h Loading commit data...
audit_read.h Loading commit data...
audit_signal.h Loading commit data...
audit_write.h Loading commit data...
barrier.h Loading commit data...
bitops.h Loading commit data...
bitsperlong.h Loading commit data...
bug.h Loading commit data...
bugs.h Loading commit data...
cache.h Loading commit data...
cacheflush.h Loading commit data...
checksum.h Loading commit data...
clkdev.h Loading commit data...
cmpxchg-local.h Loading commit data...
cmpxchg.h Loading commit data...
cputime.h Loading commit data...
cputime_jiffies.h Loading commit data...
cputime_nsecs.h Loading commit data...
current.h Loading commit data...
delay.h Loading commit data...
device.h Loading commit data...
div64.h Loading commit data...
dma-contiguous.h Loading commit data...
dma.h Loading commit data...
early_ioremap.h Loading commit data...
emergency-restart.h Loading commit data...
exec.h Loading commit data...
fb.h Loading commit data...
fixmap.h Loading commit data...
ftrace.h Loading commit data...
futex.h Loading commit data...
getorder.h Loading commit data...
gpio.h Loading commit data...
hardirq.h Loading commit data...
hugetlb.h Loading commit data...
hw_irq.h Loading commit data...
ide_iops.h Loading commit data...
int-ll64.h Loading commit data...
io.h Loading commit data...
ioctl.h Loading commit data...
iomap.h Loading commit data...
irq.h Loading commit data...
irq_regs.h Loading commit data...
irq_work.h Loading commit data...
irqflags.h Loading commit data...
kdebug.h Loading commit data...
kmap_types.h Loading commit data...
kvm_para.h Loading commit data...
libata-portmap.h Loading commit data...
linkage.h Loading commit data...
local.h Loading commit data...
local64.h Loading commit data...
mcs_spinlock.h Loading commit data...
memory_model.h Loading commit data...
mm-arch-hooks.h Loading commit data...
mm_hooks.h Loading commit data...
mmu.h Loading commit data...
mmu_context.h Loading commit data...
module.h Loading commit data...
msi.h Loading commit data...
mutex-dec.h Loading commit data...
mutex-null.h Loading commit data...
mutex-xchg.h Loading commit data...
mutex.h Loading commit data...
page.h Loading commit data...
param.h Loading commit data...
parport.h Loading commit data...
pci.h Loading commit data...
pci_iomap.h Loading commit data...
percpu.h Loading commit data...
pgalloc.h Loading commit data...
pgtable-nopmd.h Loading commit data...
pgtable-nopud.h Loading commit data...
pgtable.h Loading commit data...
preempt.h Loading commit data...
ptrace.h Loading commit data...
qrwlock.h Loading commit data...
qrwlock_types.h Loading commit data...
qspinlock.h Loading commit data...
qspinlock_types.h Loading commit data...
resource.h Loading commit data...
rtc.h Loading commit data...
rwsem.h Loading commit data...
seccomp.h Loading commit data...
sections.h Loading commit data...
segment.h Loading commit data...
serial.h Loading commit data...
siginfo.h Loading commit data...
signal.h Loading commit data...
simd.h Loading commit data...
sizes.h Loading commit data...
spinlock.h Loading commit data...
statfs.h Loading commit data...
string.h Loading commit data...
switch_to.h Loading commit data...
syscall.h Loading commit data...
syscalls.h Loading commit data...
termios-base.h Loading commit data...
termios.h Loading commit data...
timex.h Loading commit data...
tlb.h Loading commit data...
tlbflush.h Loading commit data...
topology.h Loading commit data...
trace_clock.h Loading commit data...
uaccess-unaligned.h Loading commit data...
uaccess.h Loading commit data...
unaligned.h Loading commit data...
unistd.h Loading commit data...
user.h Loading commit data...
vga.h Loading commit data...
vmlinux.lds.h Loading commit data...
vtime.h Loading commit data...
word-at-a-time.h Loading commit data...
xor.h Loading commit data...