Received: by 10.223.185.116 with SMTP id b49csp1594803wrg; Wed, 21 Feb 2018 23:09:07 -0800 (PST) X-Google-Smtp-Source: AH8x225O5yCmhy0DvglY6m8J8Se3eNR6HjlKwm0B1mDLvCTuK5D39eXP/FZxwH89L7KX0ZnWL2vv X-Received: by 10.99.126.24 with SMTP id z24mr4789985pgc.343.1519283347686; Wed, 21 Feb 2018 23:09:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519283347; cv=none; d=google.com; s=arc-20160816; b=X4AOn6U0IpyoArXhpIvNl3wZE/6zU2m7FCIzefNkPf/6Ep2FkXREk/14n51q7iw4V3 ScNoxDSiGZnCucLhEiJKakYXcGgnKLrJ1R6AoxxoDB4ylqaccbFtsBmkJs7YdNTU/Pg9 Lhzly1VnYU078GjC+d6iG9wrUfXyYa5XZFncLP/DX3jzxaOzm/M0rEqpmFNVHqvGkEqd l8xApgeqNAqA0cCYlK77y3yR8w6MkUBT9Wu7WsGxSeoK9rqhczcSwG4C8gXRYbbx06DY SZvz3Zxq00LYbVbTrnmdOXQbXUOfwov5am5kxyQ70T8uxEq2kXQ559EB0ioOxgzw9QOa DtIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=mHqDyah0oJVOt2/GMZO7YECG7QHoLdnnUx+VBDCZJAE=; b=T8umIdnZs6DMARqNuOVKUBTT/Scnp6j4y3UEplWXmCUvxde3oy2sanOcolyj5N15A9 Ac/4KKYHat28rgOwiHP+4ZkfZndj+RDipba10KKzcXiV1lPlUNiW1MnFXKYYyUx2AoUE 85Q75BZ3Edh2b2RVp9MyNy4ZLeAozDirYXuzzk8D6Mpq7tp7YULf5FccHMcnJxxWln2G rmjnqRGW/FsHjg5KJeHPeqixXJEplqL9bRRGJqrWQJ0geX++xk9sO1+b8Ry2KNeJeZCa KPkUG5GCv1Gs7GgcS9wYf8qJuTVuqax7VY2S/+q+SiPfZwbMvfmJ7qjC2p55iwhYkUNO 25ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mOhnSkud; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id f78si3042673pfa.56.2018.02.21.23.08.53; Wed, 21 Feb 2018 23:09:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mOhnSkud; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1752848AbeBVHHt (ORCPT + 99 others); Thu, 22 Feb 2018 02:07:49 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:37985 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752747AbeBVHGp (ORCPT ); Thu, 22 Feb 2018 02:06:45 -0500 Received: by mail-wm0-f68.google.com with SMTP id z9so1712367wmb.3 for ; Wed, 21 Feb 2018 23:06:45 -0800 (PST) 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; bh=mHqDyah0oJVOt2/GMZO7YECG7QHoLdnnUx+VBDCZJAE=; b=mOhnSkudbUn4FID03/hfcRh0DcZUqggF/f44CMmkbHD+X0O6/sNU1XrwTYM/Hx/IFB HvNrbGcFmgmh/ibW/q25jdH/NvPz4AHFkQkRPtufQKhNU8I1M5uPF6bi+LQvPcBUH53X Uxb3I+nZl80DiUhGsl4iGv1ciILNs4ajb3iKriq0bM1pV4ACnDEytaJEH9Jxq/CcJjHN GrpgiYk8IigmvYkmjTeuAlF4XMkWZKaS4VvuWaFiCGaztp5txtPadwNnLX5WwruRcLM5 yfy96j/iHEwzUFCG7CYG0cXPhs9+K6AHBhU9z6t9u7Sw9ckKH5B2xF6hyfMjf6/UUpAu i6QQ== 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; bh=mHqDyah0oJVOt2/GMZO7YECG7QHoLdnnUx+VBDCZJAE=; b=dB5XAF9oNg7NcZijapMnw3yqCqLr9fhGy54uLCc9jQTYz7xvnIdbdKRCw8DgRGAaOs 69CHIcv+gSCymafTEIsc/tSkjejiivJ9shTq5Q7t6JD1+wKF1/yhPRF8HFtsluK1zot/ 2mzIuZ5HnlLp26zy73Rl2lWyQyQU2zRy2Je0drfRFWGrq08BsoMCr6WTcEvYBn0u5AhH bg8Qd8ffVyRKMZKfMq0mP2DUyhHyOvvDbtOZXl67XBvv6qRpHUCteQjaVKmfiRb8J1wf uavEgLuz0OMe3CMJOh8MwE9efjql4d+SmfUDhSpC0X9U2GQTG5ie9jDXrrf9UuG0hpIE T8CA== X-Gm-Message-State: APf1xPDvKPiPtB6XZiue/hJEfKf3B6kc7k62sDnwkzPVK//Ae5w6aa3o O7UQ7Jclc/yqFUXSmPSjUWcuQ6ZT X-Received: by 10.80.182.245 with SMTP id f50mr8213042ede.157.1519283204349; Wed, 21 Feb 2018 23:06:44 -0800 (PST) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id a17sm5224919eda.42.2018.02.21.23.06.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 23:06:43 -0800 (PST) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailauth.nyi.internal (Postfix) with ESMTP id 112BF20083; Thu, 22 Feb 2018 02:06:42 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute7.internal (MEProxy); Thu, 22 Feb 2018 02:06:42 -0500 X-ME-Sender: Received: from localhost (unknown [45.32.128.109]) by mail.messagingengine.com (Postfix) with ESMTPA id 8B8452463E; Thu, 22 Feb 2018 02:06:41 -0500 (EST) From: Boqun Feng To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Ingo Molnar , Andrea Parri , Boqun Feng Subject: [RFC tip/locking/lockdep v5 13/17] lockdep/selftest: Add more recursive read related test cases Date: Thu, 22 Feb 2018 15:09:00 +0800 Message-Id: <20180222070904.548-14-boqun.feng@gmail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180222070904.548-1-boqun.feng@gmail.com> References: <20180222070904.548-1-boqun.feng@gmail.com> 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 --(NR)--> Y --(NR)--> Z --(NR)--> X is deadlock. 2. X --(NN)--> Y --(RR)--> Z --(NR)--> X is deadlock. 3. X --(NN)--> Y --(RR)--> Z --(RN)--> X is not deadlock. 4. X --(NR)--> Y --(RR)--> Z --(NN)--> 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 c2f06b423da8..6b7a28d84fc4 100644 --- a/lib/locking-selftest.c +++ b/lib/locking-selftest.c @@ -1033,6 +1033,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. */ @@ -1258,6 +1385,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); \ @@ -1367,6 +1507,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); \ @@ -2137,6 +2293,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.16.1