Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp252828pxa; Thu, 27 Aug 2020 00:57:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNB2kX1sBb2yXyYdi8aTlKAV9lw5AmtNYzwwxukUWMIKoBei/VylUXTURaKUlGpr1biV2H X-Received: by 2002:a17:906:80da:: with SMTP id a26mr19081375ejx.311.1598515054591; Thu, 27 Aug 2020 00:57:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598515054; cv=none; d=google.com; s=arc-20160816; b=AmsUuxf2qm7ET2uAacWFOk6dp7hqKd3ApgGZYoAkEGd8+SAOf8F5Lg72JOBOvjqr2+ cqyMATCV6QHGcbu3GeanbxGRE4/zn/qBRjriw6yPuXF91AUkotYk5STwvfwnx98B8ygV oC0t4OZGAM/NkjOZ4tNiV/9g46eEPdrTvVH8jhp3Yoy++i/0tME9Db/qybtN8OpYB1Be nUTxe+qTw0G5BJtNf27ide9Vrx9SOkxCfcybiSDAM4TL2YRgXPBV3I3PzHidQC3oxIcv m48MSX3WWK2kAaT59qTZFNcVGaKfWyEiW9pIIeA4+XFqnB7yGbjZ5kKbuK1b870oMW8D Ux0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:dkim-signature :dkim-signature:date; bh=wVa/HO7M3IDLARyhmD+ozLl5NmQVSWQTbpR0Fs8sY4M=; b=b4FutlefSxg7MHRHMItgFBaftGhLgOlwX3Nph/DY5BWFqygZTWo3p6pvJ5YCecikg1 p6TlYjboctKO7e6mg4d+cRv1/9nJo6kRXoayP9sw6n+4Izb5XVVqjSAqMUCR9KGtEV8A iWUyRtsWA8YpwKTSFTSFKJI42XDsGMy7L61UzeBZXB0dbpi77zww3xyT38nbkgsZwL2O 4LGDgpz+DDuyJjaziJehxTvv4VMPAyWByx6ExX7ypaKpnYzrhPuZgAPLz4MzBZ/6D9J4 t271QDW+USCrE2R0/KbCkMwgIXRRJTXoVp2tXZqqtNNY9g+gN3A0OvA3t+NG6cylGhgn YtxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linutronix.de header.s=2020 header.b=RbVkEOYn; dkim=neutral (no key) header.i=@vger.kernel.org; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a3si847734ejc.80.2020.08.27.00.57.11; Thu, 27 Aug 2020 00:57:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@linutronix.de header.s=2020 header.b=RbVkEOYn; dkim=neutral (no key) header.i=@vger.kernel.org; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728426AbgH0Hy3 (ORCPT + 99 others); Thu, 27 Aug 2020 03:54:29 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:36528 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728088AbgH0HyS (ORCPT ); Thu, 27 Aug 2020 03:54:18 -0400 Date: Thu, 27 Aug 2020 07:54:15 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1598514856; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wVa/HO7M3IDLARyhmD+ozLl5NmQVSWQTbpR0Fs8sY4M=; b=RbVkEOYnDfD6FPa7xJfV7yIL0+ce8HwK9GbEY7P2Tfz8UmSO1FU1qsyxcVGCO7rsYJRafF GqFgi1ZCzImdXORMc4e0Fp2KL1a5bUX0c8drwaDp/i6p6S8NVKh+AfCJoz9+sZfTQJZ2xI js2czr+B0AO91uyb0wc+mzi1nB+zDM+u/aQyIdFPTfQupgaJfC1ZDpggLOF2fGDn9Sqytf ZFNIZHAG7V8eo7AEfbIe+71pUTidrdRFhEz3neS/C/t06aoZMnV8IwexGosIzw6QyR/GVV CZLN6cReDpUK1Hx25RKm2DJ7M6GU8Dxct3gE8+3KG5HLV25L3nItfEkjzvUvnw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1598514856; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wVa/HO7M3IDLARyhmD+ozLl5NmQVSWQTbpR0Fs8sY4M=; b=06JZkA48JYZ+KI/4D1MJggKR7RM2cZPqs4zKKYdTGm9rJI4T/pA26BTNihEjhvNd7D5x8X o2B9WzZ1lz999XAw== From: "tip-bot2 for Boqun Feng" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] lockdep/selftest: Add more recursive read related test cases Cc: Boqun Feng , "Peter Zijlstra (Intel)" , x86 , LKML In-Reply-To: <20200807074238.1632519-17-boqun.feng@gmail.com> References: <20200807074238.1632519-17-boqun.feng@gmail.com> MIME-Version: 1.0 Message-ID: <159851485592.20229.16708438089906327060.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the locking/core branch of tip: Commit-ID: 8ef7ca75120a39167def40f41daefee013c4b5af Gitweb: https://git.kernel.org/tip/8ef7ca75120a39167def40f41daefee013c4b5af Author: Boqun Feng AuthorDate: Fri, 07 Aug 2020 15:42:35 +08:00 Committer: Peter Zijlstra CommitterDate: Wed, 26 Aug 2020 12:42:07 +02:00 lockdep/selftest: Add more recursive read related test cases Add those four test cases: 1. X --(ER)--> Y --(ER)--> Z --(ER)--> X is deadlock. 2. X --(EN)--> Y --(SR)--> Z --(ER)--> X is deadlock. 3. X --(EN)--> Y --(SR)--> Z --(SN)--> X is not deadlock. 4. X --(ER)--> Y --(SR)--> Z --(EN)--> X is not deadlock. Those self testcases are valuable for the development of supporting recursive read related deadlock detection. Signed-off-by: Boqun Feng Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20200807074238.1632519-17-boqun.feng@gmail.com --- lib/locking-selftest.c | 161 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 161 insertions(+) diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c index f65a658..76c314a 100644 --- a/lib/locking-selftest.c +++ b/lib/locking-selftest.c @@ -1035,6 +1035,133 @@ GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_soft_wlock) #undef E3 /* + * write-read / write-read / write-read deadlock even if read is recursive + */ + +#define E1() \ + \ + WL(X1); \ + RL(Y1); \ + RU(Y1); \ + WU(X1); + +#define E2() \ + \ + WL(Y1); \ + RL(Z1); \ + RU(Z1); \ + WU(Y1); + +#define E3() \ + \ + WL(Z1); \ + RL(X1); \ + RU(X1); \ + WU(Z1); + +#include "locking-selftest-rlock.h" +GENERATE_PERMUTATIONS_3_EVENTS(W1R2_W2R3_W3R1) + +#undef E1 +#undef E2 +#undef E3 + +/* + * write-write / read-read / write-read deadlock even if read is recursive + */ + +#define E1() \ + \ + WL(X1); \ + WL(Y1); \ + WU(Y1); \ + WU(X1); + +#define E2() \ + \ + RL(Y1); \ + RL(Z1); \ + RU(Z1); \ + RU(Y1); + +#define E3() \ + \ + WL(Z1); \ + RL(X1); \ + RU(X1); \ + WU(Z1); + +#include "locking-selftest-rlock.h" +GENERATE_PERMUTATIONS_3_EVENTS(W1W2_R2R3_W3R1) + +#undef E1 +#undef E2 +#undef E3 + +/* + * write-write / read-read / read-write is not deadlock when read is recursive + */ + +#define E1() \ + \ + WL(X1); \ + WL(Y1); \ + WU(Y1); \ + WU(X1); + +#define E2() \ + \ + RL(Y1); \ + RL(Z1); \ + RU(Z1); \ + RU(Y1); + +#define E3() \ + \ + RL(Z1); \ + WL(X1); \ + WU(X1); \ + RU(Z1); + +#include "locking-selftest-rlock.h" +GENERATE_PERMUTATIONS_3_EVENTS(W1R2_R2R3_W3W1) + +#undef E1 +#undef E2 +#undef E3 + +/* + * write-read / read-read / write-write is not deadlock when read is recursive + */ + +#define E1() \ + \ + WL(X1); \ + RL(Y1); \ + RU(Y1); \ + WU(X1); + +#define E2() \ + \ + RL(Y1); \ + RL(Z1); \ + RU(Z1); \ + RU(Y1); + +#define E3() \ + \ + WL(Z1); \ + WL(X1); \ + WU(X1); \ + WU(Z1); + +#include "locking-selftest-rlock.h" +GENERATE_PERMUTATIONS_3_EVENTS(W1W2_R2R3_R3W1) + +#undef E1 +#undef E2 +#undef E3 +/* * read-lock / write-lock recursion that is actually safe. */ @@ -1259,6 +1386,19 @@ static inline void print_testname(const char *testname) dotest(name##_##nr, FAILURE, LOCKTYPE_RWLOCK); \ pr_cont("\n"); +#define DO_TESTCASE_1RR(desc, name, nr) \ + print_testname(desc"/"#nr); \ + pr_cont(" |"); \ + dotest(name##_##nr, SUCCESS, LOCKTYPE_RWLOCK); \ + pr_cont("\n"); + +#define DO_TESTCASE_1RRB(desc, name, nr) \ + print_testname(desc"/"#nr); \ + pr_cont(" |"); \ + dotest(name##_##nr, FAILURE, LOCKTYPE_RWLOCK); \ + pr_cont("\n"); + + #define DO_TESTCASE_3(desc, name, nr) \ print_testname(desc"/"#nr); \ dotest(name##_spin_##nr, FAILURE, LOCKTYPE_SPIN); \ @@ -1368,6 +1508,22 @@ static inline void print_testname(const char *testname) DO_TESTCASE_2IB(desc, name, 312); \ DO_TESTCASE_2IB(desc, name, 321); +#define DO_TESTCASE_6x1RR(desc, name) \ + DO_TESTCASE_1RR(desc, name, 123); \ + DO_TESTCASE_1RR(desc, name, 132); \ + DO_TESTCASE_1RR(desc, name, 213); \ + DO_TESTCASE_1RR(desc, name, 231); \ + DO_TESTCASE_1RR(desc, name, 312); \ + DO_TESTCASE_1RR(desc, name, 321); + +#define DO_TESTCASE_6x1RRB(desc, name) \ + DO_TESTCASE_1RRB(desc, name, 123); \ + DO_TESTCASE_1RRB(desc, name, 132); \ + DO_TESTCASE_1RRB(desc, name, 213); \ + DO_TESTCASE_1RRB(desc, name, 231); \ + DO_TESTCASE_1RRB(desc, name, 312); \ + DO_TESTCASE_1RRB(desc, name, 321); + #define DO_TESTCASE_6x6(desc, name) \ DO_TESTCASE_6I(desc, name, 123); \ DO_TESTCASE_6I(desc, name, 132); \ @@ -2144,6 +2300,11 @@ void locking_selftest(void) pr_cont(" |"); dotest(rlock_chaincache_ABBA1, FAILURE, LOCKTYPE_RWLOCK); + DO_TESTCASE_6x1RRB("rlock W1R2/W2R3/W3R1", W1R2_W2R3_W3R1); + DO_TESTCASE_6x1RRB("rlock W1W2/R2R3/W3R1", W1W2_R2R3_W3R1); + DO_TESTCASE_6x1RR("rlock W1W2/R2R3/R3W1", W1W2_R2R3_R3W1); + DO_TESTCASE_6x1RR("rlock W1R2/R2R3/W3W1", W1R2_R2R3_W3W1); + printk(" --------------------------------------------------------------------------\n"); /*