From patchwork Wed Nov 9 15:22:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 692830 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.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 3tDVMf6bqSz9vDp for ; Thu, 10 Nov 2016 02:24:14 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=daynix-com.20150623.gappssmtp.com header.i=@daynix-com.20150623.gappssmtp.com header.b="fFnl/TFN"; dkim-atps=neutral Received: from localhost ([::1]:40570 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c4UjU-0006En-Hq for incoming@patchwork.ozlabs.org; Wed, 09 Nov 2016 10:24:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49507) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c4Uhq-0004n9-PZ for qemu-devel@nongnu.org; Wed, 09 Nov 2016 10:22:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c4Uhp-0006Os-N8 for qemu-devel@nongnu.org; Wed, 09 Nov 2016 10:22:30 -0500 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:36355) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c4Uhp-0006NL-Ge for qemu-devel@nongnu.org; Wed, 09 Nov 2016 10:22:29 -0500 Received: by mail-wm0-x243.google.com with SMTP id c17so29841404wmc.3 for ; Wed, 09 Nov 2016 07:22:29 -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=0SCoscKNXyCnyAoCHKufOKHsdvAb0Uq0hf4AEBCVIQM=; b=fFnl/TFNuWknaiLTNLp4P05nLmD0FF0akPsGVp2ckl2C5velEdGHdKftOF7RgZAIny Esg1PFan9e7Gz1xgywDQlCM7ReQSSbfonLBJXDrOyPsBHTh2KBanmb/e+LSNhUK7Xh83 so43EuPhBWI4yjEA03ntOZ2Q3YoaE/2FGpmL/zztp0+rUKkc6GB7II26FFYfAIlvlsk2 Q8WQfUDxF7Vy+JDFPZTW8MZ1eiyyLWga3ZFmlsQqjRBlY7rEkyERUaRCPPZFRSsKjw6O OLLQcFSpkZxtHmHGVlO1cETRTaup+zeTisCcYSOBeF/DuSXO3Cl9qt7SO8QLK2SOfsmU PwJA== 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=0SCoscKNXyCnyAoCHKufOKHsdvAb0Uq0hf4AEBCVIQM=; b=R6ddeNWAbgfI3ho54qE+cHrwsYjdXX66B+1lKP7P8IEgdzj5Uex9FRfGcroGtDc37H xKd1TJH9D/O34y8PFkcL4FOvSyyaUf5A9OLf25yp8tWrdHlyfey6bXENa+rz44p29vjS 4zqmB6JTViiV2T6JAa+3H1q042+c4IBTF1vcFdiY9X0Vzjm6uPuXz7SDRN17fpwZwFyU jZvHW4cLg+fQIw65W3gTDIRobQRHdof0KvK08Z3c+2lfXf8LqYtcnt7UEVse38Cj6V9C wiMexkWmQrLF41IGM0iJIFTyNKfpWrE8rWM+3Uk4fs7SS/6sMWzSuHllFccx6SH4qLJ4 WDfg== X-Gm-Message-State: ABUngveEw5U7ld9AImfQNusseUrjy7vbYkDQlKwBabyM4VU7t1L6WdxjRVM/g+Tt3fFizQ== X-Received: by 10.28.63.3 with SMTP id m3mr752936wma.113.1478704948355; Wed, 09 Nov 2016 07:22:28 -0800 (PST) Received: from localhost.localdomain ([141.226.163.133]) by smtp.gmail.com with ESMTPSA id q125sm822641wmd.2.2016.11.09.07.22.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Nov 2016 07:22:27 -0800 (PST) From: yuri.benditovich@daynix.com To: "Michael S . Tsirkin" , Jason Wang , qemu-devel@nongnu.org Date: Wed, 9 Nov 2016 17:22:02 +0200 Message-Id: <1478704922-3400-4-git-send-email-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1478704922-3400-1-git-send-email-yuri.benditovich@daynix.com> References: <1478704922-3400-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 v2 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 06bfe4b..ab4e18a 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -218,6 +218,16 @@ static void virtio_net_vnet_endian_status(VirtIONet *n, uint8_t status) } } +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 void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status) { VirtIONet *n = VIRTIO_NET(vdev); @@ -262,6 +272,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); + } } } } @@ -1319,6 +1337,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; @@ -1345,6 +1368,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; }