Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp54453rdb; Mon, 4 Dec 2023 20:23:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjpMjdlLuub5K1rfwxbqg7sZcnVjY5EKot83enrwA3DILIMAtAZGX4I3Kilm85dFk8MwYl X-Received: by 2002:a25:7812:0:b0:db5:3d08:742 with SMTP id t18-20020a257812000000b00db53d080742mr8899600ybc.25.1701750194969; Mon, 04 Dec 2023 20:23:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701750194; cv=none; d=google.com; s=arc-20160816; b=S1MxmtQ6UnYSDhQCIFidpk6jG0dWabLtQW4TTTMIFH468ZPhku3Rt0Bre3zed4hfRX qgGgIL0AUiKtUOUu54zeghIROn7141ZyJ7wBiWG0ywcXRhJrP7a9D2wjFNKoVO2DPpuJ GycbWHgIQL+XbciZ6dNWSMk0HHXv2vIi+tOQ290fsgOq6H7CRencBRbUaKr+tCJDwyQ8 Q3i4gDaQmwIuGik8s5CqJtx8kvkLh6JCCM7NE4iZ/w0WG3Jn+nz0lfrOy6TARDWPHnQS ekjrrDMwcjyBfu6olEEUZLbOrJznwoWsFr9d4fwJBgbQLNcmCIwB2u/TXSPYo3eemKzl 8sDQ== 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=vtb2YZSYOVILKTMTOjpshqdL7B7/W/mm2sIqNnGkT8E=; fh=UVu76pqnMFqlrNSMuYi7tTR1QYEB7ncOfXHY3oLILcs=; b=LWaCAay+qoZJvAFf8toJzC9tFJRzrwwRXjTVqnMcHsIN9kC4RKCngSsUxKLnoEaPME TtQ1H2C8tBLHEdBTmHRlp9sW64fI35+Oo0EZOoAdka497XaveNLfSudph4T3M+peko3C dV98GVEG4EagHBx3O+tPViAXqOC2pbecceWBpthiTm0af5rBNX8AKWIrl9ehJ7BP6MyP wmKWBBL7sKuxsjssg/L4H5bqHciNjzSScZo628Bj1lAPylE+V5APc0TEtlW9DbrXWY+t ho22av/bCQ6aDhFDh8MhE0HSSOHWjVnFgPQ4x2cEAMk0ic7hdTIHO+HSKIBJ+T//cIfD awEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QXlXmQpE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id lk16-20020a17090b33d000b00286ce76ff01si1393668pjb.146.2023.12.04.20.23.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 20:23:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QXlXmQpE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 28EA28077FC6; Mon, 4 Dec 2023 20:23:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231669AbjLEEW4 (ORCPT + 99 others); Mon, 4 Dec 2023 23:22:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230074AbjLEEWz (ORCPT ); Mon, 4 Dec 2023 23:22:55 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE9369C for ; Mon, 4 Dec 2023 20:23:01 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81833C433C8; Tue, 5 Dec 2023 04:23:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701750181; bh=w/Bk/WJxSr5QEyyq9W+SD+SihawEDWaEohg5h1i0Keo=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=QXlXmQpEo+Ca6kqEdj0E119zOei8gUzaGcyvM/woNAACeAgMFx1j8YPfzA88c+b8g vq8ChUgWgOWJgC4k3fH+i6G9Mhsllxtmv2d9KV38726HJgsgm0SfIu4PjbgKOpltLR cjlD+3/FD0oXuq/756f1M2DWWkm+uzUu1NGQaJjZYC13FURwHC8Lp6Ev/x6QqbmzyP nihuFqb+9BTzns40owbm2R6fAYgmWVmITsujhlm6Nuiar4JlOrY6QpoSnmItuKZlCF prZdQpz/dUtXD0bs3SZ+0r22y9m0Ise5qsLcmcq0gbQXMZrswjcxCwE/gQrcY3oxa8 tArufEqBFyKfQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 14277CE1147; Mon, 4 Dec 2023 20:23:01 -0800 (PST) Date: Mon, 4 Dec 2023 20:23:01 -0800 From: "Paul E. McKenney" To: Sebastian Andrzej Siewior Cc: Boqun Feng , Peter Zijlstra , linux-kernel@vger.kernel.org, rcu@vger.kernel.org, Frederic Weisbecker , Ingo Molnar , Joel Fernandes , John Ogness , Josh Triplett , Lai Jiangshan , Mathieu Desnoyers , Neeraj Upadhyay , Steven Rostedt , Thomas Gleixner , Waiman Long , Will Deacon , Zqiang Subject: Re: [PATCH v2] srcu: Use try-lock lockdep annotation for NMI-safe access. Message-ID: Reply-To: paulmck@kernel.org References: <20231121123315.egrgopGN@linutronix.de> <20231130132729.niM5FJPc@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231130132729.niM5FJPc@linutronix.de> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 04 Dec 2023 20:23:12 -0800 (PST) On Thu, Nov 30, 2023 at 02:27:29PM +0100, Sebastian Andrzej Siewior wrote: > It is claimed that srcu_read_lock_nmisafe() NMI-safe. However it > triggers a lockdep if used from NMI because lockdep expects a deadlock > since nothing disables NMIs while the lock is acquired. > > This is because commit f0f44752f5f61 ("rcu: Annotate SRCU's update-side > lockdep dependencies") annotates synchronize_srcu() as a write lock > usage. This helps to detect a deadlocks such as > srcu_read_lock(); > synchronize_srcu(); > srcu_read_unlock(); > > The side effect is that the lock srcu_struct now has a USED usage in normal > contexts, so it conflicts with a USED_READ usage in NMI. But this shouldn't > cause a real deadlock because the write lock usage from synchronize_srcu() is a > fake one and only used for read/write deadlock detection. > > Use a try-lock annotation for srcu_read_lock_nmisafe() to avoid lockdep > complains if used from NMI. > > Fixes: f0f44752f5f61 ("rcu: Annotate SRCU's update-side lockdep dependencies") > Link: https://lore.kernel.org/r/20230927160231.XRCDDSK4@linutronix.de > Reviewed-by: Boqun Feng > Signed-off-by: Sebastian Andrzej Siewior Queued for v6.9 along with further review and testing, thank you both! Thanx, Paul > --- > include/linux/rcupdate.h | 6 ++++++ > include/linux/srcu.h | 2 +- > 2 files changed, 7 insertions(+), 1 deletion(-) > > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h > index f7206b2623c98..31d523c4e0893 100644 > --- a/include/linux/rcupdate.h > +++ b/include/linux/rcupdate.h > @@ -301,6 +301,11 @@ static inline void rcu_lock_acquire(struct lockdep_map *map) > lock_acquire(map, 0, 0, 2, 0, NULL, _THIS_IP_); > } > > +static inline void rcu_try_lock_acquire(struct lockdep_map *map) > +{ > + lock_acquire(map, 0, 1, 2, 0, NULL, _THIS_IP_); > +} > + > static inline void rcu_lock_release(struct lockdep_map *map) > { > lock_release(map, _THIS_IP_); > @@ -315,6 +320,7 @@ int rcu_read_lock_any_held(void); > #else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ > > # define rcu_lock_acquire(a) do { } while (0) > +# define rcu_try_lock_acquire(a) do { } while (0) > # define rcu_lock_release(a) do { } while (0) > > static inline int rcu_read_lock_held(void) > diff --git a/include/linux/srcu.h b/include/linux/srcu.h > index 127ef3b2e6073..236610e4a8fa5 100644 > --- a/include/linux/srcu.h > +++ b/include/linux/srcu.h > @@ -229,7 +229,7 @@ static inline int srcu_read_lock_nmisafe(struct srcu_struct *ssp) __acquires(ssp > > srcu_check_nmi_safety(ssp, true); > retval = __srcu_read_lock_nmisafe(ssp); > - rcu_lock_acquire(&ssp->dep_map); > + rcu_try_lock_acquire(&ssp->dep_map); > return retval; > } > > -- > 2.43.0