From: "Michael S. Tsirkin" <mst@redhat.com>
To: Krishna Kumar <krkumar2@in.ibm.com>
Cc: netdev@vger.kernel.org, shemminger@vyatta.com, davem@davemloft.net
Subject: Re: [PATCH] Fix panic in virtnet_remove
Date: Mon, 18 Jul 2011 16:03:59 +0300 [thread overview]
Message-ID: <20110718130359.GB6287@redhat.com> (raw)
In-Reply-To: <20110718035730.16001.77240.sendpatchset@krkumar2.in.ibm.com>
On Mon, Jul 18, 2011 at 09:27:30AM +0530, Krishna Kumar wrote:
> "Michael S. Tsirkin" <mst@redhat.com> wrote on 07/17/2011 03:42:15 PM:
>
> > > modprobe -r virtio_net panics in free_netdev() as the
> > > dev is already freed in the newly introduced virtnet_free
> > > (commit 3fa2a1df9094).
> >
> > Good catch, thanks!
> >
> > > Since virtnet_remove doesn't require
> > > dev after unregister,
> >
> > I'm not sure that true: vi used just above the line you remove
> > is I think the struct virtnet_info that is allocated
> > as part of that structure.
>
> You are right, the dev cannot be freed in the destructor.
>
> > > I am removing the free_netdev call
> > > in virtnet_remove instead of in virtnet_free (which seems
> > > to be the right place to free the dev). Confirmed that
> > > the panic is fixed with this patch.
> >
> > This might be just because the memory isn't reused.
> > Try enabling slab poisoning, I think you'll observe some problems.
> >
> > Do we absolutely have to have a destructor?
> > Can't we move the per cpu counter free from
> > virtnet_free to virtnet_remove, and get rid of
> > virtnet_free completely?
>
> I see some other drivers doing that, e.g. xennet_remove:
> ...
> free_percpu(info->stats);
> free_netdev(info->netdev);
> ...
>
> How about this patch (compile tested only)?
>
> Signed-off-by: Krishna Kumar <krkumar2@in.ibm.com>
This is what I had in mind. Pls test it and if OK resubmit
with proper description etc.
> ---
> drivers/net/virtio_net.c | 10 +---------
> 1 file changed, 1 insertion(+), 9 deletions(-)
>
> diff -ruNp org/drivers/net/virtio_net.c new/drivers/net/virtio_net.c
> --- org/drivers/net/virtio_net.c 2011-07-18 09:14:02.000000000 +0530
> +++ new/drivers/net/virtio_net.c 2011-07-18 09:16:35.000000000 +0530
> @@ -705,14 +705,6 @@ static void virtnet_netpoll(struct net_d
> }
> #endif
>
> -static void virtnet_free(struct net_device *dev)
> -{
> - struct virtnet_info *vi = netdev_priv(dev);
> -
> - free_percpu(vi->stats);
> - free_netdev(dev);
> -}
> -
> static int virtnet_open(struct net_device *dev)
> {
> struct virtnet_info *vi = netdev_priv(dev);
> @@ -959,7 +951,6 @@ static int virtnet_probe(struct virtio_d
> /* Set up network device as normal. */
> dev->netdev_ops = &virtnet_netdev;
> dev->features = NETIF_F_HIGHDMA;
> - dev->destructor = virtnet_free;
>
> SET_ETHTOOL_OPS(dev, &virtnet_ethtool_ops);
> SET_NETDEV_DEV(dev, &vdev->dev);
> @@ -1122,6 +1113,7 @@ static void __devexit virtnet_remove(str
> while (vi->pages)
> __free_pages(get_a_page(vi, GFP_KERNEL), 0);
>
> + free_percpu(vi->stats);
> free_netdev(vi->dev);
> }
>
next prev parent reply other threads:[~2011-07-18 13:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-18 3:57 [PATCH] Fix panic in virtnet_remove Krishna Kumar
2011-07-18 13:03 ` Michael S. Tsirkin [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-07-20 7:43 Krishna Kumar
2011-07-20 15:17 ` Stephen Hemminger
2011-07-15 9:16 Krishna Kumar
2011-07-15 15:19 ` David Miller
2011-07-16 5:32 ` Krishna Kumar2
2011-07-17 10:12 ` Michael S. Tsirkin
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=20110718130359.GB6287@redhat.com \
--to=mst@redhat.com \
--cc=davem@davemloft.net \
--cc=krkumar2@in.ibm.com \
--cc=netdev@vger.kernel.org \
--cc=shemminger@vyatta.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 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).