diff mbox series

net/netfilter: use kvfree_rcu to simplify the code

Message ID 20250122074450.3185-1-lirongqing@baidu.com (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series net/netfilter: use kvfree_rcu to simplify the code | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success Errors and warnings before: 0 (+1) this patch: 0 (+1)
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 556 this patch: 556
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 200 this patch: 200
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 67 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 9 this patch: 9
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-01-22--09-00 (tests: 885)

Commit Message

lirongqing Jan. 22, 2025, 7:44 a.m. UTC
From: Li RongQing <lirongqing@baidu.com>

The callback function of call_rcu() just calls kvfree(), so we can
use kvfree_rcu() instead of call_rcu() + callback function.

and move struct rcu_head into struct nf_hook_entries, then struct
nf_hook_entries_rcu_head can be removed

Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 include/linux/netfilter.h | 13 +------------
 net/netfilter/core.c      | 21 ++-------------------
 2 files changed, 3 insertions(+), 31 deletions(-)

Comments

Simon Horman Jan. 22, 2025, 9:59 a.m. UTC | #1
On Wed, Jan 22, 2025 at 03:44:50PM +0800, lirongqing wrote:
> From: Li RongQing <lirongqing@baidu.com>
> 
> The callback function of call_rcu() just calls kvfree(), so we can
> use kvfree_rcu() instead of call_rcu() + callback function.
> 
> and move struct rcu_head into struct nf_hook_entries, then struct
> nf_hook_entries_rcu_head can be removed
> 
> Signed-off-by: Li RongQing <lirongqing@baidu.com>

Reviewed-by: Simon Horman <horms@kernel.org>

...
diff mbox series

Patch

diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
index 2b8aac2..c751b0a 100644
--- a/include/linux/netfilter.h
+++ b/include/linux/netfilter.h
@@ -111,28 +111,17 @@  struct nf_hook_entry {
 	void				*priv;
 };
 
-struct nf_hook_entries_rcu_head {
-	struct rcu_head head;
-	void	*allocation;
-};
-
 struct nf_hook_entries {
 	u16				num_hook_entries;
+	struct rcu_head rcu;
 	/* padding */
 	struct nf_hook_entry		hooks[];
 
 	/* trailer: pointers to original orig_ops of each hook,
-	 * followed by rcu_head and scratch space used for freeing
-	 * the structure via call_rcu.
 	 *
 	 *   This is not part of struct nf_hook_entry since its only
 	 *   needed in slow path (hook register/unregister):
 	 * const struct nf_hook_ops     *orig_ops[]
-	 *
-	 *   For the same reason, we store this at end -- its
-	 *   only needed when a hook is deleted, not during
-	 *   packet path processing:
-	 * struct nf_hook_entries_rcu_head     head
 	 */
 };
 
diff --git a/net/netfilter/core.c b/net/netfilter/core.c
index b9f551f0..8889f09 100644
--- a/net/netfilter/core.c
+++ b/net/netfilter/core.c
@@ -52,8 +52,7 @@  static struct nf_hook_entries *allocate_hook_entries_size(u16 num)
 	struct nf_hook_entries *e;
 	size_t alloc = sizeof(*e) +
 		       sizeof(struct nf_hook_entry) * num +
-		       sizeof(struct nf_hook_ops *) * num +
-		       sizeof(struct nf_hook_entries_rcu_head);
+		       sizeof(struct nf_hook_ops *) * num;
 
 	if (num == 0)
 		return NULL;
@@ -64,28 +63,12 @@  static struct nf_hook_entries *allocate_hook_entries_size(u16 num)
 	return e;
 }
 
-static void __nf_hook_entries_free(struct rcu_head *h)
-{
-	struct nf_hook_entries_rcu_head *head;
-
-	head = container_of(h, struct nf_hook_entries_rcu_head, head);
-	kvfree(head->allocation);
-}
-
 static void nf_hook_entries_free(struct nf_hook_entries *e)
 {
-	struct nf_hook_entries_rcu_head *head;
-	struct nf_hook_ops **ops;
-	unsigned int num;
-
 	if (!e)
 		return;
 
-	num = e->num_hook_entries;
-	ops = nf_hook_entries_get_hook_ops(e);
-	head = (void *)&ops[num];
-	head->allocation = e;
-	call_rcu(&head->head, __nf_hook_entries_free);
+	kvfree_rcu(e, rcu);
 }
 
 static unsigned int accept_all(void *priv,