From: Eric Dumazet <eric.dumazet@gmail.com>
To: Jiri Pirko <jiri@resnulli.us>
Cc: "Ivan Vecera" <ivecera@redhat.com>,
"Jiri Pirko" <jpirko@redhat.com>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Andy Gospodarek" <andy@greyhouse.net>,
"David S. Miller" <davem@davemloft.net>,
LKML <linux-kernel@vger.kernel.org>,
netdev <netdev@vger.kernel.org>,
"Nicolas de Pesloüan" <nicolas.2p.debian@gmail.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Guy Streeter" <streeter@redhat.com>,
"Paul E. McKenney" <paulmck@us.ibm.com>,
stephen@networkplumber.org
Subject: Re: [PATCH] net: add a synchronize_net() in netdev_rx_handler_unregister()
Date: Fri, 29 Mar 2013 09:46:00 -0700 [thread overview]
Message-ID: <1364575560.5113.45.camel@edumazet-glaptop> (raw)
In-Reply-To: <20130329161219.GA1668@minipsycho.orion>
On Fri, 2013-03-29 at 17:12 +0100, Jiri Pirko wrote:
> Fri, Mar 29, 2013 at 04:38:15PM CET, eric.dumazet@gmail.com wrote:
> >On Fri, 2013-03-29 at 16:11 +0100, Ivan Vecera wrote:
> >
> >> Erik, why doesn't help the write barrier between the assignments. It
> >> should guarantee their orders... or not?
> >>
> >
> >Its not enough, I wont explain here why as RCU is quite well documented
> >in Documentation/RCU
>
> Can you point me exact paragraph? I'm unable to find that :(
>
You need a bit of RCU history to understand the issue
rcu_assign_pointer(dev->rx_handler, NULL) is certainly not needing a
barrier _before_ setting rx_handler to NULL.
Old kernels had this rcu_assign_pointer() implementation since
commit d99c4f6b13b3149bc83703ab1493beaeaaaf8a2d
(Remove rcu_assign_pointer() penalty for NULL pointers)
#define rcu_assign_pointer(p, v) \
({ \
if (!__builtin_constant_p(v) || \
((v) != NULL)) \
smp_wmb(); \
(p) = (v); \
})
Note that wmb() was _not_ done if v was NULL
Because of various sparse issues, commit
d322f45ceed525daa9401154590bbae3222cfefb
(rcu: Make rcu_assign_pointer() unconditionally insert a memory barrier)
removed the conditional, because RCU_INIT_POINTER() was available.
In the rx_handler/rx_handler_data, we use two pointers protected by RCU,
but we want to only test rx_hander being NULL, and avoid testing
rx_handler_data.
Nothing in RCU guarantees that two different pointers have any order.
Here is what could happen
CPU0 CPU1
handler = rcu_dereference(dev->rx_handler)
if (handler) {
handler(dev, ...);
dev->rx_handler = NULL;
smp_wmb(); // OR NOT
dev->rx_handler_data = NULL;
smp_wmb(); // OR NOT
handler(dev)
priv_data = rcu_dereference(dev->rx_handler_data);
x = priv_data->some_field; // CRASH because priv_data is NULL
next prev parent reply other threads:[~2013-03-29 16:46 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-28 17:16 [BUG] Crash with NULL pointer dereference in bond_handle_frame in -rt (possibly mainline) Steven Rostedt
2013-03-28 17:29 ` Eric Dumazet
2013-03-28 17:44 ` Steven Rostedt
2013-03-29 9:48 ` Jiri Pirko
2013-03-29 13:01 ` [PATCH] net: add a synchronize_net() in netdev_rx_handler_unregister() Eric Dumazet
2013-03-29 13:17 ` Steven Rostedt
2013-03-29 13:38 ` Eric Dumazet
2013-03-29 15:11 ` Ivan Vecera
2013-03-29 15:38 ` Eric Dumazet
2013-03-29 16:12 ` Jiri Pirko
2013-03-29 16:46 ` Eric Dumazet [this message]
2013-03-29 19:20 ` Paul E. McKenney
2013-03-29 19:26 ` Eric Dumazet
2013-03-29 19:39 ` David Miller
2013-03-29 15:46 ` [BUG] Crash with NULL pointer dereference in bond_handle_frame in -rt (possibly mainline) Stephen Hemminger
2013-03-29 18:36 ` Steven Rostedt
2013-03-29 19:55 ` Steven Rostedt
2013-03-30 9:19 ` Jiri Pirko
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=1364575560.5113.45.camel@edumazet-glaptop \
--to=eric.dumazet@gmail.com \
--cc=andy@greyhouse.net \
--cc=davem@davemloft.net \
--cc=ivecera@redhat.com \
--cc=jiri@resnulli.us \
--cc=jpirko@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nicolas.2p.debian@gmail.com \
--cc=paulmck@us.ibm.com \
--cc=rostedt@goodmis.org \
--cc=stephen@networkplumber.org \
--cc=streeter@redhat.com \
--cc=tglx@linutronix.de \
/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