From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752356AbdANMyD (ORCPT ); Sat, 14 Jan 2017 07:54:03 -0500 Received: from terminus.zytor.com ([198.137.202.10]:52530 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750792AbdANMyB (ORCPT ); Sat, 14 Jan 2017 07:54:01 -0500 Date: Sat, 14 Jan 2017 04:52:52 -0800 From: tip-bot for Chris Wilson Message-ID: Cc: dev@mblankhorst.nl, paulmck@linux.vnet.ibm.com, linux-kernel@vger.kernel.org, mingo@kernel.org, akpm@linux-foundation.org, peterz@infradead.org, chris@chris-wilson.co.uk, nhaehnle@gmail.com, tglx@linutronix.de, hpa@zytor.com, torvalds@linux-foundation.org Reply-To: dev@mblankhorst.nl, paulmck@linux.vnet.ibm.com, nhaehnle@gmail.com, peterz@infradead.org, linux-kernel@vger.kernel.org, mingo@kernel.org, chris@chris-wilson.co.uk, akpm@linux-foundation.org, hpa@zytor.com, tglx@linutronix.de, torvalds@linux-foundation.org In-Reply-To: <20161201114711.28697-3-chris@chris-wilson.co.uk> References: <20161201114711.28697-3-chris@chris-wilson.co.uk> To: linux-tip-commits@vger.kernel.org Subject: [tip:locking/core] locking/ww_mutex: Add ww_mutex to locktorture test Git-Commit-ID: 0186a6cbdc6287fde65858e5d9c714dc167b8ace X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 0186a6cbdc6287fde65858e5d9c714dc167b8ace Gitweb: http://git.kernel.org/tip/0186a6cbdc6287fde65858e5d9c714dc167b8ace Author: Chris Wilson AuthorDate: Thu, 1 Dec 2016 11:47:05 +0000 Committer: Ingo Molnar CommitDate: Sat, 14 Jan 2017 11:37:14 +0100 locking/ww_mutex: Add ww_mutex to locktorture test Although ww_mutexes degenerate into mutexes, it would be useful to torture the deadlock handling between multiple ww_mutexes in addition to torturing the regular mutexes. Signed-off-by: Chris Wilson Signed-off-by: Peter Zijlstra (Intel) Cc: Andrew Morton Cc: Linus Torvalds Cc: Maarten Lankhorst Cc: Nicolai Hähnle Cc: Paul E. McKenney Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/20161201114711.28697-3-chris@chris-wilson.co.uk Signed-off-by: Ingo Molnar --- kernel/locking/locktorture.c | 73 ++++++++++++++++++++++ .../selftests/rcutorture/configs/lock/CFLIST | 1 + .../rcutorture/configs/lock/{LOCK06 => LOCK07} | 0 .../selftests/rcutorture/configs/lock/LOCK07.boot | 1 + 4 files changed, 75 insertions(+) diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c index f8c5af5..9bffedd 100644 --- a/kernel/locking/locktorture.c +++ b/kernel/locking/locktorture.c @@ -372,6 +372,78 @@ static struct lock_torture_ops mutex_lock_ops = { .name = "mutex_lock" }; +#include +static DEFINE_WW_CLASS(torture_ww_class); +static DEFINE_WW_MUTEX(torture_ww_mutex_0, &torture_ww_class); +static DEFINE_WW_MUTEX(torture_ww_mutex_1, &torture_ww_class); +static DEFINE_WW_MUTEX(torture_ww_mutex_2, &torture_ww_class); + +static int torture_ww_mutex_lock(void) +__acquires(torture_ww_mutex_0) +__acquires(torture_ww_mutex_1) +__acquires(torture_ww_mutex_2) +{ + LIST_HEAD(list); + struct reorder_lock { + struct list_head link; + struct ww_mutex *lock; + } locks[3], *ll, *ln; + struct ww_acquire_ctx ctx; + + locks[0].lock = &torture_ww_mutex_0; + list_add(&locks[0].link, &list); + + locks[1].lock = &torture_ww_mutex_1; + list_add(&locks[1].link, &list); + + locks[2].lock = &torture_ww_mutex_2; + list_add(&locks[2].link, &list); + + ww_acquire_init(&ctx, &torture_ww_class); + + list_for_each_entry(ll, &list, link) { + int err; + + err = ww_mutex_lock(ll->lock, &ctx); + if (!err) + continue; + + ln = ll; + list_for_each_entry_continue_reverse(ln, &list, link) + ww_mutex_unlock(ln->lock); + + if (err != -EDEADLK) + return err; + + ww_mutex_lock_slow(ll->lock, &ctx); + list_move(&ll->link, &list); + } + + ww_acquire_fini(&ctx); + return 0; +} + +static void torture_ww_mutex_unlock(void) +__releases(torture_ww_mutex_0) +__releases(torture_ww_mutex_1) +__releases(torture_ww_mutex_2) +{ + ww_mutex_unlock(&torture_ww_mutex_0); + ww_mutex_unlock(&torture_ww_mutex_1); + ww_mutex_unlock(&torture_ww_mutex_2); +} + +static struct lock_torture_ops ww_mutex_lock_ops = { + .writelock = torture_ww_mutex_lock, + .write_delay = torture_mutex_delay, + .task_boost = torture_boost_dummy, + .writeunlock = torture_ww_mutex_unlock, + .readlock = NULL, + .read_delay = NULL, + .readunlock = NULL, + .name = "ww_mutex_lock" +}; + #ifdef CONFIG_RT_MUTEXES static DEFINE_RT_MUTEX(torture_rtmutex); @@ -793,6 +865,7 @@ static int __init lock_torture_init(void) &spin_lock_ops, &spin_lock_irq_ops, &rw_lock_ops, &rw_lock_irq_ops, &mutex_lock_ops, + &ww_mutex_lock_ops, #ifdef CONFIG_RT_MUTEXES &rtmutex_lock_ops, #endif diff --git a/tools/testing/selftests/rcutorture/configs/lock/CFLIST b/tools/testing/selftests/rcutorture/configs/lock/CFLIST index b9611c5..41bae58 100644 --- a/tools/testing/selftests/rcutorture/configs/lock/CFLIST +++ b/tools/testing/selftests/rcutorture/configs/lock/CFLIST @@ -4,3 +4,4 @@ LOCK03 LOCK04 LOCK05 LOCK06 +LOCK07 diff --git a/tools/testing/selftests/rcutorture/configs/lock/LOCK06 b/tools/testing/selftests/rcutorture/configs/lock/LOCK07 similarity index 100% copy from tools/testing/selftests/rcutorture/configs/lock/LOCK06 copy to tools/testing/selftests/rcutorture/configs/lock/LOCK07 diff --git a/tools/testing/selftests/rcutorture/configs/lock/LOCK07.boot b/tools/testing/selftests/rcutorture/configs/lock/LOCK07.boot new file mode 100644 index 0000000..97dadd1 --- /dev/null +++ b/tools/testing/selftests/rcutorture/configs/lock/LOCK07.boot @@ -0,0 +1 @@ +locktorture.torture_type=ww_mutex_lock