From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752211AbdANMyi (ORCPT ); Sat, 14 Jan 2017 07:54:38 -0500 Received: from terminus.zytor.com ([198.137.202.10]:52630 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750734AbdANMyh (ORCPT ); Sat, 14 Jan 2017 07:54:37 -0500 Date: Sat, 14 Jan 2017 04:54:00 -0800 From: tip-bot for Chris Wilson Message-ID: Cc: paulmck@linux.vnet.ibm.com, nhaehnle@gmail.com, peterz@infradead.org, dev@mblankhorst.nl, linux-kernel@vger.kernel.org, tglx@linutronix.de, torvalds@linux-foundation.org, hpa@zytor.com, mingo@kernel.org, akpm@linux-foundation.org, chris@chris-wilson.co.uk Reply-To: paulmck@linux.vnet.ibm.com, nhaehnle@gmail.com, peterz@infradead.org, dev@mblankhorst.nl, linux-kernel@vger.kernel.org, tglx@linutronix.de, torvalds@linux-foundation.org, hpa@zytor.com, mingo@kernel.org, chris@chris-wilson.co.uk, akpm@linux-foundation.org In-Reply-To: <20161201114711.28697-5-chris@chris-wilson.co.uk> References: <20161201114711.28697-5-chris@chris-wilson.co.uk> To: linux-tip-commits@vger.kernel.org Subject: [tip:locking/core] locking/ww_mutex: Add kselftests for ww_mutex AA deadlock detection Git-Commit-ID: c22fb3807fd0a3bdd98c13c4d2190ab064e6c09d 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: c22fb3807fd0a3bdd98c13c4d2190ab064e6c09d Gitweb: http://git.kernel.org/tip/c22fb3807fd0a3bdd98c13c4d2190ab064e6c09d Author: Chris Wilson AuthorDate: Thu, 1 Dec 2016 11:47:07 +0000 Committer: Ingo Molnar CommitDate: Sat, 14 Jan 2017 11:37:15 +0100 locking/ww_mutex: Add kselftests for ww_mutex AA deadlock detection 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-5-chris@chris-wilson.co.uk Signed-off-by: Ingo Molnar --- kernel/locking/test-ww_mutex.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/kernel/locking/test-ww_mutex.c b/kernel/locking/test-ww_mutex.c index 472d5b1..835fa7a 100644 --- a/kernel/locking/test-ww_mutex.c +++ b/kernel/locking/test-ww_mutex.c @@ -118,6 +118,41 @@ static int test_mutex(void) return 0; } +static int test_aa(void) +{ + struct ww_mutex mutex; + struct ww_acquire_ctx ctx; + int ret; + + ww_mutex_init(&mutex, &ww_class); + ww_acquire_init(&ctx, &ww_class); + + ww_mutex_lock(&mutex, &ctx); + + if (ww_mutex_trylock(&mutex)) { + pr_err("%s: trylocked itself!\n", __func__); + ww_mutex_unlock(&mutex); + ret = -EINVAL; + goto out; + } + + ret = ww_mutex_lock(&mutex, &ctx); + if (ret != -EALREADY) { + pr_err("%s: missed deadlock for recursing, ret=%d\n", + __func__, ret); + if (!ret) + ww_mutex_unlock(&mutex); + ret = -EINVAL; + goto out; + } + + ret = 0; +out: + ww_mutex_unlock(&mutex); + ww_acquire_fini(&ctx); + return ret; +} + static int __init test_ww_mutex_init(void) { int ret; @@ -126,6 +161,10 @@ static int __init test_ww_mutex_init(void) if (ret) return ret; + ret = test_aa(); + if (ret) + return ret; + return 0; }