Skip to contentSkip to conversation

flow_table: do not try to add already offloaded entries

PATCH In review Marcelo Ricardo Leitner 2 participants 7 messages Jun 27, 2022 – Jun 28, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 flow_table: do not try to add already offloaded entries

Currently, whenever act_ct tries to match a packet against the flow table, it will also try to refresh the offload. That is, at the end of tcf_ct_flow_table_lookup() it will call flow_offload_refresh().

The problem is that flow_offload_refresh() will try to offload entries that are actually already offloaded, leading to expensive and useless work. Before this patch, with a simple iperf3 test on OVS + TC (hw_offload=true) + CT test entirely in sw, it looks like:

- 39,81% tcf_classify
- fl_classify
- 37,09% tcf_action_exec
+ 33,18% tcf_mirred_act
- 2,69% tcf_ct_act
- 2,39% tcf_ct_flow_table_lookup
- 1,67% queue_work_on
- 1,52% __queue_work
1,20% try_to_wake_up
+ 0,80% tcf_pedit_act
+ 2,28% fl_mask_lookup

The patch here aborts the add operation if the entry is already present in hw. With this patch, then:

- 43,94% tcf_classify
- fl_classify
- 39,64% tcf_action_exec
+ 38,00% tcf_mirred_act
- 1,04% tcf_ct_act
0,63% tcf_ct_flow_table_lookup
+ 3,19% fl_mask_lookup

---
 net/netfilter/nf_flow_table_offload.c | 3 +++
 1 file changed, 3 insertions(+)
net/netfilter/nf_flow_table_offload.c +3 -0
index 11b6e19420920bc8efda9877af0dab5311c8a096..9a8fc61581400b4e13aa356972d366892bb71b9b 100644
@@ -1026,6 +1026,9 @@ void nf_flow_offload_add(struct nf_flowtable *flowtable,
 {
 	struct flow_offload_work *offload;
 
+	if (test_bit(NF_FLOW_HW, &flow->flags))
+		return;
+
 	offload = nf_flow_offload_work_alloc(flowtable, flow, FLOW_CLS_REPLACE);
 	if (!offload)
 		return;
Signature · 1 line
2.35.3
#1 lore raw

Hi Marcelo,

Quoted 7 lines · Marcelo Ricardo Leitner

Currently, whenever act_ct tries to match a packet against the flow table, it will also try to refresh the offload. That is, at the end of tcf_ct_flow_table_lookup() it will call flow_offload_refresh().

The problem is that flow_offload_refresh() will try to offload entries that are actually already offloaded, leading to expensive and useless work. Before this patch, with a simple iperf3 test on OVS + TC

Packets of offloaded connections are expected to process in hardware.
As such, it is not expected to receive packets in software from offloaded connections.

However, hardware offload may fail due to various reasons (e.g. size limits, insertion rate throttling etc.). The "refresh" mechanism is the enabler for offload retries.

Quoted 35 lines

(hw_offload=true) + CT test entirely in sw, it looks like:

- 39,81% tcf_classify
- fl_classify
- 37,09% tcf_action_exec
+ 33,18% tcf_mirred_act
- 2,69% tcf_ct_act
- 2,39% tcf_ct_flow_table_lookup
- 1,67% queue_work_on
- 1,52% __queue_work
1,20% try_to_wake_up
+ 0,80% tcf_pedit_act
+ 2,28% fl_mask_lookup

The patch here aborts the add operation if the entry is already present in hw. With this patch, then:

- 43,94% tcf_classify
- fl_classify
- 39,64% tcf_action_exec
+ 38,00% tcf_mirred_act
- 1,04% tcf_ct_act
0,63% tcf_ct_flow_table_lookup
+ 3,19% fl_mask_lookup

---
  net/netfilter/nf_flow_table_offload.c | 3 +++
  1 file changed, 3 insertions(+)
net/netfilter/nf_flow_table_offload.c +0 -0
index 11b6e19420920bc8efda9877af0dab5311c8a096..9a8fc61581400b4e13aa356972d366892bb71b9b 100644

net/netfilter/nf_flow_table_offload.c void nf_flow_offload_add(struct nf_flowtable *flowtable, · line 1031

Quoted 6 lines
net/netfilter/nf_flow_table_offload.c +3 -0
@@ -1026,6 +1026,9 @@ void nf_flow_offload_add(struct nf_flowtable *flowtable,
  {
  	struct flow_offload_work *offload;
 
+	if (test_bit(NF_FLOW_HW, &flow->flags))
+		return;
+

This change will make the refresh call obsolete as the NF_FLOW_HW bit is set on the first flow offload attempt.

Quoted 3 lines
net/netfilter/nf_flow_table_offload.c +0 -0
  	offload = nf_flow_offload_work_alloc(flowtable, flow, FLOW_CLS_REPLACE);
  	if (!offload)
  		return;
#2 lore raw

Hi Oz,

Quoted 11 lines · Oz Shlomo

Hi Marcelo,

Quoted 7 lines · Marcelo Ricardo Leitner

Currently, whenever act_ct tries to match a packet against the flow table, it will also try to refresh the offload. That is, at the end of tcf_ct_flow_table_lookup() it will call flow_offload_refresh().

The problem is that flow_offload_refresh() will try to offload entries that are actually already offloaded, leading to expensive and useless work. Before this patch, with a simple iperf3 test on OVS + TC

Quoted 7 lines

Packets of offloaded connections are expected to process in hardware. As such, it is not expected to receive packets in software from offloaded connections.

However, hardware offload may fail due to various reasons (e.g. size limits, insertion rate throttling etc.).
The "refresh" mechanism is the enabler for offload retries.

Thanks for the quick review.

Right. I don't mean to break this mechanism. Act_ct can also be used in semi/pure sw datapath, and then the premise of packets being expected to be handled in hw is not valid anymore. I can provide a more detailed use case if you need.

Quoted 32 lines
Quoted 32 lines

(hw_offload=true) + CT test entirely in sw, it looks like:

- 39,81% tcf_classify
- fl_classify
- 37,09% tcf_action_exec
+ 33,18% tcf_mirred_act
- 2,69% tcf_ct_act
- 2,39% tcf_ct_flow_table_lookup
- 1,67% queue_work_on
- 1,52% __queue_work
1,20% try_to_wake_up
+ 0,80% tcf_pedit_act
+ 2,28% fl_mask_lookup

The patch here aborts the add operation if the entry is already present in hw. With this patch, then:

- 43,94% tcf_classify
- fl_classify
- 39,64% tcf_action_exec
+ 38,00% tcf_mirred_act
- 1,04% tcf_ct_act
0,63% tcf_ct_flow_table_lookup
+ 3,19% fl_mask_lookup

---
  net/netfilter/nf_flow_table_offload.c | 3 +++
  1 file changed, 3 insertions(+)
Quoted 13 lines

net/netfilter/nf_flow_table_offload.c void nf_flow_offload_add(struct nf_flowtable *flowtable, · line 1030

Quoted 10 lines
net/netfilter/nf_flow_table_offload.c +3 -0
index 11b6e19420920bc8efda9877af0dab5311c8a096..9a8fc61581400b4e13aa356972d366892bb71b9b 100644
@@ -1026,6 +1026,9 @@ void nf_flow_offload_add(struct nf_flowtable *flowtable,
  {
  	struct flow_offload_work *offload;
+	if (test_bit(NF_FLOW_HW, &flow->flags))
+		return;
+

This change will make the refresh call obsolete as the NF_FLOW_HW bit is set on the first flow offload attempt.

Oh oh.. I was quite sure it was getting cleared when the entry was removed from HW, but not.

So instead of the if() above, what about:
+ if (test_and_set_bit(IPS_HW_OFFLOAD_BIT, &flow->ct->status))

AFAICT it will keep trying while the entry is not present in the flow table, and stop while it is there. Once the entry is aged from HW, it is also removed from the flow table, so this part should be okay. But if the offload failed for some reason like you said above, and the entry is left on the flow table, it won't retry until it ages out from the flow table.

If you expect that this situation can be easily triggered, we may need to add a rate limit instead then. Even for these connections that failed to offload, this "busy retrying" is expensive and may backfire in such situation.

Quoted 4 lines
Quoted 4 lines
net/netfilter/nf_flow_table_offload.c +0 -0
  	offload = nf_flow_offload_work_alloc(flowtable, flow, FLOW_CLS_REPLACE);
  	if (!offload)
  		return;
#3 lore raw

Hi Marcelo,

Quoted 22 lines · Marcelo Ricardo Leitner

Hi Oz,

Quoted 11 lines · Oz Shlomo

Hi Marcelo,

Quoted 7 lines · Marcelo Ricardo Leitner

Currently, whenever act_ct tries to match a packet against the flow table, it will also try to refresh the offload. That is, at the end of tcf_ct_flow_table_lookup() it will call flow_offload_refresh().

The problem is that flow_offload_refresh() will try to offload entries that are actually already offloaded, leading to expensive and useless work. Before this patch, with a simple iperf3 test on OVS + TC

Quoted 7 lines

Packets of offloaded connections are expected to process in hardware. As such, it is not expected to receive packets in software from offloaded connections.

However, hardware offload may fail due to various reasons (e.g. size limits, insertion rate throttling etc.).
The "refresh" mechanism is the enabler for offload retries.

Quoted 6 lines

Thanks for the quick review.

Right. I don't mean to break this mechanism. Act_ct can also be used in semi/pure sw datapath, and then the premise of packets being expected to be handled in hw is not valid anymore. I can provide a more detailed use case if you need.

It is clear that the refresh design introduces some overhead when act_ct is used in a pure sw datapath.

Quoted 47 lines
Quoted 33 lines
Quoted 33 lines

(hw_offload=true) + CT test entirely in sw, it looks like:

- 39,81% tcf_classify
- fl_classify
- 37,09% tcf_action_exec
+ 33,18% tcf_mirred_act
- 2,69% tcf_ct_act
- 2,39% tcf_ct_flow_table_lookup
- 1,67% queue_work_on
- 1,52% __queue_work
1,20% try_to_wake_up
+ 0,80% tcf_pedit_act
+ 2,28% fl_mask_lookup

The patch here aborts the add operation if the entry is already present in hw. With this patch, then:

- 43,94% tcf_classify
- fl_classify
- 39,64% tcf_action_exec
+ 38,00% tcf_mirred_act
- 1,04% tcf_ct_act
0,63% tcf_ct_flow_table_lookup
+ 3,19% fl_mask_lookup

---
   net/netfilter/nf_flow_table_offload.c | 3 +++
   1 file changed, 3 insertions(+)
Quoted 13 lines

net/netfilter/nf_flow_table_offload.c void nf_flow_offload_add(struct nf_flowtable *flowtable, · line 1030

Quoted 10 lines
net/netfilter/nf_flow_table_offload.c +3 -0
index 11b6e19420920bc8efda9877af0dab5311c8a096..9a8fc61581400b4e13aa356972d366892bb71b9b 100644
@@ -1026,6 +1026,9 @@ void nf_flow_offload_add(struct nf_flowtable *flowtable,
   {
   	struct flow_offload_work *offload;
+	if (test_bit(NF_FLOW_HW, &flow->flags))
+		return;
+

This change will make the refresh call obsolete as the NF_FLOW_HW bit is set on the first flow offload attempt.

Quoted 5 lines

Oh oh.. I was quite sure it was getting cleared when the entry was removed from HW, but not.

So instead of the if() above, what about:
+ if (test_and_set_bit(IPS_HW_OFFLOAD_BIT, &flow->ct->status))

I think this will set the IPS_HW_OFFLOAD_BIT prematurely.
Currently this bit is set only when the the flow has been successfully offloaded.

Quoted 7 lines

AFAICT it will keep trying while the entry is not present in the flow table, and stop while it is there. Once the entry is aged from HW, it is also removed from the flow table, so this part should be okay. But if the offload failed for some reason like you said above, and the entry is left on the flow table, it won't retry until it ages out from the flow table.

But then we will never have the chance to re-install it in hardware while the connection is still active.

Quoted 5 lines

If you expect that this situation can be easily triggered, we may need to add a rate limit instead then. Even for these connections that failed to offload, this "busy retrying" is expensive and may backfire in such situation.

Perhaps we can refresh only if the flow_block callbacks list is not empty.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
net/netfilter/nf_flow_table_offload.c +0 -0
   	offload = nf_flow_offload_work_alloc(flowtable, flow, FLOW_CLS_REPLACE);
   	if (!offload)
   		return;
#4 lore raw
Quoted 28 lines · Oz Shlomo

Hi Marcelo,

Quoted 24 lines · Marcelo Ricardo Leitner

Hi Oz,

Quoted 11 lines · Oz Shlomo

Hi Marcelo,

Quoted 7 lines · Marcelo Ricardo Leitner

Currently, whenever act_ct tries to match a packet against the flow table, it will also try to refresh the offload. That is, at the end of tcf_ct_flow_table_lookup() it will call flow_offload_refresh().

The problem is that flow_offload_refresh() will try to offload entries that are actually already offloaded, leading to expensive and useless work. Before this patch, with a simple iperf3 test on OVS + TC

Quoted 7 lines

Packets of offloaded connections are expected to process in hardware. As such, it is not expected to receive packets in software from offloaded connections.

However, hardware offload may fail due to various reasons (e.g. size limits, insertion rate throttling etc.).
The "refresh" mechanism is the enabler for offload retries.

Thanks for the quick review.

Quoted 7 lines
Quoted 4 lines

Right. I don't mean to break this mechanism. Act_ct can also be used in semi/pure sw datapath, and then the premise of packets being expected to be handled in hw is not valid anymore. I can provide a more detailed use case if you need.

It is clear that the refresh design introduces some overhead when act_ct is used in a pure sw datapath.

Cool.

Quoted 51 lines
Quoted 51 lines
Quoted 34 lines
Quoted 34 lines

(hw_offload=true) + CT test entirely in sw, it looks like:

- 39,81% tcf_classify
- fl_classify
- 37,09% tcf_action_exec
+ 33,18% tcf_mirred_act
- 2,69% tcf_ct_act
- 2,39% tcf_ct_flow_table_lookup
- 1,67% queue_work_on
- 1,52% __queue_work
1,20% try_to_wake_up
+ 0,80% tcf_pedit_act
+ 2,28% fl_mask_lookup

The patch here aborts the add operation if the entry is already present in hw. With this patch, then:

- 43,94% tcf_classify
- fl_classify
- 39,64% tcf_action_exec
+ 38,00% tcf_mirred_act
- 1,04% tcf_ct_act
0,63% tcf_ct_flow_table_lookup
+ 3,19% fl_mask_lookup

---
   net/netfilter/nf_flow_table_offload.c | 3 +++
   1 file changed, 3 insertions(+)
Quoted 13 lines

net/netfilter/nf_flow_table_offload.c void nf_flow_offload_add(struct nf_flowtable *flowtable, · line 1030

Quoted 10 lines
net/netfilter/nf_flow_table_offload.c +3 -0
index 11b6e19420920bc8efda9877af0dab5311c8a096..9a8fc61581400b4e13aa356972d366892bb71b9b 100644
@@ -1026,6 +1026,9 @@ void nf_flow_offload_add(struct nf_flowtable *flowtable,
   {
   	struct flow_offload_work *offload;
+	if (test_bit(NF_FLOW_HW, &flow->flags))
+		return;
+

This change will make the refresh call obsolete as the NF_FLOW_HW bit is set on the first flow offload attempt.

Oh oh.. I was quite sure it was getting cleared when the entry was removed from HW, but not.

Quoted 6 lines
Quoted 2 lines

So instead of the if() above, what about:
+ if (test_and_set_bit(IPS_HW_OFFLOAD_BIT, &flow->ct->status))

I think this will set the IPS_HW_OFFLOAD_BIT prematurely. Currently this bit is set only when the the flow has been successfully offloaded.

Indeed. It was my cat that typed _and_set in there. ;-] (joking) sorry.

Quoted 11 lines
Quoted 8 lines

AFAICT it will keep trying while the entry is not present in the flow table, and stop while it is there. Once the entry is aged from HW, it is also removed from the flow table, so this part should be okay. But if the offload failed for some reason like you said above, and the entry is left on the flow table, it won't retry until it ages out from the flow table.

But then we will never have the chance to re-install it in hardware while the connection is still active.

Unless it goes idle, yes.

Quoted 8 lines
Quoted 6 lines

If you expect that this situation can be easily triggered, we may need to add a rate limit instead then. Even for these connections that failed to offload, this "busy retrying" is expensive and may backfire in such situation.

Perhaps we can refresh only if the flow_block callbacks list is not empty.

It may not be empty even for sw datapath. If you have packets coming from the wire towards a veth/virtio, for example. It will likely having a matching act_ct with the same zone number on both directions. And/or if a zone is shared, as the the flow table then is also shared.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
net/netfilter/nf_flow_table_offload.c +0 -0
   	offload = nf_flow_offload_work_alloc(flowtable, flow, FLOW_CLS_REPLACE);
   	if (!offload)
   		return;
#5 lore raw
Quoted 120 lines · Marcelo Ricardo Leitner
Quoted 28 lines · Oz Shlomo

Hi Marcelo,

Quoted 24 lines · Marcelo Ricardo Leitner

Hi Oz,

Quoted 11 lines · Oz Shlomo

Hi Marcelo,

Quoted 7 lines · Marcelo Ricardo Leitner

Currently, whenever act_ct tries to match a packet against the flow table, it will also try to refresh the offload. That is, at the end of tcf_ct_flow_table_lookup() it will call flow_offload_refresh().

The problem is that flow_offload_refresh() will try to offload entries that are actually already offloaded, leading to expensive and useless work. Before this patch, with a simple iperf3 test on OVS + TC

Quoted 7 lines

Packets of offloaded connections are expected to process in hardware. As such, it is not expected to receive packets in software from offloaded connections.

However, hardware offload may fail due to various reasons (e.g. size limits, insertion rate throttling etc.).
The "refresh" mechanism is the enabler for offload retries.

Thanks for the quick review.

Quoted 7 lines
Quoted 4 lines

Right. I don't mean to break this mechanism. Act_ct can also be used in semi/pure sw datapath, and then the premise of packets being expected to be handled in hw is not valid anymore. I can provide a more detailed use case if you need.

It is clear that the refresh design introduces some overhead when act_ct is used in a pure sw datapath.

Cool.

Quoted 51 lines
Quoted 51 lines
Quoted 34 lines
Quoted 34 lines

(hw_offload=true) + CT test entirely in sw, it looks like:

- 39,81% tcf_classify
- fl_classify
- 37,09% tcf_action_exec
+ 33,18% tcf_mirred_act
- 2,69% tcf_ct_act
- 2,39% tcf_ct_flow_table_lookup
- 1,67% queue_work_on
- 1,52% __queue_work
1,20% try_to_wake_up
+ 0,80% tcf_pedit_act
+ 2,28% fl_mask_lookup

The patch here aborts the add operation if the entry is already present in hw. With this patch, then:

- 43,94% tcf_classify
- fl_classify
- 39,64% tcf_action_exec
+ 38,00% tcf_mirred_act
- 1,04% tcf_ct_act
0,63% tcf_ct_flow_table_lookup
+ 3,19% fl_mask_lookup

---
    net/netfilter/nf_flow_table_offload.c | 3 +++
    1 file changed, 3 insertions(+)
Quoted 13 lines

net/netfilter/nf_flow_table_offload.c void nf_flow_offload_add(struct nf_flowtable *flowtable, · line 1030

Quoted 10 lines
net/netfilter/nf_flow_table_offload.c +3 -0
index 11b6e19420920bc8efda9877af0dab5311c8a096..9a8fc61581400b4e13aa356972d366892bb71b9b 100644
@@ -1026,6 +1026,9 @@ void nf_flow_offload_add(struct nf_flowtable *flowtable,
    {
    	struct flow_offload_work *offload;
+	if (test_bit(NF_FLOW_HW, &flow->flags))
+		return;
+

This change will make the refresh call obsolete as the NF_FLOW_HW bit is set on the first flow offload attempt.

Oh oh.. I was quite sure it was getting cleared when the entry was removed from HW, but not.

Quoted 6 lines
Quoted 2 lines

So instead of the if() above, what about:
+ if (test_and_set_bit(IPS_HW_OFFLOAD_BIT, &flow->ct->status))

I think this will set the IPS_HW_OFFLOAD_BIT prematurely. Currently this bit is set only when the the flow has been successfully offloaded.

Indeed. It was my cat that typed _and_set in there. ;-] (joking) sorry.

Quoted 11 lines
Quoted 8 lines

AFAICT it will keep trying while the entry is not present in the flow table, and stop while it is there. Once the entry is aged from HW, it is also removed from the flow table, so this part should be okay. But if the offload failed for some reason like you said above, and the entry is left on the flow table, it won't retry until it ages out from the flow table.

But then we will never have the chance to re-install it in hardware while the connection is still active.

Unless it goes idle, yes.

Quoted 7 lines
Quoted 6 lines

If you expect that this situation can be easily triggered, we may need to add a rate limit instead then. Even for these connections that failed to offload, this "busy retrying" is expensive and may backfire in such situation.

Quoted 6 lines
Quoted 1 line

Perhaps we can refresh only if the flow_block callbacks list is not empty.

It may not be empty even for sw datapath. If you have packets coming from the wire towards a veth/virtio, for example. It will likely having a matching act_ct with the same zone number on both directions. And/or if a zone is shared, as the the flow table then is also shared.

Hmm, I was thinking that you are targeting the use case of deployments with no ct offload supporting hardware.

CT action is usually proceeded by a goto action. So, a filter with ct and goto action list will offload even if the last chain forwards to a veth/virtio device.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
net/netfilter/nf_flow_table_offload.c +0 -0
    	offload = nf_flow_offload_work_alloc(flowtable, flow, FLOW_CLS_REPLACE);
    	if (!offload)
    		return;
#6 lore raw
Quoted 125 lines · Oz Shlomo
Quoted 122 lines · Marcelo Ricardo Leitner
Quoted 28 lines · Oz Shlomo

Hi Marcelo,

Quoted 24 lines · Marcelo Ricardo Leitner

Hi Oz,

Quoted 11 lines · Oz Shlomo

Hi Marcelo,

Quoted 7 lines · Marcelo Ricardo Leitner

Currently, whenever act_ct tries to match a packet against the flow table, it will also try to refresh the offload. That is, at the end of tcf_ct_flow_table_lookup() it will call flow_offload_refresh().

The problem is that flow_offload_refresh() will try to offload entries that are actually already offloaded, leading to expensive and useless work. Before this patch, with a simple iperf3 test on OVS + TC

Quoted 7 lines

Packets of offloaded connections are expected to process in hardware. As such, it is not expected to receive packets in software from offloaded connections.

However, hardware offload may fail due to various reasons (e.g. size limits, insertion rate throttling etc.).
The "refresh" mechanism is the enabler for offload retries.

Thanks for the quick review.

Quoted 7 lines
Quoted 4 lines

Right. I don't mean to break this mechanism. Act_ct can also be used in semi/pure sw datapath, and then the premise of packets being expected to be handled in hw is not valid anymore. I can provide a more detailed use case if you need.

It is clear that the refresh design introduces some overhead when act_ct is used in a pure sw datapath.

Cool.

Quoted 51 lines
Quoted 51 lines
Quoted 34 lines
Quoted 34 lines

(hw_offload=true) + CT test entirely in sw, it looks like:

- 39,81% tcf_classify
- fl_classify
- 37,09% tcf_action_exec
+ 33,18% tcf_mirred_act
- 2,69% tcf_ct_act
- 2,39% tcf_ct_flow_table_lookup
- 1,67% queue_work_on
- 1,52% __queue_work
1,20% try_to_wake_up
+ 0,80% tcf_pedit_act
+ 2,28% fl_mask_lookup

The patch here aborts the add operation if the entry is already present in hw. With this patch, then:

- 43,94% tcf_classify
- fl_classify
- 39,64% tcf_action_exec
+ 38,00% tcf_mirred_act
- 1,04% tcf_ct_act
0,63% tcf_ct_flow_table_lookup
+ 3,19% fl_mask_lookup

---
    net/netfilter/nf_flow_table_offload.c | 3 +++
    1 file changed, 3 insertions(+)
Quoted 13 lines

net/netfilter/nf_flow_table_offload.c void nf_flow_offload_add(struct nf_flowtable *flowtable, · line 1030

Quoted 10 lines
net/netfilter/nf_flow_table_offload.c +3 -0
index 11b6e19420920bc8efda9877af0dab5311c8a096..9a8fc61581400b4e13aa356972d366892bb71b9b 100644
@@ -1026,6 +1026,9 @@ void nf_flow_offload_add(struct nf_flowtable *flowtable,
    {
    	struct flow_offload_work *offload;
+	if (test_bit(NF_FLOW_HW, &flow->flags))
+		return;
+

This change will make the refresh call obsolete as the NF_FLOW_HW bit is set on the first flow offload attempt.

Oh oh.. I was quite sure it was getting cleared when the entry was removed from HW, but not.

Quoted 6 lines
Quoted 2 lines

So instead of the if() above, what about:
+ if (test_and_set_bit(IPS_HW_OFFLOAD_BIT, &flow->ct->status))

I think this will set the IPS_HW_OFFLOAD_BIT prematurely. Currently this bit is set only when the the flow has been successfully offloaded.

Indeed. It was my cat that typed _and_set in there. ;-] (joking) sorry.

Quoted 11 lines
Quoted 8 lines

AFAICT it will keep trying while the entry is not present in the flow table, and stop while it is there. Once the entry is aged from HW, it is also removed from the flow table, so this part should be okay. But if the offload failed for some reason like you said above, and the entry is left on the flow table, it won't retry until it ages out from the flow table.

But then we will never have the chance to re-install it in hardware while the connection is still active.

Unless it goes idle, yes.

Quoted 8 lines
Quoted 6 lines

If you expect that this situation can be easily triggered, we may need to add a rate limit instead then. Even for these connections that failed to offload, this "busy retrying" is expensive and may backfire in such situation.

Perhaps we can refresh only if the flow_block callbacks list is not empty.

Quoted 7 lines
Quoted 4 lines

It may not be empty even for sw datapath. If you have packets coming from the wire towards a veth/virtio, for example. It will likely having a matching act_ct with the same zone number on both directions. And/or if a zone is shared, as the the flow table then is also shared.

Hmm, I was thinking that you are targeting the use case of deployments with no ct offload supporting hardware.

Ahh.

Quoted 4 lines

CT action is usually proceeded by a goto action. So, a filter with ct and goto action list will offload even if the last chain forwards to a veth/virtio device.

Right, but there's the outbound traffic. Traffic coming from a container that is using veth, and going out to the wire. And also traffic from one container to another in the same host, that can also trigger this, if at least one of them is not annotated to use the offloading.
These will be using ingress tc filters on veth interfaces, which won't offload.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
net/netfilter/nf_flow_table_offload.c +0 -0
    	offload = nf_flow_offload_work_alloc(flowtable, flow, FLOW_CLS_REPLACE);
    	if (!offload)
    		return;