[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 15/37] virtio-net: byteswap virtio-net header
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 15/37] virtio-net: byteswap virtio-net header |
Date: |
Sun, 29 Jun 2014 19:58:56 +0300 |
From: Cédric Le Goater <address@hidden>
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 <address@hidden>
[ Ported from PowerKVM,
Greg Kurz <address@hidden> ]
Signed-off-by: Greg Kurz <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
hw/net/virtio-net.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index e51d753..ea1a081 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -875,6 +875,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
@@ -910,6 +918,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 = {
@@ -1118,6 +1127,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
--
MST
- [Qemu-devel] [PULL 06/37] mc146818rtc: add rtc-reset-reinjection QMP command, (continued)
- [Qemu-devel] [PULL 06/37] mc146818rtc: add rtc-reset-reinjection QMP command, Michael S. Tsirkin, 2014/06/29
- [Qemu-devel] [PULL 08/37] pc: make isapc and pc-0.10 to pc-0.13 have 1.7.0 memory layout, Michael S. Tsirkin, 2014/06/29
- [Qemu-devel] [PULL 05/37] pc: Fix "prog_if" typo on PC_COMPAT_2_0, Michael S. Tsirkin, 2014/06/29
- [Qemu-devel] [PULL 07/37] vhost-user: fix wrong ids in documentation, Michael S. Tsirkin, 2014/06/29
- [Qemu-devel] [PULL 09/37] Allow mismatched virtio config-len, Michael S. Tsirkin, 2014/06/29
- [Qemu-devel] [PULL 11/37] numa: Reject duplicate node IDs, Michael S. Tsirkin, 2014/06/29
- [Qemu-devel] [PULL 10/37] numa: Keep track of NUMA nodes present on the command-line, Michael S. Tsirkin, 2014/06/29
- [Qemu-devel] [PULL 12/37] numa: Reject configuration if not all node IDs are present, Michael S. Tsirkin, 2014/06/29
- [Qemu-devel] [PULL 13/37] vhost-user: fix regions provied with VHOST_USER_SET_MEM_TABLE message, Michael S. Tsirkin, 2014/06/29
- [Qemu-devel] [PULL 14/37] vhost-user: typo fixups, Michael S. Tsirkin, 2014/06/29
- [Qemu-devel] [PULL 15/37] virtio-net: byteswap virtio-net header,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 17/37] virtio: introduce device specific migration calls, Michael S. Tsirkin, 2014/06/29
- [Qemu-devel] [PULL 16/37] virtio-serial: don't migrate the config space, Michael S. Tsirkin, 2014/06/29
- [Qemu-devel] [PULL 18/37] virtio-net: implement per-device migration calls, Michael S. Tsirkin, 2014/06/29
- [Qemu-devel] [PULL 19/37] virtio-blk: implement per-device migration calls, Michael S. Tsirkin, 2014/06/29
- [Qemu-devel] [PULL 20/37] virtio-serial: implement per-device migration calls, Michael S. Tsirkin, 2014/06/29
- [Qemu-devel] [PULL 21/37] virtio-balloon: implement per-device migration calls, Michael S. Tsirkin, 2014/06/29
- [Qemu-devel] [PULL 22/37] virtio-rng: implement per-device migration calls, Michael S. Tsirkin, 2014/06/29
- [Qemu-devel] [PULL 23/37] virtio: add subsections to the migration stream, Michael S. Tsirkin, 2014/06/29
- [Qemu-devel] [PULL 24/37] exec: introduce target_words_bigendian() helper, Michael S. Tsirkin, 2014/06/29
- [Qemu-devel] [PULL 25/37] cpu: introduce CPUClass::virtio_is_big_endian(), Michael S. Tsirkin, 2014/06/29