From: Eric Dumazet <dada1@cosmosbay.com>
To: "David S. Miller" <davem@davemloft.net>,
Harald Welte <laforge@netfilter.org>,
kaber@trash.net, Andrew Morton <akpm@osdl.org>
Cc: netdev@vger.kernel.org, netfilter-devel@lists.netfilter.org
Subject: [PATCH (resent with the attachment !)] netfilter : zap get_cpu()/put_cpu() calls from ip_tables
Date: Fri, 25 Nov 2005 12:28:47 +0100 [thread overview]
Message-ID: <4386F56F.7020205@cosmosbay.com> (raw)
In-Reply-To: <4386F440.5020505@cosmosbay.com>
[-- Attachment #1: Type: text/plain, Size: 677 bytes --]
The 'ip_tables: NUMA-aware allocation' patch
(http://www.kernel.org/git/?p=linux/kernel/git/davem/net-2.6.16.git;a=commit;h=6d1273850cac8db77c462caaa145b813d93adc55)
introduced a problem with get_cpu()/put_cpu()
The problem is that get_cpu() disables preemption and the thread is not
allowed to sleep.
As the intent was only to give a hint, relax the enforcement and switch to a
hint : If the current thread is preempted and migrated to another cpu, this is
not a problem. Most of the time, thread wont be migrated anyway.
This patch removes get_cpu()/put_cpu() pairs and uses raw_smp_processor_id()
were appropriate.
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
[-- Attachment #2: zap_getput_cpu.patch --]
[-- Type: text/plain, Size: 9865 bytes --]
--- net-2.6.16-orig/net/ipv4/netfilter/ip_tables.c 2005-11-25 10:24:02.000000000 +0100
+++ net-2.6.16/net/ipv4/netfilter/ip_tables.c 2005-11-25 11:44:40.000000000 +0100
@@ -988,11 +988,14 @@
{
unsigned int cpu;
unsigned int i;
- unsigned int curcpu = get_cpu();
+ unsigned int curcpu;
/* Instead of clearing (by a previous call to memset())
* the counters and using adds, we set the counters
- * with data used by current CPU */
+ * with data used by 'current' CPU
+ * We dont care about preemption here.
+ */
+ curcpu = raw_smp_processor_id();
i = 0;
IPT_ENTRY_ITERATE(t->entries[curcpu],
@@ -1011,7 +1014,6 @@
counters,
&i);
}
- put_cpu();
}
static int
@@ -1029,7 +1031,7 @@
(other than comefrom, which userspace doesn't care
about). */
countersize = sizeof(struct ipt_counters) * table->private->number;
- counters = vmalloc(countersize);
+ counters = vmalloc_node(countersize, numa_node_id());
if (counters == NULL)
return -ENOMEM;
@@ -1039,8 +1041,11 @@
get_counters(table->private, counters);
write_unlock_bh(&table->lock);
- /* choose the copy that is on our node/cpu, ... */
- loc_cpu_entry = table->private->entries[get_cpu()];
+ /* choose the copy that is on our node/cpu, ...
+ * This choice is lazy (because current thread is
+ * allowed to migrate to another cpu)
+ */
+ loc_cpu_entry = table->private->entries[raw_smp_processor_id()];
/* ... then copy entire thing ... */
if (copy_to_user(userptr, loc_cpu_entry, total_size) != 0) {
ret = -EFAULT;
@@ -1091,7 +1096,6 @@
}
free_counters:
- put_cpu();
vfree(counters);
return ret;
}
@@ -1189,7 +1193,7 @@
return -ENOMEM;
/* choose the copy that is our node/cpu */
- loc_cpu_entry = newinfo->entries[get_cpu()];
+ loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
if (copy_from_user(loc_cpu_entry, user + sizeof(tmp),
tmp.size) != 0) {
ret = -EFAULT;
@@ -1242,9 +1246,8 @@
/* Get the old counters. */
get_counters(oldinfo, counters);
/* Decrease module usage counts and free resource */
- loc_cpu_old_entry = oldinfo->entries[smp_processor_id()];
+ loc_cpu_old_entry = oldinfo->entries[raw_smp_processor_id()];
IPT_ENTRY_ITERATE(loc_cpu_old_entry, oldinfo->size, cleanup_entry,NULL);
- put_cpu();
free_table_info(oldinfo);
if (copy_to_user(tmp.counters, counters,
sizeof(struct ipt_counters) * tmp.num_counters) != 0)
@@ -1261,7 +1264,6 @@
free_newinfo_counters:
vfree(counters);
free_newinfo:
- put_cpu();
free_table_info(newinfo);
return ret;
}
@@ -1303,7 +1305,7 @@
if (len != sizeof(tmp) + tmp.num_counters*sizeof(struct ipt_counters))
return -EINVAL;
- paddc = vmalloc(len);
+ paddc = vmalloc_node(len, numa_node_id());
if (!paddc)
return -ENOMEM;
@@ -1326,7 +1328,7 @@
i = 0;
/* Choose the copy that is on our node */
- loc_cpu_entry = t->private->entries[smp_processor_id()];
+ loc_cpu_entry = t->private->entries[raw_smp_processor_id()];
IPT_ENTRY_ITERATE(loc_cpu_entry,
t->private->size,
add_counter_to_entry,
@@ -1525,8 +1527,10 @@
if (!newinfo)
return -ENOMEM;
- /* choose the copy on our node/cpu */
- loc_cpu_entry = newinfo->entries[get_cpu()];
+ /* choose the copy on our node/cpu
+ * but dont care of preemption
+ */
+ loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
memcpy(loc_cpu_entry, repl->entries, repl->size);
ret = translate_table(table->name, table->valid_hooks,
@@ -1534,7 +1538,6 @@
repl->num_entries,
repl->hook_entry,
repl->underflow);
- put_cpu();
if (ret != 0) {
free_table_info(newinfo);
return ret;
@@ -1584,10 +1587,9 @@
up(&ipt_mutex);
/* Decrease module usage counts and free resources */
- loc_cpu_entry = table->private->entries[get_cpu()];
+ loc_cpu_entry = table->private->entries[raw_smp_processor_id()];
IPT_ENTRY_ITERATE(loc_cpu_entry, table->private->size,
cleanup_entry, NULL);
- put_cpu();
free_table_info(table->private);
}
--- net-2.6.16-orig/net/ipv6/netfilter/ip6_tables.c 2005-11-25 10:24:02.000000000 +0100
+++ net-2.6.16/net/ipv6/netfilter/ip6_tables.c 2005-11-25 11:23:03.000000000 +0100
@@ -1074,11 +1074,14 @@
{
unsigned int cpu;
unsigned int i;
- unsigned int curcpu = get_cpu();
+ unsigned int curcpu;
/* Instead of clearing (by a previous call to memset())
* the counters and using adds, we set the counters
- * with data used by current CPU */
+ * with data used by 'current' CPU
+ * We dont care about preemption here.
+ */
+ curcpu = raw_smp_processor_id();
i = 0;
IP6T_ENTRY_ITERATE(t->entries[curcpu],
@@ -1097,7 +1100,6 @@
counters,
&i);
}
- put_cpu();
}
static int
@@ -1126,7 +1128,7 @@
write_unlock_bh(&table->lock);
/* choose the copy that is on ourc node/cpu */
- loc_cpu_entry = table->private->entries[get_cpu()];
+ loc_cpu_entry = table->private->entries[raw_smp_processor_id()];
if (copy_to_user(userptr, loc_cpu_entry, total_size) != 0) {
ret = -EFAULT;
goto free_counters;
@@ -1176,7 +1178,6 @@
}
free_counters:
- put_cpu();
vfree(counters);
return ret;
}
@@ -1271,7 +1272,7 @@
return -ENOMEM;
/* choose the copy that is on our node/cpu */
- loc_cpu_entry = newinfo->entries[get_cpu()];
+ loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
if (copy_from_user(loc_cpu_entry, user + sizeof(tmp),
tmp.size) != 0) {
ret = -EFAULT;
@@ -1324,9 +1325,8 @@
/* Get the old counters. */
get_counters(oldinfo, counters);
/* Decrease module usage counts and free resource */
- loc_cpu_old_entry = oldinfo->entries[smp_processor_id()];
+ loc_cpu_old_entry = oldinfo->entries[raw_smp_processor_id()];
IP6T_ENTRY_ITERATE(loc_cpu_old_entry, oldinfo->size, cleanup_entry,NULL);
- put_cpu();
free_table_info(oldinfo);
if (copy_to_user(tmp.counters, counters,
sizeof(struct ip6t_counters) * tmp.num_counters) != 0)
@@ -1343,7 +1343,6 @@
free_newinfo_counters:
vfree(counters);
free_newinfo:
- put_cpu();
free_table_info(newinfo);
return ret;
}
@@ -1609,7 +1608,7 @@
return -ENOMEM;
/* choose the copy on our node/cpu */
- loc_cpu_entry = newinfo->entries[get_cpu()];
+ loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
memcpy(loc_cpu_entry, repl->entries, repl->size);
ret = translate_table(table->name, table->valid_hooks,
@@ -1617,7 +1616,6 @@
repl->num_entries,
repl->hook_entry,
repl->underflow);
- put_cpu();
if (ret != 0) {
free_table_info(newinfo);
return ret;
@@ -1667,10 +1665,9 @@
up(&ip6t_mutex);
/* Decrease module usage counts and free resources */
- loc_cpu_entry = table->private->entries[get_cpu()];
+ loc_cpu_entry = table->private->entries[raw_smp_processor_id()];
IP6T_ENTRY_ITERATE(loc_cpu_entry, table->private->size,
cleanup_entry, NULL);
- put_cpu();
free_table_info(table->private);
}
--- net-2.6.16-orig/net/ipv4/netfilter/arp_tables.c 2005-11-25 10:24:02.000000000 +0100
+++ net-2.6.16/net/ipv4/netfilter/arp_tables.c 2005-11-25 11:15:50.000000000 +0100
@@ -814,11 +814,14 @@
{
unsigned int cpu;
unsigned int i;
- unsigned int curcpu = get_cpu();
+ unsigned int curcpu;
/* Instead of clearing (by a previous call to memset())
* the counters and using adds, we set the counters
- * with data used by current CPU */
+ * with data used by 'current' CPU
+ * We dont care about preemption here.
+ */
+ curcpu = raw_smp_processor_id();
i = 0;
ARPT_ENTRY_ITERATE(t->entries[curcpu],
@@ -837,7 +840,6 @@
counters,
&i);
}
- put_cpu();
}
static int copy_entries_to_user(unsigned int total_size,
@@ -865,7 +867,7 @@
get_counters(table->private, counters);
write_unlock_bh(&table->lock);
- loc_cpu_entry = table->private->entries[get_cpu()];
+ loc_cpu_entry = table->private->entries[raw_smp_processor_id()];
/* ... then copy entire thing ... */
if (copy_to_user(userptr, loc_cpu_entry, total_size) != 0) {
ret = -EFAULT;
@@ -898,7 +900,6 @@
}
free_counters:
- put_cpu();
vfree(counters);
return ret;
}
@@ -996,7 +997,7 @@
return -ENOMEM;
/* choose the copy that is on our node/cpu */
- loc_cpu_entry = newinfo->entries[get_cpu()];
+ loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
if (copy_from_user(loc_cpu_entry, user + sizeof(tmp),
tmp.size) != 0) {
ret = -EFAULT;
@@ -1049,9 +1050,9 @@
/* Get the old counters. */
get_counters(oldinfo, counters);
/* Decrease module usage counts and free resource */
- loc_cpu_old_entry = oldinfo->entries[smp_processor_id()];
+ loc_cpu_old_entry = oldinfo->entries[raw_smp_processor_id()];
ARPT_ENTRY_ITERATE(loc_cpu_old_entry, oldinfo->size, cleanup_entry,NULL);
- put_cpu();
+
free_table_info(oldinfo);
if (copy_to_user(tmp.counters, counters,
sizeof(struct arpt_counters) * tmp.num_counters) != 0)
@@ -1068,7 +1069,6 @@
free_newinfo_counters:
vfree(counters);
free_newinfo:
- put_cpu();
free_table_info(newinfo);
return ret;
}
@@ -1295,7 +1295,7 @@
}
/* choose the copy on our node/cpu */
- loc_cpu_entry = newinfo->entries[get_cpu()];
+ loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
memcpy(loc_cpu_entry, repl->entries, repl->size);
ret = translate_table(table->name, table->valid_hooks,
@@ -1303,7 +1303,6 @@
repl->num_entries,
repl->hook_entry,
repl->underflow);
- put_cpu();
duprintf("arpt_register_table: translate table gives %d\n", ret);
if (ret != 0) {
free_table_info(newinfo);
@@ -1354,10 +1353,9 @@
up(&arpt_mutex);
/* Decrease module usage counts and free resources */
- loc_cpu_entry = table->private->entries[get_cpu()];
+ loc_cpu_entry = table->private->entries[raw_smp_processor_id()];
ARPT_ENTRY_ITERATE(loc_cpu_entry, table->private->size,
cleanup_entry, NULL);
- put_cpu();
free_table_info(table->private);
}
next prev parent reply other threads:[~2005-11-25 11:28 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-19 17:09 [PATCH, netfilter] NUMA aware ipv4/netfilter/ip_tables.c Eric dumazet
2005-09-19 17:20 ` Eric Dumazet
2005-09-19 17:48 ` Andi Kleen
2005-09-19 19:09 ` Eric Dumazet
2005-09-20 9:47 ` Eric Dumazet
2005-09-20 16:30 ` Andi Kleen
2005-09-20 17:02 ` Eric Dumazet
2005-09-20 21:45 ` [PATCH] Adds sys_set_mempolicy() in include/linux/syscalls.h , " Eric Dumazet
2005-09-20 21:46 ` [PATCH] Adds sys_set_mempolicy() in include/linux/syscalls.h Eric Dumazet
2005-09-21 21:24 ` [PATCH 0/3] netfilter : 3 patches to boost ip_tables performance Eric Dumazet
2005-09-21 22:43 ` Christoph Lameter
2005-09-22 0:34 ` David S. Miller
2005-09-22 1:44 ` Christoph Lameter
2005-09-22 12:11 ` Eric Dumazet
2005-09-22 12:49 ` Christoph Hellwig
2005-09-22 12:54 ` Andi Kleen
2005-09-22 12:58 ` Christoph Hellwig
2005-09-22 13:05 ` Andi Kleen
2005-09-22 15:37 ` Christoph Lameter
2005-09-22 15:50 ` Eric Dumazet
2005-09-22 15:55 ` Christoph Lameter
2005-09-23 17:11 ` Harald Welte
2005-09-23 17:44 ` Christoph Lameter
2005-09-23 18:04 ` Dave Hansen
2005-09-23 17:47 ` Eric Dumazet
2005-09-23 18:00 ` Kyle Moffett
2005-09-22 4:18 ` James Morris
2005-09-22 5:07 ` Eric Dumazet
2005-09-22 13:03 ` Andi Kleen
2005-09-22 13:30 ` Eric Dumazet
2005-09-23 17:09 ` Harald Welte
2005-09-27 16:23 ` Andi Kleen
2005-09-28 0:25 ` Henrik Nordstrom
2005-09-28 8:32 ` Harald Welte
2005-09-28 8:37 ` Andi Kleen
2005-10-04 17:01 ` Patrick McHardy
2005-10-05 16:53 ` Andi Kleen
2005-10-07 2:38 ` Harald Welte
2005-10-06 17:59 ` Andi Kleen
2005-10-07 17:08 ` Patrick McHardy
2005-10-07 17:21 ` Andi Kleen
2005-10-07 17:50 ` Patrick McHardy
2005-09-28 10:34 ` Henrik Nordstrom
2005-11-25 11:23 ` [PATCH] netfilter : zap get_cpu()/put_cpu() calls from ip_tables Eric Dumazet
2005-11-25 11:28 ` Eric Dumazet [this message]
2005-11-25 18:20 ` [PATCH (resent with the attachment !)] " Patrick McHardy
2005-09-21 21:29 ` [PATCH 1/3] netfilter : 3 patches to boost ip_tables performance Eric Dumazet
2005-09-22 12:57 ` Harald Welte
2005-09-22 13:17 ` Eric Dumazet
2005-09-21 21:32 ` [PATCH 2/3] " Eric Dumazet
2005-09-22 12:48 ` Harald Welte
2005-09-22 13:05 ` Eric Dumazet
2005-09-23 4:02 ` Willy Tarreau
2005-09-23 5:14 ` Eric Dumazet
2005-09-23 11:33 ` Willy Tarreau
2005-09-23 14:00 ` Tim Mattox
2005-09-21 21:37 ` [PATCH 3/3] " Eric Dumazet
2005-09-22 12:50 ` 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=4386F56F.7020205@cosmosbay.com \
--to=dada1@cosmosbay.com \
--cc=akpm@osdl.org \
--cc=davem@davemloft.net \
--cc=kaber@trash.net \
--cc=laforge@netfilter.org \
--cc=netdev@vger.kernel.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 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).