Received: by 10.223.185.116 with SMTP id b49csp3573270wrg; Mon, 26 Feb 2018 02:18:02 -0800 (PST) X-Google-Smtp-Source: AH8x227+qimwiVD84HU/yPb/w86oRTm556z7MnPlFdOqfXBK5Giub/I38aVgtqFdtKa9lTA56qCn X-Received: by 2002:a17:902:149:: with SMTP id 67-v6mr10053312plb.73.1519640282487; Mon, 26 Feb 2018 02:18:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519640282; cv=none; d=google.com; s=arc-20160816; b=yqdTQqqcjTLOtk2Qe91y6LwckS665negJq9cunlPubq3wuqThuCxa/2jrZW/fLR/rG +CwHFptbCX2V8HvMr5Cz/CPChi2KAmcoDyuunfjH28uIMzd/tF3+stIZulY7qoxjNjf/ b17Nv9rOvgVpX2Rm4d8ZN2Jo62/zoLNqST5Gxz208Ye0/2OX8EailVCg+1wKgmctZGN2 N1/RJQkRcAAfuQdzZ28v84QH01iS2Qvx93ahZY4q/6F0jrCckQGHmnZ5D6RWPhxuuJir Rj7PuS5dSW2LFoohdMM9Fg8+6Z3lzLT5MFqFX8ULZU3OoYuXI30S4MaikELLJo+k4kgj gi2Q== 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:arc-authentication-results; bh=9CESGkF49HKXKz1hBlBVNynlVrVpaphHeBw0I6A9yk4=; b=wxrTE8ib23/uPySUSC0To/l/izSCcsSTyxgOHrvol5ZCI2FChXswqu+hy93jXSpEBX ncGV9N56+1f7xBnj1cbugymLIwZa0ZMfAaSMKMBKReMshgKygGW1TPJcZc1z8JIGsqGi ZwwB3rlY72NWRqMn0SXgFV+vsVwv6WFeKnx2fm2NCzwC/7AhXdDDLX8iIpXS0r+E2uuN 335uE/KHUM3zOBnwu/0qCvGiozx5EEwxzNT5+pqJp7OsvfyOiSoy5Ch4rckSlOE2Wz6c uFbUteyK1olbZu6jC5GnheMzQRMXu7EqhcItKA6JjbJcdYclDO5Blr6DXnhx7L3usxNi OIwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=upuQutBx; 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 m63-v6si6522535pld.602.2018.02.26.02.17.48; Mon, 26 Feb 2018 02:18:02 -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=upuQutBx; 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 S1752517AbeBZKQs (ORCPT + 99 others); Mon, 26 Feb 2018 05:16:48 -0500 Received: from mail-qt0-f169.google.com ([209.85.216.169]:35408 "EHLO mail-qt0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752048AbeBZKQr (ORCPT ); Mon, 26 Feb 2018 05:16:47 -0500 Received: by mail-qt0-f169.google.com with SMTP id z14so992160qti.2 for ; Mon, 26 Feb 2018 02:16:46 -0800 (PST) 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=9CESGkF49HKXKz1hBlBVNynlVrVpaphHeBw0I6A9yk4=; b=upuQutBx5a/ogQvYAfd5eK64ppTlVAqgIgnoHmbplY6JNAm1WCXvwpGLl2oTqyrWE2 Qlug1i/cmLaR8tPU3gMZlgumUdmvFpGhicgQkgD8oTl9tXKHsZZgaeQldgUfI8asxHJ9 A1CqVajnmc7IDqTL8hGseMi1YQRaohyI4g4VadA8nNjMLVFMi4Cl1gh4ME0i3wXwcCLO cdaPsYNnQM+aiHebhJTB0VvS1LJQy5HlI2i2nhncj3bf9B1B1ouJl0OoRRFBu26ho2sb 6gu9H7IP9iqGT0KsNd8BCToAwchx30NOFF/7Uu+MFdhgcjj/lvHOghU+Hhrxi2YxOTML U/LA== 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=9CESGkF49HKXKz1hBlBVNynlVrVpaphHeBw0I6A9yk4=; b=VHqCZ3P9Ld2tnwYzm86+Nc5v4AQljT/PVq+NllAFGhbvWbWMie+msIvwU0SlnUJAsN tM9VUesOqmhib1iX0JXt9dmZp/qKrqyHimuECoomFC8fHwfy7ayUVIU+VqNDW+jvcs+E kalyHuqm5/pT8Kk3fqTp765y3ksrSP3orrWvKiU5S/IxYsBeEKyidHHZuBSSWcXlWMMi wdikGmKFWR3dFKwYNXwP/5RHSL9V68/s79G8mHKvIE1n/HhN3LJ0liL74WjMb4mAK5fK GG8X+SPs3zvFVeFusKEnozFLQkNAtLKLN8PwYo8DZiQpTj1JRIudeVgdCe3wTEzqT0fN yz8A== X-Gm-Message-State: APf1xPAIGigTQdDA7d8SSobVWYA5cMKjCFz5zjiHObNXYQyyBmWKYnk/ 8QRNqOOiMKJSEJruRNmjOSw= X-Received: by 10.200.70.9 with SMTP id p9mr16419924qtn.5.1519640206517; Mon, 26 Feb 2018 02:16:46 -0800 (PST) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id h190sm5273445qka.10.2018.02.26.02.16.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 02:16:45 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 3DA0820BF3; Mon, 26 Feb 2018 05:16:45 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute6.internal (MEProxy); Mon, 26 Feb 2018 05:16:45 -0500 X-ME-Sender: Received: from localhost (unknown [45.32.128.109]) by mail.messagingengine.com (Postfix) with ESMTPA id A099E7E188; Mon, 26 Feb 2018 05:16:44 -0500 (EST) Date: Mon, 26 Feb 2018 18:20:16 +0800 From: Boqun Feng To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Ingo Molnar , Andrea Parri Subject: Re: [RFC tip/locking/lockdep v5 04/17] lockdep: Introduce lock_list::dep Message-ID: <20180226102016.4rms4ro6wcwwsw7d@tardis> References: <20180222070904.548-5-boqun.feng@gmail.com> <20180223115520.GV25181@hirez.programming.kicks-ass.net> <20180223123732.acxbavnf2ktd4lzl@tardis> <20180224053250.ketrlbq4gtx573qo@tardis> <20180224063005.efbowkoq2v4qndan@tardis> <20180224083807.GB25201@hirez.programming.kicks-ass.net> <20180224090019.3smjampkk4zoacb3@tardis> <20180224092651.hjxznghmuiyj4rnp@tardis> <20180226090050.GE25201@hirez.programming.kicks-ass.net> <20180226101524.xaarifgmhzdzq7gs@tardis> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="pdbmadqmexido3oa" Content-Disposition: inline In-Reply-To: <20180226101524.xaarifgmhzdzq7gs@tardis> User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --pdbmadqmexido3oa Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Feb 26, 2018 at 06:15:24PM +0800, Boqun Feng wrote: > On Mon, Feb 26, 2018 at 10:00:50AM +0100, Peter Zijlstra wrote: > > On Sat, Feb 24, 2018 at 05:26:52PM +0800, Boqun Feng wrote: > > > > This is for case like: > > > >=20 > > > > TASK1: > > > > read_lock(A); > > > > read_lock(B); > > > > =09 > > > > TASK2: > > > > write_lock(B); > > > > read_lock(C); > > > > =09 > > > > TASK3: > > > > read_lock(B); > > > > write_lock(C); > > > >=20 > > > > TASK4: > > > > read_lock(C); > > > > write_lock(A); > > > >=20 > > > > , which is not a deadlock. > > > >=20 > > >=20 > > > After TASK 1,2,3 have executed, we have A -(RR)-> B, B -(RN/NR)-> C, = and > > > when TASK4 executed, we will try to add C -(RN)-> A into the graph. > > > Before that we need to check whether we have a A -> ... -(*N)-> C path > > > in the graph already, so we search from A (@prev is C and @this is A): > > >=20 > > > * we set A->have_xr to false, because the dependency we are adding > > > is a RN. > > >=20 > > > * we find A -(RR)-> B, and since have_xr (=3D A->have_xr) is false, > > > we can pick this dependency, and since for A -> B, we only have > > > RR, so we set B->have_xr to true. > > >=20 > > > * we then find B -(RN/NR)-> C, and since have_xr (=3D B->have_xr) is > > > true, we will pick it only only_rx(C->dep) return false, > > > otherwise we skip. Because we have RN and NR for B -> C, > > > therefore we won't skip B -> C. > > >=20 > > > * Now we try to set C->have_xr, if we set it to only_xr(C->dep), > > > we will set it to false, right? Because B -> C has RN. > > >=20 > > > * Since we now find a entry equal to @prev, we go into the > > > hlock_conflict() logic and for expression > > > =09 > > > hlock->read !=3D 2 || !entry->have_xr=20 > > > =09 > > > @hlock is the C in TASK4, so hlock->read =3D=3D 2, and @entry is the > > > C whose ->have_xr we just set, so entry->have_xr is false. > > > Therefore hlock_conflict() returns true. And that indicates we > > > find a deadlock in the search. But the above senario can not > > > introduce a deadlock. > > >=20 > > > Could this help you, or I miss something? > >=20 > > Yes, although it took me forever to grasp because I have snot for brains > > atm :-( > >=20 >=20 > Take care! >=20 > > Would something like: > >=20 > >=20 > > dep =3D entry->dep; > >=20 > > /* Mask out all *R -> R* relations. */ > > if (have_xr) > > dep &=3D ~(RR_MASK | RN_MASK); > >=20 > > /* If nothing left, we're done. */ > > if (!dep) > > continue; > >=20 > > /* If there are (only) *R left, set that for the next step. */ > > entry->have_xr =3D !(dep & (RN_MASK | NN_MASK)); > >=20 > >=20 > > Work? I think that reads fairly simple. >=20 > I think that works, will apply this simplification to see whether the > self tests agree. >=20 And the self tests agree this works ;-) Thank you! Regards, Boqun > Btw, given the comments in the code, I think it's better to name > "have_xr" as "only_xr"? I have a feeling that my comment-less code > somehow misled you to that name ;-( >=20 > Regards, > Boqun >=20 --pdbmadqmexido3oa Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEj5IosQTPz8XU1wRHSXnow7UH+rgFAlqT310ACgkQSXnow7UH +riesgf/XuROhOCzU01HK8REoVFuiOnBNYDY2FzfZtKj1NC5skZ1Uw0WJt81kyVt +5TYUH4h9eBfHq9zbOAg3KHEBvS0xWwdtjfWUTVoETGXQvqoaUTJdeWGY57oJgco EfABVzafTecuwAPpzFEpMIPvP0o66igt5zHT0K8gi3rGzcBx0NMaz5B+zmJHldUB C6iRrE9if7wksFFSlul7sA+9MVykYS9jx+yi8dJtS46nhR7Sj6iEwuuc1NPGokBQ HY/Ej58uO0/ocgp+esjHracDOXlGV9mjohidhNDtGbhZlc8J9cgLQCmfxraOJHfY 5t7PMtEFl7b8wj6jks7sYGYr6UXQ0g== =B6LP -----END PGP SIGNATURE----- --pdbmadqmexido3oa--