Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp304248rdb; Thu, 30 Nov 2023 05:27:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IG+FcjBBZJchc2Ah0YwzwniK3E7Hqi02AEN1Ddf9VG04I1DB6NSN4cTUV0ymDW7WfxC+5B3 X-Received: by 2002:a05:6a20:840d:b0:18d:1e16:8017 with SMTP id c13-20020a056a20840d00b0018d1e168017mr5154723pzd.8.1701350864880; Thu, 30 Nov 2023 05:27:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701350864; cv=none; d=google.com; s=arc-20160816; b=iJr+CbdScxJVbdLENaI01T+v483LO6ge+EZFiZIkrb8cpLenGPfcnGt+h/B+O7c3hF xqnmpslWiyeANDsfE0Z1Gv9AjLWtWkDORn2IM+Jba0OE5UeMN6Zd/ql1n2NF0A84wvHn OWbC8xPGpqp1CIvyNvAGuQ15Pkv4Kn9GiLhNryMJZbl/N2ecVO3aYJZGXgM+CSGKVZhN KwabAvUb+/+PIgRL2L/5/HQ93i5tiL2UaPKJrBTkJuNUMr7voc+5q1oAQtJ1ZNc/PKw/ v2DzscEIJT2454fyAdcLNt+GnmRkLnsP5OkqVN32iZ9/HNeH8E11oaBey5iXIh/4lm0d oUrw== 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:message-id:subject:cc:to:from:dkim-signature :dkim-signature:date; bh=qdri7M8cZwmmxj44/up6D+Gy+1F00rDNzTB9GeEu0HE=; fh=LKrmCJRNOukkGbiiD3xB+e4+iwid1GQKSC2YQMIMOU4=; b=JEcqpRsFHUZDC7F0ATD4Axup08FOJ2Z7SwbQlvqtd4H/w0AD2+enUA+Spug0KsdqVe PaGn7FOotmyeeMMHcvte/ZN6s9+iURTI7YQ+uVdBLKceCeesM/URj7qPQ8haSGV5HvtF Iu1tEmoFcGiD4EVsB57iUS+a73fBCI/HchAyr+0X4PDH19fvvHJlhd81+CPvBRkVCLUO rbbZpxxYHHSf3RCIoB2IRGQwIYIgX1aT3ZS4oy3aWcWl2GYSaZaN5uhbEG2KxHpR0fi8 7qty9iziGo0wXFkfSl8em8BMIs3w9Pj3DFqjjjePit0nRnImZShu5KM90xTDciMwW20+ hC9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=41jNNMnH; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=2KYyMwc2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id b14-20020a056a000a8e00b006cdc6987539si1271879pfl.266.2023.11.30.05.27.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 05:27:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=41jNNMnH; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=2KYyMwc2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 09B5183EB32D; Thu, 30 Nov 2023 05:27:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345518AbjK3N12 (ORCPT + 99 others); Thu, 30 Nov 2023 08:27:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232159AbjK3N10 (ORCPT ); Thu, 30 Nov 2023 08:27:26 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35CE999; Thu, 30 Nov 2023 05:27:33 -0800 (PST) Date: Thu, 30 Nov 2023 14:27:29 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1701350850; 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: in-reply-to:in-reply-to:references:references; bh=qdri7M8cZwmmxj44/up6D+Gy+1F00rDNzTB9GeEu0HE=; b=41jNNMnHU+E+y5VkeBh3gn0gu3VGhCmUdhi32wfcmJtVqGBgo8YC8Wsqhv3JzME0/vbQa5 Pbg20X1N8aXvdVkYUVU7ZbhVCUzzESpyUiFzTG6ztx5qxgQciUUCZqQ92Wu3/FH0mzBI0i 3ehFeLsyenoFwu487bQBmSUfw5XVvmr14YICRAbTZd1xsy2WKRbvQKiomhoh0sTx1D8nK+ tObrmEAvRTonyQGPcc9dF5HlVlEgIhoTeSAIgUWmohMs3CeVCJTaGYTdmLPqHhX3itWZZ+ dF9iuRtmQbrCAC0afosB+AjfZbEBchmjkqNeEvJHHRcx85a70r0vYYI0MTH+/w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1701350850; 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: in-reply-to:in-reply-to:references:references; bh=qdri7M8cZwmmxj44/up6D+Gy+1F00rDNzTB9GeEu0HE=; b=2KYyMwc2gGnf3SLL8kQG3kOMzJ2bdiXpBeX4KUeBQXp/yCsR9/Km5TqD6CA/OHC7uczcLd BFsDGfDI7B1/kKAg== From: Sebastian Andrzej Siewior To: Boqun Feng Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, rcu@vger.kernel.org, "Paul E. McKenney" , 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: [PATCH v2] srcu: Use try-lock lockdep annotation for NMI-safe access. Message-ID: <20231130132729.niM5FJPc@linutronix.de> References: <20231121123315.egrgopGN@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: 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,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 howler.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 (howler.vger.email [0.0.0.0]); Thu, 30 Nov 2023 05:27:42 -0800 (PST) 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 --- 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