Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6217220ybi; Wed, 29 May 2019 04:46:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwBv1DPvl8aQtT4j9KmRc0Y36x/zgU9h8OPYkduDRgj97pNjTpREl9EWeLOj205b5Yb5s/I X-Received: by 2002:aa7:82cd:: with SMTP id f13mr150247914pfn.203.1559130379903; Wed, 29 May 2019 04:46:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559130379; cv=none; d=google.com; s=arc-20160816; b=Kg+02aAWr2Rli/upfBOCDjmte/OVtrfLrN8K8DqjNl5uPSLT/afXkXXAZDlQL65fnU /LJv7BbiibNPMvrY1Xp8J/M33onCGQCtt6Mf1nsWD6GIv1V/T0GtipzuCJx1NtAPz4q2 jW21m+XYJDdkIDVLYAdArVvntVwA3QUbmTy8HN4vCrLQEh/F2v5LDx2BuHLzvM+L5bAH J89+O2AnqCescimhK20KiVg5MBfwwO7+ZOy9NNObNTrsVDZZQNk53AMzMeFtTFXb5OkH 682wdol1WfJhk6Xn8ntN/c9hyNzMayMjG89dkIfjL/tpfdPcTPPBdKdgwV9ToX+8UtQ8 MrDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=saTss3WI4v6NFzjGLfT7HQ5xbm2l2+yyVHdCJ+dqTy0=; b=OoPuFdVaxIL64dH9wuGlE5LOd/kbRixDiZ8OQV8UWBw9FYjQG0MA/vNvjplY717snM qeueWuikEZY7nQ0orkM2R+52WXzhJx53se4s8S3gU8Na/HJFOFHubS9q67FnlLgvG/c2 ghbbzC8FJmSQPGydawJb3sUxsQgRxfWf/7Lh8aVAZlJcMdtWx6+crTVmm0Q2vfusbHph 0K7fa0ZErulF83lPIoqeyw/pYsa/N4Oxx25t835bOrChkgYZBSzZRJtQCR1cEvDs5QL+ 5wg03auT45XYIeIUkI9CqVohZo4qg45UEOeZ3HyIxGHrp5cl7Cq5g2106paXCkEdVhBO 8drQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZanEG8f6; 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 cp14si27258579plb.183.2019.05.29.04.46.03; Wed, 29 May 2019 04:46:19 -0700 (PDT) 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=ZanEG8f6; 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 S1726881AbfE2LpA (ORCPT + 99 others); Wed, 29 May 2019 07:45:00 -0400 Received: from mail-qk1-f193.google.com ([209.85.222.193]:35612 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726256AbfE2Lo7 (ORCPT ); Wed, 29 May 2019 07:44:59 -0400 Received: by mail-qk1-f193.google.com with SMTP id l128so1221465qke.2 for ; Wed, 29 May 2019 04:44:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=saTss3WI4v6NFzjGLfT7HQ5xbm2l2+yyVHdCJ+dqTy0=; b=ZanEG8f6daZ6KHNn/3CokKUxEz4szRiJWaFDVc2AnzBbLWG9bQY/uZWmRoN7XMwiY+ 7ZXDUvXIiLdEAyzgj849pP+dgDDBxZTZTScctzwO/G1i4EA3kVjTMxC+zvhG4gk+cgup T/9IkbXPIJRHOQ1VuP8SVumqDTURuImbEaeNF3MHcjT3EztTTCMUI30ckr9EZ8QwD+V7 kCE9Tp1tNQC7ElBhOPaQ/sWaQZE49PiLQTHKBdKLaxf5re8vClN0ibK2r6tZH/pr/3dV 72Ck+DkKyK0p58plgzsYsq7PrhaKzlzx2UKuQubcxS7wq9ULYkHttujgHifYiV7a4gIk fneg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=saTss3WI4v6NFzjGLfT7HQ5xbm2l2+yyVHdCJ+dqTy0=; b=ulgGphX+8DLv91+jBd0CPxVLQeW5tMivxNedDdDKZFEXd8AoLGFjT6ia6s2dUl1ryc WGzZBy3gYnGv+Ym5HdqhsJgPZNc+gat3r6H2uI23XDqYmxSKZQYdajBhMYWSTaialVga Lqy8yxw/wR6tC2xci+2pgl58uCs8EahUmPCYE95nedm393yqElEkRKzXAoeirAjgSsi+ r2QNh/eQGMMo5VeMaf1CKnUcG00xz0rHhUa00kymvEiN3SwlG9XYo+pf3tW7rtC4BXuK gAJeoCx0UmzgrKLxtFwvD0ZgxmrjjWNQI1qdn0WisinFBrzq4zN5zE4b6/+yX7MHk9Ud PWbw== X-Gm-Message-State: APjAAAVII6yre7VnXshBlyKlCFlDgkFNJN4LGi8z7WWv+uoxVmakFX4V 7pJrrTJkkcD4QuXcynFo3as= X-Received: by 2002:a37:a4d3:: with SMTP id n202mr13523412qke.84.1559130298504; Wed, 29 May 2019 04:44:58 -0700 (PDT) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id n26sm554309qtn.36.2019.05.29.04.44.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 May 2019 04:44:57 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id C89EE22095; Wed, 29 May 2019 07:44:56 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 29 May 2019 07:44:56 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddruddvjedggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjfgesghdtreertdervdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucfkphepge ehrdefvddruddvkedruddtleenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdo mhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqddujeejke ehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgr mhgvnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from localhost (unknown [45.32.128.109]) by mail.messagingengine.com (Postfix) with ESMTPA id DAA40380073; Wed, 29 May 2019 07:44:54 -0400 (EDT) Date: Wed, 29 May 2019 19:44:51 +0800 From: Boqun Feng To: Yuyang Du Cc: peterz@infradead.org, will.deacon@arm.com, mingo@kernel.org, bvanassche@acm.org, ming.lei@redhat.com, frederic@kernel.org, tglx@linutronix.de, paulmck@linux.ibm.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 11/17] locking/lockdep: Adjust lockdep selftest cases Message-ID: <20190529114451.GA12812@tardis> References: <20190516080015.16033-1-duyuyang@gmail.com> <20190516080015.16033-12-duyuyang@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="fUYQa+Pmc3FrFX/N" Content-Disposition: inline In-Reply-To: <20190516080015.16033-12-duyuyang@gmail.com> User-Agent: Mutt/1.11.4 (2019-03-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --fUYQa+Pmc3FrFX/N Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, May 16, 2019 at 04:00:09PM +0800, Yuyang Du wrote: > With read-write lock support, some read-write lock cases need to be updat= ed, > specifically, some read-lock involved deadlocks are actually not deadlock= s. > Hope I am not wildly wrong. >=20 > Signed-off-by: Yuyang Du > --- > lib/locking-selftest.c | 44 +++++++++++++++++++++++++++++++++----------- > 1 file changed, 33 insertions(+), 11 deletions(-) >=20 > diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c > index a170554..f83f047 100644 > --- a/lib/locking-selftest.c > +++ b/lib/locking-selftest.c > @@ -424,7 +424,7 @@ static void rwsem_ABBA2(void) > ML(Y1); > RSL(X1); > RSU(X1); > - MU(Y1); // should fail > + MU(Y1); // should NOT fail I'm afraid you get this wrong ;-) reader of rwsem is non-recursive if I understand correctly, so case like: Task 0 Task 1 down_read(A); mutex_lock(B); down_read(A); mutex_lock(B); can be a deadlock, if we consider a third independent task: Task 0 Task 1 Task 2 down_read(A); mutex_lock(B); down_write(A); down_read(A); mutex_lock(B); in this case, Task 1 can not get it's lock for A, therefore, deadlock. Regards, Boqun > } > =20 > =20 > @@ -462,12 +462,13 @@ static void rwsem_ABBA3(void) > =20 > /* > * ABBA deadlock: > + * > + * Should fail except for either A or B is read lock. > */ > - > #define E() \ > \ > LOCK_UNLOCK_2(A, B); \ > - LOCK_UNLOCK_2(B, A); /* fail */ > + LOCK_UNLOCK_2(B, A); > =20 > /* > * 6 testcases: > @@ -494,13 +495,15 @@ static void rwsem_ABBA3(void) > =20 > /* > * AB BC CA deadlock: > + * > + * Should fail except for read or recursive-read locks. > */ > =20 > #define E() \ > \ > LOCK_UNLOCK_2(A, B); \ > LOCK_UNLOCK_2(B, C); \ > - LOCK_UNLOCK_2(C, A); /* fail */ > + LOCK_UNLOCK_2(C, A); > =20 > /* > * 6 testcases: > @@ -527,13 +530,15 @@ static void rwsem_ABBA3(void) > =20 > /* > * AB CA BC deadlock: > + * > + * Should fail except for read or recursive-read locks. > */ > =20 > #define E() \ > \ > LOCK_UNLOCK_2(A, B); \ > LOCK_UNLOCK_2(C, A); \ > - LOCK_UNLOCK_2(B, C); /* fail */ > + LOCK_UNLOCK_2(B, C); > =20 > /* > * 6 testcases: > @@ -560,6 +565,8 @@ static void rwsem_ABBA3(void) > =20 > /* > * AB BC CD DA deadlock: > + * > + * Should fail except for read or recursive-read locks. > */ > =20 > #define E() \ > @@ -567,7 +574,7 @@ static void rwsem_ABBA3(void) > LOCK_UNLOCK_2(A, B); \ > LOCK_UNLOCK_2(B, C); \ > LOCK_UNLOCK_2(C, D); \ > - LOCK_UNLOCK_2(D, A); /* fail */ > + LOCK_UNLOCK_2(D, A); > =20 > /* > * 6 testcases: > @@ -594,13 +601,15 @@ static void rwsem_ABBA3(void) > =20 > /* > * AB CD BD DA deadlock: > + * > + * Should fail except for read or recursive-read locks. > */ > #define E() \ > \ > LOCK_UNLOCK_2(A, B); \ > LOCK_UNLOCK_2(C, D); \ > LOCK_UNLOCK_2(B, D); \ > - LOCK_UNLOCK_2(D, A); /* fail */ > + LOCK_UNLOCK_2(D, A); > =20 > /* > * 6 testcases: > @@ -627,13 +636,15 @@ static void rwsem_ABBA3(void) > =20 > /* > * AB CD BC DA deadlock: > + * > + * Should fail except for read or recursive-read locks. > */ > #define E() \ > \ > LOCK_UNLOCK_2(A, B); \ > LOCK_UNLOCK_2(C, D); \ > LOCK_UNLOCK_2(B, C); \ > - LOCK_UNLOCK_2(D, A); /* fail */ > + LOCK_UNLOCK_2(D, A); > =20 > /* > * 6 testcases: > @@ -1238,7 +1249,7 @@ static inline void print_testname(const char *testn= ame) > /* > * 'read' variant: rlocks must not trigger. > */ > -#define DO_TESTCASE_6R(desc, name) \ > +#define DO_TESTCASE_6AA(desc, name) \ > print_testname(desc); \ > dotest(name##_spin, FAILURE, LOCKTYPE_SPIN); \ > dotest(name##_wlock, FAILURE, LOCKTYPE_RWLOCK); \ > @@ -1249,6 +1260,17 @@ static inline void print_testname(const char *test= name) > dotest_rt(name##_rtmutex, FAILURE, LOCKTYPE_RTMUTEX); \ > pr_cont("\n"); > =20 > +#define DO_TESTCASE_6R(desc, name) \ > + print_testname(desc); \ > + dotest(name##_spin, FAILURE, LOCKTYPE_SPIN); \ > + dotest(name##_wlock, FAILURE, LOCKTYPE_RWLOCK); \ > + dotest(name##_rlock, SUCCESS, LOCKTYPE_RWLOCK); \ > + dotest(name##_mutex, FAILURE, LOCKTYPE_MUTEX); \ > + dotest(name##_wsem, FAILURE, LOCKTYPE_RWSEM); \ > + dotest(name##_rsem, SUCCESS, LOCKTYPE_RWSEM); \ > + dotest_rt(name##_rtmutex, FAILURE, LOCKTYPE_RTMUTEX); \ > + pr_cont("\n"); > + > #define DO_TESTCASE_2I(desc, name, nr) \ > DO_TESTCASE_1("hard-"desc, name##_hard, nr); \ > DO_TESTCASE_1("soft-"desc, name##_soft, nr); > @@ -1991,7 +2013,7 @@ void locking_selftest(void) > debug_locks_silent =3D !debug_locks_verbose; > lockdep_set_selftest_task(current); > =20 > - DO_TESTCASE_6R("A-A deadlock", AA); > + DO_TESTCASE_6AA("A-A deadlock", AA); > DO_TESTCASE_6R("A-B-B-A deadlock", ABBA); > DO_TESTCASE_6R("A-B-B-C-C-A deadlock", ABBCCA); > DO_TESTCASE_6R("A-B-C-A-B-C deadlock", ABCABC); > @@ -2048,7 +2070,7 @@ void locking_selftest(void) > pr_cont(" |"); > dotest(rlock_ABBA2, SUCCESS, LOCKTYPE_RWLOCK); > pr_cont(" |"); > - dotest(rwsem_ABBA2, FAILURE, LOCKTYPE_RWSEM); > + dotest(rwsem_ABBA2, SUCCESS, LOCKTYPE_RWSEM); > =20 > print_testname("mixed write-lock/lock-write ABBA"); > pr_cont(" |"); > --=20 > 1.8.3.1 >=20 --fUYQa+Pmc3FrFX/N Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEj5IosQTPz8XU1wRHSXnow7UH+rgFAlzucK8ACgkQSXnow7UH +riNDAf+MRdBMrKvao3O0YfV7Rg8vEb2/KwZVHdj78NXb+1rkkK9EbP7pGomyp+u f8gr5mAm014BOZe5cd1pvyDrS+ZxA7monBzqNRpFXTbgcmrKV3H+09mK3vrj3XhY 92x5Y+6uyY5Bf4kToz5k+qzyXDGoYXvGCKqimzWbASM+PAa6XFn2VOBYtD+04aeE AUNva+H8RUbkX1qrflr0jozdWpnL/ELuK0fVpRS8W32Cy3dQxZs4qpj2djO/Tnza gANrdIWLuERDlelXec00Q2O0qXjZKwgSFURCYhjYcH8rrq+F8UBmfC9fy42VA14C 0IMQW4dUBC9guMRKttCKkBOsF9a8wQ== =/l2M -----END PGP SIGNATURE----- --fUYQa+Pmc3FrFX/N--