Subject: Re: [PATCH] net/netfilter: use kvfree_rcu to simplify the code

From: Pablo Neira Ayuso <[email-masked]>
Date: Wed, 12 Mar 2025 16:37:29 +0100

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

This structure is accessed from the packet path.

>  	/* 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

I think it is convenient to keep struct rcu_head at the end of it.