android_kernel_oneplus_msm8998/kernel/locking
Imre Deak aa147b3bcd locking/lockdep: Fix merging of hlocks with non-zero references
[ Upstream commit d9349850e188b8b59e5322fda17ff389a1c0cd7d ]

The sequence

	static DEFINE_WW_CLASS(test_ww_class);

	struct ww_acquire_ctx ww_ctx;
	struct ww_mutex ww_lock_a;
	struct ww_mutex ww_lock_b;
	struct ww_mutex ww_lock_c;
	struct mutex lock_c;

	ww_acquire_init(&ww_ctx, &test_ww_class);

	ww_mutex_init(&ww_lock_a, &test_ww_class);
	ww_mutex_init(&ww_lock_b, &test_ww_class);
	ww_mutex_init(&ww_lock_c, &test_ww_class);

	mutex_init(&lock_c);

	ww_mutex_lock(&ww_lock_a, &ww_ctx);

	mutex_lock(&lock_c);

	ww_mutex_lock(&ww_lock_b, &ww_ctx);
	ww_mutex_lock(&ww_lock_c, &ww_ctx);

	mutex_unlock(&lock_c);	(*)

	ww_mutex_unlock(&ww_lock_c);
	ww_mutex_unlock(&ww_lock_b);
	ww_mutex_unlock(&ww_lock_a);

	ww_acquire_fini(&ww_ctx); (**)

will trigger the following error in __lock_release() when calling
mutex_release() at **:

	DEBUG_LOCKS_WARN_ON(depth <= 0)

The problem is that the hlock merging happening at * updates the
references for test_ww_class incorrectly to 3 whereas it should've
updated it to 4 (representing all the instances for ww_ctx and
ww_lock_[abc]).

Fix this by updating the references during merging correctly taking into
account that we can have non-zero references (both for the hlock that we
merge into another hlock or for the hlock we are merging into).

Signed-off-by: Imre Deak <imre.deak@intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= <ville.syrjala@linux.intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will.deacon@arm.com>
Link: https://lkml.kernel.org/r/20190524201509.9199-2-imre.deak@intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-08-04 09:34:44 +02:00
..
lglock.c
lockdep.c locking/lockdep: Fix merging of hlocks with non-zero references 2019-08-04 09:34:44 +02:00
lockdep_internals.h
lockdep_proc.c
lockdep_states.h
locktorture.c locktorture: Fix potential memory leak with rw lock test 2017-09-13 14:09:46 -07:00
Makefile
mcs_spinlock.h
mutex-debug.c
mutex-debug.h
mutex.c locking/mutex: Allow next waiter lockless wakeup 2018-01-17 09:35:27 +01:00
mutex.h
osq_lock.c locking/osq_lock: Fix osq_lock queue corruption 2018-09-19 22:48:56 +02:00
percpu-rwsem.c
qrwlock.c
qspinlock.c locking/qspinlock: Ensure node->count is updated before initialising node 2018-05-30 07:48:57 +02:00
qspinlock_paravirt.h
rtmutex-debug.c
rtmutex-debug.h
rtmutex.c futex,rt_mutex: Restructure rt_mutex_finish_proxy_lock() 2019-03-23 08:44:28 +01:00
rtmutex.h
rtmutex_common.h futex,rt_mutex: Restructure rt_mutex_finish_proxy_lock() 2019-03-23 08:44:28 +01:00
rwsem-spinlock.c
rwsem-xadd.c locking/rwsem-xadd: Fix missed wakeup due to reordering of load 2018-09-19 22:48:56 +02:00
rwsem.c
rwsem.h
semaphore.c
spinlock.c
spinlock_debug.c