Skip to contentSkip to conversation

virtio-net: correct error handling of virtqueue_kick()

PATCH In review Jason Wang 3 participants 3 messages Mar 26, 2014 – Mar 27, 2014

Subsystems (4)
lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH 1/1 virtio-net: correct error handling of virtqueue_kick()

Current error handling of virtqueue_kick() was wrong in two places:
- The skb were freed immediately when virtqueue_kick() fail during xmit. This may lead double free since the skb was not detached from the virtqueue.
- try_fill_recv() returns false when virtqueue_kick() fail. This will lead unnecessary rescheduling of refill work.

Actually, it's safe to just ignore the kick failure in those two places. So this patch fixes this by partially revert commit 67975901183799af8e93ec60e322f9e2a1940b9b.

Fixes 67975901183799af8e93ec60e322f9e2a1940b9b (virtio_net: verify if virtqueue_kick() succeeded).

Cc Heinz Graalfs <[email protected]>
Cc Rusty Russell <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
---
 drivers/net/virtio_net.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/virtio_net.c +3 -3
index 5632a99..841b608 100644
@@ -671,8 +671,7 @@ static bool try_fill_recv(struct receive_queue *rq, gfp_t gfp)
 		if (err)
 			break;
 	} while (rq->vq->num_free);
-	if (unlikely(!virtqueue_kick(rq->vq)))
-		return false;
+	virtqueue_kick(rq->vq);
 	return !oom;
 }
 
@@ -877,7 +876,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
 	err = xmit_skb(sq, skb);
 
 	/* This should not happen! */
-	if (unlikely(err) || unlikely(!virtqueue_kick(sq->vq))) {
+	if (unlikely(err)) {
 		dev->stats.tx_fifo_errors++;
 		if (net_ratelimit())
 			dev_warn(&dev->dev,
@@ -886,6 +885,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
 		kfree_skb(skb);
 		return NETDEV_TX_OK;
 	}
+	virtqueue_kick(sq->vq);
 
 	/* Don't wait up for transmitted skbs to be freed. */
 	skb_orphan(skb);
Signature · 1 line
1.7.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Jason Wang

Current error handling of virtqueue_kick() was wrong in two places:
- The skb were freed immediately when virtqueue_kick() fail during xmit. This may lead double free since the skb was not detached from the virtqueue.
- try_fill_recv() returns false when virtqueue_kick() fail. This will lead unnecessary rescheduling of refill work.

Actually, it's safe to just ignore the kick failure in those two places. So this patch fixes this by partially revert commit 67975901183799af8e93ec60e322f9e2a1940b9b.

Quoted 7 lines

Fixes 67975901183799af8e93ec60e322f9e2a1940b9b (virtio_net: verify if virtqueue_kick() succeeded).

Cc Heinz Graalfs <[email protected]>
Cc Rusty Russell <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
Quoted 37 lines
---
 drivers/net/virtio_net.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/virtio_net.c +3 -3
index 5632a99..841b608 100644
@@ -671,8 +671,7 @@ static bool try_fill_recv(struct receive_queue *rq, gfp_t gfp)
 		if (err)
 			break;
 	} while (rq->vq->num_free);
-	if (unlikely(!virtqueue_kick(rq->vq)))
-		return false;
+	virtqueue_kick(rq->vq);
 	return !oom;
 }
 
@@ -877,7 +876,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
 	err = xmit_skb(sq, skb);
 
 	/* This should not happen! */
-	if (unlikely(err) || unlikely(!virtqueue_kick(sq->vq))) {
+	if (unlikely(err)) {
 		dev->stats.tx_fifo_errors++;
 		if (net_ratelimit())
 			dev_warn(&dev->dev,
@@ -886,6 +885,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
 		kfree_skb(skb);
 		return NETDEV_TX_OK;
 	}
+	virtqueue_kick(sq->vq);
 
 	/* Don't wait up for transmitted skbs to be freed. */
 	skb_orphan(skb);
Signature · 1 line
1.7.1
maintainer
#2 lore raw
In reply to Jason Wang

From: Jason Wang <[email protected]>
Date: Wed, 26 Mar 2014 13:03:00 +0800

Quoted 11 lines

Current error handling of virtqueue_kick() was wrong in two places:
- The skb were freed immediately when virtqueue_kick() fail during xmit. This may lead double free since the skb was not detached from the virtqueue.
- try_fill_recv() returns false when virtqueue_kick() fail. This will lead unnecessary rescheduling of refill work.

Actually, it's safe to just ignore the kick failure in those two places. So this patch fixes this by partially revert commit 67975901183799af8e93ec60e322f9e2a1940b9b.

Quoted 7 lines

Fixes 67975901183799af8e93ec60e322f9e2a1940b9b (virtio_net: verify if virtqueue_kick() succeeded).

Cc Heinz Graalfs <[email protected]>
Cc Rusty Russell <[email protected]>
Cc Michael S. Tsirkin <[email protected]>

Applied and queued up for -stable, thanks.