virtio-net: use the backend cross-endian capabilities
commit1bfa316ce776d1f90ac96c59b4b69910db19ed6d
authorGreg Kurz <gkurz@linux.vnet.ibm.com>
Fri, 5 Feb 2016 10:43:11 +0000 (5 11:43 +0100)
committerMichael S. Tsirkin <mst@redhat.com>
Tue, 16 Feb 2016 10:05:17 +0000 (16 12:05 +0200)
treea79ba833913b876538710018fec6aee1858483f7
parenta5af12871fd4601c44f08d9e49131e9ca13ef102
virtio-net: use the backend cross-endian capabilities

When running a fully emulated device in cross-endian conditions, including
a virtio 1.0 device offered to a big endian guest, we need to fix the vnet
headers. This is currently handled by the virtio_net_hdr_swap() function
in the core virtio-net code but it should actually be handled by the net
backend.

With this patch, virtio-net now tries to configure the backend to do the
endian fixing when the device starts (i.e. drivers sets the CONFIG_OK bit).
If the backend cannot support the requested endiannes, we have to fallback
onto virtio_net_hdr_swap(): this is recorded in the needs_vnet_hdr_swap flag,
to be used in the TX and RX paths.

Note that we reset the backend to the default behaviour (guest native
endianness) when the device stops (i.e. device status had CONFIG_OK bit and
driver unsets it). This is needed, with the linux tap backend at least,
otherwise the guest may lose network connectivity if rebooted into a
different endianness.

The current vhost-net code also tries to configure net backends. This will
be no more needed and will be reverted in a subsequent patch.

Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Laurent Vivier <lvivier@redhat.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>
Reviewed-by: Laurent Vivier <lvivier@redhat.com>
hw/net/virtio-net.c
include/hw/virtio/virtio-access.h
include/hw/virtio/virtio-net.h