All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] netfilter: flowtable: Fix expired flow not being deleted from software
@ 2020-05-06 11:27 Paul Blakey
  2020-05-10 22:26 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Blakey @ 2020-05-06 11:27 UTC (permalink / raw)
  To: Paul Blakey, Oz Shlomo, Pablo Neira Ayuso, Roi Dayan, netdev,
	Saeed Mahameed
  Cc: netfilter-devel

Once a flow is considered expired, it is marked as DYING, and
scheduled a delete from hardware. The flow will be deleted from
software, in the next gc_step after hardware deletes the flow
(and flow is marked DEAD). Till that happens, the flow's timeout
might be updated from a previous scheduled stats, or software packets
(refresh). This will cause the gc_step to no longer consider the flow
expired, and it will not be deleted from software.

Fix that by looking at the DYING flag as in deciding
a flow should be deleted from software.

Fixes: c29f74e0df7a ("netfilter: nf_flow_table: hardware offload support")
Signed-off-by: Paul Blakey <paulb@mellanox.com>
Reviewed-by: Oz Shlomo <ozsh@mellanox.com>
Reviewed-by: Roi Dayan <roid@mellanox.com>
---
 net/netfilter/nf_flow_table_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
index c0cb7949..b0e9f7a 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -362,7 +362,8 @@ static void nf_flow_offload_gc_step(struct flow_offload *flow, void *data)
 	struct nf_flowtable *flow_table = data;
 
 	if (nf_flow_has_expired(flow) || nf_ct_is_dying(flow->ct) ||
-	    test_bit(NF_FLOW_TEARDOWN, &flow->flags)) {
+	    test_bit(NF_FLOW_TEARDOWN, &flow->flags) ||
+	    test_bit(NF_FLOW_HW_DYING, &flow->flags)) {
 		if (test_bit(NF_FLOW_HW, &flow->flags)) {
 			if (!test_bit(NF_FLOW_HW_DYING, &flow->flags))
 				nf_flow_offload_del(flow_table, flow);
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net] netfilter: flowtable: Fix expired flow not being deleted from software
  2020-05-06 11:27 [PATCH net] netfilter: flowtable: Fix expired flow not being deleted from software Paul Blakey
@ 2020-05-10 22:26 ` Pablo Neira Ayuso
  2020-05-11  7:24   ` Paul Blakey
  0 siblings, 1 reply; 5+ messages in thread
From: Pablo Neira Ayuso @ 2020-05-10 22:26 UTC (permalink / raw)
  To: Paul Blakey; +Cc: Oz Shlomo, Roi Dayan, netdev, Saeed Mahameed, netfilter-devel

[-- Attachment #1: Type: text/plain, Size: 716 bytes --]

On Wed, May 06, 2020 at 02:27:29PM +0300, Paul Blakey wrote:
> Once a flow is considered expired, it is marked as DYING, and
> scheduled a delete from hardware. The flow will be deleted from
> software, in the next gc_step after hardware deletes the flow
> (and flow is marked DEAD). Till that happens, the flow's timeout
> might be updated from a previous scheduled stats, or software packets
> (refresh). This will cause the gc_step to no longer consider the flow
> expired, and it will not be deleted from software.
> 
> Fix that by looking at the DYING flag as in deciding
> a flow should be deleted from software.

Would this work for you?

The idea is to skip the refresh if this has already expired.

Thanks.

[-- Attachment #2: expired.patch --]
[-- Type: text/x-diff, Size: 1235 bytes --]

diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
index 4344e572b7f9..862efa7c606d 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -252,10 +252,18 @@ int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow)
 }
 EXPORT_SYMBOL_GPL(flow_offload_add);
 
+static inline bool nf_flow_has_expired(const struct flow_offload *flow)
+{
+	return nf_flow_timeout_delta(flow->timeout) <= 0;
+}
+
 void flow_offload_refresh(struct nf_flowtable *flow_table,
 			  struct flow_offload *flow)
 {
-	flow->timeout = nf_flowtable_time_stamp + NF_FLOW_TIMEOUT;
+	if (!nf_flow_has_expired(flow)) {
+		flow->timeout = nf_flowtable_time_stamp + NF_FLOW_TIMEOUT;
+		return;
+	}
 
 	if (likely(!nf_flowtable_hw_offload(flow_table) ||
 		   !test_and_clear_bit(NF_FLOW_HW_REFRESH, &flow->flags)))
@@ -265,11 +273,6 @@ void flow_offload_refresh(struct nf_flowtable *flow_table,
 }
 EXPORT_SYMBOL_GPL(flow_offload_refresh);
 
-static inline bool nf_flow_has_expired(const struct flow_offload *flow)
-{
-	return nf_flow_timeout_delta(flow->timeout) <= 0;
-}
-
 static void flow_offload_del(struct nf_flowtable *flow_table,
 			     struct flow_offload *flow)
 {

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net] netfilter: flowtable: Fix expired flow not being deleted from software
  2020-05-10 22:26 ` Pablo Neira Ayuso
@ 2020-05-11  7:24   ` Paul Blakey
  2020-05-11  8:42     ` Pablo Neira Ayuso
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Blakey @ 2020-05-11  7:24 UTC (permalink / raw)
  To: Pablo Neira Ayuso
  Cc: Oz Shlomo, Roi Dayan, netdev, Saeed Mahameed, netfilter-devel



On 5/11/2020 1:26 AM, Pablo Neira Ayuso wrote:
> On Wed, May 06, 2020 at 02:27:29PM +0300, Paul Blakey wrote:
>> Once a flow is considered expired, it is marked as DYING, and
>> scheduled a delete from hardware. The flow will be deleted from
>> software, in the next gc_step after hardware deletes the flow
>> (and flow is marked DEAD). Till that happens, the flow's timeout
>> might be updated from a previous scheduled stats, or software packets
>> (refresh). This will cause the gc_step to no longer consider the flow
>> expired, and it will not be deleted from software.
>>
>> Fix that by looking at the DYING flag as in deciding
>> a flow should be deleted from software.
> Would this work for you?
>
> The idea is to skip the refresh if this has already expired.
>
> Thanks.

The idea is ok, but timeout check + update isn't atomic (need atomic_inc_unlesss
or something like that), and there is also
the hardware stats which if comes too late (after gc finds it expired) might
bring a flow back to life.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] netfilter: flowtable: Fix expired flow not being deleted from software
  2020-05-11  7:24   ` Paul Blakey
@ 2020-05-11  8:42     ` Pablo Neira Ayuso
  2020-05-11  9:50       ` Paul Blakey
  0 siblings, 1 reply; 5+ messages in thread
From: Pablo Neira Ayuso @ 2020-05-11  8:42 UTC (permalink / raw)
  To: Paul Blakey; +Cc: Oz Shlomo, Roi Dayan, netdev, Saeed Mahameed, netfilter-devel

[-- Attachment #1: Type: text/plain, Size: 1346 bytes --]

On Mon, May 11, 2020 at 10:24:44AM +0300, Paul Blakey wrote:
> 
> 
> On 5/11/2020 1:26 AM, Pablo Neira Ayuso wrote:
> > On Wed, May 06, 2020 at 02:27:29PM +0300, Paul Blakey wrote:
> >> Once a flow is considered expired, it is marked as DYING, and
> >> scheduled a delete from hardware. The flow will be deleted from
> >> software, in the next gc_step after hardware deletes the flow
> >> (and flow is marked DEAD). Till that happens, the flow's timeout
> >> might be updated from a previous scheduled stats, or software packets
> >> (refresh). This will cause the gc_step to no longer consider the flow
> >> expired, and it will not be deleted from software.
> >>
> >> Fix that by looking at the DYING flag as in deciding
> >> a flow should be deleted from software.
> > Would this work for you?
> >
> > The idea is to skip the refresh if this has already expired.
> >
> > Thanks.
> 
> The idea is ok, but timeout check + update isn't atomic (need atomic_inc_unlesss
> or something like that), and there is also
> the hardware stats which if comes too late (after gc finds it expired) might
> bring a flow back to life.

Right. Once the entry has expired, there should not be a way turning
back.

I'm attaching a new sketch, it's basically using the teardown state to
specify that the gc already made the decision to remove this entry.

Thanks.

[-- Attachment #2: x.patch --]
[-- Type: text/x-diff, Size: 1046 bytes --]

diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
index 4344e572b7f9..42da6e337276 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -284,7 +284,7 @@ static void flow_offload_del(struct nf_flowtable *flow_table,
 
 	if (nf_flow_has_expired(flow))
 		flow_offload_fixup_ct(flow->ct);
-	else if (test_bit(NF_FLOW_TEARDOWN, &flow->flags))
+	else
 		flow_offload_fixup_ct_timeout(flow->ct);
 
 	flow_offload_free(flow);
@@ -361,8 +361,10 @@ static void nf_flow_offload_gc_step(struct flow_offload *flow, void *data)
 {
 	struct nf_flowtable *flow_table = data;
 
-	if (nf_flow_has_expired(flow) || nf_ct_is_dying(flow->ct) ||
-	    test_bit(NF_FLOW_TEARDOWN, &flow->flags)) {
+	if (nf_flow_has_expired(flow) || nf_ct_is_dying(flow->ct))
+		set_bit(NF_FLOW_TEARDOWN, &flow->flags);
+
+	if (test_bit(NF_FLOW_TEARDOWN, &flow->flags)) {
 		if (test_bit(NF_FLOW_HW, &flow->flags)) {
 			if (!test_bit(NF_FLOW_HW_DYING, &flow->flags))
 				nf_flow_offload_del(flow_table, flow);

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net] netfilter: flowtable: Fix expired flow not being deleted from software
  2020-05-11  8:42     ` Pablo Neira Ayuso
@ 2020-05-11  9:50       ` Paul Blakey
  0 siblings, 0 replies; 5+ messages in thread
From: Paul Blakey @ 2020-05-11  9:50 UTC (permalink / raw)
  To: Pablo Neira Ayuso
  Cc: Oz Shlomo, Roi Dayan, netdev, Saeed Mahameed, netfilter-devel



On 5/11/2020 11:42 AM, Pablo Neira Ayuso wrote:
> On Mon, May 11, 2020 at 10:24:44AM +0300, Paul Blakey wrote:
>>
>> On 5/11/2020 1:26 AM, Pablo Neira Ayuso wrote:
>>> On Wed, May 06, 2020 at 02:27:29PM +0300, Paul Blakey wrote:
>>>> Once a flow is considered expired, it is marked as DYING, and
>>>> scheduled a delete from hardware. The flow will be deleted from
>>>> software, in the next gc_step after hardware deletes the flow
>>>> (and flow is marked DEAD). Till that happens, the flow's timeout
>>>> might be updated from a previous scheduled stats, or software packets
>>>> (refresh). This will cause the gc_step to no longer consider the flow
>>>> expired, and it will not be deleted from software.
>>>>
>>>> Fix that by looking at the DYING flag as in deciding
>>>> a flow should be deleted from software.
>>> Would this work for you?
>>>
>>> The idea is to skip the refresh if this has already expired.
>>>
>>> Thanks.
>> The idea is ok, but timeout check + update isn't atomic (need atomic_inc_unlesss
>> or something like that), and there is also
>> the hardware stats which if comes too late (after gc finds it expired) might
>> bring a flow back to life.
> Right. Once the entry has expired, there should not be a way turning
> back.
>
> I'm attaching a new sketch, it's basically using the teardown state to
> specify that the gc already made the decision to remove this entry.
>
> Thanks.

Looks fine to me, are you submitting that instead?


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-05-11  9:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-06 11:27 [PATCH net] netfilter: flowtable: Fix expired flow not being deleted from software Paul Blakey
2020-05-10 22:26 ` Pablo Neira Ayuso
2020-05-11  7:24   ` Paul Blakey
2020-05-11  8:42     ` Pablo Neira Ayuso
2020-05-11  9:50       ` Paul Blakey

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.