dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

Blame 0194-net-fix-usbnet_receive-packet-drops.patch

5544c1
From 14294fa1c903ab239bce3d2839e9e1883141b4f1 Mon Sep 17 00:00:00 2001
5544c1
From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
5544c1
Date: Fri, 24 Aug 2012 13:37:29 +0100
5544c1
Subject: [PATCH] net: fix usbnet_receive() packet drops
5544c1
5544c1
The USB network interface has a single buffer which the guest reads
5544c1
from.  This patch prevents multiple calls to usbnet_receive() from
5544c1
clobbering the input buffer.  Instead we queue packets until buffer
5544c1
space becomes available again.
5544c1
5544c1
This is inspired by virtio-net and e1000 rxbuf handling.
5544c1
5544c1
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
5544c1
(cherry picked from commit 190563f9a90c9df8ad32fc7f3e4b166deda949a6)
5544c1
5544c1
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1
---
5544c1
 hw/usb/dev-network.c | 19 ++++++++++++++++---
5544c1
 1 file changed, 16 insertions(+), 3 deletions(-)
5544c1
5544c1
diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c
5544c1
index 0b5cb71..e4a4359 100644
5544c1
--- a/hw/usb/dev-network.c
5544c1
+++ b/hw/usb/dev-network.c
5544c1
@@ -1001,6 +1001,13 @@ static int rndis_keepalive_response(USBNetState *s,
5544c1
     return 0;
5544c1
 }
5544c1
 
5544c1
+/* Prepare to receive the next packet */
5544c1
+static void usb_net_reset_in_buf(USBNetState *s)
5544c1
+{
5544c1
+    s->in_ptr = s->in_len = 0;
5544c1
+    qemu_flush_queued_packets(&s->nic->nc);
5544c1
+}
5544c1
+
5544c1
 static int rndis_parse(USBNetState *s, uint8_t *data, int length)
5544c1
 {
5544c1
     uint32_t msg_type;
5544c1
@@ -1025,7 +1032,8 @@ static int rndis_parse(USBNetState *s, uint8_t *data, int length)
5544c1
 
5544c1
     case RNDIS_RESET_MSG:
5544c1
         rndis_clear_responsequeue(s);
5544c1
-        s->out_ptr = s->in_ptr = s->in_len = 0;
5544c1
+        s->out_ptr = 0;
5544c1
+        usb_net_reset_in_buf(s);
5544c1
         return rndis_reset_response(s, (rndis_reset_msg_type *) data);
5544c1
 
5544c1
     case RNDIS_KEEPALIVE_MSG:
5544c1
@@ -1135,7 +1143,7 @@ static int usb_net_handle_datain(USBNetState *s, USBPacket *p)
5544c1
     int ret = USB_RET_NAK;
5544c1
 
5544c1
     if (s->in_ptr > s->in_len) {
5544c1
-        s->in_ptr = s->in_len = 0;
5544c1
+        usb_net_reset_in_buf(s);
5544c1
         ret = USB_RET_NAK;
5544c1
         return ret;
5544c1
     }
5544c1
@@ -1152,7 +1160,7 @@ static int usb_net_handle_datain(USBNetState *s, USBPacket *p)
5544c1
     if (s->in_ptr >= s->in_len &&
5544c1
                     (is_rndis(s) || (s->in_len & (64 - 1)) || !ret)) {
5544c1
         /* no short packet necessary */
5544c1
-        s->in_ptr = s->in_len = 0;
5544c1
+        usb_net_reset_in_buf(s);
5544c1
     }
5544c1
 
5544c1
 #ifdef TRAFFIC_DEBUG
5544c1
@@ -1263,6 +1271,11 @@ static ssize_t usbnet_receive(NetClientState *nc, const uint8_t *buf, size_t siz
5544c1
         return -1;
5544c1
     }
5544c1
 
5544c1
+    /* Only accept packet if input buffer is empty */
5544c1
+    if (s->in_len > 0) {
5544c1
+        return 0;
5544c1
+    }
5544c1
+
5544c1
     if (is_rndis(s)) {
5544c1
         struct rndis_packet_msg_type *msg;
5544c1
 
5544c1
-- 
5544c1
1.7.12.1
5544c1