Received: by 10.223.185.116 with SMTP id b49csp3516370wrg; Mon, 26 Feb 2018 01:03:39 -0800 (PST) X-Google-Smtp-Source: AH8x226tKYU1653p09k/HBzcT2bhlCb3Rqj1XUbWjyb3El52nhTjSUICbFhnJH26UTW6Xc1ZDDwl X-Received: by 10.98.18.70 with SMTP id a67mr9895407pfj.213.1519635819422; Mon, 26 Feb 2018 01:03:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519635819; cv=none; d=google.com; s=arc-20160816; b=SRFeHzmH6C5alakJ5/WeBalIJZES6T0GYOH+v2hMxTItq3NNRwU8QFqQFjxaG1shoy 7RKdbA24JQP8t2dJxuIJ/IH4U99osxSt61ax94X+kq1miDIbDAAxy0svO9BwFXs0egBd IA3ZkPHiYmqERcd34YaK8vr4aJnJeLPgZsxVLfbofeKAd8f1lXu26tlXkyN1C7PQ7uq3 IVuUNZajF5cw7rBINQo+z+Ttq4iLHPdRVv3bTsaijqZBTZGnfReSS5ZavTv4SC3w2L16 5V6F+sAcJf3JHyqAq19mYm6CZKYlLCd0ko0XfMNYla162nzTS08FGshyB3C4pjfoYz7G H9fg== 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=+APQr7zY3JOPz/KssUZlxfCaJR1IXM4pOAl9T0woM5Y=; b=WoG6DhIYFm/UGYcgLy1GHzg8S0rIJ0r2kcruJDo9x6Ln6eHffxAGCRW4D3RFlW46KQ dBx+vULQIC6bAYFxn1LPqXW13LEgjy7AxDXlincX4fQAa1d1pV2IMzp4m9xi3j08dRa/ j+R8JAImlIsyCrI2CvyKCLZi/EkUVCifaRVvesykApOvSNJn2rlF0vNOTUerm4aFp/fR zCAfrlRsrPI+3v4+5M6YbQicNKs6cQEOqdNKBBAc6MwjZQubhNJZ5J4o+59leDmsC8gu sYwyEg3jHOvKCfDvN2FCMMZ+ovU0RmAWYY1dLGg3rvVCJ2kPuXNKi2bEgdI38gj9eU6W RbaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=Rq2RmeyL; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d8-v6si6386495plo.17.2018.02.26.01.03.25; Mon, 26 Feb 2018 01:03:39 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=Rq2RmeyL; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752346AbeBZJBq (ORCPT + 99 others); Mon, 26 Feb 2018 04:01:46 -0500 Received: from merlin.infradead.org ([205.233.59.134]:55672 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752114AbeBZJA6 (ORCPT ); Mon, 26 Feb 2018 04:00:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=+APQr7zY3JOPz/KssUZlxfCaJR1IXM4pOAl9T0woM5Y=; b=Rq2RmeyLCIlO0ZhwPzUArtcwm mTQUcIiTDreTkjT6YxgFgpa0benuo0t3vnJ5egDuj9GOhmCkeW00fbX7XwKwVJy4h+9REP4rQ7So8 KUF8jTxiTnGEo80uxQ3zHrRvtI4BgFmd3ErWg+HbqzkD23+EvDbEvBUkaVSREGmAjsdGuc4ckK9bl JR+tb1f/p7IyY9yPkTGxaNcRBzzkcqGwun6xD0FsMo4Ov4v7AFYn3dpOsA/ZrNwaAnybxZQcBTb47 xfy1CaDY9FcotE6P8ngBreCv3NU8hnlvHhc+w3uJIP3+cVTKKNYHb4Fhnt67Bfwbcla0gUulXjI32 Dvqdn1Q9w==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.89 #1 (Red Hat Linux)) id 1eqEeT-000433-1K; Mon, 26 Feb 2018 09:00:53 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id C8AA72029F1E2; Mon, 26 Feb 2018 10:00:50 +0100 (CET) Date: Mon, 26 Feb 2018 10:00:50 +0100 From: Peter Zijlstra To: Boqun Feng 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: <20180226090050.GE25201@hirez.programming.kicks-ass.net> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180224092651.hjxznghmuiyj4rnp@tardis> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Feb 24, 2018 at 05:26:52PM +0800, Boqun Feng wrote: > > This is for case like: > > > > TASK1: > > read_lock(A); > > read_lock(B); > > > > TASK2: > > write_lock(B); > > read_lock(C); > > > > TASK3: > > read_lock(B); > > write_lock(C); > > > > TASK4: > > read_lock(C); > > write_lock(A); > > > > , which is not a deadlock. > > > > 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 (= 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 (= 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 > > hlock->read != 2 || !entry->have_xr > > @hlock is the C in TASK4, so hlock->read == 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? Yes, although it took me forever to grasp because I have snot for brains atm :-( Would something like: dep = entry->dep; /* Mask out all *R -> R* relations. */ if (have_xr) dep &= ~(RR_MASK | RN_MASK); /* If nothing left, we're done. */ if (!dep) continue; /* If there are (only) *R left, set that for the next step. */ entry->have_xr = !(dep & (RN_MASK | NN_MASK)); Work? I think that reads fairly simple.