netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/4] netfilter patches for net-next
@ 2022-09-21  9:49 Florian Westphal
  2022-09-21  9:49 ` [PATCH net-next 1/4] netfilter: conntrack: fix the gc rescheduling delay Florian Westphal
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Florian Westphal @ 2022-09-21  9:49 UTC (permalink / raw)
  To: netdev
  Cc: netfilter-devel, Jakub Kicinski, Paolo Abeni, David S. Miller,
	Eric Dumazet, Florian Westphal

Hello,

The following set contains netfilter changes for the *net-next* tree.

Remove GPL license copypastry in uapi files, those have SPDX tags.
From Christophe Jaillet.

Remove unused variable in rpfilter, from Guillaume Nault.

Rework gc resched delay computation in conntrack, from Antoine Tenart.

Please consider pulling these changes from
  git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git


----------------------------------------------------------------
The following changes since commit c29b068215906d33f75378d44526edc37ad08276:

  liquidio: CN23XX: delete repeated words, add missing words and fix typo in comment (2022-09-20 16:50:21 -0700)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git master

for you to fetch changes up to 72f5c89804636b5b4c8599354a92d6df8cff42cc:

  netfilter: rpfilter: Remove unused variable 'ret'. (2022-09-21 10:44:56 +0200)

----------------------------------------------------------------
Antoine Tenart (2):
      netfilter: conntrack: fix the gc rescheduling delay
      netfilter: conntrack: revisit the gc initial rescheduling bias

Christophe JAILLET (1):
      headers: Remove some left-over license text in include/uapi/linux/netfilter/

Guillaume Nault (1):
      netfilter: rpfilter: Remove unused variable 'ret'.

 include/uapi/linux/netfilter/ipset/ip_set.h |  4 ----
 include/uapi/linux/netfilter/xt_AUDIT.h     |  4 ----
 include/uapi/linux/netfilter/xt_connmark.h  | 13 ++++---------
 include/uapi/linux/netfilter/xt_osf.h       | 14 --------------
 net/ipv4/netfilter/ipt_rpfilter.c           |  1 -
 net/netfilter/nf_conntrack_core.c           | 18 +++++++++++++-----
 6 files changed, 17 insertions(+), 37 deletions(-)

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

* [PATCH net-next 1/4] netfilter: conntrack: fix the gc rescheduling delay
  2022-09-21  9:49 [PATCH net-next 0/4] netfilter patches for net-next Florian Westphal
@ 2022-09-21  9:49 ` Florian Westphal
  2022-09-22  2:00   ` patchwork-bot+netdevbpf
  2022-09-21  9:49 ` [PATCH net-next 2/4] netfilter: conntrack: revisit the gc initial rescheduling bias Florian Westphal
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Florian Westphal @ 2022-09-21  9:49 UTC (permalink / raw)
  To: netdev
  Cc: netfilter-devel, Jakub Kicinski, Paolo Abeni, David S. Miller,
	Eric Dumazet, Antoine Tenart, Florian Westphal

From: Antoine Tenart <atenart@kernel.org>

Commit 2cfadb761d3d ("netfilter: conntrack: revisit gc autotuning")
changed the eviction rescheduling to the use average expiry of scanned
entries (within 1-60s) by doing:

  for (...) {
      expires = clamp(nf_ct_expires(tmp), ...);
      next_run += expires;
      next_run /= 2;
  }

The issue is the above will make the average ('next_run' here) more
dependent on the last expiration values than the firsts (for sets > 2).
Depending on the expiration values used to compute the average, the
result can be quite different than what's expected. To fix this we can
do the following:

  for (...) {
      expires = clamp(nf_ct_expires(tmp), ...);
      next_run += (expires - next_run) / ++count;
  }

Fixes: 2cfadb761d3d ("netfilter: conntrack: revisit gc autotuning")
Cc: Florian Westphal <fw@strlen.de>
Signed-off-by: Antoine Tenart <atenart@kernel.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
 net/netfilter/nf_conntrack_core.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index c5851e1321e7..8efa6bd5703c 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -67,6 +67,7 @@ struct conntrack_gc_work {
 	struct delayed_work	dwork;
 	u32			next_bucket;
 	u32			avg_timeout;
+	u32			count;
 	u32			start_time;
 	bool			exiting;
 	bool			early_drop;
@@ -1466,6 +1467,7 @@ static void gc_worker(struct work_struct *work)
 	unsigned int expired_count = 0;
 	unsigned long next_run;
 	s32 delta_time;
+	long count;
 
 	gc_work = container_of(work, struct conntrack_gc_work, dwork.work);
 
@@ -1475,10 +1477,12 @@ static void gc_worker(struct work_struct *work)
 
 	if (i == 0) {
 		gc_work->avg_timeout = GC_SCAN_INTERVAL_INIT;
+		gc_work->count = 1;
 		gc_work->start_time = start_time;
 	}
 
 	next_run = gc_work->avg_timeout;
+	count = gc_work->count;
 
 	end_time = start_time + GC_SCAN_MAX_DURATION;
 
@@ -1498,8 +1502,8 @@ static void gc_worker(struct work_struct *work)
 
 		hlist_nulls_for_each_entry_rcu(h, n, &ct_hash[i], hnnode) {
 			struct nf_conntrack_net *cnet;
-			unsigned long expires;
 			struct net *net;
+			long expires;
 
 			tmp = nf_ct_tuplehash_to_ctrack(h);
 
@@ -1513,6 +1517,7 @@ static void gc_worker(struct work_struct *work)
 
 				gc_work->next_bucket = i;
 				gc_work->avg_timeout = next_run;
+				gc_work->count = count;
 
 				delta_time = nfct_time_stamp - gc_work->start_time;
 
@@ -1528,8 +1533,8 @@ static void gc_worker(struct work_struct *work)
 			}
 
 			expires = clamp(nf_ct_expires(tmp), GC_SCAN_INTERVAL_MIN, GC_SCAN_INTERVAL_CLAMP);
+			expires = (expires - (long)next_run) / ++count;
 			next_run += expires;
-			next_run /= 2u;
 
 			if (nf_conntrack_max95 == 0 || gc_worker_skip_ct(tmp))
 				continue;
@@ -1570,6 +1575,7 @@ static void gc_worker(struct work_struct *work)
 		delta_time = nfct_time_stamp - end_time;
 		if (delta_time > 0 && i < hashsz) {
 			gc_work->avg_timeout = next_run;
+			gc_work->count = count;
 			gc_work->next_bucket = i;
 			next_run = 0;
 			goto early_exit;
-- 
2.35.1


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

* [PATCH net-next 2/4] netfilter: conntrack: revisit the gc initial rescheduling bias
  2022-09-21  9:49 [PATCH net-next 0/4] netfilter patches for net-next Florian Westphal
  2022-09-21  9:49 ` [PATCH net-next 1/4] netfilter: conntrack: fix the gc rescheduling delay Florian Westphal
@ 2022-09-21  9:49 ` Florian Westphal
  2022-09-21  9:49 ` [PATCH net-next 3/4] headers: Remove some left-over license text in include/uapi/linux/netfilter/ Florian Westphal
  2022-09-21  9:50 ` [PATCH net-next 4/4] netfilter: rpfilter: Remove unused variable 'ret' Florian Westphal
  3 siblings, 0 replies; 6+ messages in thread
From: Florian Westphal @ 2022-09-21  9:49 UTC (permalink / raw)
  To: netdev
  Cc: netfilter-devel, Jakub Kicinski, Paolo Abeni, David S. Miller,
	Eric Dumazet, Antoine Tenart, Florian Westphal

From: Antoine Tenart <atenart@kernel.org>

The previous commit changed the way the rescheduling delay is computed
which has a side effect: the bias is now represented as much as the
other entries in the rescheduling delay which makes the logic to kick in
only with very large sets, as the initial interval is very large
(INT_MAX).

Revisit the GC initial bias to allow more frequent GC for smaller sets
while still avoiding wakeups when a machine is mostly idle. We're moving
from a large initial value to pretending we have 100 entries expiring at
the upper bound. This way only a few entries having a small timeout
won't impact much the rescheduling delay and non-idle machines will have
enough entries to lower the delay when needed. This also improves
readability as the initial bias is now linked to what is computed
instead of being an arbitrary large value.

Fixes: 2cfadb761d3d ("netfilter: conntrack: revisit gc autotuning")
Suggested-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Antoine Tenart <atenart@kernel.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
 net/netfilter/nf_conntrack_core.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 8efa6bd5703c..8208a28ea342 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -86,10 +86,12 @@ static DEFINE_MUTEX(nf_conntrack_mutex);
 /* clamp timeouts to this value (TCP unacked) */
 #define GC_SCAN_INTERVAL_CLAMP	(300ul * HZ)
 
-/* large initial bias so that we don't scan often just because we have
- * three entries with a 1s timeout.
+/* Initial bias pretending we have 100 entries at the upper bound so we don't
+ * wakeup often just because we have three entries with a 1s timeout while still
+ * allowing non-idle machines to wakeup more often when needed.
  */
-#define GC_SCAN_INTERVAL_INIT	INT_MAX
+#define GC_SCAN_INITIAL_COUNT	100
+#define GC_SCAN_INTERVAL_INIT	GC_SCAN_INTERVAL_MAX
 
 #define GC_SCAN_MAX_DURATION	msecs_to_jiffies(10)
 #define GC_SCAN_EXPIRED_MAX	(64000u / HZ)
@@ -1477,7 +1479,7 @@ static void gc_worker(struct work_struct *work)
 
 	if (i == 0) {
 		gc_work->avg_timeout = GC_SCAN_INTERVAL_INIT;
-		gc_work->count = 1;
+		gc_work->count = GC_SCAN_INITIAL_COUNT;
 		gc_work->start_time = start_time;
 	}
 
-- 
2.35.1


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

* [PATCH net-next 3/4] headers: Remove some left-over license text in include/uapi/linux/netfilter/
  2022-09-21  9:49 [PATCH net-next 0/4] netfilter patches for net-next Florian Westphal
  2022-09-21  9:49 ` [PATCH net-next 1/4] netfilter: conntrack: fix the gc rescheduling delay Florian Westphal
  2022-09-21  9:49 ` [PATCH net-next 2/4] netfilter: conntrack: revisit the gc initial rescheduling bias Florian Westphal
@ 2022-09-21  9:49 ` Florian Westphal
  2022-09-21  9:50 ` [PATCH net-next 4/4] netfilter: rpfilter: Remove unused variable 'ret' Florian Westphal
  3 siblings, 0 replies; 6+ messages in thread
From: Florian Westphal @ 2022-09-21  9:49 UTC (permalink / raw)
  To: netdev
  Cc: netfilter-devel, Jakub Kicinski, Paolo Abeni, David S. Miller,
	Eric Dumazet, Christophe JAILLET, Florian Westphal

From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

When the SPDX-License-Identifier tag has been added, the corresponding
license text has not been removed.

Remove it now.

Also, in xt_connmark.h, move the copyright text at the top of the file
which is a much more common pattern.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
 include/uapi/linux/netfilter/ipset/ip_set.h |  4 ----
 include/uapi/linux/netfilter/xt_AUDIT.h     |  4 ----
 include/uapi/linux/netfilter/xt_connmark.h  | 13 ++++---------
 include/uapi/linux/netfilter/xt_osf.h       | 14 --------------
 4 files changed, 4 insertions(+), 31 deletions(-)

diff --git a/include/uapi/linux/netfilter/ipset/ip_set.h b/include/uapi/linux/netfilter/ipset/ip_set.h
index 6397d75899bc..79e5d68b87af 100644
--- a/include/uapi/linux/netfilter/ipset/ip_set.h
+++ b/include/uapi/linux/netfilter/ipset/ip_set.h
@@ -3,10 +3,6 @@
  *                         Patrick Schaaf <bof@bof.de>
  *                         Martin Josefsson <gandalf@wlug.westbo.se>
  * Copyright (C) 2003-2011 Jozsef Kadlecsik <kadlec@netfilter.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
  */
 #ifndef _UAPI_IP_SET_H
 #define _UAPI_IP_SET_H
diff --git a/include/uapi/linux/netfilter/xt_AUDIT.h b/include/uapi/linux/netfilter/xt_AUDIT.h
index 1b314e2f84ac..56a3f6092e0c 100644
--- a/include/uapi/linux/netfilter/xt_AUDIT.h
+++ b/include/uapi/linux/netfilter/xt_AUDIT.h
@@ -4,10 +4,6 @@
  *
  * (C) 2010-2011 Thomas Graf <tgraf@redhat.com>
  * (C) 2010-2011 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
  */
 
 #ifndef _XT_AUDIT_TARGET_H
diff --git a/include/uapi/linux/netfilter/xt_connmark.h b/include/uapi/linux/netfilter/xt_connmark.h
index f01c19b83a2b..41b578ccd03b 100644
--- a/include/uapi/linux/netfilter/xt_connmark.h
+++ b/include/uapi/linux/netfilter/xt_connmark.h
@@ -1,18 +1,13 @@
 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
+/* Copyright (C) 2002,2004 MARA Systems AB <https://www.marasystems.com>
+ * by Henrik Nordstrom <hno@marasystems.com>
+ */
+
 #ifndef _XT_CONNMARK_H
 #define _XT_CONNMARK_H
 
 #include <linux/types.h>
 
-/* Copyright (C) 2002,2004 MARA Systems AB <https://www.marasystems.com>
- * by Henrik Nordstrom <hno@marasystems.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
 enum {
 	XT_CONNMARK_SET = 0,
 	XT_CONNMARK_SAVE,
diff --git a/include/uapi/linux/netfilter/xt_osf.h b/include/uapi/linux/netfilter/xt_osf.h
index 6e466236ca4b..f1f097896bdf 100644
--- a/include/uapi/linux/netfilter/xt_osf.h
+++ b/include/uapi/linux/netfilter/xt_osf.h
@@ -1,20 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
 /*
  * Copyright (c) 2003+ Evgeniy Polyakov <johnpol@2ka.mxt.ru>
- *
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #ifndef _XT_OSF_H
-- 
2.35.1


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

* [PATCH net-next 4/4] netfilter: rpfilter: Remove unused variable 'ret'.
  2022-09-21  9:49 [PATCH net-next 0/4] netfilter patches for net-next Florian Westphal
                   ` (2 preceding siblings ...)
  2022-09-21  9:49 ` [PATCH net-next 3/4] headers: Remove some left-over license text in include/uapi/linux/netfilter/ Florian Westphal
@ 2022-09-21  9:50 ` Florian Westphal
  3 siblings, 0 replies; 6+ messages in thread
From: Florian Westphal @ 2022-09-21  9:50 UTC (permalink / raw)
  To: netdev
  Cc: netfilter-devel, Jakub Kicinski, Paolo Abeni, David S. Miller,
	Eric Dumazet, Guillaume Nault, Florian Westphal

From: Guillaume Nault <gnault@redhat.com>

Commit 91a178258aea ("netfilter: rpfilter: Convert
rpfilter_lookup_reverse to new dev helper") removed the need for the
'ret' variable. This went unnoticed because of the __maybe_unused
annotation.

Signed-off-by: Guillaume Nault <gnault@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
 net/ipv4/netfilter/ipt_rpfilter.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/net/ipv4/netfilter/ipt_rpfilter.c b/net/ipv4/netfilter/ipt_rpfilter.c
index 8cd3224d913e..8183bbcabb4a 100644
--- a/net/ipv4/netfilter/ipt_rpfilter.c
+++ b/net/ipv4/netfilter/ipt_rpfilter.c
@@ -33,7 +33,6 @@ static bool rpfilter_lookup_reverse(struct net *net, struct flowi4 *fl4,
 				const struct net_device *dev, u8 flags)
 {
 	struct fib_result res;
-	int ret __maybe_unused;
 
 	if (fib_lookup(net, fl4, &res, FIB_LOOKUP_IGNORE_LINKSTATE))
 		return false;
-- 
2.35.1


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

* Re: [PATCH net-next 1/4] netfilter: conntrack: fix the gc rescheduling delay
  2022-09-21  9:49 ` [PATCH net-next 1/4] netfilter: conntrack: fix the gc rescheduling delay Florian Westphal
@ 2022-09-22  2:00   ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-09-22  2:00 UTC (permalink / raw)
  To: Florian Westphal
  Cc: netdev, netfilter-devel, kuba, pabeni, davem, edumazet, atenart

Hello:

This series was applied to netdev/net-next.git (master)
by Florian Westphal <fw@strlen.de>:

On Wed, 21 Sep 2022 11:49:57 +0200 you wrote:
> From: Antoine Tenart <atenart@kernel.org>
> 
> Commit 2cfadb761d3d ("netfilter: conntrack: revisit gc autotuning")
> changed the eviction rescheduling to the use average expiry of scanned
> entries (within 1-60s) by doing:
> 
>   for (...) {
>       expires = clamp(nf_ct_expires(tmp), ...);
>       next_run += expires;
>       next_run /= 2;
>   }
> 
> [...]

Here is the summary with links:
  - [net-next,1/4] netfilter: conntrack: fix the gc rescheduling delay
    https://git.kernel.org/netdev/net-next/c/95eabdd20702
  - [net-next,2/4] netfilter: conntrack: revisit the gc initial rescheduling bias
    https://git.kernel.org/netdev/net-next/c/2aa192757005
  - [net-next,3/4] headers: Remove some left-over license text in include/uapi/linux/netfilter/
    https://git.kernel.org/netdev/net-next/c/7b5541a932c2
  - [net-next,4/4] netfilter: rpfilter: Remove unused variable 'ret'.
    https://git.kernel.org/netdev/net-next/c/72f5c8980463

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2022-09-22  2:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-21  9:49 [PATCH net-next 0/4] netfilter patches for net-next Florian Westphal
2022-09-21  9:49 ` [PATCH net-next 1/4] netfilter: conntrack: fix the gc rescheduling delay Florian Westphal
2022-09-22  2:00   ` patchwork-bot+netdevbpf
2022-09-21  9:49 ` [PATCH net-next 2/4] netfilter: conntrack: revisit the gc initial rescheduling bias Florian Westphal
2022-09-21  9:49 ` [PATCH net-next 3/4] headers: Remove some left-over license text in include/uapi/linux/netfilter/ Florian Westphal
2022-09-21  9:50 ` [PATCH net-next 4/4] netfilter: rpfilter: Remove unused variable 'ret' Florian Westphal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).