From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05F14C27C65 for ; Tue, 11 Jun 2024 17:25:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9CF766B009D; Tue, 11 Jun 2024 13:25:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 97EBE6B009E; Tue, 11 Jun 2024 13:25:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 86E356B009F; Tue, 11 Jun 2024 13:25:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 6B9136B009D for ; Tue, 11 Jun 2024 13:25:56 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 29A63160FD3 for ; Tue, 11 Jun 2024 17:25:56 +0000 (UTC) X-FDA: 82219285512.03.9F3FC69 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf09.hostedemail.com (Postfix) with ESMTP id 6B41814000C for ; Tue, 11 Jun 2024 17:25:54 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=iSUMuMCe; spf=pass (imf09.hostedemail.com: domain of "SRS0=Qdzl=NN=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" designates 139.178.84.217 as permitted sender) smtp.mailfrom="SRS0=Qdzl=NN=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org"; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718126754; h=from:from:sender:reply-to: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IJsrFG+ta04YKqi4Qy616eSV9kmCcdDcKA4WxqhqPlc=; b=y3Hf7Eiliw6qrTAok1gIJQiKBQNAX/6TLox4XNrvbp7i05BW+flZGlIpsc3SkowZAu8Sps rIjAhZ0WQFmErqWlLtyRJoSv4Y9kRLFMFRfEbeMcxK7kEXociDk4LNTxKmPPuHyLojgp5q dEqRPQ2nY+WAcz8em9wXbZdAuG5vLXM= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=iSUMuMCe; spf=pass (imf09.hostedemail.com: domain of "SRS0=Qdzl=NN=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" designates 139.178.84.217 as permitted sender) smtp.mailfrom="SRS0=Qdzl=NN=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org"; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718126754; a=rsa-sha256; cv=none; b=2ooA3gc9Q64QzHOlr4LPjs+o9Pe/t/gx3VehyiJgVBP38Qn6p8+U4mNPMSjLYAbEC5yRAC WGvRTNxmv8Kznc9wt+Nb3pqb5bIkqGpcwTCLCVQa4Zxrh4k7UiDzEmmZ5ZN/vM4fOo5q8n uEqSBdrwdz6SgC0lo+TpHMOkx2IkgtM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 30E1A60F86; Tue, 11 Jun 2024 17:25:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D832CC2BD10; Tue, 11 Jun 2024 17:25:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718126752; bh=h3Fw4LVxQan3oHF80TjCbqhGZePFij6LDDZYP2gTes8=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=iSUMuMCenL4iT+NZT/XWrri2sMiE9aRMA9swLcBgvI3EqacJ3eYmHSFISIeUE57eB P6OWwnb4e24EZiAfB1fdKeBkMfRgAF/93b2eBXQdXVLJmVitL7Y9Afuf3NElb65V6F L2eYpliZMoXgiN0gJkjzRxDMgIRbF7bFDl999NlIoslsGS4dpJ/nGkuogaqUfT4c4m tPiv4dkVIK29J38zoGV2ruEopKUslcu09izr3WUTH98yOf4CmeWwBed4QYshjQtpdT 3E4f7Vd5z4sM6hazKeriJ458eoDFUrCXvQ6/AODd/IQKdvYbGV/Hp5s0gRAU07trsN RptVypv0xLOLg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 63D7ECE0991; Tue, 11 Jun 2024 10:25:52 -0700 (PDT) Date: Tue, 11 Jun 2024 10:25:52 -0700 From: "Paul E. McKenney" To: Uladzislau Rezki Cc: Julia Lawall , Vlastimil Babka , "linux-mm@kvack.org" , RCU , cocci@inria.fr Subject: Re: [cocci] patch idea: convert trivial call_rcu users to kfree_rcu Message-ID: Reply-To: paulmck@kernel.org References: <2dd5bafb-ceb1-238d-2f51-83ebf135b73@inria.fr> <2ec7eb0f-0950-4d65-b33a-64df7c5f89c9@paulmck-laptop> <77531e55-3418-d4be-f538-7ddc904ed88f@inria.fr> <21a32cbb-d388-4a8c-9298-ef8c82330f9e@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 6B41814000C X-Stat-Signature: mdigzt1xwpna79c7obnb8pe6t386kqgu X-HE-Tag: 1718126754-802575 X-HE-Meta: U2FsdGVkX18J1kHKMkmO6FM/GnknhgONOQ9K+nJkMiNm7uu9qgxdjAvPoWHjMYitygnUisPyTQYyCLbM9TZjf0tyC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J54JD4jC8uNZ1kbEZwq9cENXC2kAnoKokIgSaofNI3MFxeL8Wi87GUss+ATKY81a0uWVyKlcgLv8Z7ysvjREHW6k2bA/4+/NWp1ATv5xhBODmmP1aCtzbykp0RfZ3aFXThYR3EmWXWK0XdA2HDrDv6k+33YCPQwtk5mEVCSM3Tc0Em/c+PkqxKgeeUBq2gzcSwEs40EKSDRMhNP8Ypno6UWf50TmA4HmqBIOhGaVRyuwZ9haBQNsqBqTcsu8GSH5V0GziTMlx8JY4aRqdQP3zrn4r8ftheqK3ERI3GnKV8a4U1ZVTRhI6xR1T+F/6NxY31SqKLV/gbm9djvq12W+cd4T6277ZCelcWfWG3baSgcDmg7IIDKbvJsY6Zz7KP8G34ruj6owy3sgUoWbYVkDCKUDgkaI2GFdyvp6sNhMTivF/jAzcob5wxo/vMJQEHzgkoSw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Jun 11, 2024 at 06:40:49PM +0200, Uladzislau Rezki wrote: > > > > > > These look ok to me. In the last two cases, the callback function is also > > > stored in a data structure, eg: > > > > > > static struct mfc6_cache *ip6mr_cache_alloc(void) > > > { > > > struct mfc6_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_KERNEL); > > > if (!c) > > > return NULL; > > > c->_c.mfc_un.res.last_assert = jiffies - MFC_ASSERT_THRESH - 1; > > > c->_c.mfc_un.res.minvif = MAXMIFS; > > > c->_c.free = ip6mr_cache_free_rcu; > > > refcount_set(&c->_c.mfc_un.res.refcount, 1); > > > return c; > > > } > > > > > > Should that be left as it is? > > > > Given that ->_c.free isn't used in the RCU callback, I am guessing that > > this is intended for debugging purposes, so that you can see from a crash > > dump how this will be freed. But I could be completely off-base here. > > > > One approach would be to remove the ->_c.free field and call attention > > to this in the patches' commit logs. > > > > Another would be to instead put the address of the allocation function > > in ->_c.free, and again call attention to this in the commit logs. > > > > Is there a better approach than these three? ;-) > > > IMO, "_c.free" should be removed: Why not send the patch and see what the maintainers say? If they object, you can always fall back to one of the other two methods, depending on the nature of their objection. Thanx, Paul > diff --git a/include/linux/mroute_base.h b/include/linux/mroute_base.h > index 9dd4bf157255..45f220f761df 100644 > --- a/include/linux/mroute_base.h > +++ b/include/linux/mroute_base.h > @@ -130,7 +130,6 @@ enum { > * @refcount: reference count for this entry > * @list: global entry list > * @rcu: used for entry destruction > - * @free: Operation used for freeing an entry under RCU > */ > struct mr_mfc { > struct rhlist_head mnode; > @@ -156,13 +155,12 @@ struct mr_mfc { > } mfc_un; > struct list_head list; > struct rcu_head rcu; > - void (*free)(struct rcu_head *head); > }; > > static inline void mr_cache_put(struct mr_mfc *c) > { > if (refcount_dec_and_test(&c->mfc_un.res.refcount)) > - call_rcu(&c->rcu, c->free); > + kfree_rcu(c, rcu); > } > > static inline void mr_cache_hold(struct mr_mfc *c) > diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c > index 6c750bd13dd8..5d2e339f09cc 100644 > --- a/net/ipv4/ipmr.c > +++ b/net/ipv4/ipmr.c > @@ -702,16 +702,9 @@ static int vif_delete(struct mr_table *mrt, int vifi, int notify, > return 0; > } > > -static void ipmr_cache_free_rcu(struct rcu_head *head) > -{ > - struct mr_mfc *c = container_of(head, struct mr_mfc, rcu); > - > - kmem_cache_free(mrt_cachep, (struct mfc_cache *)c); > -} > - > static void ipmr_cache_free(struct mfc_cache *c) > { > - call_rcu(&c->_c.rcu, ipmr_cache_free_rcu); > + kfree_rcu(c, _c.rcu); > } > > /* Destroy an unresolved cache entry, killing queued skbs > @@ -959,7 +952,6 @@ static struct mfc_cache *ipmr_cache_alloc(void) > if (c) { > c->_c.mfc_un.res.last_assert = jiffies - MFC_ASSERT_THRESH - 1; > c->_c.mfc_un.res.minvif = MAXVIFS; > - c->_c.free = ipmr_cache_free_rcu; > refcount_set(&c->_c.mfc_un.res.refcount, 1); > } > return c; > diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c > index dd342e6ecf3f..1634fa794ea2 100644 > --- a/net/ipv6/ip6mr.c > +++ b/net/ipv6/ip6mr.c > @@ -753,16 +753,9 @@ static int mif6_delete(struct mr_table *mrt, int vifi, int notify, > return 0; > } > > -static inline void ip6mr_cache_free_rcu(struct rcu_head *head) > -{ > - struct mr_mfc *c = container_of(head, struct mr_mfc, rcu); > - > - kmem_cache_free(mrt_cachep, (struct mfc6_cache *)c); > -} > - > static inline void ip6mr_cache_free(struct mfc6_cache *c) > { > - call_rcu(&c->_c.rcu, ip6mr_cache_free_rcu); > + kfree_rcu(c, _c.rcu); > } > > /* Destroy an unresolved cache entry, killing queued skbs > @@ -985,7 +978,6 @@ static struct mfc6_cache *ip6mr_cache_alloc(void) > return NULL; > c->_c.mfc_un.res.last_assert = jiffies - MFC_ASSERT_THRESH - 1; > c->_c.mfc_un.res.minvif = MAXMIFS; > - c->_c.free = ip6mr_cache_free_rcu; > refcount_set(&c->_c.mfc_un.res.refcount, 1); > return c; > } > > -- > Uladzislau Rezki