From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Florian Westphal <fw@strlen.de>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nf-next 01/11] netfilter: nf_tables: make struct nft_trans first member of derived subtypes
Date: Tue, 18 Jun 2024 10:28:12 +0200 [thread overview]
Message-ID: <ZnFFHIcI1HRIDzbh@calendula> (raw)
In-Reply-To: <20240513130057.11014-2-fw@strlen.de>
On Mon, May 13, 2024 at 03:00:41PM +0200, Florian Westphal wrote:
> There is 'struct nft_trans', the basic structure for all transactional
> objects, and the the various different transactional objects, such as
> nft_trans_table, chain, set, set_elem and so on.
>
> Right now 'struct nft_trans' uses a flexible member at the tail
> (data[]), and casting is needed to access the actual type-specific
> members.
>
> Change this to make the hierarchy visible in source code, i.e. make
> struct nft_trans the first member of all derived subtypes.
>
> This has several advantages:
> 1. pahole output reflects the real size needed by the particular subtype
> 2. allows to use container_of() to convert the base type to the actual
> object type instead of casting ->data to the overlay structure.
> 3. It makes it easy to add intermediate types.
>
> 'struct nft_trans' contains a 'binding_list' that is only needed
> by two subtypes, so it should be part of the two subtypes, not in
> the base structure.
>
> But that makes it hard to interate over the binding_list, because
> there is no common base structure.
>
> A follow patch moves the bind list to a new struct:
>
> struct nft_trans_binding {
> struct nft_trans nft_trans;
> struct list_head binding_list;
> };
>
> ... and makes that structure the new 'first member' for both
> nft_trans_chain and nft_trans_set.
>
> No functional change intended in this patch.
>
> Some numbers:
> struct nft_trans { /* size: 88, cachelines: 2, members: 5 */
> struct nft_trans_chain { /* size: 152, cachelines: 3, members: 10 */
> struct nft_trans_elem { /* size: 112, cachelines: 2, members: 4 */
> struct nft_trans_flowtable { /* size: 128, cachelines: 2, members: 5 */
> struct nft_trans_obj { /* size: 112, cachelines: 2, members: 4 */
> struct nft_trans_rule { /* size: 112, cachelines: 2, members: 5 */
> struct nft_trans_set { /* size: 120, cachelines: 2, members: 8 */
> struct nft_trans_table { /* size: 96, cachelines: 2, members: 2 */
>
> Of particular interest is nft_trans_elem, which needs to be allocated
> once for each pending (to be added or removed) set element.
>
> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
> include/net/netfilter/nf_tables.h | 88 +++++++++++++++++--------------
> net/netfilter/nf_tables_api.c | 10 ++--
> 2 files changed, 54 insertions(+), 44 deletions(-)
>
> diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h
> index 2796153b03da..af0ef21f3780 100644
> --- a/include/net/netfilter/nf_tables.h
> +++ b/include/net/netfilter/nf_tables.h
> @@ -1608,14 +1608,16 @@ static inline int nft_set_elem_is_dead(const struct nft_set_ext *ext)
> }
>
> /**
> - * struct nft_trans - nf_tables object update in transaction
> + * struct nft_trans - nf_tables object update in transaction
> *
> - * @list: used internally
> - * @binding_list: list of objects with possible bindings
> - * @msg_type: message type
> - * @put_net: ctx->net needs to be put
> - * @ctx: transaction context
> - * @data: internal information related to the transaction
> + * @list: used internally
> + * @binding_list: list of objects with possible bindings
> + * @msg_type: message type
> + * @put_net: ctx->net needs to be put
> + * @ctx: transaction context
> + *
> + * This is the information common to all objects in the transaction,
> + * this must always be the first member of derived sub-types.
> */
> struct nft_trans {
> struct list_head list;
> @@ -1623,10 +1625,10 @@ struct nft_trans {
> int msg_type;
> bool put_net;
> struct nft_ctx ctx;
> - char data[];
> };
>
> struct nft_trans_rule {
> + struct nft_trans nft_trans;
> struct nft_rule *rule;
> struct nft_flow_rule *flow;
> u32 rule_id;
> @@ -1634,15 +1636,16 @@ struct nft_trans_rule {
> };
>
> #define nft_trans_rule(trans) \
> - (((struct nft_trans_rule *)trans->data)->rule)
> + container_of(trans, struct nft_trans_rule, nft_trans)->rule
Another nitpicking comestic issue:
Maybe I can get this series slightly smaller if
nft_trans_rule_container
is added here and use it, instead of the opencoded container_of.
For consistency with:
#define nft_trans_container_set(t)
which is used everywhere in this header in a follow up patch.
I mangle this at the expense of adding my own bugs :)
[...]
> #define nft_trans_set(trans) \
> - (((struct nft_trans_set *)trans->data)->set)
> + container_of(trans, struct nft_trans_set, nft_trans)->set
> #define nft_trans_set_id(trans) \
> - (((struct nft_trans_set *)trans->data)->set_id)
> + container_of(trans, struct nft_trans_set, nft_trans)->set_id
> #define nft_trans_set_bound(trans) \
> - (((struct nft_trans_set *)trans->data)->bound)
> + container_of(trans, struct nft_trans_set, nft_trans)->bound
> #define nft_trans_set_update(trans) \
> - (((struct nft_trans_set *)trans->data)->update)
> + container_of(trans, struct nft_trans_set, nft_trans)->update
> #define nft_trans_set_timeout(trans) \
> - (((struct nft_trans_set *)trans->data)->timeout)
> + container_of(trans, struct nft_trans_set, nft_trans)->timeout
> #define nft_trans_set_gc_int(trans) \
> - (((struct nft_trans_set *)trans->data)->gc_int)
> + container_of(trans, struct nft_trans_set, nft_trans)->gc_int
> #define nft_trans_set_size(trans) \
> - (((struct nft_trans_set *)trans->data)->size)
> + container_of(trans, struct nft_trans_set, nft_trans)->size
next prev parent reply other threads:[~2024-06-18 8:28 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-13 13:00 [PATCH nf-next 00/11] netfilter: nf_tables: reduce transaction log memory usage Florian Westphal
2024-05-13 13:00 ` [PATCH nf-next 01/11] netfilter: nf_tables: make struct nft_trans first member of derived subtypes Florian Westphal
2024-06-18 8:28 ` Pablo Neira Ayuso [this message]
2024-06-18 9:20 ` Florian Westphal
2024-05-13 13:00 ` [PATCH nf-next 02/11] netfilter: nf_tables: move bind list_head into relevant subtypes Florian Westphal
2024-06-18 8:24 ` Pablo Neira Ayuso
2024-06-18 9:21 ` Florian Westphal
2024-06-24 19:16 ` Pablo Neira Ayuso
2024-06-24 21:18 ` Florian Westphal
2024-06-25 18:49 ` Pablo Neira Ayuso
2024-06-26 11:28 ` Pablo Neira Ayuso
2024-05-13 13:00 ` [PATCH nf-next 03/11] netfilter: nf_tables: compact chain+ft transaction objects Florian Westphal
2024-05-13 13:00 ` [PATCH nf-next 04/11] netfilter: nf_tables: reduce trans->ctx.table references Florian Westphal
2024-05-13 13:00 ` [PATCH nf-next 05/11] netfilter: nf_tables: pass nft_chain to destroy function, not nft_ctx Florian Westphal
2024-05-13 13:00 ` [PATCH nf-next 06/11] netfilter: nf_tables: pass more specific nft_trans_chain where possible Florian Westphal
2024-05-13 13:00 ` [PATCH nf-next 07/11] netfilter: nf_tables: avoid usage of embedded nft_ctx Florian Westphal
2024-05-13 13:00 ` [PATCH nf-next 08/11] netfilter: nf_tables: store chain pointer in rule transaction Florian Westphal
2024-05-13 13:00 ` [PATCH nf-next 09/11] netfilter: nf_tables: reduce trans->ctx.chain references Florian Westphal
2024-05-13 13:00 ` [PATCH nf-next 10/11] netfilter: nf_tables: pass nft_table to destroy function Florian Westphal
2024-05-13 13:00 ` [PATCH nf-next 11/11] netfilter: nf_tables: do not store nft_ctx in transaction objects Florian Westphal
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=ZnFFHIcI1HRIDzbh@calendula \
--to=pablo@netfilter.org \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.