Skip to contentSkip to conversation

netfilter: flowtable: consolidate unsupported hardware offload check

PATCH New Pablo Neira Ayuso 1 participant 2 messages Oct 15

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/2 netfilter: flowtable: consolidate unsupported hardware offload check

Move this check to the function that allocates and enqueues the hardware offload work.

Fixes 6c5dcab95f4c ("netfilter: flowtable: IPIP tunnel hardware offload is not yet support")

---
new in this series, this is required by patch 2/2

 net/netfilter/nf_flow_table_offload.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
net/netfilter/nf_flow_table_offload.c +12 -9
index 4365859220e6..44e4c6a64431 100644
@@ -1079,12 +1079,24 @@ static void flow_offload_queue_work(struct flow_offload_work *offload)
 	}
 }
 
+static bool nf_flow_offload_unsupported(struct flow_offload *flow)
+{
+	if (flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.tun_num ||
+	    flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].tuple.tun_num)
+		return true;
+
+	return false;
+}
+
 static struct flow_offload_work *
 nf_flow_offload_work_alloc(struct nf_flowtable *flowtable,
 			   struct flow_offload *flow, unsigned int cmd)
 {
 	struct flow_offload_work *offload;
 
+	if (nf_flow_offload_unsupported(flow))
+		return NULL;
+
 	if (test_and_set_bit(NF_FLOW_PENDING, &flow->flags))
 		return NULL;
 
@@ -1102,15 +1114,6 @@ nf_flow_offload_work_alloc(struct nf_flowtable *flowtable,
 	return offload;
 }
 
-static bool nf_flow_offload_unsupported(struct flow_offload *flow)
-{
-	if (flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.tun_num ||
-	    flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].tuple.tun_num)
-		return true;
-
-	return false;
-}
-
 void nf_flow_offload_refresh(struct nf_flowtable *flowtable,
 			     struct flow_offload *flow)
 {
Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH 2/2 netfilter: flowtable: move hardware offload refresh to GC worker

Sashiko reports that refreshing hw offload from packet path is racy since the flow might be already going away. Refresh the flow instead via GC worker to address this, ie. if hardware offload fails, next GC run will give this flow a chance to offload it to hardware.

Since commit 7c549fb7eecd ("netfilter: flowtable: generalize pending status bit"), GC skips flow entries that are still pending to be offloaded, then it is possible to set NF_FLOW_HW flag once the flow entry has been offloaded. If this fails, GC will give it another offload try later.

Fixes 8b3646d6e0c4 ("net/sched: act_ct: Support refreshing the flow table entries")

---
v2: re-target to nf-next, restore postponing NF_FLOW_HW bit

 net/netfilter/nf_flow_table_core.c    | 11 ++---------
 net/netfilter/nf_flow_table_offload.c |  6 +-----
 2 files changed, 3 insertions(+), 14 deletions(-)
net/netfilter/nf_flow_table_core.c +2 -9
index 2f5df3bf3943..6ed542d1f57d 100644
@@ -374,15 +374,6 @@ void flow_offload_refresh(struct nf_flowtable *flow_table,
 	timeout = nf_flowtable_time_stamp + flow_offload_get_timeout(flow);
 	if (force || timeout - READ_ONCE(flow->timeout) > HZ)
 		WRITE_ONCE(flow->timeout, timeout);
-	else
-		return;
-
-	if (likely(!nf_flowtable_hw_offload(flow_table)) ||
-	    test_bit(NF_FLOW_CLOSING, &flow->flags))
-		return;
-
-	if (test_bit(NF_FLOW_HW, &flow->flags))
-		nf_flow_offload_refresh(flow_table, flow);
 }
 EXPORT_SYMBOL_GPL(flow_offload_refresh);
 
@@ -656,6 +647,8 @@ static void nf_flow_offload_gc_step(struct nf_flowtable *flow_table,
 		nf_flow_offload_del(flow_table, flow);
 	} else if (test_bit(NF_FLOW_HW, &flow->flags)) {
 		nf_flow_offload_stats(flow_table, flow);
+	} else if (nf_flowtable_hw_offload(flow_table)) {
+		nf_flow_offload_refresh(flow_table, flow);
 	}
 }
 
net/netfilter/nf_flow_table_offload.c +1 -5
index 44e4c6a64431..5955b520d0a2 100644
@@ -984,7 +984,7 @@ static void flow_offload_work_add(struct flow_offload_work *offload)
 		goto out;
 
 	set_bit(IPS_HW_OFFLOAD_BIT, &offload->flow->ct->status);
-
+	set_bit(NF_FLOW_HW, &offload->flow->flags);
 out:
 	nf_flow_offload_destroy(flow_rule);
 }
@@ -1129,10 +1129,6 @@ void nf_flow_offload_refresh(struct nf_flowtable *flowtable,
 void nf_flow_offload_add(struct nf_flowtable *flowtable,
 			 struct flow_offload *flow)
 {
-	if (nf_flow_offload_unsupported(flow))
-		return;
-
-	set_bit(NF_FLOW_HW, &flow->flags);
 	nf_flow_offload_refresh(flowtable, flow);
 }
 
Signature · 1 line
2.47.3