From: "Sébastien Bernard" <seb@frankengul.org>
To: Harald Welte <laforge@netfilter.org>
Cc: netfilter-devel@lists.netfilter.org, bdschuym@pandora.be,
"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH] fix iptables on systems with discontiguous processor ids
Date: Tue, 11 Oct 2005 23:54:13 +0200 [thread overview]
Message-ID: <434C3485.2000700@frankengul.org> (raw)
In-Reply-To: <20051011175457.GC13415@rama.de.gnumonks.org>
Harald Welte a écrit :
>*sigh*
>
>forgot to attach the patch.
>
>This probably still has the same problem that was reported (oops when
>get_entries() is called).
>
>
>
>------------------------------------------------------------------------
>
>diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
>--- a/include/linux/cpumask.h
>+++ b/include/linux/cpumask.h
>@@ -392,4 +392,18 @@ extern cpumask_t cpu_present_map;
> #define for_each_online_cpu(cpu) for_each_cpu_mask((cpu), cpu_online_map)
> #define for_each_present_cpu(cpu) for_each_cpu_mask((cpu), cpu_present_map)
>
>+/* Find the highest possible smp_processor_id() */
>+static inline unsigned int highest_possible_processor_id(void)
>+{
>+ unsigned int cpu, highest = 0;
>+
>+ for_each_cpu_mask(cpu, cpu_possible_map) {
>+ if (cpu > highest)
>+ highest = cpu;
>+ }
>+
>+ return highest;
>+}
>+
>+
> #endif /* __LINUX_CPUMASK_H */
>diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
>--- a/net/bridge/netfilter/ebtables.c
>+++ b/net/bridge/netfilter/ebtables.c
>@@ -26,6 +26,7 @@
> #include <linux/spinlock.h>
> #include <asm/uaccess.h>
> #include <linux/smp.h>
>+#include <linux/cpumask.h>
> #include <net/sock.h>
> /* needed for logical [in,out]-dev filtering */
> #include "../br_private.h"
>@@ -823,10 +824,11 @@ static int translate_table(struct ebt_re
> /* this will get free'd in do_replace()/ebt_register_table()
> if an error occurs */
> newinfo->chainstack = (struct ebt_chainstack **)
>- vmalloc(num_possible_cpus() * sizeof(struct ebt_chainstack));
>+ vmalloc((highest_possible_processor_id()+1)
>+ * sizeof(struct ebt_chainstack));
> if (!newinfo->chainstack)
> return -ENOMEM;
>- for (i = 0; i < num_possible_cpus(); i++) {
>+ for_each_cpu_mask(i, cpu_possible_map) {
> newinfo->chainstack[i] =
> vmalloc(udc_cnt * sizeof(struct ebt_chainstack));
> if (!newinfo->chainstack[i]) {
>@@ -893,11 +895,8 @@ static void get_counters(struct ebt_coun
> int i, cpu;
> struct ebt_counter *counter_base;
>
>- /* counters of cpu 0 */
>- memcpy(counters, oldcounters,
>- sizeof(struct ebt_counter) * nentries);
> /* add other counters to those of cpu 0 */
>- for (cpu = 1; cpu < num_possible_cpus(); cpu++) {
>+ for_each_cpu_mask(cpu, cpu_possible_map) {
> counter_base = COUNTER_BASE(oldcounters, nentries, cpu);
> for (i = 0; i < nentries; i++) {
> counters[i].pcnt += counter_base[i].pcnt;
>@@ -929,7 +928,8 @@ static int do_replace(void __user *user,
> BUGPRINT("Entries_size never zero\n");
> return -EINVAL;
> }
>- countersize = COUNTER_OFFSET(tmp.nentries) * num_possible_cpus();
>+ countersize = COUNTER_OFFSET(tmp.nentries) *
>+ (highest_possible_processor_id()+1);
> newinfo = (struct ebt_table_info *)
> vmalloc(sizeof(struct ebt_table_info) + countersize);
> if (!newinfo)
>@@ -1022,7 +1022,7 @@ static int do_replace(void __user *user,
>
> vfree(table->entries);
> if (table->chainstack) {
>- for (i = 0; i < num_possible_cpus(); i++)
>+ for_each_cpu_mask(i, cpu_possible_map)
> vfree(table->chainstack[i]);
> vfree(table->chainstack);
> }
>@@ -1040,7 +1040,7 @@ free_counterstmp:
> vfree(counterstmp);
> /* can be initialized in translate_table() */
> if (newinfo->chainstack) {
>- for (i = 0; i < num_possible_cpus(); i++)
>+ for_each_cpu_mask(i, cpu_possible_map)
> vfree(newinfo->chainstack[i]);
> vfree(newinfo->chainstack);
> }
>@@ -1132,7 +1132,8 @@ int ebt_register_table(struct ebt_table
> return -EINVAL;
> }
>
>- countersize = COUNTER_OFFSET(table->table->nentries) * num_possible_cpus();
>+ countersize = COUNTER_OFFSET(table->table->nentries) *
>+ (highest_possible_processor_id()+1);
> newinfo = (struct ebt_table_info *)
> vmalloc(sizeof(struct ebt_table_info) + countersize);
> ret = -ENOMEM;
>@@ -1186,7 +1187,7 @@ free_unlock:
> up(&ebt_mutex);
> free_chainstack:
> if (newinfo->chainstack) {
>- for (i = 0; i < num_possible_cpus(); i++)
>+ for_each_cpu_mask(i, cpu_possible_map)
> vfree(newinfo->chainstack[i]);
> vfree(newinfo->chainstack);
> }
>@@ -1209,7 +1210,7 @@ void ebt_unregister_table(struct ebt_tab
> up(&ebt_mutex);
> vfree(table->private->entries);
> if (table->private->chainstack) {
>- for (i = 0; i < num_possible_cpus(); i++)
>+ for_each_cpu_mask(i, cpu_possible_map)
> vfree(table->private->chainstack[i]);
> vfree(table->private->chainstack);
> }
>diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
>--- a/net/ipv4/netfilter/arp_tables.c
>+++ b/net/ipv4/netfilter/arp_tables.c
>@@ -716,8 +716,8 @@ static int translate_table(const char *n
> }
>
> /* 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));
> }
>@@ -767,7 +767,7 @@ static void get_counters(const struct ar
> unsigned int cpu;
> unsigned int i;
>
>- for (cpu = 0; cpu < num_possible_cpus(); cpu++) {
>+ for_each_cpu_mask(cpu, cpu_possible_map) {
> i = 0;
> ARPT_ENTRY_ITERATE(t->entries + TABLE_OFFSET(t, cpu),
> t->size,
>@@ -885,7 +885,8 @@ static int do_replace(void __user *user,
> return -ENOMEM;
>
> newinfo = vmalloc(sizeof(struct arpt_table_info)
>- + SMP_ALIGN(tmp.size) * num_possible_cpus());
>+ + SMP_ALIGN(tmp.size) *
>+ (highest_possible_processor_id()+1));
> if (!newinfo)
> return -ENOMEM;
>
>@@ -1158,7 +1159,8 @@ int arpt_register_table(struct arpt_tabl
> = { 0, 0, 0, { 0 }, { 0 }, { } };
>
> newinfo = vmalloc(sizeof(struct arpt_table_info)
>- + SMP_ALIGN(repl->size) * num_possible_cpus());
>+ + SMP_ALIGN(repl->size) *
>+ (highest_possible_processor_id()+1));
> if (!newinfo) {
> ret = -ENOMEM;
> return ret;
>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>
>
>@@ -921,8 +922,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 +944,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 +991,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 +1129,8 @@ 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_possible_processor_id()+1));
> if (!newinfo)
> return -ENOMEM;
>
>@@ -1458,7 +1460,8 @@ 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_possible_processor_id()+1));
> if (!newinfo)
> return -ENOMEM;
>
>diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
>--- a/net/ipv6/netfilter/ip6_tables.c
>+++ b/net/ipv6/netfilter/ip6_tables.c
>@@ -28,6 +28,7 @@
> #include <asm/uaccess.h>
> #include <asm/semaphore.h>
> #include <linux/proc_fs.h>
>+#include <linux/cpumask.h>
>
> #include <linux/netfilter_ipv6/ip6_tables.h>
>
>@@ -950,8 +951,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));
> }
>@@ -973,6 +974,7 @@ replace_table(struct ip6t_table *table,
> unsigned int i;
>
> for (i = 0; i < num_possible_cpus(); i++) {
>+ for_each_cpu_mask(i, cpu_possible_mask) {
> table_base =
> (void *)newinfo->entries
> + TABLE_OFFSET(newinfo, i);
>@@ -1019,7 +1021,7 @@ get_counters(const struct ip6t_table_inf
> unsigned int cpu;
> unsigned int i;
>
>- for (cpu = 0; cpu < num_possible_cpus(); cpu++) {
>+ for_each_cpu_mask(cpu, cpu_possible_map) {
> i = 0;
> IP6T_ENTRY_ITERATE(t->entries + TABLE_OFFSET(t, cpu),
> t->size,
>@@ -1153,7 +1155,8 @@ do_replace(void __user *user, unsigned i
> return -ENOMEM;
>
> newinfo = vmalloc(sizeof(struct ip6t_table_info)
>- + SMP_ALIGN(tmp.size) * num_possible_cpus());
>+ + SMP_ALIGN(tmp.size) *
>+ (highest_possible_processor_id()+1));
> if (!newinfo)
> return -ENOMEM;
>
>@@ -1467,7 +1470,8 @@ int ip6t_register_table(struct ip6t_tabl
> = { 0, 0, 0, { 0 }, { 0 }, { } };
>
> newinfo = vmalloc(sizeof(struct ip6t_table_info)
>- + SMP_ALIGN(repl->size) * num_possible_cpus());
>+ + SMP_ALIGN(repl->size) *
>+ (highest_possible_processor_id()+1));
> if (!newinfo)
> return -ENOMEM;
>
>
>
On sparc64, cpu_possible_map does not exist.
You have either
cpu_online_map
or
phys_cpu_present_map.
Seb
next prev parent reply other threads:[~2005-10-11 21:54 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=434C3485.2000700@frankengul.org \
--to=seb@frankengul.org \
--cc=bdschuym@pandora.be \
--cc=davem@davemloft.net \
--cc=laforge@netfilter.org \
--cc=netfilter-devel@lists.netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.