Skip to contentSkip to conversation

Fix panic in virtnet_remove

PATCH Applied Krishna Kumar 3 participants 5 messages Jul 20, 2011 – Jul 22, 2011

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix panic in virtnet_remove

Fix a panic in virtnet_remove. unregister_netdev has already freed up the netdev (and virtnet_info) due to dev->destructor being set, while virtnet_info is still required. Remove virtnet_free altogether, and move the freeing of the per-cpu statistics from virtnet_free to virtnet_remove.

Tested patch below.

---
(Michael suggested me to re-post with copy to all maintainers)

 drivers/net/virtio_net.c |   10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/net/virtio_net.c +1 -9
diff -ruNp org/drivers/net/virtio_net.c new/drivers/net/virtio_net.c
@@ -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);
 }
 
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Krishna Kumar

Fix a panic in virtnet_remove. unregister_netdev has already freed up the netdev (and virtnet_info) due to dev->destructor being set, while virtnet_info is still required. Remove virtnet_free altogether, and move the freeing of the per-cpu statistics from virtnet_free to virtnet_remove.

Tested patch below.

Also note that the crash was apparently introduced by 3fa2a1df909482cc234524906e4bd30dee3514df in net-next, so this is a net-next only patch.

Stephen, was there any special reason to free the memory in the destructor like you did?

Quoted 40 lines

---
(Michael suggested me to re-post with copy to all maintainers)

 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

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(str
 	while (vi->pages)
 		__free_pages(get_a_page(vi, GFP_KERNEL), 0);
 
+	free_percpu(vi->stats);
 	free_netdev(vi->dev);
 }
 
maintainer Applied
#2 lore raw

From: "Michael S. Tsirkin" <[email protected]>
Date: Wed, 20 Jul 2011 17:31:15 +0300

Quoted 11 lines · Krishna Kumar
Quoted 9 lines

Fix a panic in virtnet_remove. unregister_netdev has already freed up the netdev (and virtnet_info) due to dev->destructor being set, while virtnet_info is still required. Remove virtnet_free altogether, and move the freeing of the per-cpu statistics from virtnet_free to virtnet_remove.

Tested patch below.

Quoted 8 lines

Also note that the crash was apparently introduced by 3fa2a1df909482cc234524906e4bd30dee3514df in net-next, so this is a net-next only patch.

Stephen, was there any special reason to free the memory in the destructor like you did?

Applied.

maintainer Applied
#3 lore raw
In reply to Michael S. Tsirkin

From: "Michael S. Tsirkin" <[email protected]>
Date: Wed, 20 Jul 2011 17:31:15 +0300

Quoted 11 lines · Krishna Kumar
Quoted 9 lines

Fix a panic in virtnet_remove. unregister_netdev has already freed up the netdev (and virtnet_info) due to dev->destructor being set, while virtnet_info is still required. Remove virtnet_free altogether, and move the freeing of the per-cpu statistics from virtnet_free to virtnet_remove.

Tested patch below.

Quoted 8 lines

Also note that the crash was apparently introduced by 3fa2a1df909482cc234524906e4bd30dee3514df in net-next, so this is a net-next only patch.

Stephen, was there any special reason to free the memory in the destructor like you did?

Applied.

maintainer Acked-by on v1 1/1
#4 lore raw
In reply to Krishna Kumar
Quoted 9 lines · Krishna Kumar

Fix a panic in virtnet_remove. unregister_netdev has already freed up the netdev (and virtnet_info) due to dev->destructor being set, while virtnet_info is still required. Remove virtnet_free altogether, and move the freeing of the per-cpu statistics from virtnet_free to virtnet_remove.

Tested patch below.

Also note that the crash was apparently introduced by 3fa2a1df909482cc234524906e4bd30dee3514df in net-next, so this is a net-next only patch.

Stephen, was there any special reason to free the memory in the destructor like you did?

Quoted 40 lines

---
(Michael suggested me to re-post with copy to all maintainers)

 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

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(str
 	while (vi->pages)
 		__free_pages(get_a_page(vi, GFP_KERNEL), 0);
 
+	free_percpu(vi->stats);
 	free_netdev(vi->dev);
 }