From patchwork Tue Dec 13 08:12:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 9471887 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 3EF08607EE for ; Tue, 13 Dec 2016 08:17:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F273284C3 for ; Tue, 13 Dec 2016 08:17:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2300328537; Tue, 13 Dec 2016 08:17:09 +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 B3D5D284C3 for ; Tue, 13 Dec 2016 08:17:08 +0000 (UTC) Received: from localhost ([::1]:36093 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cGiGp-0003ng-QN for patchwork-qemu-devel@patchwork.kernel.org; Tue, 13 Dec 2016 03:17:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52138) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cGiDk-0001m5-HP for qemu-devel@nongnu.org; Tue, 13 Dec 2016 03:13:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cGiDh-000404-B5 for qemu-devel@nongnu.org; Tue, 13 Dec 2016 03:13:56 -0500 Received: from mail-wj0-f194.google.com ([209.85.210.194]:36845) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cGiDh-0003vD-50 for qemu-devel@nongnu.org; Tue, 13 Dec 2016 03:13:53 -0500 Received: by mail-wj0-f194.google.com with SMTP id j10so15104164wjb.3 for ; Tue, 13 Dec 2016 00:13:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=leWXwyzaxDDSXlT75HCfqtVBXxJk3HcFjKT9zCUtz64=; b=CaS0rV+CIYA2e3rCZvHf7ykhK3kTq+lKsK7A3Mb3KCZ8AKjYa6WYZ4FIP1nlekyGXV 2n6HiSObgTJ9VF0KTrzmlnwvaYkYQUCmaqZO/4KZA2bpxdTFtBGCTlDzYIpduiAfOQR7 3TckP5LUSf4WkZNUSwIygWOGVEtIH+nyD4p7qBZiRDQC8R4r6fQFJsmeG9Ghm//PM5GP ZghV3ZcPyke7x6osNwkXS9hEPhJF1a7PIJHmJU6rljB0D8sG3Edt7yK6Vnvw5Cvwv4co ou7cHK/P+q2gA/tObaDRk0pT5zhWJaNo29yCjGtAjmDOBWd6agIZGoVo0PqW1TzRdOqN rmtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=leWXwyzaxDDSXlT75HCfqtVBXxJk3HcFjKT9zCUtz64=; b=acJTQkXT/5Xx/GIsXVtTkdUa7Rwyscj+p7Y9UHrSoBOkjy8lYSwfEJ7ETahB0gTbgN ZTNM6qsHx8OsdgU7OrvFtBLcmv24gboCpoQ3aNBatOSnPDiRjOP9X9mw6d2xHWNQGnwt nYJwcLrQ3h0TiHqjFPhCoqfUyR9Lb3Ui6TDW2y7g5BuMc5tZXDj+iwHtTluuQOr1hPOC KNMbuM/6YqlAslu8pVkNR+QSLK4V7PsQ+lo7qYwVtI7hk3P54LXWPHdCkFPumU5VkOrF oic0It0caDpziV/FbWvvLezjhMPx63WtvBD9tvptJVxj+Njq5NiTvtCQ0VLq8NYn6LvD PwAw== X-Gm-Message-State: AKaTC0170clYVsQM1TgaDqJ3pcvktL9t+a7CSgTKLAydyToQY/+OSZmU5+pxmC2x2PsJdg== X-Received: by 10.195.30.43 with SMTP id kb11mr82208976wjd.131.1481616749433; Tue, 13 Dec 2016 00:12:29 -0800 (PST) Received: from localhost.localdomain ([141.226.163.133]) by smtp.gmail.com with ESMTPSA id d17sm60996111wjr.14.2016.12.13.00.12.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Dec 2016 00:12:29 -0800 (PST) From: Yuri Benditovich To: qemu-devel@nongnu.org, Jason Wang , "Michael S . Tsirkin" Date: Tue, 13 Dec 2016 10:12:08 +0200 Message-Id: <1481616728-148412-5-git-send-email-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1481616728-148412-1-git-send-email-yuri.benditovich@daynix.com> References: <1481616728-148412-1-git-send-email-yuri.benditovich@daynix.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.210.194 Subject: [Qemu-devel] [PATCH v3 4/4] 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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 5009533..6f98eab 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -218,6 +218,14 @@ static void virtio_net_vnet_endian_status(VirtIONet *n, uint8_t status) } } +static void virtio_net_drop_tx_queue_data(VirtIODevice *vdev, VirtQueue *vq) +{ + unsigned int dropped = virtqueue_drop_all(vq); + if (dropped) { + virtio_notify(vdev, vq); + } +} + static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status) { VirtIONet *n = VIRTIO_NET(vdev); @@ -262,6 +270,14 @@ static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status) } else { qemu_bh_cancel(q->tx_bh); } + if ((n->status & VIRTIO_NET_S_LINK_UP) == 0 && + (queue_status & VIRTIO_CONFIG_S_DRIVER_OK)) { + /* if tx is waiting we are likely have some packets in tx queue + * and disabled notification */ + q->tx_waiting = 0; + virtio_queue_set_notification(q->tx_vq, 1); + virtio_net_drop_tx_queue_data(vdev, q->tx_vq); + } } } } @@ -1323,6 +1339,11 @@ static void virtio_net_handle_tx_timer(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; + } + /* This happens when device was stopped but VCPU wasn't. */ if (!vdev->vm_running) { q->tx_waiting = 1; @@ -1349,6 +1370,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; }