From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60002) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1IRC-0007Iq-78 for qemu-devel@nongnu.org; Sun, 29 Jun 2014 12:58:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X1IR6-0003Gt-1R for qemu-devel@nongnu.org; Sun, 29 Jun 2014 12:58:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36516) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1IR5-0003Gj-F6 for qemu-devel@nongnu.org; Sun, 29 Jun 2014 12:58:39 -0400 Date: Sun, 29 Jun 2014 19:58:56 +0300 From: "Michael S. Tsirkin" Message-ID: <1404060115-27410-16-git-send-email-mst@redhat.com> References: <1404060115-27410-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1404060115-27410-1-git-send-email-mst@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 15/37] virtio-net: byteswap virtio-net header List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , =?us-ascii?B?PT9VVEYtOD9xP0M9QzM9QTlkcmljPTIwTGU9MjBHb2F0ZXI/PQ==?= , Anthony Liguori , Greg Kurz From: C=E9dric Le Goater 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=3D8704/4096 len=3D74 [ 455.702554] skbuff: bad partial csum: csum=3D8704/4096 len=3D74 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=E9dric Le Goater [ Ported from PowerKVM, Greg Kurz ] Signed-off-by: Greg Kurz Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- 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; } =20 +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 =3D (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 =3D { @@ -1118,6 +1127,14 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue = *q) exit(1); } =20 + 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 --=20 MST