LKML Archive on
 help / color / Atom feed
From: Guenter Roeck <>
To: Peter Zijlstra <>
Cc:, Guenter Roeck <>,
	Will Deacon <>,
	Chris Wilson <>,
	Ingo Molnar <>
Subject: [PATCH] locking: Fix runtime warning in ww mutex selftest
Date: Tue,  2 Oct 2018 14:48:49 -0700
Message-ID: <> (raw)

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:
irq event stamp: 1305

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 <>
Cc: Chris Wilson <>
Cc: Peter Zijlstra <>
Cc: Ingo Molnar <>
Signed-off-by: Guenter Roeck <>
 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_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->a_mutex);
+	if (!erra)
+		ww_mutex_unlock(&cycle->a_mutex);
-	cycle->result = err;
+	cycle->result = err ?: erra;
 static int __test_cycle(unsigned int nthreads)

             reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-02 21:48 Guenter Roeck [this message]
2018-10-03  7:32 ` [tip:locking/urgent] locking/ww_mutex: Fix runtime warning in the WW " tip-bot for Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

LKML Archive on

Archives are clonable:
	git clone --mirror lkml/git/0.git
	git clone --mirror lkml/git/1.git
	git clone --mirror lkml/git/2.git
	git clone --mirror lkml/git/3.git
	git clone --mirror lkml/git/4.git
	git clone --mirror lkml/git/5.git
	git clone --mirror lkml/git/6.git
	git clone --mirror lkml/git/7.git
	git clone --mirror lkml/git/8.git
	git clone --mirror lkml/git/9.git
	git clone --mirror lkml/git/10.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ \
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone