Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2896851rdh; Wed, 27 Sep 2023 16:57:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGZk85MTdaRAjjc2j9/HO8XInzLFmQJudZI0OoXayhKPXKz2ct9YGz0Wn/a4tUhcHzFPk0E X-Received: by 2002:a05:6a20:7da4:b0:137:c971:6a0c with SMTP id v36-20020a056a207da400b00137c9716a0cmr4570990pzj.31.1695859076105; Wed, 27 Sep 2023 16:57:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695859076; cv=none; d=google.com; s=arc-20160816; b=hbwvbshjF8RPgSNTwQv7KnVhSJ2D5u27mtQJr0z0VehyuI9FKT+gr31bh6lf0LJAwe t3wU5nm129ZDhdeHLPmg01Z8Dp52KCIdl5b/nMihnGbyYkECSqux5tQ9eHtqWFp3PxbT OK/qCFYII3dOPxcTIrCtZvIRVcMheLXujItfgEqDo+JzBAVz73AXWFIr+5DIXLMooSnR /+I4+6fbEJjRRTjr7K3RZ45FJ8Ra0yqPgaeLHIVaYrrOUjMDhygbB3xz9pVtPpRwrD5o PmQANSKwIybxzJuvUDyjjwQRP1/jvp/0t8avSSb9bd0EUVDjfYErWkva2rMsYZ5x/Cnq mU7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-disposition :mime-version:message-id:subject:cc:to:from:dkim-signature :dkim-signature:date; bh=EdCiO/WzKECbYs7KtcCYhKCOSLS8gRQvCAW/vFRb9F4=; fh=CvjwasYIGIUnqmxBvRAiLCy1NXiZncROBTI+6xPTls0=; b=HeuoKUNvtp9zEtGoRRKK+vFVC0636WzkKHTFg5sG/CDJTtZFfxb10CciCxoykGRZ6+ aRR/Jf7X+JwfZjIh4RYzCBnYsSMXGnbQyVm56OSiduca1NbwJMBcD2xcqv5odKNyg9KR 2x811pQXhQZX+1VVdiqM/h8kFLg2u/8tRJHpF5qCjyA0JnwdSF+IRrCWHbfzMuI3ZuqT CF4HkBrV6L+zybKs4Yx81j4qNbGooXGG5gBMFQ/nnfs+iaAfFcIjh3S33C2B1HS3qvaQ JYQJ1UYmgVXmDx5/WtJBOrsCUn8swIluBU1b7/bz8ZilnX1auFaZA3ab6RWY0nqZXX3X RjZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="gA8E7/z/"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=YReDyt9J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id i21-20020a056a00225500b00690d42e334fsi16532899pfu.181.2023.09.27.16.57.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 16:57:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="gA8E7/z/"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=YReDyt9J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id E40A980239B5; Wed, 27 Sep 2023 09:03:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231947AbjI0QD0 (ORCPT + 99 others); Wed, 27 Sep 2023 12:03:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232838AbjI0QDM (ORCPT ); Wed, 27 Sep 2023 12:03:12 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70B7C121; Wed, 27 Sep 2023 09:02:35 -0700 (PDT) Date: Wed, 27 Sep 2023 18:02:31 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695830553; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=EdCiO/WzKECbYs7KtcCYhKCOSLS8gRQvCAW/vFRb9F4=; b=gA8E7/z/ye+UWQvTptCUxfM7HS3iYd/tK9vXkmkbp6ehYQxjZfhSnwUbo4yeTQVXJ9IyaK 8wwAtn2uo82b34MM6QBT6xBYWLHHZHhUQxGiLRWHByNXFKXmbA2NGgWBwPixIIC7qn67Q0 rXHrEqx5L933ymrrywoXolbIUbAnG0yGsz7c0XyJmjfTWkMe8gKDoTyWp+Q9+TsYh6mrfE ZNxJCnQvTyxZ13dpeZ7/wj6oYmTKRHzkxrouy8xoZEUrQ6rMcvQcIQGGMWXBr8+Rz1ibrB q0E2C/9dyj2TETBAiMJrYc13NWVAl8mzXrUff1NU3ponoQLgs3BldvxYTFfGrg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695830553; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=EdCiO/WzKECbYs7KtcCYhKCOSLS8gRQvCAW/vFRb9F4=; b=YReDyt9JG3c9HFVm3jjR59KBPrudAz6g1lOu804uGt8ruhv64qozjuWhLyNqZHyepfHAYV cCC1Rw8pXSmPDmAg== From: Sebastian Andrzej Siewior To: linux-kernel@vger.kernel.org, rcu@vger.kernel.org Cc: "Paul E. McKenney" , Boqun Feng , Frederic Weisbecker , Ingo Molnar , Joel Fernandes , John Ogness , Josh Triplett , Lai Jiangshan , Mathieu Desnoyers , Neeraj Upadhyay , Peter Zijlstra , Steven Rostedt , Thomas Gleixner , Waiman Long , Will Deacon , Zqiang Subject: [RFC PATCH] srcu: Use try-lock lockdep annotation for NMI-safe access. Message-ID: <20230927160231.XRCDDSK4@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Wed, 27 Sep 2023 09:03:37 -0700 (PDT) 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. Use a try-lock annotation for srcu_read_lock_nmisafe() to avoid lockdep complains if used from NMI. Signed-off-by: Sebastian Andrzej Siewior --- The splat: | =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D | WARNING: inconsistent lock state | 6.6.0-rc3-rt5+ #85 Not tainted | -------------------------------- | inconsistent {INITIAL USE} -> {IN-NMI} usage. | swapper/0/0 [HC1[1]:SC0[0]:HE0:SE1] takes: | ffffffff828e6c90 (console_srcu){....}-{0:0}, at: console_srcu_read_lock+0= x3a/0x50 | {INITIAL USE} state was registered at: =E2=80=A6 | CPU0 | ---- | lock(console_srcu); | | lock(console_srcu); | | *** DEADLOCK *** | My guess is that trylock annotation should not apply to rcu_lock_acquire(). This would distinguish it from from non-NMI safe srcu_read_lock_nmisafe() and NMI check in rcu_read_unlock() is only there to survive if accidentally used in-NMI. 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 5e5f920ade909..44aab5c0bd2c1 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h @@ -303,6 +303,11 @@ static inline void rcu_lock_acquire(struct lockdep_map= *map) lock_acquire(map, 0, 0, 2, 0, NULL, _THIS_IP_); } =20 +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_); @@ -317,6 +322,7 @@ int rcu_read_lock_any_held(void); #else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ =20 # 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) =20 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_st= ruct *ssp) __acquires(ssp =20 srcu_check_nmi_safety(ssp, true); retval =3D __srcu_read_lock_nmisafe(ssp); - rcu_lock_acquire(&ssp->dep_map); + rcu_try_lock_acquire(&ssp->dep_map); return retval; } =20 --=20 2.40.1