b448bfa
From: Jason Wang <jasowang@redhat.com>
b448bfa
Date: Fri, 25 Sep 2015 13:21:30 +0800
b448bfa
Subject: [PATCH] virtio-net: correctly drop truncated packets
b448bfa
b448bfa
When packet is truncated during receiving, we drop the packets but
b448bfa
neither discard the descriptor nor add and signal used
b448bfa
descriptor. This will lead several issues:
b448bfa
b448bfa
- sg mappings are leaked
b448bfa
- rx will be stalled if a lots of packets were truncated
b448bfa
b448bfa
In order to be consistent with vhost, fix by discarding the descriptor
b448bfa
in this case.
b448bfa
b448bfa
Cc: Michael S. Tsirkin <mst@redhat.com>
b448bfa
Signed-off-by: Jason Wang <jasowang@redhat.com>
b448bfa
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
b448bfa
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
b448bfa
b448bfa
(cherry picked from commit 0cf33fb6b49a19de32859e2cdc6021334f448fb3)
b448bfa
---
b448bfa
 hw/net/virtio-net.c | 8 +-------
b448bfa
 1 file changed, 1 insertion(+), 7 deletions(-)
b448bfa
b448bfa
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
b448bfa
index 1510839..775389b 100644
b448bfa
--- a/hw/net/virtio-net.c
b448bfa
+++ b/hw/net/virtio-net.c
b448bfa
@@ -1086,13 +1086,7 @@ static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf, size_t
b448bfa
          * must have consumed the complete packet.
b448bfa
          * Otherwise, drop it. */
b448bfa
         if (!n->mergeable_rx_bufs && offset < size) {
b448bfa
-#if 0
b448bfa
-            error_report("virtio-net truncated non-mergeable packet: "
b448bfa
-                         "i %zd mergeable %d offset %zd, size %zd, "
b448bfa
-                         "guest hdr len %zd, host hdr len %zd",
b448bfa
-                         i, n->mergeable_rx_bufs,
b448bfa
-                         offset, size, n->guest_hdr_len, n->host_hdr_len);
b448bfa
-#endif
b448bfa
+            virtqueue_discard(q->rx_vq, &elem, total);
b448bfa
             return size;
b448bfa
         }
b448bfa