All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Sven Eckelmann <sven.eckelmann@gmx.de>
Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.net,
	davem@davemloft.net
Subject: Re: [B.A.T.M.A.N.] [PATCHv4] net: Add batman-adv meshing protocol
Date: Tue, 7 Sep 2010 11:10:00 -0700	[thread overview]
Message-ID: <20100907181000.GF2448@linux.vnet.ibm.com> (raw)
In-Reply-To: <201009071956.54499.sven.eckelmann@gmx.de>

On Tue, Sep 07, 2010 at 07:56:53PM +0200, Sven Eckelmann wrote:
> Thanks for your comment. I removed the parts you don't refer to (makes it lot 
> easier to find the actual comment).

I guess I can always refer to the original to see the related code.  ;-)

> Paul E. McKenney wrote:
> > > +
> > > +#include <linux/if_arp.h>
> > > +
> > > +#define MIN(x, y) ((x) < (y) ? (x) : (y))
> > > +
> > > +struct batman_if *get_batman_if_by_netdev(struct net_device *net_dev)
> > > +{
> > > +     struct batman_if *batman_if;
> > > +
> > > +     rcu_read_lock();
> > > +     list_for_each_entry_rcu(batman_if, &if_list, list) {
> > > +             if (batman_if->net_dev == net_dev)
> > > +                     goto out;
> > > +     }
> > > +
> > > +     batman_if = NULL;
> > > +
> > > +out:
> > > +     rcu_read_unlock();
> > 
> > Here we are leaking an RCU-protected pointer outside of the RCU read-side
> > critical section.  Why is this safe?
> 
> First thing: Their is another rcu related problem with a call_rcu and the 
> missing explicit (so not done implizit by another function) synchronize_rcu 
> before the shutdown. This was fixed right after this patch was send for a 
> review... bad timing, but ok.

Fair enough!

> > Here is the sequence of events that I am concerned about:
> > 
> > 1.      CPU 0 executes the code above, obtains a pointer, and is about
> >         ready to return.
> > 
> > 2.      CPU 1 executes hardif_remove_interface(), and calls
> >         hardif_disable_interface(), which calls
> >         hardif_deactivate_interface(), which sets ->if_status to
> >         IF_INACTIVE.  Then hardif_disable_interface() sets ->if_status
> >         to IF_NOT_IN_USE.  Then hardif_remove_interface() frees
> >         the interface via call_rcu().
> > 
> > 3.      Of course, call_rcu() waits for an RCU grace period to elapse,
> >         but we are no longer in an RCU read-side critical section,
> >         so there is nothing stopping the grace period from completing
> >         before we are done with the batman_if pointer.
> > 
> > Or am I missing some other interlock that prevents
> > hardif_remove_interface() from freeing this structure?
> > 
> > I have similar concerns with your other RCU read-side critical sections.
> 
> Looks to me like a valid point. I have to think a little bit how to solve it 
> correctly. Feel free to add more comments about other rcu cruelties in it.

One approach would be to extend the RCU read-side critical section to
cover all uses of the RCU-protected pointer.  Another approach would be
to take a reference count (or something similar) before the pointer
leaves the RCU read-side critical section.

Could you please take a look at Documentation/RCU/checklist.txt?

Because I am not familiar with the BATMAN device, it is all too easy
for me to miss subtleties in the code.

							Thanx, Paul

WARNING: multiple messages have this Message-ID (diff)
From: "Paul E. McKenney" <paulmck-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
To: Sven Eckelmann <sven.eckelmann-Mmb7MZpHnFY@public.gmane.org>
Cc: netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	b.a.t.m.a.n-ZwoEplunGu2X36UT3dwlltHuzzzSOjJt@public.gmane.org,
	davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org
Subject: Re: [PATCHv4] net: Add batman-adv meshing protocol
Date: Tue, 7 Sep 2010 11:10:00 -0700	[thread overview]
Message-ID: <20100907181000.GF2448@linux.vnet.ibm.com> (raw)
In-Reply-To: <201009071956.54499.sven.eckelmann-Mmb7MZpHnFY@public.gmane.org>

On Tue, Sep 07, 2010 at 07:56:53PM +0200, Sven Eckelmann wrote:
> Thanks for your comment. I removed the parts you don't refer to (makes it lot 
> easier to find the actual comment).

I guess I can always refer to the original to see the related code.  ;-)

> Paul E. McKenney wrote:
> > > +
> > > +#include <linux/if_arp.h>
> > > +
> > > +#define MIN(x, y) ((x) < (y) ? (x) : (y))
> > > +
> > > +struct batman_if *get_batman_if_by_netdev(struct net_device *net_dev)
> > > +{
> > > +     struct batman_if *batman_if;
> > > +
> > > +     rcu_read_lock();
> > > +     list_for_each_entry_rcu(batman_if, &if_list, list) {
> > > +             if (batman_if->net_dev == net_dev)
> > > +                     goto out;
> > > +     }
> > > +
> > > +     batman_if = NULL;
> > > +
> > > +out:
> > > +     rcu_read_unlock();
> > 
> > Here we are leaking an RCU-protected pointer outside of the RCU read-side
> > critical section.  Why is this safe?
> 
> First thing: Their is another rcu related problem with a call_rcu and the 
> missing explicit (so not done implizit by another function) synchronize_rcu 
> before the shutdown. This was fixed right after this patch was send for a 
> review... bad timing, but ok.

Fair enough!

> > Here is the sequence of events that I am concerned about:
> > 
> > 1.      CPU 0 executes the code above, obtains a pointer, and is about
> >         ready to return.
> > 
> > 2.      CPU 1 executes hardif_remove_interface(), and calls
> >         hardif_disable_interface(), which calls
> >         hardif_deactivate_interface(), which sets ->if_status to
> >         IF_INACTIVE.  Then hardif_disable_interface() sets ->if_status
> >         to IF_NOT_IN_USE.  Then hardif_remove_interface() frees
> >         the interface via call_rcu().
> > 
> > 3.      Of course, call_rcu() waits for an RCU grace period to elapse,
> >         but we are no longer in an RCU read-side critical section,
> >         so there is nothing stopping the grace period from completing
> >         before we are done with the batman_if pointer.
> > 
> > Or am I missing some other interlock that prevents
> > hardif_remove_interface() from freeing this structure?
> > 
> > I have similar concerns with your other RCU read-side critical sections.
> 
> Looks to me like a valid point. I have to think a little bit how to solve it 
> correctly. Feel free to add more comments about other rcu cruelties in it.

One approach would be to extend the RCU read-side critical section to
cover all uses of the RCU-protected pointer.  Another approach would be
to take a reference count (or something similar) before the pointer
leaves the RCU read-side critical section.

Could you please take a look at Documentation/RCU/checklist.txt?

Because I am not familiar with the BATMAN device, it is all too easy
for me to miss subtleties in the code.

							Thanx, Paul

  reply	other threads:[~2010-09-07 18:10 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-05  0:25 [B.A.T.M.A.N.] [PATCHv4] net: Add batman-adv meshing protocol Sven Eckelmann
2010-09-05  0:25 ` Sven Eckelmann
2010-09-07 17:19 ` [B.A.T.M.A.N.] " Paul E. McKenney
2010-09-07 17:19   ` Paul E. McKenney
2010-09-07 17:56   ` [B.A.T.M.A.N.] " Sven Eckelmann
2010-09-07 17:56     ` Sven Eckelmann
2010-09-07 18:10     ` Paul E. McKenney [this message]
2010-09-07 18:10       ` Paul E. McKenney
2010-09-07 18:24       ` [B.A.T.M.A.N.] " Sven Eckelmann
2010-09-07 18:24         ` Sven Eckelmann
2010-09-08  7:14 ` [B.A.T.M.A.N.] " Andi Kleen
2010-09-08  7:14   ` Andi Kleen
2010-09-08  9:42   ` [B.A.T.M.A.N.] " Sven Eckelmann
2010-09-08  9:42     ` Sven Eckelmann
2010-09-08 18:22     ` [B.A.T.M.A.N.] " Jesse Gross
2010-09-08 18:22       ` Jesse Gross
2010-09-08 18:58       ` [B.A.T.M.A.N.] " Sven Eckelmann
2010-09-08 18:58         ` Sven Eckelmann
2010-09-08 19:54         ` [B.A.T.M.A.N.] " Jesse Gross
2010-09-08 19:54           ` Jesse Gross
2010-09-08 20:25           ` [B.A.T.M.A.N.] " Sven Eckelmann
2010-09-08 20:25             ` Sven Eckelmann
2010-09-08 20:42             ` [B.A.T.M.A.N.] " Sven Eckelmann
2010-09-08 20:42               ` Sven Eckelmann
2010-09-08 23:13             ` [B.A.T.M.A.N.] " Justin Pettit
2010-09-08 23:13               ` Justin Pettit
2010-09-08 23:37             ` [B.A.T.M.A.N.] " Jesse Gross
2010-09-08 23:37               ` Jesse Gross
2010-09-14 19:21               ` [B.A.T.M.A.N.] " Simon Wunderlich
2010-09-14 19:21                 ` Simon Wunderlich
2010-09-08 19:12       ` [B.A.T.M.A.N.] " Marek Lindner
2010-09-08 19:12         ` Marek Lindner
2010-09-08 20:07         ` [B.A.T.M.A.N.] " Jesse Gross
2010-09-08 20:07           ` Jesse Gross

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=20100907181000.GF2448@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=b.a.t.m.a.n@lists.open-mesh.net \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=sven.eckelmann@gmx.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.