Received: by 10.223.185.116 with SMTP id b49csp1643714wrg; Sat, 24 Feb 2018 00:57:48 -0800 (PST) X-Google-Smtp-Source: AH8x224sqhTsWOeL8Fkh9hT8WaRMrAyKBP726qzD9dZKBhSE+2vi8h8qrz02upv01SdPjSG1WfcA X-Received: by 10.99.123.80 with SMTP id k16mr3669233pgn.134.1519462668207; Sat, 24 Feb 2018 00:57:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519462668; cv=none; d=google.com; s=arc-20160816; b=VN2Lxd79qekMZcZS2vc4Krwe5iuVbYrXXjx3zdxrpJGQRCh2YPxMBn16VrBp6pE878 5UMG5RDrGyefM8+ixtWbVRl9vs4VR+nrMBv5i+rwZcFdMJEEuY2gNSrSjSXBT/MPD1gn wei1il5jz901kVDt2JiManxrHHq+c8CtvoezGJoLZMPUvvgvMp5vOsZ6ahEkRo/b6fA8 TxbTH1LirxV8NTjmEAxnOYUwwgRCXZKKY+H8HvlZzed7POiyyBSrR5I89gLG6LbvvAHD mxowXyj+ygMgAPSefjxsZD2kiqqklYdEo5OdwGwpmrvnl0qkduALP5LhKqfbiN/mWHRs b+AA== 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=/akt3vogF0H3skeYOIPDHmS04viInyT+YPDX7DLlU7o=; b=uf+UobuuFlmrmpnNsrYGycfR9rfrFoZf9aZKl+WHj1V2jHw7CDEzIW6pp2VkIqznZ2 E43jl9WWNyY0Ir1rt94ZOGrMYyrbZAa18obkVHRz+C+KcF55cljJo3+8mt63V3G+lGyU 60zge/a+6xZRTzGvHFrbFUFvDYqfTBcZHktnB/Cr1GqxGs0mRNWPjYgquIG969oW7IgP 19kfSnCQNbNI0gpv/Exg3ym9LELc1/ibPSsaWNAaxlZYlKh+52dGkB15mBNUIgXnCgtJ s6yIH/MHqNJ95eXVzr+9Wmbl1XIW+8Z5KWkQ2oxVnzOab5XnmXEKGqFrVY5xF0oXZbh2 kaHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FeMBPYp6; 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 z23-v6si2680289plo.272.2018.02.24.00.57.34; Sat, 24 Feb 2018 00:57:48 -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=FeMBPYp6; 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 S1751296AbeBXI45 (ORCPT + 99 others); Sat, 24 Feb 2018 03:56:57 -0500 Received: from mail-wm0-f42.google.com ([74.125.82.42]:35503 "EHLO mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750852AbeBXI44 (ORCPT ); Sat, 24 Feb 2018 03:56:56 -0500 Received: by mail-wm0-f42.google.com with SMTP id x7so6276134wmc.0 for ; Sat, 24 Feb 2018 00:56:55 -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=/akt3vogF0H3skeYOIPDHmS04viInyT+YPDX7DLlU7o=; b=FeMBPYp6lyM+QjzL4Yq2qMR/zfpbN31f7OwJou+c/ukZ256azOYUIoXbdGNyjcmxMz AAjy18OfhULs6LiytjPF9M9RNOwx9nM6K3NdzjpExC4/tLbWUQb0ZJSxh4DFf2mxWlN9 KUnnzRWGMjNMDcYjuoODGFDGVZu/D64sV7jTRKrOq/CBAJXJcIklEtB8sqz0hAoj1MfZ YRMAT6xtF5hourm6RbQFWh4RuO7uN9kx7T/Rx3NJ5gQpOsWgZdIQK1IzHq1N9/ZPrlS7 AlN43LLnU9T6HMhfgVtrSa9B1CSAoPetK94oRrBUIrTsO9k2pqtC7dPCFIBQtS6kYXqK PH5Q== 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=/akt3vogF0H3skeYOIPDHmS04viInyT+YPDX7DLlU7o=; b=C/IIJfxipO0Y34OqECvh3mWLwahe9ZExGfiiJKOkhblhbo6Q2fo9hs0Mn8dqvaO6At SDLU5I4NUJh5DVDZ1ehXj4lx0SX6jenGnDiRuTi4b/IHDSEcE3YQsn6sxCJrwYdjIGV4 5rRB50WxM2vQ1IS8xc6/n8HV96jp6QtJAJMD/L4QccuA7MmtxjJaOe6/p3USchkVQDAj pxkoJSyD+scnF0gDNEYAkkaPoJBNgeR8xFu8Y0KSvBGJJKVHgGJCl3DEUeSpHEqjOzvF 9kKTFHzcXWdrhr2roHgQcrm1lz3xq+7WMh2+HEKNY9uSgBaWChdyjC7UJtvTmm0dJsUS IB5A== X-Gm-Message-State: APf1xPDS94rEKqfe9/DIeh2ncNV8leYiYN3oMlpZxInjGNYqLjKp59Mj PguD34eA0VhAFXYIcDLowQQ= X-Received: by 10.80.135.16 with SMTP id i16mr6119860edb.233.1519462614483; Sat, 24 Feb 2018 00:56:54 -0800 (PST) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id o6sm3452189edj.65.2018.02.24.00.56.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Feb 2018 00:56:53 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 36E6020E5F; Sat, 24 Feb 2018 03:56:51 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute6.internal (MEProxy); Sat, 24 Feb 2018 03:56:51 -0500 X-ME-Sender: Received: from localhost (unknown [45.32.128.109]) by mail.messagingengine.com (Postfix) with ESMTPA id A21797E0ED; Sat, 24 Feb 2018 03:56:50 -0500 (EST) Date: Sat, 24 Feb 2018 17:00:19 +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: <20180224090019.3smjampkk4zoacb3@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> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="xdcpymzgkkvrxpgg" Content-Disposition: inline In-Reply-To: <20180224083807.GB25201@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 --xdcpymzgkkvrxpgg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. ->read = =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->de= p)); > >=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 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. This is for case like: TASK1: read_lock(A); read_lock(B); =09 TASK2: write_lock(B); read_lock(C); =09 TASK3: read_lock(B); write_lock(C); TASK4: read_lock(C); write_lock(A); , which is not a deadlock. Am I missing something sublte? =09 Regards, Boqun > So can you elaborate a bit? --xdcpymzgkkvrxpgg Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEj5IosQTPz8XU1wRHSXnow7UH+rgFAlqRKaAACgkQSXnow7UH +rhOAgf6ArSpXp5sy98SkqwMUOoRF9Soy9nSDHashhwXCPqwBB4TGFoopwCT5W9Y 5UwjotT4t17yw6BthMKej3SNf6AEYArH0sGv4cXaIkX62hYLTdRnONsfQX9XHUBd aDey0838RLascH9gGjHgJkvgwPa3xf4eudQt0nrQ1iKldzFE6H0tHwKFjn4CWtiG lypY9oqPTXjv4hvC+p9FgF7QsYTStPByMQAI8GT8Qz09OZ1D5Aa9zrFh5/jOJIWl MhBgvQhAkzBL/FPefaI+ESTMJIYNb5EldOCBvLIE16Ja9/NJPpm17Wr/11xWLsx0 pzOf//Dcmc+9NaxZZONVHODHYoQkEw== =ZMeq -----END PGP SIGNATURE----- --xdcpymzgkkvrxpgg--