summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Le Goater <clg@fr.ibm.com>2014-06-24 19:11:32 +0200
committerMichael Roth <mdroth@linux.vnet.ibm.com>2014-07-15 19:28:01 -0500
commit0fd14a556436386311c3c5aeeac501ce468c8df0 (patch)
tree158d11132a63e52e3dc3ebf70fe5a8167ee48449
parent7a3cd5ab408d06fac4e1ae6aa88b823a48db085c (diff)
downloadqemu-0fd14a556436386311c3c5aeeac501ce468c8df0.tar.gz
virtio-net: byteswap virtio-net header
TCP connectivity fails when the guest has a different endianness. The packets are silently dropped on the host by the tap backend when they are read from user space because the endianness of the virtio-net header is in the wrong order. These lines may appear in the guest console: [ 454.709327] skbuff: bad partial csum: csum=8704/4096 len=74 [ 455.702554] skbuff: bad partial csum: csum=8704/4096 len=74 The issue that got first spotted with a ppc64le PowerKVM guest, but it also exists for the less common case of a x86_64 guest run by a big-endian ppc64 TCG hypervisor. Signed-off-by: Cédric Le Goater <clg@fr.ibm.com> [ Ported from PowerKVM, Greg Kurz <gkurz@linux.vnet.ibm.com> ] Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> (cherry picked from commit 032a74a1c0fcdd5fd1c69e56126b4c857ee36611) Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
-rw-r--r--hw/net/virtio-net.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 29c5f35c57..6246725614 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -843,6 +843,14 @@ static int virtio_net_has_buffers(VirtIONetQueue *q, int bufsize)
return 1;
}
+static void virtio_net_hdr_swap(struct virtio_net_hdr *hdr)
+{
+ tswap16s(&hdr->hdr_len);
+ tswap16s(&hdr->gso_size);
+ tswap16s(&hdr->csum_start);
+ tswap16s(&hdr->csum_offset);
+}
+
/* dhclient uses AF_PACKET but doesn't pass auxdata to the kernel so
* it never finds out that the packets don't have valid checksums. This
* causes dhclient to get upset. Fedora's carried a patch for ages to
@@ -878,6 +886,7 @@ static void receive_header(VirtIONet *n, const struct iovec *iov, int iov_cnt,
void *wbuf = (void *)buf;
work_around_broken_dhclient(wbuf, wbuf + n->host_hdr_len,
size - n->host_hdr_len);
+ virtio_net_hdr_swap(wbuf);
iov_from_buf(iov, iov_cnt, 0, buf, sizeof(struct virtio_net_hdr));
} else {
struct virtio_net_hdr hdr = {
@@ -1086,6 +1095,14 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)
exit(1);
}
+ if (n->has_vnet_hdr) {
+ if (out_sg[0].iov_len < n->guest_hdr_len) {
+ error_report("virtio-net header incorrect");
+ exit(1);
+ }
+ virtio_net_hdr_swap((void *) out_sg[0].iov_base);
+ }
+
/*
* If host wants to see the guest header as is, we can
* pass it on unchanged. Otherwise, copy just the parts