Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753906AbZDMXrs (ORCPT ); Mon, 13 Apr 2009 19:47:48 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751482AbZDMXrj (ORCPT ); Mon, 13 Apr 2009 19:47:39 -0400 Received: from smtp1.linux-foundation.org ([140.211.169.13]:46682 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750747AbZDMXri (ORCPT ); Mon, 13 Apr 2009 19:47:38 -0400 Date: Mon, 13 Apr 2009 16:37:26 -0700 (PDT) From: Linus Torvalds X-X-Sender: torvalds@localhost.localdomain To: Andrew Morton cc: Stephen Hemminger , paulmck@linux.vnet.ibm.com, davem@davemloft.net, paulus@samba.org, mingo@elte.hu, laijs@cn.fujitsu.com, jeff.chua.linux@gmail.com, dada1@cosmosbay.com, jengelh@medozas.de, kaber@trash.net, r000n@r000n.net, linux-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org, netdev@vger.kernel.org, benh@kernel.crashing.org Subject: Re: [PATCH] netfilter: use per-cpu spinlock rather than RCU In-Reply-To: <20090413162620.01353461.akpm@linux-foundation.org> Message-ID: References: <20090411174801.GG6822@linux.vnet.ibm.com> <18913.53699.544083.320542@cargo.ozlabs.ibm.com> <20090412173108.GO6822@linux.vnet.ibm.com> <20090412.181330.23529546.davem@davemloft.net> <20090413040413.GQ6822@linux.vnet.ibm.com> <20090413095309.631cf395@nehalam> <20090413152437.c48723f6.akpm@linux-foundation.org> <20090413162000.5f8d9a05@nehalam> <20090413162620.01353461.akpm@linux-foundation.org> User-Agent: Alpine 2.00 (LFD 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1616 Lines: 47 On Mon, 13 Apr 2009, Andrew Morton wrote: > > > > > > > > - rcu_read_lock_bh(); > > > > - private = rcu_dereference(table->private); > > > > - table_base = rcu_dereference(private->entries[smp_processor_id()]); > > > > + local_bh_disable(); > > > > + spin_lock(&__get_cpu_var(ip_tables_lock)); > > > > > > spin_lock_bh()? > > > > No. get_cpu_var implies smp_processor_id which is not safe > > without preempt_disable (ie bh disable). > > spin_lock_bh() will dtrt, but spelling it out seems a good idea. No, spin_lock_bh() will _not_ do the right thing. On UP it will actually work for two reasons: it will work because (a) it's UP, so there are no issues with smp_processor_id() to beging with, but also because even if there _were_ issues, it would still work because it would all expand as a macro, and the preempt_disable() will actually happen before the argument is evaluated. But on SMP, spin_lock_bh() expands to just _spin_lock_bh(), and is a real function - and the argument will be evaluated before the call (obviously), and thus before the preempt_disable(). So local_bh_disable(); spin_lock(&__get_cpu_var(ip_tables_lock)); is correct, and spin_lock_bh(&__get_cpu_var(ip_tables_lock)); is _not_ correct. The latter will do "&__get_cpu_var(ip_tables_lock)" with no protection from the process being switched to another CPU. Linus -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/