Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755584AbcK3AgM (ORCPT ); Tue, 29 Nov 2016 19:36:12 -0500 Received: from mail-wj0-f193.google.com ([209.85.210.193]:33561 "EHLO mail-wj0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755233AbcK3AgB (ORCPT ); Tue, 29 Nov 2016 19:36:01 -0500 From: Chris Wilson To: linux-kernel@vger.kernel.org Cc: Chris Wilson , Peter Zijlstra , Maarten Lankhorst , =?UTF-8?q?Nicolai=20H=C3=A4hnle?= Subject: [PATCH 2/4] locking: Add kselftests for ww_mutex AA deadlock detection Date: Wed, 30 Nov 2016 00:35:46 +0000 Message-Id: <20161130003548.22266-2-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161130003548.22266-1-chris@chris-wilson.co.uk> References: <1480335612-12069-1-git-send-email-nhaehnle@gmail.com> <20161130003548.22266-1-chris@chris-wilson.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1443 Lines: 67 Signed-off-by: Chris Wilson Cc: Peter Zijlstra Cc: Maarten Lankhorst Cc: Nicolai Hähnle --- 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 e94b807e06c2..02a4bacf8aac 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; } -- 2.10.2