Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3502519lqp; Tue, 26 Mar 2024 10:47:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWBFvqLWA5sivRtd7eL0aymbyAhxEPZygBGbhCKgIfPMSNpcc1PqPe0TPlAepgqyV3DXryvl07/ak7VSvqvgYqazoaEyACQt5bLJ5JXOA== X-Google-Smtp-Source: AGHT+IGBWcbS2itq9OsQtaEi3Ywe8X4xhuelHCEavpCTAhTQKXIWxHol10hHKqFCBwmWkB7EWaNm X-Received: by 2002:a17:90a:6308:b0:2a0:440d:6923 with SMTP id e8-20020a17090a630800b002a0440d6923mr9832802pjj.42.1711475231847; Tue, 26 Mar 2024 10:47:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711475231; cv=pass; d=google.com; s=arc-20160816; b=g1Lu0Ca6r5HlZIugYLr/GUIc9n3isHD3GCwyVoRSbKuY6a0kynEVqOALZRIGL2j16m tJB7wkbqEE+Xr6Y2zMcwNRdHYM0xIzHFk/ftgtWiUk3aqUcKbSe0f+Yj4YZpK4tew3A7 d61WE9dqt2kG3irnSgEP9zhN0t6YWVzqG7LRYJxNtiQ3dbSupHYrGvWUNB7B12v/D8wn 3gOJOxNmFb5BSfhHVd83AW6IOK3KEbbSz5ip6jyj2GsgHbNwgVcjwc7c7FKN9dzTIiJX Ds/bBC55109IlrLqZYAzdOwuCQ0mezY1Nc5hCSlVDOANGYgbN/HPG2UKTzbx6RVLKZSL ejJg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=V9jjbtoYs/LKXAYrvD+yEqnhOtfFBKpx5MZ66lU2mU4=; fh=On092NnDwekvE9xkYmcA2It8fe5H4YcfAVwFOWukLe8=; b=InIjh8ytDUxg4X2XCmIvdnKKXj8hedK1MvQeVxEElFVi5Ou7PQqZED859j99/VjiYJ DTnTqYzKvTmEVpuS04CN9KbGjzpEqlMWgotuTo2RMcKOS5jAv5Mv+Xx0CZU0HzK0FFrs zzCDn2DE/BaddWxLnY0jStx+Eixwnwqne0+m6wQskl4Ta/RbsgKxqag+kcC7crZS93Wr fHOPo11aHGm6eqHfMt81rMTNesosMM/bUPMeEi/Rv2VKt1apXpXMjpXIsJhutl0QY/Ot TcFAKDEsqdF36F35gf1oVLaWtgLCwpBOkUSiTfBJ6myVBtfHx88Ef+7sCGL+jLWv1tBj eX8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ria7CDjh; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-119575-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119575-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id lm14-20020a17090b334e00b002a04eef19a5si7455650pjb.141.2024.03.26.10.47.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 10:47:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-119575-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ria7CDjh; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-119575-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119575-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 293C2B25F87 for ; Tue, 26 Mar 2024 17:21:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ACBC51CD20; Tue, 26 Mar 2024 17:21:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ria7CDjh" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D4F1617BA0; Tue, 26 Mar 2024 17:21:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711473701; cv=none; b=c8HSqMcCBZuit11Mio3ue9Zur+4oRaYUwgJ67TUo9m5a4pVN6p5pfWxslv7E/d2ZaT+HamynyH+a5EIiOiPgo9C87LGWDv5ng+FlsGR+jYlsV3kB8d9TZru47GakxZZOf7gbUK9P+Bk8YSNBhbarHX7Lifrhsoz4NodLxJyx4js= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711473701; c=relaxed/simple; bh=Y2psVmmKz1IVlz2128aKGOfPLJwSPX4Xp8L0iyNSHXg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WkxD6UD6C00107XOZId2QlYQYE3xJ9jVNB871yAg9Sf2dQtDlZYSXaaOpNBSxbADvDgYlj2EwlZnrD6FMW2ROWuk1hLqYOV39HexxTlydSSDzVyV+ssefY60Bp4nlSeSjp4eKIYvzpnWWzNnCu9H2yQ94DVtUnAa1tmthZgBSxg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ria7CDjh; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54CBDC433F1; Tue, 26 Mar 2024 17:21:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711473701; bh=Y2psVmmKz1IVlz2128aKGOfPLJwSPX4Xp8L0iyNSHXg=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=Ria7CDjhdCEvJpQdokB9O8PlgR9VLZJzLYOIlMZCdtpy7kjHFDktOj9wx9xxoIxjY Drjm+nVZAgdaY/LGr7ruUXIkjlsrp+MCT24lwKVI5fyMgSiJGiVX/3MoF64X5SuZES LJaIWm6SA+hlbHxL09dvBETD4pq7NjxebfMaRofF4gKa8HevLZlo+gR1TDyLQdMlcU 9W93oHL9OOu15RrBASTjhOxShjdWg55uEtbUWGPRQ2d0KtbdalOkugrFIbnqoK1tXm O24REZM2D/HXGmqhqQ7U54aqz6CEHd3gKGjkEg8nZUtT6iPaxRYm0yhgrU8P7Nmet6 hqzlMflXAaDQw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 4B673CE129B; Tue, 26 Mar 2024 10:21:40 -0700 (PDT) Date: Tue, 26 Mar 2024 10:21:40 -0700 From: "Paul E. McKenney" To: Boqun Feng Cc: Johannes Berg , rcu@vger.kernel.org, linux-kernel@vger.kernel.org, Frederic Weisbecker , Josh Triplett , Peter Zijlstra , Johannes Berg Subject: Re: [PATCH v2] rcu: mollify sparse with RCU guard Message-ID: Reply-To: paulmck@kernel.org References: <20240325183907.7205bf36489a.Ic3ac66ff5d6a9bd8a610858060117e1364641a3f@changeid> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Mar 25, 2024 at 10:41:36AM -0700, Boqun Feng wrote: > On Mon, Mar 25, 2024 at 06:39:08PM +0100, Johannes Berg wrote: > > 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 > > Reviewed-by: Boqun Feng Queued, thank you both! Thanx, Paul > Regards, > Boqun > > > --- > > 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 > >