Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2858434lqp; Mon, 25 Mar 2024 11:11:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUev/F5Tbqj+Dtmwleqkt9V8VcDXtgTGSNHc1b2TgvNNSYZruCrMpvX8FYuBpzJelMUgFmgNyoDPB5fjQXKWayl3c3kW/jfTc5pVvUYpg== X-Google-Smtp-Source: AGHT+IFwHIqKUkvtYbb0M8mWanq6HbHNbmn0hwOQRHS64r7VNnRSQjToAqXqokAgy9lFa00vRKTM X-Received: by 2002:a05:6808:1582:b0:3c3:5ff0:9736 with SMTP id t2-20020a056808158200b003c35ff09736mr8631318oiw.40.1711390292042; Mon, 25 Mar 2024 11:11:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711390292; cv=pass; d=google.com; s=arc-20160816; b=gYVg/A8K8xHDI//RSZ4NCal1x+Z2CuZQQlBIa68cLgZrzO2hsPYyGF24PAf0QDPsnM 7wd6/6Wz0p30D50aDvJqQuWvJNiNp+bj8WHW7VWpdmrgk8Tby6NPL1uIudsU9gj0ryqP Mwt7UKY3oP7aKFbC+Hzl9MlI0okZIlKtMoJLiNovxvPXWAfGtjGq/uRRYwlHKtLvIw+R FmeKwWJvUxqcMvYsXNyzGfDE+97QhGVhjZC/KBpAlCDCL2t9dwIp5toxfXuANp5pLXLp 8L6J8Q/r+m9lm0WXZy+Yqo4xiRgbsAElCBqkCKJAlfFzBSq+8NQRro0wGT12uvmQ3mr9 dxMw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=63cbUxYgirJ/YEr84TXKagJ5rL0dwPUYDKl8NOveKNg=; fh=y6hkPvphkO+K0Bn0A7RuQONeW3hOTTwO80xjmCYSU3k=; b=KKi+uUwCYlsb2xxoHwSA+a5aSvZDWAaRKFeJmB5+HKHcHmVFfuSzo7djr3hJIZcmnM ZyvlsX8MwdcuD0LKaOZi80pF+46/pJ0l/0ptg8dkiE0UeOSevoSb+4mapyIJaSsHOfT7 +bPgmh+1rAfv/RjDBYfVsLoYwMFy8ubxN7eyxmkuwuMU5ZQ+W4dxdrMBMXR2mQyh5TLn 00zG2N2LIs50mgk+303lctxAL949QK8X8BkxvVFDiDHHWmf1nHvbZvrX2C5WqCeLMuO6 wWn2J3JyJSgaIxHGOMUb9gWAdOe57Y9K+a+82y+pcBns2qdMOJAG/rj+mioEt1D2gU6r oQxw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=lQsiruC+; arc=pass (i=1 spf=pass spfdomain=sipsolutions.net dkim=pass dkdomain=sipsolutions.net dmarc=pass fromdomain=sipsolutions.net); spf=pass (google.com: domain of linux-kernel+bounces-117611-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117611-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id j14-20020a05620a410e00b0078a56957c2bsi3097913qko.731.2024.03.25.11.11.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 11:11:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117611-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=lQsiruC+; arc=pass (i=1 spf=pass spfdomain=sipsolutions.net dkim=pass dkdomain=sipsolutions.net dmarc=pass fromdomain=sipsolutions.net); spf=pass (google.com: domain of linux-kernel+bounces-117611-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117611-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id BC0F31C3D9B6 for ; Mon, 25 Mar 2024 18:11:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2B02947784; Mon, 25 Mar 2024 17:39:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="lQsiruC+" Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD4251E534; Mon, 25 Mar 2024 17:39:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711388356; cv=none; b=GrvfWuhsK382Bnuyzb+qU6GMMDs4vqPQ6b1Lj+ahr4TRYMNCfk5v4Tx3CHEjQVWx87KodXGwlilKzJlVJXBxDb7LuuKYN6/gClLWfOfgYFzFXnqdLd8/2Kz5j/TawQ8fmj6P4RCGHVKm1omDqf3AxcAOoEAzzoMxGxlKmYf+KO4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711388356; c=relaxed/simple; bh=QPEBF84eE88+YdJFYseicHFa0CBVX+qcQXwPqlTEfGY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=OfxdyXgiPF5ZdG+QeC19uD+tsExEo5d+FoIbEZQmeg0lBLRP9++OZjpCHIRRcu6RCTsH5iL/r3mC5rdLXCRy/nY0yuTjw7F67Ncc4wmg0LoTmgwmI+2k9hcoDFQMi6Rlb1pYhKzNknioHPP5MRyp4qW+CKJTZicksM16U4wxeXo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=lQsiruC+; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-To:Resent-Cc: Resent-Message-ID:In-Reply-To:References; bh=63cbUxYgirJ/YEr84TXKagJ5rL0dwPUYDKl8NOveKNg=; t=1711388355; x=1712597955; b=lQsiruC+mSHcuQqvWrBnJUmlWirkAGeOnoYRWmRE5sH0ATeRYTUJYRTOF1jJfsU3cdCf76XFhsY yt/UzPRaZlEUhDOzkM21UjOwJ1Oy5OAX5ukrfK5vMUtnHN+HHXR79B9opsuEs1N6wwe7XMqryOJsz hJkJPBB2gQhxS9Uh5GMsuBxfFyJSlqug2XEEh2+5e+mx/10KGOxZjYgi4bgpmrxNdua23fqFeNtTC SBiPejYCd24NYQQENsFs6qTOnYUhVmw3fT0oaUZW6gtiy187AwVq1yEOgyLU5ovmTg31peEMJZZcd o3eZj4wjW78yn6tm+6kvslDq1T7ZX1iYe59g==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.97) (envelope-from ) id 1rooHu-0000000DzY9-2PtP; Mon, 25 Mar 2024 18:39:10 +0100 From: Johannes Berg To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, "Paul E. McKenney" , Frederic Weisbecker , Josh Triplett , Peter Zijlstra , Boqun Feng , Johannes Berg Subject: [PATCH v2] rcu: mollify sparse with RCU guard Date: Mon, 25 Mar 2024 18:39:08 +0100 Message-ID: <20240325183907.7205bf36489a.Ic3ac66ff5d6a9bd8a610858060117e1364641a3f@changeid> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Johannes Berg When using "guard(rcu)();" sparse will complain, because even though it now understands the cleanup attribute, it doesn't evaluate the calls from it at function exit, and thus doesn't count the context correctly. Given that there's a conditional in the resulting code: static inline void class_rcu_destructor(class_rcu_t *_T) { if (_T->lock) { rcu_read_unlock(); } } it seems that even trying to teach sparse to evalulate the cleanup attribute function it'd still be difficult to really make it understand the full context here. Suppress the sparse warning by just releasing the context in the acquisition part of the function, after all we know it's safe with the guard, that's the whole point of it. Signed-off-by: Johannes Berg --- v2: add a comment after discussion with Boqun --- include/linux/rcupdate.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index 0746b1b0b663..6a3c52b3c180 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h @@ -1059,6 +1059,18 @@ rcu_head_after_call_rcu(struct rcu_head *rhp, rcu_callback_t f) extern int rcu_expedited; extern int rcu_normal; -DEFINE_LOCK_GUARD_0(rcu, rcu_read_lock(), rcu_read_unlock()) +DEFINE_LOCK_GUARD_0(rcu, + do { + rcu_read_lock(); + /* + * sparse doesn't call the cleanup function, + * so just release immediately and don't track + * the context. We don't need to anyway, since + * the whole point of the guard is to not need + * the explicit unlock. + */ + __release(RCU); + } while(0), + rcu_read_unlock()) #endif /* __LINUX_RCUPDATE_H */ -- 2.44.0