Received: by 10.223.185.116 with SMTP id b49csp1663648wrg; Sat, 24 Feb 2018 01:24:31 -0800 (PST) X-Google-Smtp-Source: AH8x226/R2yn5VgfxkMrByOcy5lhnMYINOzOOgK8epWbhtdg8a1GcSqDVWxvNFvJt7mODXGcW0XY X-Received: by 10.99.111.137 with SMTP id k131mr3605219pgc.11.1519464271296; Sat, 24 Feb 2018 01:24:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519464271; cv=none; d=google.com; s=arc-20160816; b=M5hsFel5Rbh08OolNgOdpzY92j5rDdY69CWLLQVH4TJ+UAzVuOODokUMkC3L77dtmW xbv+UnQiACq7DXIkQ5AH89JSO16DdzyATvOKVAeVk2ll4at9m4bit6WvLL+GN7nmC4q1 6jbJ9u+p4ahCuSNxHqsHV2fLge/BZ475j81b1aVbyMX12ER1y5gTZUhPRcMzQLUBYQAN BCirlAICr4XBJcqhLuYwlIh8J+SF6remEPz6/3qg7Nb5ywuySBlKKrsigQ2Nxna3tF68 qYN4EFJStdhl7o5b2Ab9mdhkl6mN3aWSUxYBaJbBNwBJPoC+KiowuqiZ0JDI0ftttjB2 PRvQ== 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=KF5Jb/XkIn9Cjzql+BujZqrIsle1J40LYeaI7C/zN2c=; b=l3ETqDnVjzwhle2e8nIIN5qy97/2Ng0nPte1/SRG83xlPg1b8flrBEwoTZwRWC08SR 6UYu1ARfUakymIqCgJKu0KUEJ9qX77Tm7N4jmnYjyfv0DjdWATdx7+Mtk2hCPysPPIcO BHSgZd+XcrMPqc2qJ4TcY7ew2GkgGP3EwubxkcEo+hPyEBJYP23JHGk4WkeXg2uVUoPH sVOxu+pimHjk3Wg7rb6KIL0Wv+1yRCK7Vh76ZnZc8HPtbXfIHP9FPI8OXppQFDRGBkfm 294Z2UlcbAOwkDuFiSjTyFlxnVigUbknh8hO2o0oN47QMju9Mu0vXUap2boQ4fvTrlrW 8EtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RWq2t/JC; 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 u123si2754018pgb.16.2018.02.24.01.24.16; Sat, 24 Feb 2018 01:24:31 -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=RWq2t/JC; 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 S1751340AbeBXJXd (ORCPT + 99 others); Sat, 24 Feb 2018 04:23:33 -0500 Received: from mail-wm0-f43.google.com ([74.125.82.43]:39776 "EHLO mail-wm0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750852AbeBXJX3 (ORCPT ); Sat, 24 Feb 2018 04:23:29 -0500 Received: by mail-wm0-f43.google.com with SMTP id 191so8661876wmm.4 for ; Sat, 24 Feb 2018 01:23:28 -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=KF5Jb/XkIn9Cjzql+BujZqrIsle1J40LYeaI7C/zN2c=; b=RWq2t/JCBMeEYCe63GqwH/3w0u614Jpx/LwKiPkYtAsEBEOgjH8HeUpOJleVkgpYf6 XVd2wMxJi/xiWaDDHQjxLuxBBNoYSfwA5T+xFvBoBDK1QlOG+FUKmq0BSO2n8cXcyreV tplOCHyyX7cowDiLZ8h5rC2nZSffHR1VKCCTNIFMlNdPC6TaXJ2+IbM+JHi/h7Hvx5Hf V/wyP2rv/owD5+AqAehSfExhS94186qLTkZ6KPo3wSPGsOSwrnjJjxwsgH89vgBZ+dOj xaoPzONbWzwOoBjPsBaKda3uGQl0S2wmuYW9MsMKzPNWJPlYt3zfygkO8qrC4YzM5WMX iL8A== 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=KF5Jb/XkIn9Cjzql+BujZqrIsle1J40LYeaI7C/zN2c=; b=Tp8SlQ+T/mOEidxyrjB05WyyDZxI9NpmcsGduR113qfmYRT4UA1fwnm1SWZO5wStO7 1OIi4AAeiUcsWPM01RK5Lhl2GsEqBJFm5J299kep59EeBjAE9D0j5fUkANulPMqvbwmR 2vBV9giq4//XzmF3MT/MifIt3Edk7g0E66kpjPu6Sx0oCpl0Tc8/LH/SmpksT46Y5iTr T/lqi7S+U+qMtknVwO73ZmIXk/BVHL6acMeIw30ZdgFuVoV95IQGDP17HbTCm8lcggOQ tHW7rUs/9twh10U7mhrG2nySv9h6YOFWDZ4W5eKNJUmFyWuRCzR+t+eopxxfcwuEbn9c vnug== X-Gm-Message-State: APf1xPAsFgzCgY4OvwGt11Ka+dGj0LtWD/zDpOY/fNdGuVU9hyLSYQ71 h5vcSiioWTQHUoT/03jrgaE= X-Received: by 10.80.213.8 with SMTP id u8mr6275206edi.224.1519464207890; Sat, 24 Feb 2018 01:23:27 -0800 (PST) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id o93sm3454721edb.18.2018.02.24.01.23.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Feb 2018 01:23:25 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 3188121141; Sat, 24 Feb 2018 04:23:24 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute6.internal (MEProxy); Sat, 24 Feb 2018 04:23:24 -0500 X-ME-Sender: Received: from localhost (unknown [45.32.128.109]) by mail.messagingengine.com (Postfix) with ESMTPA id 541EC7E4A8; Sat, 24 Feb 2018 04:23:22 -0500 (EST) Date: Sat, 24 Feb 2018 17:26:52 +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: <20180224092651.hjxznghmuiyj4rnp@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> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="svy3zkwelixvks2a" Content-Disposition: inline In-Reply-To: <20180224090019.3smjampkk4zoacb3@tardis> User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --svy3zkwelixvks2a Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Feb 24, 2018 at 05:00:19PM +0800, Boqun Feng wrote: > On Sat, Feb 24, 2018 at 09:38:07AM +0100, Peter Zijlstra wrote: > > On Sat, Feb 24, 2018 at 02:30:05PM +0800, Boqun Feng wrote: > > > On Sat, Feb 24, 2018 at 01:32:50PM +0800, Boqun Feng wrote: > >=20 > > > > /* > > > > * DEP_*_BIT in lock_list::dep > > > > * > > > > * For dependency @prev -> @next: > > > > * > > > > * RR: both @prev and @next are recursive read locks, i.e. ->rea= d =3D=3D 2. > > > > * RN: @prev is recursive and @next is non-recursive. > > > > * NR: @prev is a not recursive and @next is recursive. > > > > * NN: both @prev and @next are non-recursive. > > > > *=20 > > > > * Note that we define the value of DEP_*_BITs so that: > > > > * bit0 is prev->read !=3D 2 > > > > * bit1 is next->read !=3D 2 > > > > */ > > > > #define DEP_RR_BIT 0 > > > > #define DEP_RN_BIT 1 > > > > #define DEP_NR_BIT 2 > > > > #define DEP_NN_BIT 3 > > > >=20 > > > > #define DEP_RR_MASK (1U << (DEP_RR_BIT)) > > > > #define DEP_RN_MASK (1U << (DEP_RN_BIT)) > > > > #define DEP_NR_MASK (1U << (DEP_NR_BIT)) > > > > #define DEP_NN_MASK (1U << (DEP_NN_BIT)) > > > >=20 > > > > static inline unsigned int > > > > __calc_dep_bit(struct held_lock *prev, struct held_lock *next) > > > > { > > > > return (prev->read !=3D 2) + ((next->read !=3D 2) << 1) > > > > } > > > >=20 > > > > static inline u8 calc_dep(struct held_lock *prev, struct held_lock= *next) > > > > { > > > > return 1U << __calc_dep_bit(prev, next); > > > > } > > > >=20 > > > > static inline bool only_rx(u8 dep) > > > > { > > > > return !(dep & (DEP_NR_MASK | DEP_NN_MASK)); > > > > } > > > >=20 > > > > static inline bool only_xr(u8 dep) > > > > { > > > > return !(dep & (DEP_NR_MASK | DEP_NN_MASK)); > > > > } > > > >=20 > >=20 > > > > > > if (have_xr && is_rx(entry->dep)) > > > > > > continue; > > > > > >=20 > > > > > > entry->have_xr =3D is_xr(entry->dep); > > > > > >=20 > > >=20 > > > Hmm.. I think this part also needs some tweak: > > >=20 > > > /* if -> prev is *R, and we only have R* for prev -> this, * skip*/ > > > if (have_xr && only_rx(entry->dep)) > > > continue; > > > =09 > > > /* > > > * we pick a *R for prev -> this only if: > > > * prev -> this dependencies are all *R=20 > > > * or > > > * -> prev is *R, and we don't have NN for prev -> this > > > */ > > > entry->have_xr =3D only_xr(entry->dep) || (have_xr && !is_nn(entry->= dep)); > > >=20 > > > otherwise, we will wrongly set entry->have_xr to false if have_xr is > > > true and we have RN for prev -> this. > >=20 > > OK, so its saturday morning and such, but what? Why should we set > > have_xr true when we have RN? Note that if we only had RN we'd already > > have bailed on the continue due to only_rx(). > >=20 >=20 > But what if we have RN and NR? only_rx() will return false, but due to > have_xr is true, we can not pick RN, so entry->have_xr should be set to > true (due to we have to pick NR), however only_xr() is false becuase we > have RN, so if we set entry->have_xr to only_xr(), we set it as false. >=20 > 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 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): * we set A->have_xr to false, because the dependency we are adding is a RN. * 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. * 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. * 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. * 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. Could this help you, or I miss something? Regards, Boqun > Am I missing something sublte? > =09 >=20 > Regards, > Boqun >=20 > > So can you elaborate a bit? --svy3zkwelixvks2a Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEj5IosQTPz8XU1wRHSXnow7UH+rgFAlqRL9gACgkQSXnow7UH +rhy0gf/YCPNb79Ga3FOtrNtKsayr33vhFANXciw/Jc7RLLulPIarTkqYhgHHp7M LOz8lsgdYswqizt44DRESmXCcIqhMipWH2NwC3H5ovKiRAE1tZ96H47o7SG06uD3 /9bKC5LJGwYvNNq6twRkU7kZKAkgTPs0lOMtgvVg23+rrBZJP0Eus/UPXmbzHVwy q2Z5dmq5nOq2PaJ6OpZJadkAJOXpddqCeWyA+obPMXTfkc7kJpfwWYbIk8yiwySy sTtb7lAtmcCOgfQ4LNiCu8IoFc/wBLHVRccxxK6+oDa1kzYbywIAWZtoCL4DDKap X1SI0xgvukZtWCyBpXjQq+ulaOnjDA== =xRfP -----END PGP SIGNATURE----- --svy3zkwelixvks2a--