Skip to contentSkip to conversation

netfilter: nf_tables: defer all object release via rcu

RFC PATCH In review Pablo Neira Ayuso 2 participants 3 messages Apr 10, 2014

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

RFC PATCH 1/1 netfilter: nf_tables: defer all object release via rcu

Now that all objects are released in the reverse order via the transaction infrastructure, we can enqueue the release via call_rcu to save one synchronize_rcu. For small rule-sets loaded via nft -f, it now takes between 50ms and 100ms less here.

---

This is a follow up patch that applies on top of the new transaction infrastructure.

It has downside effect which is that I had to remove anonymous set event notification since we lack of the skb/nlh/nla context from there.

I think we can adapt the nf_tables_set_notify to skip report and portid when we don't have any context, so we still send events for the anonymous sets. I believe the remaining pointers in the context area should be valid for several reasons:

1) The objects are released in reverse order according to the commands.

2) We hold a reference to the afi family module, so the module has to be there until we delete the table, which should be the last object in the queue to be released.

3) The table and chain pointers should correspond to objects that still exists (they cannot be deleted as use counter is > 1) or that are in the rcu queue to be released after us.

That patch would be slightly larger though and set_notify needs to be adjusted.

 include/net/netfilter/nf_tables.h |    2 +
 net/netfilter/nf_tables_api.c     |  100 ++++++++++++++++++++++---------------
 2 files changed, 62 insertions(+), 40 deletions(-)
include/net/netfilter/nf_tables.h +2 -0
index b08f2a9..65656f7 100644
@@ -391,12 +391,14 @@ struct nft_rule {
 /**
  *	struct nft_trans - nf_tables object update in transaction
  *
+ *	rcu_head: rcu head to defer release of transaction data
  *	@list: used internally
  *	@msg_type: message type
  *	@ctx: transaction context
  *	@data: internal information related to the transaction
  */
 struct nft_trans {
+	struct rcu_head			rcu_head;
 	struct list_head		list;
 	int				msg_type;
 	struct nft_ctx			ctx;
net/netfilter/nf_tables_api.c +60 -40

131 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#1 lore raw

Hi Pablo,

2 minor issues.

include/net/netfilter/nf_tables.h struct nft_rule { · line 394

Quoted 13 lines
  include/net/netfilter/nf_tables.h |    2 +
  net/netfilter/nf_tables_api.c     |  100 ++++++++++++++++++++++---------------
  2 files changed, 62 insertions(+), 40 deletions(-)
include/net/netfilter/nf_tables.h +1 -0
index b08f2a9..65656f7 100644
@@ -391,12 +391,14 @@ struct nft_rule {
  /**
   *	struct nft_trans - nf_tables object update in transaction
   *
+ *	rcu_head: rcu head to defer release of transaction data

an '@' is missing

Quoted 15 lines
include/net/netfilter/nf_tables.h +1 -0
   *	@list: used internally
   *	@msg_type: message type
   *	@ctx: transaction context
   *	@data: internal information related to the transaction
   */
  struct nft_trans {
+	struct rcu_head			rcu_head;
  	struct list_head		list;
  	int				msg_type;
  	struct nft_ctx			ctx;
net/netfilter/nf_tables_api.c +0 -0
index 5606ae30..fd03212 100644

net/netfilter/nf_tables_api.c static void nft_set_destroy(struct nft_set *set) · line 2616

Quoted 6 lines
net/netfilter/nf_tables_api.c +2 -1
@@ -2612,7 +2612,8 @@ static void nft_set_destroy(struct nft_set *set)
  static void nf_tables_set_destroy(const struct nft_ctx *ctx, struct nft_set *set)
  {
  	list_del(&set->list);
-	nf_tables_set_notify(ctx, set, NFT_MSG_DELSET);
+	if (!set->flags & NFT_SET_ANONYMOUS)
+		nf_tables_set_notify(ctx, set, NFT_MSG_DELSET);

It's a fix for anonymous set, so it's should be on another patch.

Tomasz

author maintainer
#2 lore raw
Quoted 8 lines · Tomasz Bursztyka

Hi Pablo,

2 minor issues.

Quoted 4 lines
 include/net/netfilter/nf_tables.h |    2 +
 net/netfilter/nf_tables_api.c     |  100 ++++++++++++++++++++++---------------
 2 files changed, 62 insertions(+), 40 deletions(-)
Quoted 11 lines

include/net/netfilter/nf_tables.h struct nft_rule { · line 394

Quoted 9 lines
include/net/netfilter/nf_tables.h +1 -0
index b08f2a9..65656f7 100644
@@ -391,12 +391,14 @@ struct nft_rule {
 /**
  *	struct nft_trans - nf_tables object update in transaction
  *
+ *	rcu_head: rcu head to defer release of transaction data

an '@' is missing

Right.

Quoted 15 lines
Quoted 15 lines
include/net/netfilter/nf_tables.h +1 -0
  *	@list: used internally
  *	@msg_type: message type
  *	@ctx: transaction context
  *	@data: internal information related to the transaction
  */
 struct nft_trans {
+	struct rcu_head			rcu_head;
 	struct list_head		list;
 	int				msg_type;
 	struct nft_ctx			ctx;
net/netfilter/nf_tables_api.c +0 -0
index 5606ae30..fd03212 100644
@@ -2612,7 +2612,8 @@ static void nft_set_destroy(struct nft_set *set)
Quoted 8 lines

net/netfilter/nf_tables_api.c static void nft_set_destroy(struct nft_set *set) · line 2616

Quoted 6 lines
net/netfilter/nf_tables_api.c +2 -1
 static void nf_tables_set_destroy(const struct nft_ctx *ctx, struct nft_set *set)
 {
 	list_del(&set->list);
-	nf_tables_set_notify(ctx, set, NFT_MSG_DELSET);
+	if (!set->flags & NFT_SET_ANONYMOUS)
+		nf_tables_set_notify(ctx, set, NFT_MSG_DELSET);

It's a fix for anonymous set, so it's should be on another patch.

Not a fix, we currently have anonymous set notifications which are possible. Please, have a look at the changelog in this patch, it discusses the reason for this and alternative solutions.