Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2026229pxa; Fri, 7 Aug 2020 00:47:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkIUj9RN2ZeoZ6Q5BVb9aCXcsNZ1oo4u/4eCrmoQBSq9LC2l7G/eRXZJz0SNJu9S/Nk55Q X-Received: by 2002:a17:906:6a84:: with SMTP id p4mr8458573ejr.374.1596786473379; Fri, 07 Aug 2020 00:47:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596786473; cv=none; d=google.com; s=arc-20160816; b=z1Z+vcGGK79Od/CbBRdc6xXeaTDZ22QBr0mf1LD+HXZSlB/rPcdEY73kLyzAg8r5bX dnQv0WkXKRVZvd7ao5Rg6mgFtRulxjgD2el1XiplDUFGhiQETt8fzQUBOVXAkGiv87WI v824FegATXPVyvVm7k33eDgGvTmFd5f5FaqBou7wG639v0vqYk0vX/jrjHqyz6KS1mf6 EzUCjMnG5obdX2QatXEaiFvr8ULLKSEtK3d90nO6UnfIjCvzEYi0Mz06L9Z6M4PeJRGt 8XNoJ0N16zjbK8RKeeQY3abul5OXu/PeKg5fAzOULKSEPEJ4a/Ylb3G3HHFUvZ32NDXv Usxw== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Wi17FMMgE94rR1w5syCb0jJ8vGHETYbbJ/4ifa0mtRQ=; b=kVT/14LTg355lmwjy98QXMX5eFBcXCD2CPxVDSlEJP9m9at9tpqL6MsNS5iGAfMdIe bCJCDY1iF3x9s1Uhyos/zqO42UbD9THriqr+4NWosO0Z5LQlJ8+Yfehwe2HVpQV38OGX mkJq0uFoaU92jqDIoB3EoTiQOKBRwNCCFrzhL5GtKgVHhTSDbBX4aJ07vt0q/eLh9vci KJtXFISmu1ER5h7Ls6PJbjJ8/Vops6e8PDcjFzzZ4dT84ftTxZ/JdrmRjFD7qqn/YXNT w27lN9pYlLdBMNeId3IXwSMnc/QqXJT7l1pn/03F6PDuiojQ3uqfJQEzm8qm238Dedeq vH7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BYe2VyXl; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h12si4846513edz.228.2020.08.07.00.47.29; Fri, 07 Aug 2020 00:47:53 -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=pass header.i=@gmail.com header.s=20161025 header.b=BYe2VyXl; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727791AbgHGHqG (ORCPT + 99 others); Fri, 7 Aug 2020 03:46:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726891AbgHGHqF (ORCPT ); Fri, 7 Aug 2020 03:46:05 -0400 Received: from mail-qv1-xf44.google.com (mail-qv1-xf44.google.com [IPv6:2607:f8b0:4864:20::f44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E142C061574; Fri, 7 Aug 2020 00:46:05 -0700 (PDT) Received: by mail-qv1-xf44.google.com with SMTP id a19so357755qvy.3; Fri, 07 Aug 2020 00:46:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Wi17FMMgE94rR1w5syCb0jJ8vGHETYbbJ/4ifa0mtRQ=; b=BYe2VyXlXHY5SJsCzDFzsKf6qFa/Y54TQFErFeh2mz4FG9euUqsPTcOeDmYJzA06yT R62vmtQiI4ON68rFy+oUCx9LOf06tGPnmYLxbUDD9Y+azmTB7M6/mMrh5dQLpKQNbszJ /3U9vT5bd80CQ8Cm1QapuH+mv6+um9cqyZokL/hxG7v2itGR1diKIlAb+KQwGls4UGjg Qrqr2OrOm39h7zgjx+f82dGDICgkSYSuH6TR66MtzYpnOL1N+s56m8WPzoZ8b3trXNDa 3cZfIthFCNx1EtEMYaiLkYlb8ndnBU+qOV15pJyuCaZdZUQTMXdPLJEnCYRzNUQiA/db XWYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Wi17FMMgE94rR1w5syCb0jJ8vGHETYbbJ/4ifa0mtRQ=; b=iyga7l0REtVaOQyYv+lpTLsAmuJRjvikC0KSkTdb3BH43sGg7w5X66qg6XMIP5s3qp R/O0x+xuN6zJnD+o90V4qvJ61hjCu3B6sGr/g71mSzJdgelJVCAbJgDlC+Y1YsAS9i4o Rf7asbnLosm59x8OYeUdEZ3AdgDxXrPRiL3afy3YGXTHhLWrOjBoXhP7lkBDZFCfehdC JuCb1olSEuagQdcXbTE9LcUTmJteqIWTtFC8ddybmxOjFwJ+R3gAjR1TPvG1uKIQVExc 7Sz67i8s6sxGbVyyh6RUsJdP73gv6JaVyobQ9SOy9Tf3fT9nBNBxxpqCT0JDKpWSxFN2 cKzA== X-Gm-Message-State: AOAM533ZFszLBVR2AE2bujwPmuWmfQTTjujZFdsBKGIK8agSuu8qLfFx WaDrO9buBCgHSonzJLQrimg= X-Received: by 2002:a0c:d64b:: with SMTP id e11mr7312610qvj.169.1596786364140; Fri, 07 Aug 2020 00:46:04 -0700 (PDT) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id i30sm7572370qte.30.2020.08.07.00.46.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Aug 2020 00:46:03 -0700 (PDT) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailauth.nyi.internal (Postfix) with ESMTP id 58EB827C0054; Fri, 7 Aug 2020 03:46:03 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Fri, 07 Aug 2020 03:46:03 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrkedugdduvdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeeuohhquhhn ucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrth htvghrnhephedvveetfefgiedutedtfeevvddvleekjeeuffffleeguefhhfejteekieeu ueelnecukfhppeduudegrdekhedrudektddrvdduheenucevlhhushhtvghrufhiiigvpe einecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhquhhnodhmvghsmhhtphgruhhthhhp vghrshhonhgrlhhithihqdeiledvgeehtdeigedqudejjeekheehhedvqdgsohhquhhnpe epfhhigihmvgdrnhgrmhgvsehfihigmhgvrdhnrghmvg X-ME-Proxy: Received: from localhost (unknown [114.85.180.215]) by mail.messagingengine.com (Postfix) with ESMTPA id 575DB3280059; Fri, 7 Aug 2020 03:46:01 -0400 (EDT) From: Boqun Feng To: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Peter Zijlstra , Ingo Molnar , Will Deacon , Jonathan Corbet , Waiman Long , Boqun Feng Subject: [RFC v7 16/19] lockdep/selftest: Add more recursive read related test cases Date: Fri, 7 Aug 2020 15:42:35 +0800 Message-Id: <20200807074238.1632519-17-boqun.feng@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200807074238.1632519-1-boqun.feng@gmail.com> References: <20200807074238.1632519-1-boqun.feng@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- lib/locking-selftest.c | 161 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c index f65a658cc9e3..76c314ab4f03 100644 --- a/lib/locking-selftest.c +++ b/lib/locking-selftest.c @@ -1034,6 +1034,133 @@ GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_soft_wlock) #undef E2 #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"); /* -- 2.28.0