Skip to contentSkip to conversation

netfilter: conntrack: Fix CT offload timeout on heavily loaded systems

PATCH Superseded Roi Dayan 2 participants 7 messages Jul 28, 2020 – Aug 3, 2020

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Roi Dayan

author
#0 lore raw

cover netfilter: conntrack: Fix CT offload timeout on heavily loaded systems

On heavily loaded systems the GC can take time to go over all existing conns and reset their timeout. At that time other calls like from nf_conntrack_in() can call of nf_ct_is_expired() and see the conn as expired. To fix this when we set the offload bit we should also reset the timeout instead of counting on GC to finish first iteration over all conns before the initial timeout.

First commit is to expose the function that updates the timeout. Second commit is to use it from act_ct.

Roi Dayan (2):
netfilter: conntrack: Move nf_ct_offload_timeout to header file net/sched: act_ct: Set offload timeout when setting the offload bit

 include/net/netfilter/nf_conntrack.h | 12 ++++++++++++
 net/netfilter/nf_conntrack_core.c    | 12 ------------
 net/sched/act_ct.c                   |  2 ++
 3 files changed, 14 insertions(+), 12 deletions(-)
Signature · 1 line
2.8.4
author
#2 lore raw

PATCH 2/2 net/sched: act_ct: Set offload timeout when setting the offload bit

On heavily loaded systems the GC can take time to go over all existing conns and reset their timeout. At that time other calls like from nf_conntrack_in() can call of nf_ct_is_expired() and see the conn as expired. To fix this when we set the offload bit we should also reset the timeout instead of counting on GC to finish first iteration over all conns before the initial timeout.

Fixes 64ff70b80fd4 ("net/sched: act_ct: Offload established connections to flow table")
---
 net/sched/act_ct.c | 2 ++
 1 file changed, 2 insertions(+)
net/sched/act_ct.c +2 -0
index e9f3576cbf71..650c2d78a346 100644
@@ -366,6 +366,8 @@ static void tcf_ct_flow_table_add(struct tcf_ct_flow_table *ct_ft,
 	if (err)
 		goto err_add;
 
+	nf_ct_offload_timeout(ct);
+
 	return;
 
 err_add:
Signature · 1 line
2.8.4
author
#1 lore raw

PATCH 1/2 netfilter: conntrack: Move nf_ct_offload_timeout to header file

In reply to Roi Dayan

To be used by callers from other modules.

---
 include/net/netfilter/nf_conntrack.h | 12 ++++++++++++
 net/netfilter/nf_conntrack_core.c    | 12 ------------
 2 files changed, 12 insertions(+), 12 deletions(-)
include/net/netfilter/nf_conntrack.h +12 -0
index 90690e37a56f..8481819ff632 100644
@@ -279,6 +279,18 @@ static inline bool nf_ct_should_gc(const struct nf_conn *ct)
 	       !nf_ct_is_dying(ct);
 }
 
+#define	DAY	(86400 * HZ)
+
+/* Set an arbitrary timeout large enough not to ever expire, this save
+ * us a check for the IPS_OFFLOAD_BIT from the packet path via
+ * nf_ct_is_expired().
+ */
+static inline void nf_ct_offload_timeout(struct nf_conn *ct)
+{
+	if (nf_ct_expires(ct) < DAY / 2)
+		ct->timeout = nfct_time_stamp + DAY;
+}
+
 struct kernel_param;
 
 int nf_conntrack_set_hashsize(const char *val, const struct kernel_param *kp);
net/netfilter/nf_conntrack_core.c +0 -12
index 79cd9dde457b..947c6d9437c3 100644
@@ -1344,18 +1344,6 @@ static bool gc_worker_can_early_drop(const struct nf_conn *ct)
 	return false;
 }
 
-#define	DAY	(86400 * HZ)
-
-/* Set an arbitrary timeout large enough not to ever expire, this save
- * us a check for the IPS_OFFLOAD_BIT from the packet path via
- * nf_ct_is_expired().
- */
-static void nf_ct_offload_timeout(struct nf_conn *ct)
-{
-	if (nf_ct_expires(ct) < DAY / 2)
-		ct->timeout = nfct_time_stamp + DAY;
-}
-
 static void gc_worker(struct work_struct *work)
 {
 	unsigned int min_interval = max(HZ / GC_MAX_BUCKETS_DIV, 1u);
Signature · 1 line
2.8.4
#3 lore raw

Re: [PATCH net 2/2] net/sched: act_ct: Set offload timeout when setting the offload bit

In reply to Roi Dayan

net/sched/act_ct.c static void tcf_ct_flow_table_add(struct tcf_ct_flow_table *ct_ft,

Quoted 19 lines · Roi Dayan

On heavily loaded systems the GC can take time to go over all existing conns and reset their timeout. At that time other calls like from nf_conntrack_in() can call of nf_ct_is_expired() and see the conn as expired. To fix this when we set the offload bit we should also reset the timeout instead of counting on GC to finish first iteration over all conns before the initial timeout.

Fixes 64ff70b80fd4 ("net/sched: act_ct: Offload established connections to flow table")
---
 net/sched/act_ct.c | 2 ++
 1 file changed, 2 insertions(+)
net/sched/act_ct.c +0 -0
index e9f3576cbf71..650c2d78a346 100644
@@ -366,6 +366,8 @@ static void tcf_ct_flow_table_add(struct tcf_ct_flow_table *ct_ft,

Extra context line:

	err = flow_offload_add(&ct_ft->nf_ft, entry);

net/sched/act_ct.c static void tcf_ct_flow_table_add(struct tcf_ct_flow_table *ct_ft, · line 370

Quoted 5 lines
net/sched/act_ct.c +2 -0
 	if (err)
 		goto err_add;
 
+	nf_ct_offload_timeout(ct);
+

What about adding this to flow_offload_add() instead? It is already adjusting the flow_offload timeout there and then it also effective for nft.

Quoted 6 lines
net/sched/act_ct.c +0 -0
 	return;
 
 err_add:
Signature · 1 line
2.8.4
author
#4 lore raw

Re: [PATCH net 2/2] net/sched: act_ct: Set offload timeout when setting the offload bit

Quoted 26 lines · Marcelo Ricardo Leitner

net/sched/act_ct.c static void tcf_ct_flow_table_add(struct tcf_ct_flow_table *ct_ft,

Quoted 19 lines · Roi Dayan

On heavily loaded systems the GC can take time to go over all existing conns and reset their timeout. At that time other calls like from nf_conntrack_in() can call of nf_ct_is_expired() and see the conn as expired. To fix this when we set the offload bit we should also reset the timeout instead of counting on GC to finish first iteration over all conns before the initial timeout.

Fixes 64ff70b80fd4 ("net/sched: act_ct: Offload established connections to flow table")
---
 net/sched/act_ct.c | 2 ++
 1 file changed, 2 insertions(+)
net/sched/act_ct.c +0 -0
index e9f3576cbf71..650c2d78a346 100644
@@ -366,6 +366,8 @@ static void tcf_ct_flow_table_add(struct tcf_ct_flow_table *ct_ft,

Extra context line:

	err = flow_offload_add(&ct_ft->nf_ft, entry);
Quoted 3 lines
net/sched/act_ct.c +0 -0
 	if (err)
 		goto err_add;
 
Quoted 7 lines

net/sched/act_ct.c static void tcf_ct_flow_table_add(struct tcf_ct_flow_table *ct_ft, · line 370

Quoted 2 lines
net/sched/act_ct.c +2 -0
+	nf_ct_offload_timeout(ct);
+

What about adding this to flow_offload_add() instead? It is already adjusting the flow_offload timeout there and then it also effective for nft.

As you said, in flow_offload_add() we adjust the flow timeout. Here we adjust the conn timeout.
So it's outside flow_offload_add() which only touch the flow struct. I guess it's like conn offload bit is set outside here and for nft. What do you think?

Quoted 6 lines
Quoted 6 lines
net/sched/act_ct.c +0 -0
 	return;
 
 err_add:
Signature · 1 line
2.8.4
#5 lore raw

Re: [PATCH net 2/2] net/sched: act_ct: Set offload timeout when setting the offload bit

Quoted 37 lines · Roi Dayan
Quoted 26 lines · Marcelo Ricardo Leitner

net/sched/act_ct.c static void tcf_ct_flow_table_add(struct tcf_ct_flow_table *ct_ft,

Quoted 19 lines · Roi Dayan

On heavily loaded systems the GC can take time to go over all existing conns and reset their timeout. At that time other calls like from nf_conntrack_in() can call of nf_ct_is_expired() and see the conn as expired. To fix this when we set the offload bit we should also reset the timeout instead of counting on GC to finish first iteration over all conns before the initial timeout.

Fixes 64ff70b80fd4 ("net/sched: act_ct: Offload established connections to flow table")
---
 net/sched/act_ct.c | 2 ++
 1 file changed, 2 insertions(+)
net/sched/act_ct.c +0 -0
index e9f3576cbf71..650c2d78a346 100644
@@ -366,6 +366,8 @@ static void tcf_ct_flow_table_add(struct tcf_ct_flow_table *ct_ft,

Extra context line:

	err = flow_offload_add(&ct_ft->nf_ft, entry);
Quoted 3 lines
net/sched/act_ct.c +0 -0
 	if (err)
 		goto err_add;
 
Quoted 7 lines

net/sched/act_ct.c static void tcf_ct_flow_table_add(struct tcf_ct_flow_table *ct_ft, · line 370

Quoted 2 lines
net/sched/act_ct.c +2 -0
+	nf_ct_offload_timeout(ct);
+

What about adding this to flow_offload_add() instead? It is already adjusting the flow_offload timeout there and then it also effective for nft.

Quoted 4 lines

As you said, in flow_offload_add() we adjust the flow timeout. Here we adjust the conn timeout.
So it's outside flow_offload_add() which only touch the flow struct. I guess it's like conn offload bit is set outside here and for nft.

Right, but

Quoted 1 line

What do you think?

I don't see why it can't update both. flow_offload_fixup_ct_timeout(), called by flow_offload_del(), is updating ct->timeout already. It looks consistent to me to update it in _add as well then.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
net/sched/act_ct.c +0 -0
 	return;
 
 err_add:
Signature · 1 line
2.8.4
author
#6 lore raw

Re: [PATCH net 2/2] net/sched: act_ct: Set offload timeout when setting the offload bit

Quoted 43 lines · Marcelo Ricardo Leitner
Quoted 37 lines · Roi Dayan
Quoted 26 lines · Marcelo Ricardo Leitner

net/sched/act_ct.c static void tcf_ct_flow_table_add(struct tcf_ct_flow_table *ct_ft,

Quoted 19 lines · Roi Dayan

On heavily loaded systems the GC can take time to go over all existing conns and reset their timeout. At that time other calls like from nf_conntrack_in() can call of nf_ct_is_expired() and see the conn as expired. To fix this when we set the offload bit we should also reset the timeout instead of counting on GC to finish first iteration over all conns before the initial timeout.

Fixes 64ff70b80fd4 ("net/sched: act_ct: Offload established connections to flow table")
---
 net/sched/act_ct.c | 2 ++
 1 file changed, 2 insertions(+)
net/sched/act_ct.c +0 -0
index e9f3576cbf71..650c2d78a346 100644
@@ -366,6 +366,8 @@ static void tcf_ct_flow_table_add(struct tcf_ct_flow_table *ct_ft,

Extra context line:

	err = flow_offload_add(&ct_ft->nf_ft, entry);
Quoted 3 lines
net/sched/act_ct.c +0 -0
 	if (err)
 		goto err_add;
 
Quoted 7 lines

net/sched/act_ct.c static void tcf_ct_flow_table_add(struct tcf_ct_flow_table *ct_ft, · line 370

Quoted 2 lines
net/sched/act_ct.c +2 -0
+	nf_ct_offload_timeout(ct);
+

What about adding this to flow_offload_add() instead? It is already adjusting the flow_offload timeout there and then it also effective for nft.

Quoted 4 lines

As you said, in flow_offload_add() we adjust the flow timeout. Here we adjust the conn timeout.
So it's outside flow_offload_add() which only touch the flow struct. I guess it's like conn offload bit is set outside here and for nft.

Quoted 8 lines

Right, but

Quoted 1 line

What do you think?

I don't see why it can't update both. flow_offload_fixup_ct_timeout(), called by flow_offload_del(), is updating ct->timeout already. It looks consistent to me to update it in _add as well then.

I don't mind. just add is not consistent with del. del also clears the ips_offload_bit but add doesn't add it. i'll send v2 with your suggestion.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
net/sched/act_ct.c +0 -0
 	return;
 
 err_add:
Signature · 1 line
2.8.4