From nobody Sun Apr 28 12:14:36 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.zohomail.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 1522047758505690.6578888534264; Mon, 26 Mar 2018 00:02:38 -0700 (PDT) Received: from localhost ([::1]:54932 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0M9N-0003Do-Pa for importer@patchew.org; Mon, 26 Mar 2018 03:02:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42832) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0M7h-0002JF-9U for qemu-devel@nongnu.org; Mon, 26 Mar 2018 03:00:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f0M7b-0000tH-35 for qemu-devel@nongnu.org; Mon, 26 Mar 2018 03:00:53 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39288 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f0M7a-0000t9-Th; Mon, 26 Mar 2018 03:00:47 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 560F0722C0; Mon, 26 Mar 2018 07:00:46 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-191.pek2.redhat.com [10.72.12.191]) by smtp.corp.redhat.com (Postfix) with ESMTP id 74178215CDAA; Mon, 26 Mar 2018 07:00:40 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Mon, 26 Mar 2018 15:00:28 +0800 Message-Id: <1522047629-27658-2-git-send-email-jasowang@redhat.com> In-Reply-To: <1522047629-27658-1-git-send-email-jasowang@redhat.com> References: <1522047629-27658-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 26 Mar 2018 07:00:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 26 Mar 2018 07:00:46 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jasowang@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 1/2] virtio_net: flush uncompleted TX on reset 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: Jason Wang , Greg Kurz , qemu-stable@nongnu.org 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" From: Greg Kurz If the backend could not transmit a packet right away for some reason, the packet is queued for asynchronous sending. The corresponding vq element is tracked in the async_tx.elem field of the VirtIONetQueue, for later freeing when the transmission is complete. If a reset happens before completion, virtio_net_tx_complete() will push async_tx.elem back to the guest anyway, and we end up with the inuse flag of the vq being equal to -1. The next call to virtqueue_pop() is then likely to fail with "Virtqueue size exceeded". This can be reproduced easily by starting a guest with an hubport backend that is not connected to a functional network, eg, -device virtio-net-pci,netdev=3Dhub0 -netdev hubport,id=3Dhub0,hubid=3D0 and no other -netdev hubport,hubid=3D0 on the command line. The appropriate fix is to ensure that such an asynchronous transmission cannot survive a device reset. So for all queues, we first try to send the packet again, and eventually we purge it if the backend still could not deliver it. CC: qemu-stable@nongnu.org Reported-by: R. Nageswara Sastry Buglink: https://github.com/open-power-host-os/qemu/issues/37 Signed-off-by: Greg Kurz Tested-by: R. Nageswara Sastry Signed-off-by: Jason Wang --- hw/net/virtio-net.c | 11 +++++++++++ include/net/net.h | 1 + net/net.c | 1 - 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 67ad38c..90502fc 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -427,6 +427,7 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClien= tState *nc) static void virtio_net_reset(VirtIODevice *vdev) { VirtIONet *n =3D VIRTIO_NET(vdev); + int i; =20 /* Reset back to compatibility mode */ n->promisc =3D 1; @@ -450,6 +451,16 @@ static void virtio_net_reset(VirtIODevice *vdev) memcpy(&n->mac[0], &n->nic->conf->macaddr, sizeof(n->mac)); qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac); memset(n->vlans, 0, MAX_VLAN >> 3); + + /* Flush any async TX */ + for (i =3D 0; i < n->max_queues; i++) { + NetClientState *nc =3D qemu_get_subqueue(n->nic, i); + + if (nc->peer) { + qemu_flush_or_purge_queued_packets(nc->peer, true); + assert(!virtio_net_get_subqueue(nc)->async_tx.elem); + } + } } =20 static void peer_test_vnet_hdr(VirtIONet *n) diff --git a/include/net/net.h b/include/net/net.h index a943e96..1f7341e 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -153,6 +153,7 @@ ssize_t qemu_send_packet_async(NetClientState *nc, cons= t uint8_t *buf, int size, NetPacketSent *sent_cb); void qemu_purge_queued_packets(NetClientState *nc); void qemu_flush_queued_packets(NetClientState *nc); +void qemu_flush_or_purge_queued_packets(NetClientState *nc, bool purge); void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6]); bool qemu_has_ufo(NetClientState *nc); bool qemu_has_vnet_hdr(NetClientState *nc); diff --git a/net/net.c b/net/net.c index 5222e45..29f8398 100644 --- a/net/net.c +++ b/net/net.c @@ -595,7 +595,6 @@ void qemu_purge_queued_packets(NetClientState *nc) qemu_net_queue_purge(nc->peer->incoming_queue, nc); } =20 -static void qemu_flush_or_purge_queued_packets(NetClientState *nc, bool purge) { nc->receive_disabled =3D 0; --=20 2.7.4 From nobody Sun Apr 28 12:14:36 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.zohomail.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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1522047848299660.8798091455244; Mon, 26 Mar 2018 00:04:08 -0700 (PDT) Received: from localhost ([::1]:54938 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0MAg-0004SM-IN for importer@patchew.org; Mon, 26 Mar 2018 03:03:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42828) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0M7g-0002Im-J2 for qemu-devel@nongnu.org; Mon, 26 Mar 2018 03:00:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f0M7f-0000u1-DP for qemu-devel@nongnu.org; Mon, 26 Mar 2018 03:00:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50374 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f0M7f-0000tv-9G for qemu-devel@nongnu.org; Mon, 26 Mar 2018 03:00:51 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BC2404072CC5; Mon, 26 Mar 2018 07:00:50 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-191.pek2.redhat.com [10.72.12.191]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98397215CDAA; Mon, 26 Mar 2018 07:00:46 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Mon, 26 Mar 2018 15:00:29 +0800 Message-Id: <1522047629-27658-3-git-send-email-jasowang@redhat.com> In-Reply-To: <1522047629-27658-1-git-send-email-jasowang@redhat.com> References: <1522047629-27658-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 26 Mar 2018 07:00:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 26 Mar 2018 07:00:50 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jasowang@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 2/2] net/vde: print error on vde_open() failure 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: Jason Wang , Julia Suvorova 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" From: Julia Suvorova via Qemu-devel Despite the fact that now when the initialization of vde fails, qemu does not end silently, no informative error is printed. The patch generates an error and pushes it through the calling function. Related bug: https://bugs.launchpad.net/qemu/+bug/676029 Signed-off-by: Julia Suvorova Signed-off-by: Jason Wang --- net/vde.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/vde.c b/net/vde.c index e50e5d6..99189cc 100644 --- a/net/vde.c +++ b/net/vde.c @@ -30,6 +30,7 @@ #include "qemu-common.h" #include "qemu/option.h" #include "qemu/main-loop.h" +#include "qapi/error.h" =20 typedef struct VDEState { NetClientState nc; @@ -76,7 +77,7 @@ static NetClientInfo net_vde_info =3D { =20 static int net_vde_init(NetClientState *peer, const char *model, const char *name, const char *sock, - int port, const char *group, int mode) + int port, const char *group, int mode, Error **err= p) { NetClientState *nc; VDEState *s; @@ -92,6 +93,7 @@ static int net_vde_init(NetClientState *peer, const char = *model, =20 vde =3D vde_open(init_sock, (char *)"QEMU", &args); if (!vde){ + error_setg_errno(errp, errno, "Could not open vde"); return -1; } =20 @@ -112,7 +114,6 @@ static int net_vde_init(NetClientState *peer, const cha= r *model, int net_init_vde(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { - /* FIXME error_setg(errp, ...) on failure */ const NetdevVdeOptions *vde; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_VDE); @@ -120,7 +121,7 @@ int net_init_vde(const Netdev *netdev, const char *name, =20 /* missing optional values have been initialized to "all bits zero" */ if (net_vde_init(peer, "vde", name, vde->sock, vde->port, vde->group, - vde->has_mode ? vde->mode : 0700) =3D=3D -1) { + vde->has_mode ? vde->mode : 0700, errp) =3D=3D -1) { return -1; } =20 --=20 2.7.4