lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 27 Feb 2009 09:29:06 +0100
From:	Peter Zijlstra <peterz@...radead.org>
To:	Giacomo <delleceste@...il.com>
Cc:	linux-kernel@...r.kernel.org, netdev <netdev@...r.kernel.org>,
	"Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>
Subject: Re: correct locking in softirq

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.

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

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ