mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-25 05:34:00 +08:00
b17718d02f
Jiri reported a machine stuck in multi_cpu_stop() with migrate_swap_stop() as function and with the following src,dst cpu pairs: {11, 4} {13, 11} { 4, 13} 4 11 13 cpuM: queue(4 ,13) *Ma cpuN: queue(13,11) *N Na *M Mb cpuO: queue(11, 4) *O Oa *Nb *Ob Where *X denotes the cpu running the queueing of cpu-X and X[ab] denotes the first/second queued work. You'll observe the top of the workqueue for each cpu: 4,11,13 to be work from cpus: M, O, N resp. IOW. deadlock. Do away with the queueing trickery and introduce lg_double_lock() to lock both CPUs and fully serialize the stop_two_cpus() callers instead of the partial (and buggy) serialization we have now. Reported-by: Jiri Olsa <jolsa@redhat.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Borislav Petkov <bp@alien8.de> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rik van Riel <riel@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/20150605153023.GH19282@twins.programming.kicks-ass.net Signed-off-by: Ingo Molnar <mingo@kernel.org>
82 lines
2.5 KiB
C
82 lines
2.5 KiB
C
/*
|
|
* Specialised local-global spinlock. Can only be declared as global variables
|
|
* to avoid overhead and keep things simple (and we don't want to start using
|
|
* these inside dynamically allocated structures).
|
|
*
|
|
* "local/global locks" (lglocks) can be used to:
|
|
*
|
|
* - Provide fast exclusive access to per-CPU data, with exclusive access to
|
|
* another CPU's data allowed but possibly subject to contention, and to
|
|
* provide very slow exclusive access to all per-CPU data.
|
|
* - Or to provide very fast and scalable read serialisation, and to provide
|
|
* very slow exclusive serialisation of data (not necessarily per-CPU data).
|
|
*
|
|
* Brlocks are also implemented as a short-hand notation for the latter use
|
|
* case.
|
|
*
|
|
* Copyright 2009, 2010, Nick Piggin, Novell Inc.
|
|
*/
|
|
#ifndef __LINUX_LGLOCK_H
|
|
#define __LINUX_LGLOCK_H
|
|
|
|
#include <linux/spinlock.h>
|
|
#include <linux/lockdep.h>
|
|
#include <linux/percpu.h>
|
|
#include <linux/cpu.h>
|
|
#include <linux/notifier.h>
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
#ifdef CONFIG_DEBUG_LOCK_ALLOC
|
|
#define LOCKDEP_INIT_MAP lockdep_init_map
|
|
#else
|
|
#define LOCKDEP_INIT_MAP(a, b, c, d)
|
|
#endif
|
|
|
|
struct lglock {
|
|
arch_spinlock_t __percpu *lock;
|
|
#ifdef CONFIG_DEBUG_LOCK_ALLOC
|
|
struct lock_class_key lock_key;
|
|
struct lockdep_map lock_dep_map;
|
|
#endif
|
|
};
|
|
|
|
#define DEFINE_LGLOCK(name) \
|
|
static DEFINE_PER_CPU(arch_spinlock_t, name ## _lock) \
|
|
= __ARCH_SPIN_LOCK_UNLOCKED; \
|
|
struct lglock name = { .lock = &name ## _lock }
|
|
|
|
#define DEFINE_STATIC_LGLOCK(name) \
|
|
static DEFINE_PER_CPU(arch_spinlock_t, name ## _lock) \
|
|
= __ARCH_SPIN_LOCK_UNLOCKED; \
|
|
static struct lglock name = { .lock = &name ## _lock }
|
|
|
|
void lg_lock_init(struct lglock *lg, char *name);
|
|
|
|
void lg_local_lock(struct lglock *lg);
|
|
void lg_local_unlock(struct lglock *lg);
|
|
void lg_local_lock_cpu(struct lglock *lg, int cpu);
|
|
void lg_local_unlock_cpu(struct lglock *lg, int cpu);
|
|
|
|
void lg_double_lock(struct lglock *lg, int cpu1, int cpu2);
|
|
void lg_double_unlock(struct lglock *lg, int cpu1, int cpu2);
|
|
|
|
void lg_global_lock(struct lglock *lg);
|
|
void lg_global_unlock(struct lglock *lg);
|
|
|
|
#else
|
|
/* When !CONFIG_SMP, map lglock to spinlock */
|
|
#define lglock spinlock
|
|
#define DEFINE_LGLOCK(name) DEFINE_SPINLOCK(name)
|
|
#define DEFINE_STATIC_LGLOCK(name) static DEFINE_SPINLOCK(name)
|
|
#define lg_lock_init(lg, name) spin_lock_init(lg)
|
|
#define lg_local_lock spin_lock
|
|
#define lg_local_unlock spin_unlock
|
|
#define lg_local_lock_cpu(lg, cpu) spin_lock(lg)
|
|
#define lg_local_unlock_cpu(lg, cpu) spin_unlock(lg)
|
|
#define lg_global_lock spin_lock
|
|
#define lg_global_unlock spin_unlock
|
|
#endif
|
|
|
|
#endif
|