From patchwork Wed Mar 7 18:57:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 882720 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kaod.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zxNFs6pJJz9sd3 for ; Thu, 8 Mar 2018 05:58:24 +1100 (AEDT) Received: from localhost ([::1]:35024 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eteGc-0003Tp-6f for incoming@patchwork.ozlabs.org; Wed, 07 Mar 2018 13:58:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56847) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eteGE-0003RS-UE for qemu-devel@nongnu.org; Wed, 07 Mar 2018 13:58:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eteGC-0003Ac-7v for qemu-devel@nongnu.org; Wed, 07 Mar 2018 13:57:58 -0500 Received: from 7.mo6.mail-out.ovh.net ([46.105.59.196]:53434) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eteGB-00037b-Vb for qemu-devel@nongnu.org; Wed, 07 Mar 2018 13:57:56 -0500 Received: from player728.ha.ovh.net (unknown [10.109.120.1]) by mo6.mail-out.ovh.net (Postfix) with ESMTP id 7574514505F for ; Wed, 7 Mar 2018 19:57:47 +0100 (CET) Received: from bahia.lan (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player728.ha.ovh.net (Postfix) with ESMTPA id CE03E54008F; Wed, 7 Mar 2018 19:57:43 +0100 (CET) From: Greg Kurz To: qemu-devel@nongnu.org Date: Wed, 07 Mar 2018 19:57:37 +0100 Message-ID: <152044905701.22965.8924520463227226351.stgit@bahia.lan> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 X-Ovh-Tracer-Id: 3903213505536301567 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtfedrkedvgdduvddtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.59.196 Subject: [Qemu-devel] [PATCH] 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 , R Nageswara Sastry , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 without a net backend, doing a system reset when it is booted, and finally snapshotting it. 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. 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 --- hw/net/virtio-net.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 188744e17d57..eea3cdb2c700 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -422,6 +422,7 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc) static void virtio_net_reset(VirtIODevice *vdev) { VirtIONet *n = VIRTIO_NET(vdev); + int i; /* Reset back to compatibility mode */ n->promisc = 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 = 0; i < n->max_queues; i++) { + NetClientState *nc = qemu_get_subqueue(n->nic, i); + + if (!qemu_net_queue_flush(nc->peer->incoming_queue)) { + qemu_net_queue_purge(nc->peer->incoming_queue, nc); + } + assert(!virtio_net_get_subqueue(nc)->async_tx.elem); + } } static void peer_test_vnet_hdr(VirtIONet *n)