On Mon, 11 Jan 2016 17:12:21 +0100 Greg Kurz <gk...@linux.vnet.ibm.com> wrote:
> 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 loose network connectivity if rebooted into a s/loose/lose/ > 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. > > Signed-off-by: Greg Kurz <gk...@linux.vnet.ibm.com> (...) > +static void virtio_net_vnet_status(VirtIONet *n, uint8_t status) > +{ > + VirtIODevice *vdev = VIRTIO_DEVICE(n); > + NetClientState *peer = qemu_get_queue(n->nic)->peer; > + > + if (virtio_net_started(n, status)) { > + int r; > + > + /* Before using the device, we tell the network backend about the > + * endianness to use when parsing vnet headers. If the backend can't > + * do it, we fallback onto fixing the headers in the core virtio-net > + * code. > + */ > + if (virtio_is_big_endian(vdev)) { > + r = qemu_set_vnet_be(peer, true); > + } else { > + r = qemu_set_vnet_le(peer, true); > + } > + > + n->needs_vnet_hdr_swap = !!r; > + } else if (virtio_net_started(n, vdev->status)) { > + /* After using the device, we need to reset the network backend to > + * the default (guest native endianness), otherwise the guest may > + * loose network connectivity if it is rebooted into a different here again > + * endianness. > + */ > + if (virtio_is_big_endian(vdev)) { > + qemu_set_vnet_be(peer, false); > + } else { > + qemu_set_vnet_le(peer, false); > + } > + } > +} > + Reviewed-by: Cornelia Huck <cornelia.h...@de.ibm.com>