From nobody Sun May 5 17:05:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1494479084886326.3524358056077; Wed, 10 May 2017 22:04:44 -0700 (PDT) Received: from localhost ([::1]:46028 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8gHL-00030o-Fw for importer@patchew.org; Thu, 11 May 2017 01:04:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46515) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8gG7-0002Mv-Jd for qemu-devel@nongnu.org; Thu, 11 May 2017 01:03:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8gG2-0004iz-Lq for qemu-devel@nongnu.org; Thu, 11 May 2017 01:03:27 -0400 Received: from mga11.intel.com ([192.55.52.93]:49213) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d8gG2-0004iN-Ds for qemu-devel@nongnu.org; Thu, 11 May 2017 01:03:22 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 May 2017 22:03:21 -0700 Received: from devel-ww.sh.intel.com ([10.239.48.105]) by fmsmga002.fm.intel.com with ESMTP; 10 May 2017 22:03:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,322,1491289200"; d="scan'208";a="1167523340" From: Wei Wang To: mst@redhat.com, jasowang@redhat.com, stefanha@gmail.com, marcandre.lureau@gmail.com, pbonzini@redhat.com, virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Date: Thu, 11 May 2017 12:57:21 +0800 Message-Id: <1494478641-24549-1-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.93 Subject: [Qemu-devel] [PATCH] virtio-net: keep the packet layout intact X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wei Wang , jan.scheurich@ericsson.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The current implementation may change the packet layout when vnet_hdr needs an endianness swap. The layout change causes one more iov to be added to the iov[] passed from the guest, which is a barrier to making the TX queue size 1024 due to the possible off-by-one issue. This patch changes the implementation to remain the packet layout intact. In this case, the number of iov[] passed to writev will be equal to the number obtained from the guest. Signed-off-by: Wei Wang --- hw/net/virtio-net.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 7d091c9..a51e9a8 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1287,8 +1287,7 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q) for (;;) { ssize_t ret; unsigned int out_num; - struct iovec sg[VIRTQUEUE_MAX_SIZE], sg2[VIRTQUEUE_MAX_SIZE + 1], = *out_sg; - struct virtio_net_hdr_mrg_rxbuf mhdr; + struct iovec sg[VIRTQUEUE_MAX_SIZE], mhdr, *out_sg; =20 elem =3D virtqueue_pop(q->tx_vq, sizeof(VirtQueueElement)); if (!elem) { @@ -1305,7 +1304,10 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q) } =20 if (n->has_vnet_hdr) { - if (iov_to_buf(out_sg, out_num, 0, &mhdr, n->guest_hdr_len) < + /* Buffer to copy vnet_hdr and the possible adjacent data */ + mhdr.iov_len =3D out_sg[0].iov_len; + mhdr.iov_base =3D g_malloc0(mhdr.iov_len); + if (iov_to_buf(out_sg, out_num, 0, mhdr.iov_base, mhdr.iov_len= ) < n->guest_hdr_len) { virtio_error(vdev, "virtio-net header incorrect"); virtqueue_detach_element(q->tx_vq, elem, 0); @@ -1313,17 +1315,12 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *= q) return -EINVAL; } if (n->needs_vnet_hdr_swap) { - virtio_net_hdr_swap(vdev, (void *) &mhdr); - sg2[0].iov_base =3D &mhdr; - sg2[0].iov_len =3D n->guest_hdr_len; - out_num =3D iov_copy(&sg2[1], ARRAY_SIZE(sg2) - 1, - out_sg, out_num, - n->guest_hdr_len, -1); - if (out_num =3D=3D VIRTQUEUE_MAX_SIZE) { - goto drop; - } - out_num +=3D 1; - out_sg =3D sg2; + virtio_net_hdr_swap(vdev, mhdr.iov_base); + /* Copy the first iov where the vnet_hdr resides in */ + out_num =3D iov_copy(sg, 1, &mhdr, 1, 0, mhdr.iov_len); + out_num +=3D iov_copy(sg + 1, ARRAY_SIZE(sg) - 1, out_sg += 1, + elem->out_num - 1, 0, -1); + out_sg =3D sg; } } /* @@ -1345,13 +1342,15 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *= q) =20 ret =3D qemu_sendv_packet_async(qemu_get_subqueue(n->nic, queue_in= dex), out_sg, out_num, virtio_net_tx_compl= ete); + if (n->has_vnet_hdr) { + g_free(mhdr.iov_base); + } if (ret =3D=3D 0) { virtio_queue_set_notification(q->tx_vq, 0); q->async_tx.elem =3D elem; return -EBUSY; } =20 -drop: virtqueue_push(q->tx_vq, elem, 0); virtio_notify(vdev, q->tx_vq); g_free(elem); --=20 2.7.4