Fix panic in virtnet_remove
Subsystems (3)
"Michael S. Tsirkin" <[email protected]> wrote on 07/17/2011 03:42:15 PM:
Quoted 4 lines
Quoted 3 lines
modprobe -r
virtio_netpanics infree_netdev()as the dev is already freed in the newly introducedvirtnet_free(commit3fa2a1df9094).
Quoted 8 lines
Good catch, thanks!
Quoted 2 lines
Since
virtnet_removedoesn'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_infothat is allocated as part of that structure.
You are right, the dev cannot be freed in the destructor.
Quoted 5 lines
Quoted 4 lines
I am removing the
free_netdevcall
invirtnet_removeinstead of invirtnet_free(which seems to be the right place to free the dev). Confirmed that the panic is fixed with this patch.
Quoted 7 lines
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 fromvirtnet_freetovirtnet_remove, and get rid ofvirtnet_freecompletely?
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)?
--- drivers/net/virtio_net.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/net/virtio_net.c +1 -9
@@ -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(strwhile (vi->pages)__free_pages (get_a_page (vi,GFP_KERNEL ),0 ); +free_percpu (vi->stats);free_netdev (vi->dev); }
Michael S. Tsirkin
maintainerQuoted 31 lines · Krishna Kumar
"Michael S. Tsirkin" <[email protected]> wrote on 07/17/2011 03:42:15 PM:
Quoted 4 lines
Quoted 3 lines
modprobe -r
virtio_netpanics infree_netdev()as the dev is already freed in the newly introducedvirtnet_free(commit3fa2a1df9094).Quoted 8 lines
Good catch, thanks!
Quoted 2 lines
Since
virtnet_removedoesn'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_infothat is allocated as part of that structure.You are right, the dev cannot be freed in the destructor.
Quoted 5 lines
Quoted 4 lines
I am removing the
free_netdevcall
invirtnet_removeinstead of invirtnet_free(which seems to be the right place to free the dev). Confirmed that the panic is fixed with this patch.Quoted 7 lines
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 fromvirtnet_freetovirtnet_remove, and get rid ofvirtnet_freecompletely?I see some other drivers doing that, e.g.
xennet_remove:
Quoted 8 lines
... free_percpu(info->stats); free_netdev(info->netdev); ...How about this patch (compile tested only)?
Signed-off-by Krishna Kumar <[email protected]>
This is what I had in mind. Pls test it and if OK resubmit with proper description etc.
Quoted 38 lines
--- drivers/net/virtio_net.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)diff -ruNp
org/drivers/net/virtio_net.cnew/drivers/net/virtio_net.cdrivers/net/virtio_net.c +1
-9@@ -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(strwhile (vi->pages)__free_pages (get_a_page (vi,GFP_KERNEL ),0 ); +free_percpu (vi->stats);free_netdev (vi->dev); }