netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Giacomo <delleceste@gmail.com>,
	linux-kernel@vger.kernel.org, netdev <netdev@vger.kernel.org>
Subject: Re: correct locking in softirq
Date: Fri, 27 Feb 2009 08:59:42 -0800	[thread overview]
Message-ID: <20090227165942.GC6758@linux.vnet.ibm.com> (raw)
In-Reply-To: <1235723346.4948.1352.camel@laptop>

On Fri, Feb 27, 2009 at 09:29:06AM +0100, Peter Zijlstra wrote:
> On Fri, 2009-02-27 at 08:54 +0100, Giacomo wrote:
> > Good morning
> > 
> > Harald Welte's "The journey of a packet through the Linux 2.6.10
> > network stack" article says that packet travelling inside
> > linux kernel 2.6 (the receive / input part) runs in softirq context.
> > 
> > Hooking with netfilter's hooks in a kernel module, i need to read for
> > each packet received a list of rules.
> > 
> > Since in input and prerouting hooks the context is softirq (perhaps
> > also in forward?), I need some read lock
> > feature.
> > 
> > I currently use RCU lists and, while reading lists I use
> > 
> > READ
> > 
> > read_lock_bh()
> > 
> > together with list_for_each_rcu()
> > 
> > When changing, or flushing, rules, I use
> > 
> > WRITE
> > 
> > spin_lock() + list_add_tail_rcu() (adding)
> > 
> > or spin_lock() + list_for_each_entry() (for listing and then freeing
> > with list_del_rcu() and call_rcu() )
> > 
> > The question is:
> > 
> > - is the read part above correct? - do I really need _bh()? or should
> > I use simply read_lock() ?
> > 
> > Thanks in advance
> 
> rcu_read_lock() + call_rcu() are correct, even from softirq context, and
> mandatory if anything is exposed to anything other than softirq context.
> 
> rcu_read_lock_bh() + call_rcu_bh() is usable IFF the data is only ever
> used from softirq.

If "softirq" also includes sections of local_bh_disable()ed code in
process context, also including irq-disabled code, agreed!

> The distinction between the two RCU variants is that the _bh variant can
> have a slightly faster quiescent cycle.

Especially when under heavy interrupt/softirq load.  If a given
CPU is totally consumed handling interrupts and softirqs in a
non-CONFIG_PREEMPT_RT kernel, then the call_rcu() variant might never
invoke its callback, while the call_rcu_bh() variant would still be
able to do so in a timely fashion.  The _bh() variant was inspired by
simulate DoS attacks, work by Robert Olsson and Dipankar Sarma.

							Thanx, Paul

      reply	other threads:[~2009-02-27 16:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <885896af0902262354v47ddf79ch3d62edaeb1e940bd@mail.gmail.com>
2009-02-27  8:29 ` correct locking in softirq Peter Zijlstra
2009-02-27 16:59   ` Paul E. McKenney [this message]

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=20090227165942.GC6758@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=delleceste@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=peterz@infradead.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).