From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37CC7C433F5 for ; Thu, 21 Apr 2022 23:08:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ABEC26B0072; Thu, 21 Apr 2022 19:08:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A46E76B0073; Thu, 21 Apr 2022 19:08:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E7086B0074; Thu, 21 Apr 2022 19:08:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 7B4FD6B0072 for ; Thu, 21 Apr 2022 19:08:53 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7030121E2C for ; Thu, 21 Apr 2022 23:08:50 +0000 (UTC) X-FDA: 79382428020.12.1EEF90E Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf10.hostedemail.com (Postfix) with ESMTP id BCFF4C0024 for ; Thu, 21 Apr 2022 23:08:46 +0000 (UTC) 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 1E4F061E9B; Thu, 21 Apr 2022 23:08:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FF2AC385A7; Thu, 21 Apr 2022 23:08:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650582528; bh=dJ+oCe8hcxTkCxYaCSaUOmqH7FbT8LrdOg6l5AEm8LU=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=SEMPuSQjGaFClBbFYkbdPChiENBX4oR1NNJWBHR6s2MNkSNGhOaadOtmcWwGkSghj I/i/KzCxnWL1VSE1huavhS6Zc9qkd1Dm4cY5NmxL8FDhsv4+VFc6WtkS630z57ym2r 1Vb/2jX0gkEpCABukXSj5h0H47GERK8xg7DpMdn7coxKbe+KQWuaE6BFSdxQLU7V5w GbjjQUf6+Z9AcgXr+c8Y7HFlQGpWw1hWmtzEml/N79izN9+o3MU/uv6LJUQ392pnyJ CUpLclT5zRR0gwarV0kHlblDC7Tn2zM3/xLm5uo5NnmVvDxWhOGgA+b9sU4FAFiVEp y0iJxDFgNEM1A== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 21FA15C0510; Thu, 21 Apr 2022 16:08:48 -0700 (PDT) Date: Thu, 21 Apr 2022 16:08:48 -0700 From: "Paul E. McKenney" To: Hillf Danton Cc: Sean Christopherson , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [Question] srcu: is it making sense to recursively invoke srcu_read_lock? Message-ID: <20220421230848.GA194034@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20220421042211.2433-1-hdanton@sina.com> <20220421133414.GP4285@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220421133414.GP4285@paulmck-ThinkPad-P17-Gen-1> X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: BCFF4C0024 X-Rspam-User: Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SEMPuSQj; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf10.hostedemail.com: domain of "SRS0=OQHl=U7=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" designates 139.178.84.217 as permitted sender) smtp.mailfrom="SRS0=OQHl=U7=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" X-Stat-Signature: b5ihk5b3etkoymkoqwqwmqtokrt1p79n X-HE-Tag: 1650582526-119849 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Apr 21, 2022 at 06:34:14AM -0700, Paul E. McKenney wrote: > On Thu, Apr 21, 2022 at 12:22:11PM +0800, Hillf Danton wrote: > > Given rcu_lock_acquire() in srcu_read_lock(), > > > > iA = srcu_read_lock(foo); > > iB = srcu_read_lock(foo); // not bar > > ... > > srcu_read_unlock(foo, iB); > > srcu_read_unlock(foo, iA); > > > > can the call sequence above trigger warning with CONFIG_DEBUG_LOCK_ALLOC enabled? > > I hope not! After all, nesting SRCU read-side critical sections is > perfectly legal. But why not just try it and see? > > > Does it make sense to add srcu_lock_acquire() in line with rwsem_acquire_read() if > > warning is expected but not triggered? > > Please understand that while SRCU can often be used where an rwsem > might otherwise be used, SRCU is not an rwsem. For one thing, rwsem > readers can deadlock in ways that SRCU reader cannot. > > Now, I don't yet know of a non-destructive use case for partially > overlapping SRCU read-side critical sections, for example, if you > switched the two srcu_read_unlock() calls above. But at the same > time, I cannot prove that there is no valid use case, not yet, > anyway. But I do see one now. Imagine someone passing a callback to another function, with an SRCU read-side critical section starting before this other function is invoked and ending within the callback. Suppose that this other function also uses SRCU to protect the invocation of the callback. The two partially overlapping SRCU read-side critical sections are independent, so they are OK. When the critical sections are not independent, trouble ensues: https://paulmck.livejournal.com/40593.html Thanx, Paul > > > Thanks > > Hillf > > > > static inline void rcu_lock_acquire(struct lockdep_map *map) > > { > > lock_acquire(map, 0, 0, 2, 0, NULL, _THIS_IP_); > > } > > > > static inline void srcu_lock_acquire(struct lockdep_map *map) > > { > > lock_acquire(map, 0, 0, 1, 0, NULL, _THIS_IP_); > > }