From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44551) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIh1P-0004P5-TN for qemu-devel@nongnu.org; Mon, 11 Jan 2016 13:16:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aIh1K-0001Rn-U2 for qemu-devel@nongnu.org; Mon, 11 Jan 2016 13:16:51 -0500 Received: from e06smtp08.uk.ibm.com ([195.75.94.104]:58528) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIh1K-0001RJ-Kd for qemu-devel@nongnu.org; Mon, 11 Jan 2016 13:16:46 -0500 Received: from localhost by e06smtp08.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 11 Jan 2016 18:16:43 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id C4E7117D8042 for ; Mon, 11 Jan 2016 18:16:41 +0000 (GMT) Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u0BIGeaN4981204 for ; Mon, 11 Jan 2016 18:16:40 GMT Received: from d06av02.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u0BIGe2A003740 for ; Mon, 11 Jan 2016 11:16:40 -0700 Date: Mon, 11 Jan 2016 19:16:38 +0100 From: Cornelia Huck Message-ID: <20160111191638.189301ee.cornelia.huck@de.ibm.com> In-Reply-To: <20160111161202.17428.74331.stgit@bahia.huguette.org> References: <20160111161156.17428.20668.stgit@bahia.huguette.org> <20160111161202.17428.74331.stgit@bahia.huguette.org> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 1/5] virtio-net: use the backend cross-endian capabilities List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Greg Kurz Cc: qemu-devel@nongnu.org, "Michael S. Tsirkin" On Mon, 11 Jan 2016 17:12:21 +0100 Greg Kurz 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 (...) > +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