locking: Fix runtime warning in ww mutex selftest
PATCH 1/1 locking: Fix runtime warning in ww mutex selftest
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.
ww_mutex cyclic deadlocks")
--- kernel/locking/test-ww_mutex.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
kernel/locking/test-ww_mutex.c +6 -4
@@ -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)
Signature · 1 line
2.7.4
tip-bot for Guenter Roeck
merge bot[tip:locking/urgent] locking/ww_mutex: Fix runtime warning in the WW mutex selftest
locking/ww_mutex: Fix runtime warning in the WW mutex selftest
Commit-ID: e4a02ed2aaf447fa849e3254bfdb3b9b01e1e520 Gitweb: https://git.kernel.org/tip/e4a02ed2aaf447fa849e3254bfdb3b9b01e1e520 Author: Guenter Roeck <[email protected]> AuthorDate: Tue, 2 Oct 2018 14:48:49 -0700 Committer: Ingo Molnar <[email protected]> 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.
--- kernel/locking/test-ww_mutex.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
kernel/locking/test-ww_mutex.c +6 -4
@@ -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)