Received: by 10.223.185.116 with SMTP id b49csp3569557wrg; Mon, 26 Feb 2018 02:13:08 -0800 (PST) X-Google-Smtp-Source: AH8x2272aIqNMZn5N6HJpNctn7mEMFj+KvSYZmKQVxxYB8ENc97YXL83wUda6Hm+mjKEh/aKKgWv X-Received: by 10.99.129.66 with SMTP id t63mr7859487pgd.376.1519639988250; Mon, 26 Feb 2018 02:13:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519639988; cv=none; d=google.com; s=arc-20160816; b=XmWa8iPIiLk5PMOu443jp3HZN9jv6Zo7W80r0ndUFOZCneN7WdXlNAu2sgO/D+CBq+ QKxJQFK8XOwyV+tYIVuu1k5l4GqgscH77qxmYka3nEW3vjUYTdcKWOp8KMmK3XwlnvU9 SELrPveMOW65VI0AQmpe86ogDMgGwSF+xLIdEPC8SuIfKm3LnSkrgDfJXHsyKgqFvviX ryrgJT5m0D69jOLPfy8BZUXC7MnpWM+9aNyaP3vR4bLcAE3U0kOdEP6N2tzNCSsMBFDP 5Q5tI1ghs/O65iY/hLMCotgKQfIsNGj0iDm6ytuIKsBJjN2zalpggR2/17a0eSXeVLwO DWlQ== 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=ZhPjlvy3HkyUVs7VP525z5r6wyOoSv/vgnsUfwZRJGI=; b=X+kHYcKy1rz6sImO7Apyf42n/Jm72YsDLCI0rt3EQ0CXiqWpba4gyKHqMbGS1gJvqO 8TpnjBpdvBilPcKRR8pnEo/lIIl/Mbi0B7Tb4hkrc5k/S6hOabvEJPJa2blsYl/GU8jd pQTSkivtFS2RDPwrYF4Yv36dQf66GmCO0MzIdvDDYFAO2ewK0IogJY5+x0HbsYtHrbKx /BGiGUbVJAjULeO1K15c8PCgKbpfwAuHkUBIUhnFeaKpEZkQVzhx8vWXBwTb9SNEhKWq YbvOLJhTS9s3Zx36G3Q8lzVJhzBFGKbV9bHBrksDNM/TC2Wu8EJz9rBcf5nCdayiHzww m4Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jk7ideWt; 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 y7-v6si6459127plh.806.2018.02.26.02.12.53; Mon, 26 Feb 2018 02:13:08 -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=jk7ideWt; 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 S1752063AbeBZKMA (ORCPT + 99 others); Mon, 26 Feb 2018 05:12:00 -0500 Received: from mail-wm0-f48.google.com ([74.125.82.48]:50624 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751623AbeBZKL5 (ORCPT ); Mon, 26 Feb 2018 05:11:57 -0500 Received: by mail-wm0-f48.google.com with SMTP id w128so10309386wmw.0 for ; Mon, 26 Feb 2018 02:11:56 -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=ZhPjlvy3HkyUVs7VP525z5r6wyOoSv/vgnsUfwZRJGI=; b=jk7ideWtQ6lFg8mF0LRa5Scj9L/OClDZZ7PYIptgSJsxMhkaZujrWHvDtaUQRga2+v 8/uo1ovyvuI5Z6KPAVCeCdt7Scf8MY4vqOip3QmLZjJL0hlxP5Tpc/Zxpgx5UBkAxUFR cttQCy6nm6PK3xSxgN9fCsBa1tbpwu5YU3G49EofxArSQ8dvX4QWWN3wzm6hu/23tjwL /NesdzQj9gV/nLSF8hL+I4V4rmO4CTxf68GZllHorSL7Rj4IjXUerI60lVRplOAgK3j2 kG1wG1e8njFU/fjvfmXQCtlxVXQjU6U9qTYHWTFrXMJvm80VpJ291qN5JyiNxkKJ+tY3 GxOg== 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=ZhPjlvy3HkyUVs7VP525z5r6wyOoSv/vgnsUfwZRJGI=; b=BDYbdYrIlov7Z1wi7O2D1/ZfmHqFUEN4YEXDaApyH2mAtofKJguNsqVOsOMT76f8bX gB5vzy2kzqNt2e6S4dFCROLkepsQzBq+Z+bZgDFksumJpNTzkTMCfttzoBcyWgvK0aFe 1iI3gRMzhPd4EQwhFscZ7cXGurPvgEg4aB/Gsxkr3N0yA3eqyDh1c0lt2e9uQ5rIxZh8 x4ww87KqBJXlAJ4h//mL0F3Wx1vcrHEdcaXn24Ko/PFIRx3W+HFMI1FxG+9Htk1ZWU0q ofy1cl1hbwZ02Zkv6lx8fsmCrddObiiq3NrjXELR4UKt/vcw/dft2mF3YRSzR8s7y2cu dCZg== X-Gm-Message-State: APf1xPC6S/PMUxt2kAwl458uENwLn41cp4qTpGvgiHUKudufbftaCoeC qaNlMc6xJWPixA2yyHMEyCU= X-Received: by 10.80.186.25 with SMTP id g25mr13800212edc.28.1519639915776; Mon, 26 Feb 2018 02:11:55 -0800 (PST) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id o47sm7585403edc.10.2018.02.26.02.11.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 02:11:55 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id C103320CC6; Mon, 26 Feb 2018 05:11:52 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute6.internal (MEProxy); Mon, 26 Feb 2018 05:11:52 -0500 X-ME-Sender: Received: from localhost (unknown [45.32.128.109]) by mail.messagingengine.com (Postfix) with ESMTPA id 337DF24108; Mon, 26 Feb 2018 05:11:52 -0500 (EST) Date: Mon, 26 Feb 2018 18:15:24 +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: <20180226101524.xaarifgmhzdzq7gs@tardis> References: <20180222070904.548-1-boqun.feng@gmail.com> <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> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="zfcl3fv34euwjh74" Content-Disposition: inline In-Reply-To: <20180226090050.GE25201@hirez.programming.kicks-ass.net> User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --zfcl3fv34euwjh74 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 Take care! > 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. I think that works, will apply this simplification to see whether the self tests agree. 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 ;-( Regards, Boqun --zfcl3fv34euwjh74 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEj5IosQTPz8XU1wRHSXnow7UH+rgFAlqT3jgACgkQSXnow7UH +rgPewf7BYhsx8OnUcEPKdhbI6kFgrnkmZhCS8TaHxlyA/eCRYDz7F1Ui6BMgVEM LBx8jsNNZnIPyaduiG9xPsPuM7y3yU28rI53XShC8CMjxemKYTYzip6e2iGm0qOa eaICFerZ6rJe021lRmOaAIi/UZQu3PkCkZw5himx+BgkuEGoysW+7HJL6dgG4yj+ IXFxx3VaUGAR/u7EJQgLTuMJ5QNJ/CEJM4A/8LZt0TaCGzPmosC//aNd+I6fadqH SBef8AVH2/X3v/MvjYW2UAZhcZHOxMo0g0hoUj7UtsinORvxJ02eqi1o3tAvCp5T 3LshnxsY7F+GaEzhnEc0x5v+NufknQ== =PGHK -----END PGP SIGNATURE----- --zfcl3fv34euwjh74--