Received: by 10.213.65.68 with SMTP id h4csp239328imn; Fri, 16 Mar 2018 01:17:43 -0700 (PDT) X-Google-Smtp-Source: AG47ELt8TY+6HV7tvKrEch9jnmc0/L1I1PI/6Bq1zwuXT71+59cPIc53YD0dcpKYkSfRaGWApR3u X-Received: by 2002:a17:902:43e4:: with SMTP id j91-v6mr1174023pld.2.1521188263754; Fri, 16 Mar 2018 01:17:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521188263; cv=none; d=google.com; s=arc-20160816; b=ul92AwfTCLOZi4W3SSe5IUPK9h0J/PQVIFMGit3YoNQt7kLYXL3EgwAYbnso1G848V 3bSTbtBmPpHwA3EuWMHvso69OCHZzEBhA98LLJbTonG/W++PvIJP1UtDIuHuRHYgldX4 kvBIx9NXvqeisy3KedEiLjXq2hNyikoIZt9ZnkpNq5Vyt7CO0mYuyhx58azSwhsbLLfU I1+BQB3irDNJAtXjPjTV6lo8zXSvq8v1uK5LrHl5eZGAq0vfs8RuszwQ/V2vWhK1YhfL joVfsWqn9rK4OBGAcdy/GxNhTfQg8gUMw2t0osZgGkQxEc2GP3flubqaDhl5pY6bVsJz AYug== 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=iHxPuz0wjlmTwQB1AP8FyIJv6FHl1bY03mUdUhOWbYM=; b=SVBdSZG3L3htwtkjHQmz2AL6SkoZZuTuO28qNtx5t1Q4dW99A4COtPcTFIYRXhYYjL /O1UbALp8+oBKZQNTMPMthyFlyHsbw8ZmPgN1xFnUXxOmxCPDSSDGOlmbRLRihaUTLMT XwmAWcMCC96ex6mTf5ENXj6zagfA/tVAidF+wTftTXkuPB8SwyaBzCVKJMf3E9edFygx a30HNWvwAM3+QjHG9ycxqzTpX32ap7Dr5P7CfV10NU81nZYMP3qoQK2NphvPtxDktaou 5Ar1zfudWN19G94qcwyHQnl6rZk1W/gXmZfWI5Kht0qYOkxji5iAcHPAs7htMvPqwMvY BiAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=utk/FDJD; 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 c10si2301725pgv.591.2018.03.16.01.17.30; Fri, 16 Mar 2018 01:17:43 -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=utk/FDJD; 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 S1753139AbeCPIQb (ORCPT + 99 others); Fri, 16 Mar 2018 04:16:31 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:34333 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752848AbeCPIQ0 (ORCPT ); Fri, 16 Mar 2018 04:16:26 -0400 Received: by mail-qt0-f193.google.com with SMTP id l25so10040785qtj.1 for ; Fri, 16 Mar 2018 01:16:26 -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=iHxPuz0wjlmTwQB1AP8FyIJv6FHl1bY03mUdUhOWbYM=; b=utk/FDJD4Uu5k1ClTxVa0/4NU6aMrrPflNtfCxTjZmOC/rac0hqnBF69OXi6rapPaN /pr1hW9fUbPY9jGEQC0SkmadydOgBU1Evy+wkkny9g1+6UyMBss0McL0PWKrLjwzdHR5 LFOgw0RUBczKWr5+DDIXfXLncl6CDzfnDlyUcsRGVeATInCdDswQdu2iazhQPyDaW855 wWVohDW/OFYfQN5JDl6+3YW+d0gF7+1jVX+SeYuRRGA72uel8slY5+JPihA9W3Z3wKW0 ZlSz736WbltLvHXNqtRM4MBYijDh9jeXuLkv7sOAgEJNjAmo26cV/F72ipZE5NEtkgUh eMag== 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=iHxPuz0wjlmTwQB1AP8FyIJv6FHl1bY03mUdUhOWbYM=; b=DWpZ6oNnNlSwR6/dUg+3JoSPpYhgOAh3thEpwEz7S3+CSUot/PIoLPlZwBhGdBMKaj jdQUGZQ8zZg9KgCOWZg51VBpdII90JODl6U3+6r1YYq02SuqGqwEGI13blpjVs0M08Zi N+hCVJ4kmWXk17MIP2Fuy34Vd60qn4OpwYeZBmu1hh+ok5SxMKVX+k7XSLCzeBB99Wmd 9ZbUZIslHyNLIIOcapqq8sQz1vpnigbavQEwv9bb6Ux8+/gTjcMjHpV+MaN8YartFOVJ E++0Y3xghwxAseHQUhbRjF/cDuLiENqhYJ+VYYdUP7mcTcScoIM4W6/dVmh0iztuyjlX 4t3Q== X-Gm-Message-State: AElRT7Ezrs+LUvcF6siSNp6hUe7NaMQpbf7XkmHBWx4ijA/K12Veq52D 4/VWnyqdli5DSq4QkIot+BU= X-Received: by 10.200.14.140 with SMTP id v12mr1238879qti.289.1521188186063; Fri, 16 Mar 2018 01:16:26 -0700 (PDT) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id k29sm5319743qtc.45.2018.03.16.01.16.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Mar 2018 01:16:25 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id DEBE320C3A; Fri, 16 Mar 2018 04:16:23 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute6.internal (MEProxy); Fri, 16 Mar 2018 04:16:23 -0400 X-ME-Sender: Received: from localhost (unknown [45.32.128.109]) by mail.messagingengine.com (Postfix) with ESMTPA id DCD587E1FB; Fri, 16 Mar 2018 04:16:22 -0400 (EDT) Date: Fri, 16 Mar 2018 16:20:09 +0800 From: Boqun Feng To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Ingo Molnar , Andrea Parri Subject: Re: [RFC tip/locking/lockdep v5 07/17] lockdep: Adjust check_redundant() for recursive read change Message-ID: <20180316082009.r5rlfkedhnn3l7pa@tardis> References: <20180222070904.548-1-boqun.feng@gmail.com> <20180222070904.548-8-boqun.feng@gmail.com> <20180222172906.GU25201@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="wvwhhwjklbkuqla2" Content-Disposition: inline In-Reply-To: <20180222172906.GU25201@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 --wvwhhwjklbkuqla2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Feb 22, 2018 at 06:29:06PM +0100, Peter Zijlstra wrote: > On Thu, Feb 22, 2018 at 03:08:54PM +0800, Boqun Feng wrote: > > As we have four kinds of dependencies now, check_redundant() should only > > report redundant if we have a dependency path which is equal or > > _stronger_ than the current dependency. For example if in > > check_prev_add() we have: > >=20 > > prev->read =3D=3D 2 && next->read !=3D 2 > >=20 > > , we should only report redundant if we find a path like: > >=20 > > prev--(RN)-->....--(*N)-->next > >=20 > > and if we have: > >=20 > > prev->read =3D=3D 2 && next->read =3D=3D 2 > >=20 > > , we could report redundant if we find a path like: > >=20 > > prev--(RN)-->....--(*N)-->next > >=20 > > or > >=20 > > prev--(RN)-->....--(*R)-->next > >=20 > > To do so, we need to pass the recursive-read status of @next into > > check_redundant(). >=20 > Very hard to read that. >=20 Right.. and I find a bug about this, let me explain below.. > > Signed-off-by: Boqun Feng > > --- > > kernel/locking/lockdep.c | 13 ++++++++----- > > 1 file changed, 8 insertions(+), 5 deletions(-) > >=20 > > diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c > > index e1be088a34c4..0b0ad3db78b4 100644 > > --- a/kernel/locking/lockdep.c > > +++ b/kernel/locking/lockdep.c > > @@ -1338,9 +1338,12 @@ print_circular_bug_header(struct lock_list *entr= y, unsigned int depth, > > return 0; > > } > > =20 > > -static inline int class_equal(struct lock_list *entry, void *data) > > +static inline int hlock_equal(struct lock_list *entry, void *data) > > { > > - return entry->class =3D=3D data; > > + struct held_lock *hlock =3D (struct held_lock *)data; > > + > > + return hlock_class(hlock) =3D=3D entry->class && > > + (hlock->read =3D=3D 2 || !entry->is_rr); > > } >=20 > So I guess @data =3D @next, and we're checking if @prev -> @next already > exists. >=20 > Since we only care about forward dependencies, @next->read=3D=3D2 means *R > and if so, any existing link is equal or stronger. If @next->read!=3D2, it > means *N and we must regard *R as weaker and not match. >=20 Yep, the idea if we find a path @prev -> .. -> @next is RN, and @prev -> @next is RR, then we treat RR as weaker and redundant. Basically, if we find a strong path that could replace the about-to-add dependency (the path is stronger than or equal to the dependency), we report redundant (a match). But I miss something here, as you may see both the start and end of the path are important, so say we find a strong path RN, but the about-to-add dependency is NR, we can not report it as redundant, because the path can not replace the dependency. To make sure we find a path whose start point is stronger than @prev, we need a trick, we should initialize the ->only_xr (or ->have_xr) of the root (start point) of __bfs() to be @prev->read !=3D 2, therefore if @prev is N, __bfs() will pick N* for the first dependency, otherwise, __bfs() can pick N* or R* for the first dependency. I use a similar setup before check_noncircular(), which sets the initial ->only_xr to be @next->read =3D=3D 2, because we need @prev -> @next -> to be strong. But I should use a opposite setup for check_redundant() as I describe above. Anyway, I will fix this and prove (hopefully) enough comments for those tricks. Regards, Boqun > OK, that seems to be fine, but again, that function _really_ could do > with a comment. >=20 >=20 --wvwhhwjklbkuqla2 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEj5IosQTPz8XU1wRHSXnow7UH+rgFAlqrfjQACgkQSXnow7UH +rj5GwgAnivUInCIqkBuvYmMhl+kVccOjcp8ymSS1NH2FKQ0UQCjJWDezNU3yzJi gCx7VewXHsSl/rDeMh9eUu1Ikkz9KyeyywZyHTCOuJzYJXDflkGey7K4sJ2bm9SY P8fjsuCBz45oSy4WXlplxn89vVOR1Etktyr+uvjE4i5uC5JE957fT44dROj5iUzm f5PJmD3bVxVXv6/r8bpytjWi3Qc1XeZaVOWSKXxUnhRjY8MQ/s4GGhJnQKc3OsGw us3uoJcD5ndTl3V+xS3XiHVRvB7KFzahkjHkn8LamTio/lskQr7dEo7daMu9H+7l YOP2yYeTKRxC8h2ieynQdRIRb7V46g== =bOpP -----END PGP SIGNATURE----- --wvwhhwjklbkuqla2--