Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp3701176rwb; Mon, 16 Jan 2023 11:38:20 -0800 (PST) X-Google-Smtp-Source: AMrXdXszZA40vCnAyxcOsgvXW+2Gt8VFwBLTSB47sELm5JNUTIs3q7dqFSyFsbHBUxtjNVWXxtvB X-Received: by 2002:a17:902:b68f:b0:193:30be:d146 with SMTP id c15-20020a170902b68f00b0019330bed146mr751276pls.63.1673897900374; Mon, 16 Jan 2023 11:38:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673897900; cv=none; d=google.com; s=arc-20160816; b=rRREcM9idy08JWIEBsNfcnHX1SEC/EpGf7Judz6+qhAp7SYFh+4iUWjtG/Ehucsd4l HsPSeYtgOP4mxBp9Q2NwkDn8whjtBCXQUI7H4ZVU7r54fuHGELJkeFQwlu8GAoizsU5c 9+cQ6vrZPcJzkQEqWEJjKlSh72veBOdpXNVXSfEoHUfIRbzeeJ8AF374iHeGPe4uV7hQ OmBVRsyudhKdVeSSIUIsVaPCRDRYdp8T6L0/3LBAqWfD4/I0mArha1LMXavF+MaRhYeY AdPNE+Z+qoXM7u6JtO94yHLRc3T8LJNDLBYHU3jJYnjAYQt0NeCvIlfb0xEr//5xUNnn gkgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=Mi0Dcds4ZGR4zNWQBF3BiNvI39o+otb/rcmg7GGoL34=; b=yAsYennpZdKTvcgDSCqvPrKRJfOntL3iTxwNrF7e90SiP5rQZ4K03fc8ECovMicobl 7I4vW1sqGlUGSpqAORXjc/t4a1ExfTU9tGpCUxv3YxhmE2G7FEOj9xQosIbO8RCu1OCR wz1EeiQGSUhipD+RCDg9B37Rj/y7WadplONzk+lL/9P6x0uTTOlGTe8qu645YKTu2AeP OXCHKmVRBnG3mWpu5WY1NBGHilGyM026fTY+f+H9QJF+1aR3IMPklXVYv9GSyE2H4ZjV xv571Tzll7jmyIj+1kdL3XU/Ry69a4Naxdl13nnun5cCX0QVjuLtyzaVpaqvjSdYQPIE vV/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nNscdUa5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x3-20020a170902b40300b00189c8b6e603si27410231plr.583.2023.01.16.11.38.14; Mon, 16 Jan 2023 11:38:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nNscdUa5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233175AbjAPS4h (ORCPT + 50 others); Mon, 16 Jan 2023 13:56:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230465AbjAPS4e (ORCPT ); Mon, 16 Jan 2023 13:56:34 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 329F318B35; Mon, 16 Jan 2023 10:56:33 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C34B161117; Mon, 16 Jan 2023 18:56:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A0F2C433EF; Mon, 16 Jan 2023 18:56:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673895392; bh=DuMYZOnr0bMZvp7GSH2TEtxIL4JXiMj6qVLcpIaZmVw=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=nNscdUa5yyar00y4JkXqh/nP1LwzCLEY3fydqzu6fthUBWQOwSIevYrYNrDeChQR3 D8F6MGD1axAjkWcOE9CUsxvsxv+drEgsIAI3kRi9eBVUNaybBz/SaSx+WO2PiUSYeu ZAmA+HZE8m3lkKINt/rCVtquL3O/WI0gvQiI3NvuCbePGAdKsIsI3lyE0QSx5Fm2Mu k6slx5iTdh2aeBbVdphF/sXLKgCDo1sBOiEjbXDVZQw18FqNKLJY7QpNCY90I21QBT Y7FkrZ+SSN9B2j7NTeILgbOMm2VrGEaNX/MLj5EKYpM9tN/HfVUz6eIO76gITp2f6k fdIdMW5fVn/uA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id CB7385C0687; Mon, 16 Jan 2023 10:56:31 -0800 (PST) Date: Mon, 16 Jan 2023 10:56:31 -0800 From: "Paul E. McKenney" To: Boqun Feng Cc: Paolo Bonzini , linux-kernel@vger.kernel.org, rcu@vger.kernel.org, kvm@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Lai Jiangshan , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , David Woodhouse , seanjc@google.com, Joel Fernandes , Matthew Wilcox , Michal Luczaj Subject: Re: [PATCH 2/3] rcu: Equip sleepable RCU with lockdep dependency graph checks Message-ID: <20230116185631.GY2948950@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20230113065955.815667-1-boqun.feng@gmail.com> <20230113065955.815667-3-boqun.feng@gmail.com> <20230113112949.GX4028633@paulmck-ThinkPad-P17-Gen-1> <20230113191120.GB4028633@paulmck-ThinkPad-P17-Gen-1> <456f6c15-3043-6da2-349d-c0c3880c1a55@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 16, 2023 at 09:54:32AM -0800, Boqun Feng wrote: > On Mon, Jan 16, 2023 at 06:36:43PM +0100, Paolo Bonzini wrote: > > On 1/13/23 20:11, Paul E. McKenney wrote: > > > On Fri, Jan 13, 2023 at 10:05:22AM -0800, Boqun Feng wrote: > > > > On Fri, Jan 13, 2023 at 03:29:49AM -0800, Paul E. McKenney wrote: > > > > I prefer that the first two patches go through your tree, because it > > > > reduces the synchronization among locking, rcu and KVM trees to the > > > > synchronization betwen rcu and KVM trees. > > > > > > Very well, I have queued and pushed these with the usual wordsmithing, > > > thank you! > > > > I'm worried about this case: > > > > CPU 0 CPU 1 > > -------------------- ------------------ > > lock A srcu lock B > > srcu lock B lock A > > srcu unlock B unlock A > > unlock A srcu unlock B > > > > While a bit unclean, there is nothing that downright forbids this; as long > > as synchronize_srcu does not happen inside lock A, no deadlock can occur. > > > > First, even with my change, lockdep won't report this as a deadlock > because srcu_read_lock() is annotated as a recursive (unfair) read lock > (the "read" parameter for lock_acquire() is 2) and in this case lockdep > knows that it won't cause deadlock. > > For SRCU, the annotation mapping that is 1) srcu_read_lock() is marked > as recursive read lock and 2) synchronize_srcu() is marked as write lock > sync, recursive read locks themselves cannot cause deadlocks and lockdep > is aware of it. > > Will add a selftest for this later. > > > However, if srcu is replaced with an rwlock then lockdep should and does > > report a deadlock. Boqun, do you get a false positive or do your patches > > To be more precise, to have a deadlock, the read lock on CPU 0 has to be > a *fair* read lock (i.e. non-recursive reader, the "read" parameter for > lock_acquire is 1) > > > correctly suppress this? > > I'm pretty sure that lockdep handles this ;-) And lockdep agrees, refusing to complain about the following: idx = srcu_read_lock(&srcu1); mutex_lock(&mut1); mutex_unlock(&mut1); srcu_read_unlock(&srcu1, idx); mutex_lock(&mut1); idx = srcu_read_lock(&srcu1); srcu_read_unlock(&srcu1, idx); mutex_unlock(&mut1); Thanx, Paul