linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] locking: Fix runtime warning in ww mutex selftest
@ 2018-10-02 21:48 Guenter Roeck
  2018-10-03  7:32 ` [tip:locking/urgent] locking/ww_mutex: Fix runtime warning in the WW " tip-bot for Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Guenter Roeck @ 2018-10-02 21:48 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: linux-kernel, Guenter Roeck, Will Deacon, Chris Wilson, Ingo Molnar

If CONFIG_WW_MUTEX_SELFTEST is enabled, booting an image
in an arm64 virtual machine results in the following
traceback if 8 CPUs are enabled.

DEBUG_LOCKS_WARN_ON(__owner_task(owner) != current)
WARNING: CPU: 2 PID: 537 at kernel/locking/mutex.c:1033 __mutex_unlock_slowpath+0x1a8/0x2e0
Modules linked in:
CPU: 2 PID: 537 Comm: kworker/u16:11 Not tainted 4.18.12-rc1-00133-g74ba23ae47e5 #1
Hardware name: linux,dummy-virt (DT)
Workqueue: test-ww_mutex test_cycle_work
pstate: 40000005 (nZcv daif -PAN -UAO)
pc : __mutex_unlock_slowpath+0x1a8/0x2e0
lr : __mutex_unlock_slowpath+0x1a8/0x2e0
sp : ffff00000acbbc50
x29: ffff00000acbbc50 x28: 0000000000000000
x27: 0000000000000000 x26: ffff000009fc1d80
x25: ffff000009f86558 x24: ffff000008f8d410
x23: ffff000009f86000 x22: ffff00000926f000
x21: ffff00000acbbcb8 x20: ffff80001be208c8
x19: 0000000000000000 x18: ffffffffffffffff
x17: 0000000000000000 x16: ffff80001c2a0000
x15: ffff00000926f808 x14: ffff000089f85d3f
x13: ffff000009f85d4d x12: ffff00000928a000
x11: 0000000005f5e0ff x10: ffff00000acbb8a0
x9 : 0000000000000000 x8 : ffff00000926f808
x7 : ffff000008149180 x6 : 0000000000000000
x5 : 0000000000000000 x4 : 0000000000000000
x3 : ffffffffffffffff x2 : ffff00000928ab40
x1 : 6172e063a21fe300 x0 : 0000000000000000
Call trace:
 __mutex_unlock_slowpath+0x1a8/0x2e0
 ww_mutex_unlock+0x48/0xa0
 test_cycle_work+0xf8/0x200
 process_one_work+0x258/0x410
 worker_thread+0x40/0x458
 kthread+0x128/0x130
 ret_from_fork+0x10/0x18
irq event stamp: 1305
_raw_spin_unlock_irq+0x2c/0x60
__schedule+0xbc/0x780
__do_softirq+0x1e8/0x260
irq_exit+0x144/0x150

If requesting b_mutex fails with -EDEADLK, the error variable
is reassigned to the return value from calling ww_mutex_lock
on a_mutex again. If this call fails, a_mutex is not locked.
It is, however, unconditionally unlocked subsequently, causing
the reported warning. Fix the problem by using two error variables.

With this change, the selftest still fails as follows.

cyclic deadlock not resolved, ret[7/8] = -35

However, the traceback is gone.

Fixes: d1b42b800e5d0 ("locking/ww_mutex: Add kselftests for resolving
ww_mutex cyclic deadlocks")
Cc: Will Deacon <will.deacon@arm.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 kernel/locking/test-ww_mutex.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/kernel/locking/test-ww_mutex.c b/kernel/locking/test-ww_mutex.c
index 0be047dbd897..65a3b7e55b9f 100644
--- a/kernel/locking/test-ww_mutex.c
+++ b/kernel/locking/test-ww_mutex.c
@@ -260,7 +260,7 @@ static void test_cycle_work(struct work_struct *work)
 {
 	struct test_cycle *cycle = container_of(work, typeof(*cycle), work);
 	struct ww_acquire_ctx ctx;
-	int err;
+	int err, erra = 0;
 
 	ww_acquire_init(&ctx, &ww_class);
 	ww_mutex_lock(&cycle->a_mutex, &ctx);
@@ -270,17 +270,19 @@ static void test_cycle_work(struct work_struct *work)
 
 	err = ww_mutex_lock(cycle->b_mutex, &ctx);
 	if (err == -EDEADLK) {
+		err = 0;
 		ww_mutex_unlock(&cycle->a_mutex);
 		ww_mutex_lock_slow(cycle->b_mutex, &ctx);
-		err = ww_mutex_lock(&cycle->a_mutex, &ctx);
+		erra = ww_mutex_lock(&cycle->a_mutex, &ctx);
 	}
 
 	if (!err)
 		ww_mutex_unlock(cycle->b_mutex);
-	ww_mutex_unlock(&cycle->a_mutex);
+	if (!erra)
+		ww_mutex_unlock(&cycle->a_mutex);
 	ww_acquire_fini(&ctx);
 
-	cycle->result = err;
+	cycle->result = err ?: erra;
 }
 
 static int __test_cycle(unsigned int nthreads)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [tip:locking/urgent] locking/ww_mutex: Fix runtime warning in the WW mutex selftest
  2018-10-02 21:48 [PATCH] locking: Fix runtime warning in ww mutex selftest Guenter Roeck
@ 2018-10-03  7:32 ` tip-bot for Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for Guenter Roeck @ 2018-10-03  7:32 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, linux-kernel, will.deacon, linux, torvalds, chris, peterz,
	hpa, tglx

Commit-ID:  e4a02ed2aaf447fa849e3254bfdb3b9b01e1e520
Gitweb:     https://git.kernel.org/tip/e4a02ed2aaf447fa849e3254bfdb3b9b01e1e520
Author:     Guenter Roeck <linux@roeck-us.net>
AuthorDate: Tue, 2 Oct 2018 14:48:49 -0700
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 3 Oct 2018 08:56:31 +0200

locking/ww_mutex: Fix runtime warning in the WW mutex selftest

If CONFIG_WW_MUTEX_SELFTEST=y is enabled, booting an image
in an arm64 virtual machine results in the following
traceback if 8 CPUs are enabled:

  DEBUG_LOCKS_WARN_ON(__owner_task(owner) != current)
  WARNING: CPU: 2 PID: 537 at kernel/locking/mutex.c:1033 __mutex_unlock_slowpath+0x1a8/0x2e0
  ...
  Call trace:
   __mutex_unlock_slowpath()
   ww_mutex_unlock()
   test_cycle_work()
   process_one_work()
   worker_thread()
   kthread()
   ret_from_fork()

If requesting b_mutex fails with -EDEADLK, the error variable
is reassigned to the return value from calling ww_mutex_lock
on a_mutex again. If this call fails, a_mutex is not locked.
It is, however, unconditionally unlocked subsequently, causing
the reported warning. Fix the problem by using two error variables.

With this change, the selftest still fails as follows:

  cyclic deadlock not resolved, ret[7/8] = -35

However, the traceback is gone.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
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>
Fixes: d1b42b800e5d0 ("locking/ww_mutex: Add kselftests for resolving ww_mutex cyclic deadlocks")
Link: http://lkml.kernel.org/r/1538516929-9734-1-git-send-email-linux@roeck-us.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/locking/test-ww_mutex.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/kernel/locking/test-ww_mutex.c b/kernel/locking/test-ww_mutex.c
index 0be047dbd897..65a3b7e55b9f 100644
--- a/kernel/locking/test-ww_mutex.c
+++ b/kernel/locking/test-ww_mutex.c
@@ -260,7 +260,7 @@ static void test_cycle_work(struct work_struct *work)
 {
 	struct test_cycle *cycle = container_of(work, typeof(*cycle), work);
 	struct ww_acquire_ctx ctx;
-	int err;
+	int err, erra = 0;
 
 	ww_acquire_init(&ctx, &ww_class);
 	ww_mutex_lock(&cycle->a_mutex, &ctx);
@@ -270,17 +270,19 @@ static void test_cycle_work(struct work_struct *work)
 
 	err = ww_mutex_lock(cycle->b_mutex, &ctx);
 	if (err == -EDEADLK) {
+		err = 0;
 		ww_mutex_unlock(&cycle->a_mutex);
 		ww_mutex_lock_slow(cycle->b_mutex, &ctx);
-		err = ww_mutex_lock(&cycle->a_mutex, &ctx);
+		erra = ww_mutex_lock(&cycle->a_mutex, &ctx);
 	}
 
 	if (!err)
 		ww_mutex_unlock(cycle->b_mutex);
-	ww_mutex_unlock(&cycle->a_mutex);
+	if (!erra)
+		ww_mutex_unlock(&cycle->a_mutex);
 	ww_acquire_fini(&ctx);
 
-	cycle->result = err;
+	cycle->result = err ?: erra;
 }
 
 static int __test_cycle(unsigned int nthreads)

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-10-03  7:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-02 21:48 [PATCH] locking: Fix runtime warning in ww mutex selftest Guenter Roeck
2018-10-03  7:32 ` [tip:locking/urgent] locking/ww_mutex: Fix runtime warning in the WW " tip-bot for Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).