From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936624AbdIYWT0 (ORCPT ); Mon, 25 Sep 2017 18:19:26 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:38443 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936021AbdIYWTV (ORCPT ); Mon, 25 Sep 2017 18:19:21 -0400 X-Google-Smtp-Source: AOwi7QB2NZZc3jWSIZYsEHg2GJ94oz8CBQIlI8xyrr7Hot5UMLgxxzjioVUsvSlXRWGbRf8hK+ygfA== From: Boqun Feng To: linux-kernel@vger.kernel.org Cc: Ingo Molnar , Peter Zijlstra , Gautham R Shenoy , Byungchul Park , Boqun Feng Subject: [RFC tip/locking/lockdep v3 10/14] lockdep/selftest: Add a R-L/L-W test case specific to chain cache behavior Date: Tue, 26 Sep 2017 06:18:44 +0800 Message-Id: <20170925221848.6646-11-boqun.feng@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170925221848.6646-1-boqun.feng@gmail.com> References: <20170925221848.6646-1-boqun.feng@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As our chain cache doesn't differ read/write locks, so even we can detect a read-lock/lock-write deadlock in check_noncircular(), we can still be fooled if a read-lock/lock-read case(which is not a deadlock) comes first. So introduce this test case to test specific to the chain cache behavior on detecting recursive read lock related deadlocks. Signed-off-by: Boqun Feng --- lib/locking-selftest.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c index cd0b5c964bd0..1f794bb441a9 100644 --- a/lib/locking-selftest.c +++ b/lib/locking-selftest.c @@ -394,6 +394,49 @@ static void rwsem_ABBA1(void) MU(Y1); // should fail } +/* + * read_lock(A) + * spin_lock(B) + * spin_lock(B) + * write_lock(A) + * + * This test case is aimed at poking whether the chain cache prevents us from + * detecting a read-lock/lock-write deadlock: if the chain cache doesn't differ + * read/write locks, the following case may happen + * + * { read_lock(A)->lock(B) dependency exists } + * + * P0: + * lock(B); + * read_lock(A); + * + * { Not a deadlock, B -> A is added in the chain cache } + * + * P1: + * lock(B); + * write_lock(A); + * + * { B->A found in chain cache, not reported as a deadlock } + * + */ +static void rlock_chaincache_ABBA1(void) +{ + RL(X1); + L(Y1); + U(Y1); + RU(X1); + + L(Y1); + RL(X1); + RU(X1); + U(Y1); + + L(Y1); + WL(X1); + WU(X1); + U(Y1); // should fail +} + /* * read_lock(A) * spin_lock(B) @@ -2052,6 +2095,10 @@ void locking_selftest(void) pr_cont(" |"); dotest(rwsem_ABBA3, FAILURE, LOCKTYPE_RWSEM); + print_testname("chain cached mixed R-L/L-W ABBA"); + pr_cont(" |"); + dotest(rlock_chaincache_ABBA1, FAILURE, LOCKTYPE_RWLOCK); + printk(" --------------------------------------------------------------------------\n"); /* -- 2.14.1