All of lore.kernel.org
 help / color / mirror / Atom feed
From: Glauber de Oliveira Costa <gcosta@redhat.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: xen-devel@lists.xensource.com
Subject: Re: [PATCH] Unmatched decrementing of net device reference	count
Date: Wed, 20 Dec 2006 11:21:51 -0200	[thread overview]
Message-ID: <20061220132151.GA7900@redhat.com> (raw)
In-Reply-To: <E1Gwoqk-00051M-00@gondolin.me.apana.org.au>

On Wed, Dec 20, 2006 at 10:58:22AM +1100, Herbert Xu wrote:
> Glauber de Oliveira Costa <gcosta@redhat.com> wrote:
> > 
> > This bug was found when heavy stressing the netfront 
> > attach/detach mechanism with the following script:
> > 
> >   for i in $(seq 200); 
> >   do 
> >     xm network-attach <domid>;  
> >     xm network-detach <domid> $i;
> >   done
> > 
> > Guest kernel shows the following messages:
> > 
> > unregister_netdevice: waiting for eth1 to become free. Usage count = -1
> > 
> > After this patch, it ran okay in multiple iterations
> 
> Could you please use in-line patches? It's much easier to comment on.
It is. I could swear I inlined it, but maybe I forgot.
 
> Your patch description doesn't make sense.  unregister_netdev()
> cannot possibly cause the device to be freed.  Otherwise the
> subsequent free_netdev() call which you kept would be wrong.

In fact. I read it again, and it was confusing (I myself was confused).

I'll try to rephrase: ( I digged more, cleared things up, and it'll be
more precise now)

unregister_netdev() works as a barrier in this case. The call to
netif_disconnect_backend() introduces a new carrier watch, which hold()s a
reference to be put()'d in a future time. If we call free right after that, 
it might be the case that put() is called after free. Nothing in this
case prevents this memory region to have been allocated again to another
device. 

unregister_netdev() holds the rntl lock. It means that when the lock is
released, netdev_run_todo() (which is setup by unregister_netdev()
itself, with net_set_todo() ), will call netdev_wait_allrefs(), which 
takes care of the linkwatch_runqueue. Calling unregister_netdev()
between the carrier watch and free_netdev() guarantees that the device
will be only free'd when the watches were already handled.

There would most probably be other ways to guarantee that, such as,
calling linkwatch_runqueue() directly. But I think that we lose nothing
by calling unregister_netdev() in the middle, and gain serialization for
free. 


> So most likely what's happening is that free_netdev() is occuring
> without a preceding unregister_netdev(), which implies that there
> is a bug in the frontend state transition.

It is not the case, see above.
 
-- 
Glauber de Oliveira Costa
Red Hat Inc.
"Free as in Freedom"

  reply	other threads:[~2006-12-20 13:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-19 15:37 [PATCH] Unmatched decrementing of net device reference count Glauber de Oliveira Costa
2006-12-19 23:58 ` Herbert Xu
2006-12-20 13:21   ` Glauber de Oliveira Costa [this message]
2006-12-21  8:49     ` Herbert Xu
2006-12-21 11:03       ` Keir Fraser
2006-12-21 12:40         ` Herbert Xu
2006-12-21 13:02           ` Glauber de Oliveira Costa

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=20061220132151.GA7900@redhat.com \
    --to=gcosta@redhat.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=xen-devel@lists.xensource.com \
    /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.