From patchwork Mon Nov 7 08:20:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 9414431 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6849A60512 for ; Mon, 7 Nov 2016 08:24:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5487B28BF2 for ; Mon, 7 Nov 2016 08:24:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 489D128DD9; Mon, 7 Nov 2016 08:24:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CCB4528BF2 for ; Mon, 7 Nov 2016 08:24:47 +0000 (UTC) Received: from localhost ([::1]:52117 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c3fEV-0005ke-4W for patchwork-qemu-devel@patchwork.kernel.org; Mon, 07 Nov 2016 03:24:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57802) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c3fAj-00033N-Tc for qemu-devel@nongnu.org; Mon, 07 Nov 2016 03:20:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c3fAi-00047A-Km for qemu-devel@nongnu.org; Mon, 07 Nov 2016 03:20:53 -0500 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:34241) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c3fAi-00046J-5c for qemu-devel@nongnu.org; Mon, 07 Nov 2016 03:20:52 -0500 Received: by mail-wm0-x243.google.com with SMTP id p190so15118878wmp.1 for ; Mon, 07 Nov 2016 00:20:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jCcJ+xs85dAljpF3a9AsLmthWu8AsxiS5GcG/EqdnyA=; b=zP8NYIkRvQC+ttL392oMwpe2cMmS5qHf1BPJaKZzjoXzx/NEW8PWYyjb+H3M1KAbPP pNOSnd+2zYt+8IqezNUORiJEkN8COW3I2P8BEyxjTR/+2x+hRSf1pBzl8Nk1qxu1IQr1 cIyuA8IqSftzeQwxVvR0++TtjqDjtzjg+uBLBTahnkuknLVULwtkiJM2IDLnMjNJgnb+ uZvla/85CxdXTIvXfzC/pazMi3wEgxvM2fWI6LHiUsNoINAdAKvdHoB4w3rTHWdhrzbd 71vrh/+HnyiLoVg4gTzVxMQbZNcApTV3MylrtY7yHM2vPBChM7Iwh8BxPDa9z2M6ce6J viUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jCcJ+xs85dAljpF3a9AsLmthWu8AsxiS5GcG/EqdnyA=; b=ThNMzZq4j0vjZAaczIfRAX7cR6ZXlcwEWZVFm9hYL9XcJUQiJOT70ocD9AlpDBInIy D5kgjoujuFuS4nB7MOEJDyNUBLHtXr1PqOERVWTUCqX6fXh+KcZ7grmohRoQ8vMieSZF YG+Jxdel870Jam1vMRn+DuOLrmcLpntlp9s3o2kaT4AeuvFh/2QC/kRnBVCzDtWdGoJ7 maaPn0/33Y6mHKlfJ2E+7TSC6gsHIXpFJk5xfFwGsmNA2Ghne8s/lUwUe4RsE4iO6Lrq 8RGeD/qvmy0m/qKAolbrGG45FD25vm4O0e8Lt1zUODI6wcp2Dax6HcnTG16Yf59muUbM 3gZA== X-Gm-Message-State: ABUngveGoqpjEV7gyYwYHQMES0z3EsdhV/swN12mipC5xSO6z71SwuTMmzKz+Ys5W0eL9w== X-Received: by 10.28.189.69 with SMTP id n66mr7293063wmf.35.1478506851086; Mon, 07 Nov 2016 00:20:51 -0800 (PST) Received: from localhost.localdomain ([141.226.163.133]) by smtp.gmail.com with ESMTPSA id vf8sm29494241wjc.27.2016.11.07.00.20.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 07 Nov 2016 00:20:50 -0800 (PST) From: yuri.benditovich@daynix.com To: "Michael S . Tsirkin" , Jason Wang , qemu-devel@nongnu.org Date: Mon, 7 Nov 2016 10:20:29 +0200 Message-Id: <1478506829-9208-4-git-send-email-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1478506829-9208-1-git-send-email-yuri.benditovich@daynix.com> References: <1478506829-9208-1-git-send-email-yuri.benditovich@daynix.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PATCH 3/3] net: virtio-net discards TX data after link down 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: dmitry@daynix.com, yan@daynix.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Yuri Benditovich https://bugzilla.redhat.com/show_bug.cgi?id=1295637 Upon set_link monitor command or upon netdev deletion virtio-net sends link down indication to the guest and stops vhost if one is used. Guest driver can still submit data for TX until it recognizes link loss. If these packets not returned by the host, the Windows guest will never be able to finish disable/removal/shutdown. Now each packet sent by guest after NIC indicated link down will be completed immediately. Signed-off-by: Yuri Benditovich --- hw/net/virtio-net.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 06bfe4b..6158de0 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1200,6 +1200,16 @@ static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf, size_t return size; } +static void virtio_net_drop_tx_queue_data(VirtIODevice *vdev, VirtQueue *vq) +{ + VirtQueueElement *elem; + while ((elem = virtqueue_pop(vq, sizeof(VirtQueueElement)))) { + virtqueue_push(vq, elem, 0); + virtio_notify(vdev, vq); + g_free(elem); + } +} + static int32_t virtio_net_flush_tx(VirtIONetQueue *q); static void virtio_net_tx_complete(NetClientState *nc, ssize_t len) @@ -1345,6 +1355,11 @@ static void virtio_net_handle_tx_bh(VirtIODevice *vdev, VirtQueue *vq) VirtIONet *n = VIRTIO_NET(vdev); VirtIONetQueue *q = &n->vqs[vq2q(virtio_get_queue_index(vq))]; + if (unlikely((n->status & VIRTIO_NET_S_LINK_UP) == 0)) { + virtio_net_drop_tx_queue_data(vdev, vq); + return; + } + if (unlikely(q->tx_waiting)) { return; }