netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] virtio: fix virtio_net xmit of freed skb bug
@ 2008-05-26  7:42 Rusty Russell
  2008-05-26  7:48 ` [PATCH 2/3] virtio: fix delayed xmit of packet and freeing of old packets Rusty Russell
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Rusty Russell @ 2008-05-26  7:42 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: netdev, virtualization

If we fail to transmit a packet, we assume the queue is full and put
the skb into last_xmit_skb.  However, if more space frees up before we
xmit it, we loop, and the result can be transmitting the same skb twice.

Fix is simple: set skb to NULL if we've used it in some way, and check
before sending.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 drivers/net/virtio_net.c |   14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff -r 564237b31993 drivers/net/virtio_net.c
--- a/drivers/net/virtio_net.c	Mon May 19 12:22:00 2008 +1000
+++ b/drivers/net/virtio_net.c	Mon May 19 12:24:58 2008 +1000
@@ -287,21 +287,25 @@ again:
 	free_old_xmit_skbs(vi);
 
 	/* If we has a buffer left over from last time, send it now. */
-	if (vi->last_xmit_skb) {
+	if (unlikely(vi->last_xmit_skb)) {
 		if (xmit_skb(vi, vi->last_xmit_skb) != 0) {
 			/* Drop this skb: we only queue one. */
 			vi->dev->stats.tx_dropped++;
 			kfree_skb(skb);
+			skb = NULL;
 			goto stop_queue;
 		}
 		vi->last_xmit_skb = NULL;
 	}
 
 	/* Put new one in send queue and do transmit */
-	__skb_queue_head(&vi->send, skb);
-	if (xmit_skb(vi, skb) != 0) {
-		vi->last_xmit_skb = skb;
-		goto stop_queue;
+	if (likely(skb)) {
+		__skb_queue_head(&vi->send, skb);
+		if (xmit_skb(vi, skb) != 0) {
+			vi->last_xmit_skb = skb;
+			skb = NULL;
+			goto stop_queue;
+		}
 	}
 done:
 	vi->svq->vq_ops->kick(vi->svq);

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2008-06-14  7:39 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-26  7:42 [PATCH 1/3] virtio: fix virtio_net xmit of freed skb bug Rusty Russell
2008-05-26  7:48 ` [PATCH 2/3] virtio: fix delayed xmit of packet and freeing of old packets Rusty Russell
2008-05-26  7:53   ` [PATCH 3/3] virtio: Use __skb_queue_purge() Rusty Russell
2008-05-26  8:11     ` Wang Chen
2008-05-27 11:01   ` [PATCH 2/3] virtio: fix delayed xmit of packet and freeing of old packets Mark McLoughlin
2008-05-28  4:59     ` Rusty Russell
2008-05-27 11:06 ` [PATCH 1/3] virtio: fix virtio_net xmit of freed skb bug Mark McLoughlin
2008-05-29  6:34   ` Rusty Russell
2008-06-13 14:14     ` Mark McLoughlin
2008-06-13 19:57       ` Jeff Garzik
2008-06-14  7:39       ` Rusty Russell
2008-05-31  2:12 ` Jeff Garzik

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).