lkml.org 
[lkml]   [2009]   [Apr]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] netfilter: use per-cpu spinlock rather than RCU


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


\
 
 \ /
  Last update: 2009-04-14 01:51    [W:0.590 / U:0.076 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site