From patchwork Thu Apr 2 20:12:45 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ingo Molnar X-Patchwork-Id: 25542 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id 0CD56DDD1B for ; Fri, 3 Apr 2009 07:13:18 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762920AbZDBUNM (ORCPT ); Thu, 2 Apr 2009 16:13:12 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1757831AbZDBUNJ (ORCPT ); Thu, 2 Apr 2009 16:13:09 -0400 Received: from mx2.mail.elte.hu ([157.181.151.9]:39903 "EHLO mx2.mail.elte.hu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756653AbZDBUNF (ORCPT ); Thu, 2 Apr 2009 16:13:05 -0400 Received: from elvis.elte.hu ([157.181.1.14]) by mx2.mail.elte.hu with esmtp (Exim) id 1LpTHM-0005hr-O5 from ; Thu, 02 Apr 2009 22:12:54 +0200 Received: by elvis.elte.hu (Postfix, from userid 1004) id F3D9F3E2138; Thu, 2 Apr 2009 22:12:45 +0200 (CEST) Date: Thu, 2 Apr 2009 22:12:45 +0200 From: Ingo Molnar To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter@vger.kernel.org, "Paul E. McKenney" , Stephen Hemminger Cc: Eric Dumazet , "David S. Miller" , Patrick McHardy , Rusty Russell , coreteam@netfilter.org Subject: [PATCH] netfilter: iptables: lock free counters, PREEMPT_RCU=y fix Message-ID: <20090402201245.GA29904@elte.hu> References: <20090402200128.GA21805@elte.hu> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20090402200128.GA21805@elte.hu> User-Agent: Mutt/1.5.18 (2008-05-17) Received-SPF: neutral (mx2: 157.181.1.14 is neither permitted nor denied by domain of elte.hu) client-ip=157.181.1.14; envelope-from=mingo@elte.hu; helo=elvis.elte.hu; X-ELTE-VirusStatus: clean X-ELTE-SpamScore: -1.5 X-ELTE-SpamLevel: X-ELTE-SpamCheck: no X-ELTE-SpamVersion: ELTE 2.0 X-ELTE-SpamCheck-Details: score=-1.5 required=5.9 tests=BAYES_00 autolearn=no SpamAssassin version=3.2.3 -1.5 BAYES_00 BODY: Bayesian spam probability is 0 to 1% [score: 0.0000] Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Impact: fix log spam under CONFIG_DEBUG_PREEMPT=y This recent commit: 7845447: netfilter: iptables: lock free counters Converted a couple of netfilter codepaths from read_lock() critical sections to lockless rcu_read_lock(). What it forgot about is that under CONFIG_PREEMPT=y and CONFIG_PREEMPT_RCU=y these sections can be preempted. Under CONFIG_DEBUG_PREEMPT=y this produces such warnings: BUG: using smp_processor_id() in preemptible [00000000] code: ssh/9115 caller is ipt_do_table+0xc8/0x559 Pid: 9115, comm: ssh Tainted: G W 2.6.29-tip-08646-g45ef7c3-dirty #26231 Call Trace: [] ? printk+0x14/0x16 [] debug_smp_processor_id+0xa6/0xbc [] ipt_do_table+0xc8/0x559 [] ? _read_unlock+0x3d/0x49 [] ? fn_hash_lookup+0x94/0xa0 [] ? __inet_dev_addr_type+0x56/0x8d [] ? neigh_lookup+0xe5/0x108 [] ipt_local_hook+0x40/0x50 [] nf_iterate+0x34/0x80 [] ? dst_output+0x0/0x10 [] nf_hook_slow+0x47/0xa4 [] ? dst_output+0x0/0x10 [] __ip_local_out+0x78/0x7f [] ? dst_output+0x0/0x10 [] ip_local_out+0x10/0x20 [] ip_queue_xmit+0x2bc/0x332 [] ? __ip_route_output_key+0x112/0x77b [] ? local_bh_enable+0x10/0x12 [] ? tcp_connect+0x32a/0x3bb [] ? __inet_hash_nolisten+0x97/0xaf [] ? __copy_skb_header+0xe/0x13a [] ? tcp_connect+0x32a/0x3bb [] ? tcp_transmit_skb+0x5a5/0x61c [] tcp_transmit_skb+0x5e5/0x61c [] ? __alloc_skb+0x54/0x120 [] ? tcp_connect+0x20f/0x3bb [] tcp_connect+0x32a/0x3bb [] tcp_v4_connect+0x466/0x4be [] inet_stream_connect+0x8f/0x212 [] ? might_fault+0x75/0x77 [] ? copy_from_user+0x2f/0x117 BUG: using smp_processor_id() in preemptible [00000000] code: ssh/9114 Since it appears that the tables are RCU freed, and there are no non-preempt assumptions in the code, the using of raw_smp_processor_id() is safe. [ I also audited all of net/netfilter/*.c for smp_processor_id() use, and fixed all places that used them unsafely. ] Signed-off-by: Ingo Molnar --- net/ipv4/netfilter/arp_tables.c | 2 +- net/ipv4/netfilter/ip_tables.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c index 35c5f6a..30baf3e 100644 --- a/net/ipv4/netfilter/arp_tables.c +++ b/net/ipv4/netfilter/arp_tables.c @@ -255,7 +255,7 @@ unsigned int arpt_do_table(struct sk_buff *skb, rcu_read_lock(); private = rcu_dereference(table->private); - table_base = rcu_dereference(private->entries[smp_processor_id()]); + table_base = rcu_dereference(private->entries[raw_smp_processor_id()]); e = get_entry(table_base, private->hook_entry[hook]); back = get_entry(table_base, private->underflow[hook]); diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c index 82ee7c9..eff124e 100644 --- a/net/ipv4/netfilter/ip_tables.c +++ b/net/ipv4/netfilter/ip_tables.c @@ -280,7 +280,7 @@ static void trace_packet(struct sk_buff *skb, char *hookname, *chainname, *comment; unsigned int rulenum = 0; - table_base = (void *)private->entries[smp_processor_id()]; + table_base = (void *)private->entries[raw_smp_processor_id()]; root = get_entry(table_base, private->hook_entry[hook]); hookname = chainname = (char *)hooknames[hook]; @@ -341,7 +341,7 @@ ipt_do_table(struct sk_buff *skb, rcu_read_lock(); private = rcu_dereference(table->private); - table_base = rcu_dereference(private->entries[smp_processor_id()]); + table_base = rcu_dereference(private->entries[raw_smp_processor_id()]); e = get_entry(table_base, private->hook_entry[hook]);