All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix iptables on systems with discontiguous processor ids
@ 2005-10-10 16:41 Harald Welte
  2005-10-10 21:15 ` David S. Miller
  2005-10-10 21:48 ` Sébastien Bernard
  0 siblings, 2 replies; 40+ messages in thread
From: Harald Welte @ 2005-10-10 16:41 UTC (permalink / raw)
  To: David Miller; +Cc: Netfilter Development Mailinglist

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

Hi Dave!

This is my proposed patch for the problem you've described.  Please test
and submit.  If it works, I'll also prepare a patch for {arp,ip6}_tables.


[NETFILTER] ip_tables: fix per cpu handling 

As David Miller points out, the "smp_processor_id()'s" are not always
contiguous.  Esp. some boxes like Sun Ultra60 have CPU 0 and 2 installed in
one system, but no "1".   Therefore the current logic of how iptables
manages the per cpu copies of the ruleset is broken.  This patch is
supposed to fix it.

Signed-off-by: Harald Welte <laforge@netfilter.org>

---
commit e759eaa9e9e92330c5fcfd760d767d4f39375a03
tree 63b96f7df57f51dc7e284969c3a08b9264cc2c5f
parent 1ab8dccdbf16c09f8da124fc4c82024de24dfae2
author Harald Welte <laforge@netfilter.org> Mon, 10 Oct 2005 18:29:24 +0200
committer Harald Welte <laforge@netfilter.org> Mon, 10 Oct 2005 18:29:24 +0200

 net/ipv4/netfilter/ip_tables.c |   26 ++++++++++++++++++++------
 1 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -27,6 +27,7 @@
 #include <asm/semaphore.h>
 #include <linux/proc_fs.h>
 #include <linux/err.h>
+#include <linux/cpumask.h>
 
 #include <linux/netfilter_ipv4/ip_tables.h>
 
@@ -124,6 +125,19 @@ static LIST_HEAD(ipt_tables);
 #define up(x) do { printk("UP:%u:" #x "\n", __LINE__); up(x); } while(0)
 #endif
 
+/* Find the highest possible smp_processor_id() */
+static unsigned int highest_processor_id(void)
+{
+	unsigned int cpu, highest = 0;
+
+	for_each_cpu_mask(cpu, cpu_possible_map) {
+		if (cpu > highest)
+			highest = cpu;
+	}
+
+	return highest;
+}
+
 /* Returns whether matches rule or not. */
 static inline int
 ip_packet_match(const struct iphdr *ip,
@@ -921,8 +935,8 @@ translate_table(const char *name,
 	}
 
 	/* And one copy for every other CPU */
-	for (i = 1; i < num_possible_cpus(); i++) {
-		memcpy(newinfo->entries + SMP_ALIGN(newinfo->size)*i,
+	for_each_cpu_mask(i, cpu_possible_map) {
+		memcpy(newinfo->entries + SMP_ALIGN(newinfo->size)*(1+i),
 		       newinfo->entries,
 		       SMP_ALIGN(newinfo->size));
 	}
@@ -943,7 +957,7 @@ replace_table(struct ipt_table *table,
 		struct ipt_entry *table_base;
 		unsigned int i;
 
-		for (i = 0; i < num_possible_cpus(); i++) {
+		for_each_cpu_mask(i, cpu_possible_map) {
 			table_base =
 				(void *)newinfo->entries
 				+ TABLE_OFFSET(newinfo, i);
@@ -990,7 +1004,7 @@ get_counters(const struct ipt_table_info
 	unsigned int cpu;
 	unsigned int i;
 
-	for (cpu = 0; cpu < num_possible_cpus(); cpu++) {
+	for_each_cpu_mask(cpu, cpu_possible_map) {
 		i = 0;
 		IPT_ENTRY_ITERATE(t->entries + TABLE_OFFSET(t, cpu),
 				  t->size,
@@ -1128,7 +1142,7 @@ do_replace(void __user *user, unsigned i
 		return -ENOMEM;
 
 	newinfo = vmalloc(sizeof(struct ipt_table_info)
-			  + SMP_ALIGN(tmp.size) * num_possible_cpus());
+			  + SMP_ALIGN(tmp.size) * (highest_processor_id()+1));
 	if (!newinfo)
 		return -ENOMEM;
 
@@ -1458,7 +1472,7 @@ int ipt_register_table(struct ipt_table 
 		= { 0, 0, 0, { 0 }, { 0 }, { } };
 
 	newinfo = vmalloc(sizeof(struct ipt_table_info)
-			  + SMP_ALIGN(repl->size) * num_possible_cpus());
+			  + SMP_ALIGN(repl->size) * (highest_processor_id()+1));
 	if (!newinfo)
 		return -ENOMEM;
 
-- 
- Harald Welte <laforge@netfilter.org>                 http://netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

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

end of thread, other threads:[~2005-10-17  4:18 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-10 16:41 [PATCH] fix iptables on systems with discontiguous processor ids Harald Welte
2005-10-10 21:15 ` David S. Miller
2005-10-10 21:41   ` Patrick McHardy
2005-10-10 21:52     ` Patrick McHardy
2005-10-10 22:06       ` David S. Miller
2005-10-11 14:23         ` Harald Welte
2005-10-11 19:39           ` David S. Miller
2005-10-12  6:36             ` Harald Welte
2005-10-10 22:04     ` David S. Miller
2005-10-10 21:46   ` Harald Welte
2005-10-11 13:54     ` Henrik Nordstrom
2005-10-11 14:13       ` Eric Dumazet
2005-10-11 17:45         ` Harald Welte
2005-10-11 22:57           ` David S. Miller
2005-10-12  7:00             ` Harald Welte
2005-10-13 22:01             ` Eric Dumazet
2005-10-17  4:18               ` David S. Miller
2005-10-11 10:44   ` Harald Welte
2005-10-11 17:15     ` Bart De Schuymer
2005-10-11 17:55       ` Harald Welte
2005-10-11 17:54     ` Harald Welte
2005-10-11 21:54       ` Sébastien Bernard
2005-10-11 22:32         ` David S. Miller
2005-10-12  6:22           ` seb
2005-10-12  6:31             ` David S. Miller
2005-10-12  7:04               ` Sébastien Bernard
2005-10-12  7:34                 ` David S. Miller
2005-10-12  6:43         ` Harald Welte
2005-10-12 22:54       ` David S. Miller
2005-10-13  7:18         ` seb
2005-10-13 19:11           ` David S. Miller
2005-10-13  8:46         ` Herbert Xu
2005-10-13 21:14           ` David S. Miller
2005-10-13 22:37             ` seb
2005-10-14 18:33             ` Harald Welte
2005-10-10 21:48 ` Sébastien Bernard
2005-10-11 14:23   ` Harald Welte
2005-10-11 20:59     ` Sébastien Bernard
2005-10-11 21:33       ` David S. Miller
2005-10-12  6:40       ` Harald Welte

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.