From nobody Mon Feb 9 23:01:05 2026 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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; dkim=fail; spf=temperror (zoho.com: Error in retrieving data from DNS) 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 1529376189523997.0098795956283; Mon, 18 Jun 2018 19:43:09 -0700 (PDT) Received: from localhost ([::1]:38719 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV6bs-0004AE-P1 for importer@patchew.org; Mon, 18 Jun 2018 22:43:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46165) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV5iO-0001zW-Ok for qemu-devel@nongnu.org; Mon, 18 Jun 2018 21:45:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fV5iN-00008M-Fk for qemu-devel@nongnu.org; Mon, 18 Jun 2018 21:45:48 -0400 Received: from mail-oi0-x244.google.com ([2607:f8b0:4003:c06::244]:40539) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fV5iN-000087-A9; Mon, 18 Jun 2018 21:45:47 -0400 Received: by mail-oi0-x244.google.com with SMTP id f79-v6so16686559oib.7; Mon, 18 Jun 2018 18:45:47 -0700 (PDT) Received: from localhost ([2600:1700:70:e488:b0ee:9bda:ee6f:91be]) by smtp.gmail.com with ESMTPSA id p128-v6sm6851858oif.21.2018.06.18.18.45.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Jun 2018 18:45:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=De4ncD0ZCVnAiLZIxM/nRUIBuH9mTKHnaKsSzi5UN1w=; b=Ajp0VYGke4DEg2BwesjAfAja8LGnPsuE3iOQlR1Y89ULqmIMefYCgv8N9UG+u+AHgu hsYXTe9OcenB9JqYJ6X8OYY6uEiLwPbtPQXVU1drMhLo8M29VAVHuIE4sWvHE1X5h3AB AM05MwE1dNyUXXngHHYKdgl+G4bn4VCFq/mxgb6Tk9MopRm4vPfG0DNG8AXCgHVSjIp3 q1Gm8EhcQaR/r6fVtSaXW3TjkIqiTgOqE1khGdIXAi7mEWo88pLQDF9qpV1x7Dy7bZpx EuhfQpS86bW71BgC5TVR4bY4efcU0mnWsnY04a7waev15YXgknVXg0em5C+3zqdg1WPP HS7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=De4ncD0ZCVnAiLZIxM/nRUIBuH9mTKHnaKsSzi5UN1w=; b=rrQJ2mlSYHSOMZVxSoxA/mQ5dI3wYOSq6/R+R6tLwlfv2WTevMfZ4WeMDA3UMKdMzV F9m67CsOlZ3P2PfxZDkOpWSO5kTRERrKwHFiiz8xCcwuolcdelVE/OSRxBYZOwK7LqYp +7MKJbSEtPwjev5ef3MCMPVmMOAoObgwNzorB3lZikxF49DVA08pTXw8aV+XCEjHtpXu pRB5NAFIS7Y6RBkTBy7fIjt3ZgIKyjMaEA56BOo+DC+KMQKT6zMs596h3MZafWgMFSYY zti7ok3qn97frXXp1+E7Ba8xJBNvvm0HC0VURxrkBNQx3z/IccgA8QRTAq+OE7c9zpn5 JZRQ== X-Gm-Message-State: APt69E0/gJ0B3tgFQJl7Miwq049dJotu8j+Xxfe5lAuiTjC0JTQZzbhq iXsoXIeuJMo5DsuAe8UG6f0ZZdmH X-Google-Smtp-Source: ADUXVKKQzScGkxE4WRSB8bpL6S7HCvZlHHlmluqfqwSNv9p8+44wYUCM+kmJwfbYwGyI4XkzTZzy2A== X-Received: by 2002:aca:e7c8:: with SMTP id e191-v6mr8038428oih.202.1529372746138; Mon, 18 Jun 2018 18:45:46 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 18 Jun 2018 20:42:12 -0500 Message-Id: <20180619014319.28272-47-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180619014319.28272-1-mdroth@linux.vnet.ibm.com> References: <20180619014319.28272-1-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::244 Subject: [Qemu-devel] [PATCH 046/113] 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 , qemu-stable@nongnu.org, Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_6 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 (cherry picked from commit 94b52958b77a2a040564cf7ed716d3a9545d94e5) Signed-off-by: Michael Roth --- 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 38674b08aa..6bdef38ceb 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -422,6 +422,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; @@ -445,6 +446,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 1c55a93588..ab87d426e1 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -156,6 +156,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 39ef546708..0719358d03 100644 --- a/net/net.c +++ b/net/net.c @@ -612,7 +612,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.11.0