linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Uladzislau Rezki <urezki@gmail.com>
To: "Paul E. McKenney" <paulmck@kernel.org>,
	Julia Lawall <julia.lawall@inria.fr>
Cc: Julia Lawall <julia.lawall@inria.fr>,
	Uladzislau Rezki <urezki@gmail.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	RCU <rcu@vger.kernel.org>,
	cocci@inria.fr
Subject: Re: [cocci] patch idea: convert trivial call_rcu users to kfree_rcu
Date: Tue, 11 Jun 2024 18:40:49 +0200	[thread overview]
Message-ID: <Zmh-EYvXqL3JBt1p@pc638.lan> (raw)
In-Reply-To: <21a32cbb-d388-4a8c-9298-ef8c82330f9e@paulmck-laptop>

> > 
> > 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:

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


  reply	other threads:[~2024-06-11 16:40 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-27  7:46 Vlastimil Babka
2024-05-27  8:13 ` [cocci] " Julia Lawall
2024-05-27 19:27   ` Paul E. McKenney
2024-05-27 19:46     ` Uladzislau Rezki
2024-05-27 19:51       ` Julia Lawall
2024-05-27 20:36         ` Uladzislau Rezki
2024-05-27 20:43     ` Julia Lawall
2024-05-27 21:48       ` Paul E. McKenney
2024-05-28  5:09         ` Julia Lawall
2024-05-28 12:03       ` Uladzislau Rezki
2024-05-28 12:08         ` Julia Lawall
2024-05-28 13:21           ` Uladzislau Rezki
2024-05-28 14:29             ` Paul E. McKenney
2024-05-31 16:02               ` Julia Lawall
2024-06-03 17:25                 ` Paul E. McKenney
2024-06-03 19:29                 ` Vlastimil Babka
2024-06-03 19:51                   ` Julia Lawall
2024-06-04 11:26                 ` Uladzislau Rezki
2024-06-09  8:32                   ` Julia Lawall
2024-06-09 10:00                   ` Julia Lawall
2024-06-09 17:03                     ` Paul E. McKenney
2024-06-11 16:40                       ` Uladzislau Rezki [this message]
2024-06-11 17:25                         ` Paul E. McKenney
2024-06-11 17:27                           ` Uladzislau Rezki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Zmh-EYvXqL3JBt1p@pc638.lan \
    --to=urezki@gmail.com \
    --cc=cocci@inria.fr \
    --cc=julia.lawall@inria.fr \
    --cc=linux-mm@kvack.org \
    --cc=paulmck@kernel.org \
    --cc=rcu@vger.kernel.org \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox