From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zww3W-000867-EY for qemu-devel@nongnu.org; Thu, 12 Nov 2015 12:53:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zww3T-0007jq-7o for qemu-devel@nongnu.org; Thu, 12 Nov 2015 12:53:06 -0500 Received: from e06smtp05.uk.ibm.com ([195.75.94.101]:49963) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zww3S-0007jX-VF for qemu-devel@nongnu.org; Thu, 12 Nov 2015 12:53:03 -0500 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 12 Nov 2015 17:53:01 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 0D8BC1B0806E for ; Thu, 12 Nov 2015 17:53:16 +0000 (GMT) Received: from d06av03.portsmouth.uk.ibm.com (d06av03.portsmouth.uk.ibm.com [9.149.37.213]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id tACHqwLJ4456864 for ; Thu, 12 Nov 2015 17:52:58 GMT Received: from d06av03.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id tACHqwZF022778 for ; Thu, 12 Nov 2015 10:52:58 -0700 Date: Thu, 12 Nov 2015 18:52:55 +0100 From: Cornelia Huck Message-ID: <20151112185255.1bd6197b.cornelia.huck@de.ibm.com> In-Reply-To: <20151109174021.3075.94401.stgit@bahia.huguette.org> References: <20151109172840.3075.48900.stgit@bahia.huguette.org> <20151109174021.3075.94401.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/2] 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, 09 Nov 2015 18:41:33 +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. If the backend cannot support the > requested endiannes, we have to fall back on virtio_net_hdr_swap(): this > is recorded in the needs_vnet_hdr_swap flag. > > The current vhost-net code also tries to configure net backends. This will > be no more needed and will be addressed in a subsequent patch. > > Signed-off-by: Greg Kurz > --- > v2: - introduced virtio_net_needs_hdr_swap() to consolidate the logic in one > place > --- > hw/net/virtio-net.c | 43 ++++++++++++++++++++++++++++++++++++++-- > include/hw/virtio/virtio-net.h | 1 + > 2 files changed, 42 insertions(+), 2 deletions(-) > > diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c > index a877614e3e7a..a10f7a0b4d28 100644 > --- a/hw/net/virtio-net.c > +++ b/hw/net/virtio-net.c > @@ -152,6 +152,33 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status) > } > } > > +static int peer_has_vnet_hdr(VirtIONet *n); Hm, you do not seem to use this? > + > +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; > + > + 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) && > + !virtio_net_started(n, status)) { > + if (virtio_is_big_endian(vdev)) { > + qemu_set_vnet_be(peer, false); > + } else { > + qemu_set_vnet_le(peer, false); > + } > + } > +} > + > static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status) > { > VirtIONet *n = VIRTIO_NET(vdev); > @@ -159,6 +186,7 @@ static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status) > int i; > uint8_t queue_status; > > + virtio_net_vnet_status(n, status); > virtio_net_vhost_status(n, status); > > for (i = 0; i < n->max_queues; i++) { > @@ -949,6 +977,14 @@ static void work_around_broken_dhclient(struct virtio_net_hdr *hdr, > } > } > > +static bool virtio_net_needs_hdr_swap(VirtIONet *n) > +{ > + /* virtio_needs_swap() is constant for fixed endian targets: call it > + * first to filter them out without penalty. What do you mean with 'constant' here? It still needs to retrieve the feature bit from the device, no? > + */ > + return virtio_needs_swap(VIRTIO_DEVICE(n)) && n->needs_vnet_hdr_swap; > +} > + > static void receive_header(VirtIONet *n, const struct iovec *iov, int iov_cnt, > const void *buf, size_t size) > { > @@ -957,7 +993,10 @@ 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(VIRTIO_DEVICE(n), wbuf); > + > + if (virtio_net_needs_hdr_swap(n)) { > + virtio_net_hdr_swap(VIRTIO_DEVICE(n), wbuf); > + } > iov_from_buf(iov, iov_cnt, 0, buf, sizeof(struct virtio_net_hdr)); > } else { > struct virtio_net_hdr hdr = { > @@ -1167,7 +1206,7 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q) > error_report("virtio-net header incorrect"); > exit(1); > } > - if (virtio_needs_swap(vdev)) { > + if (virtio_net_needs_hdr_swap(n)) { > virtio_net_hdr_swap(vdev, (void *) &mhdr); > sg2[0].iov_base = &mhdr; > sg2[0].iov_len = n->guest_hdr_len; > diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h > index f3cc25feca2b..27bc868fbc7d 100644 > --- a/include/hw/virtio/virtio-net.h > +++ b/include/hw/virtio/virtio-net.h > @@ -94,6 +94,7 @@ typedef struct VirtIONet { > uint64_t curr_guest_offloads; > QEMUTimer *announce_timer; > int announce_counter; > + bool needs_vnet_hdr_swap; > } VirtIONet; > > void virtio_net_set_netclient_name(VirtIONet *n, const char *name, > >