Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1423324imm; Wed, 17 Oct 2018 20:32:26 -0700 (PDT) X-Google-Smtp-Source: ACcGV63U3JhPpLhLqapxT/ap6xRDaeU+lsWZ4+KUTADbyYtZzJDwaf7KLQzWVCN6iXIvzjnzoAXl X-Received: by 2002:a62:38d0:: with SMTP id f199-v6mr29047718pfa.48.1539833546462; Wed, 17 Oct 2018 20:32:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539833546; cv=none; d=google.com; s=arc-20160816; b=JK4RNljYUcP473NfPhe0eqs/cE1J7fhlmPmVACCz2+MfcneK/82XaIw5vSia6vMouY NDTSfhasY2Y46a2eZ4ZQk8z0mkE1Q5pdjussrVXlvJmVUiNWB53FIqbo+vStsbC6u+l/ 2Uy2Gryd8ikkdbe0WLaZ56YlrOwM6QHB+2SFfnwoUTUlB5z87bAFQMZVdCtxmaB2jRJW reINOd4BUX+FQ7f9VLcVRIX3lQ/Vv3OA6W9cDaLOFc3R4tYJKfk91YX39s3IJ0UbfgVg 8g5+KFDA2XPaAleOrrPwRJyRlDhn3uTEwe0MuX10JwSfq5tZXx043PsAVi0NbXTliKDY CY5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=3R1trxg61+4u22Fe6T6bFbsV3shP8U9dUHPHGx4y3HM=; b=ggIsElk7hyItcxNClZLANRDWSgPHzUNrtTWhR85irdD3G/IIoJ6lWKUm9VkfFpjAZd 4bK1f0UPV1drMVBjSbI5v5yK4mskemWIRdY/2cmJ3kRoRijwhP+F2qBKTCNsuK77gFJb jEuJbguFlOP8xZr7x1Ad7xiqFng64YZjl1fvoUmcS79RPifxKlwz0oawt7pPbU7xOcx7 r+ohvCkFwIE0JimXPM3oWbCu8cUvIOxtw3IKILs3peU0lqO3+iv/oqIBaYgKOJAaJu1L j8uAoA4AyQ2sdgXm8FP405c71rtQHSqVhFdWnmXAQ2M07469FwFjWphoisLuFnsWRpU7 rsug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@igel-co-jp.20150623.gappssmtp.com header.s=20150623 header.b=hCPCwfqd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x2-v6si18645244pgr.432.2018.10.17.20.32.09; Wed, 17 Oct 2018 20:32:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@igel-co-jp.20150623.gappssmtp.com header.s=20150623 header.b=hCPCwfqd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727485AbeJRLYH (ORCPT + 99 others); Thu, 18 Oct 2018 07:24:07 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:41809 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727304AbeJRLYH (ORCPT ); Thu, 18 Oct 2018 07:24:07 -0400 Received: by mail-pf1-f196.google.com with SMTP id m77-v6so14190383pfi.8 for ; Wed, 17 Oct 2018 20:25:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=igel-co-jp.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=3R1trxg61+4u22Fe6T6bFbsV3shP8U9dUHPHGx4y3HM=; b=hCPCwfqdi6Wg+d0Z7KPkGztuBl48S6y3qDYWJKNhwEJQwSUnE82McS/OwgmoLWxife Mg9wrzImNRcxghMiBX7IOBZe2pxSOE30ZgwEGd66I9rhbYxtFwqJQeSR2EWLck/Uie6n L/Qv37gUNnb6Snh1LwwWGxbBh034VUeMAxcs28i4UONMWSu0GCGryHMX22LE9vEH2oFt i25cqOCOIQ0dBgjl+CkO4zDkds+VBfqAAGkOQ5j+TLVrrBc9NQ32sWkpGTPKARcp6Vb1 1VibyCUu8EkGk374PbeZKY0FjX68nyJHL5z5WElq+BYb6D49vfCpH0rdVIwqVLb485DA 3nPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=3R1trxg61+4u22Fe6T6bFbsV3shP8U9dUHPHGx4y3HM=; b=CICP8xRZkFMWByJZtQj+NiCfXdpgVVzEMAiDip8EKW9mkjTJ3+mwCqNeu9uO2Vu5kS d06P/bTegR6Ylmc/Mz/q86AG+PdKRKuE1koeqDYrs6i0LqCQF514uAFpB5KGdxLqdTxz wF5DZvnX35oaEjAz+idQda5bzgBrYrSKiBd48XOPC0YS+E2CqydlT+Jeqn4P2Zbz4vZR n005K9wLaBoq73qOqWvsE3LugGL0Nq0HmJMLpcAnIrw2W+9ZRb64j3KRPa8viIBN+ubr ltyPYIimlzSnvLC/x16w12e2Lor5DjNtyiMqJhVKAucGnnNX6u2xypL30Vbpq4OdeIR4 lNGQ== X-Gm-Message-State: ABuFfoh37wnwISnPo1yZxr2lIQkPtJmY5R77VtpdZpQhVcNS3wldShnv srEMcXW93cckRM7WQvujTjv2WZO+XTSGIQ== X-Received: by 2002:a63:3e49:: with SMTP id l70-v6mr126124pga.96.1539833118295; Wed, 17 Oct 2018 20:25:18 -0700 (PDT) Received: from [10.16.144.1] (napt.igel.co.jp. [219.106.231.132]) by smtp.gmail.com with ESMTPSA id l83-v6sm37982086pfi.172.2018.10.17.20.25.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Oct 2018 20:25:17 -0700 (PDT) Subject: Re: [PATCH v3] virtio_net: avoid using netif_tx_disable() for serializing tx routine To: "Michael S. Tsirkin" Cc: Jason Wang , "David S. Miller" , virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <276ac5bb-90f7-5fb6-a826-0bb05ecfa069@redhat.com> <20181017104419.13003-1-ake@igel.co.jp> <20181017110741-mutt-send-email-mst@kernel.org> From: ake Message-ID: Date: Thu, 18 Oct 2018 12:25:14 +0900 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20181017110741-mutt-send-email-mst@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018/10/18 0:09, Michael S. Tsirkin wrote: > On Wed, Oct 17, 2018 at 07:44:12PM +0900, Ake Koomsin wrote: >> Commit 713a98d90c5e ("virtio-net: serialize tx routine during reset") >> introduces netif_tx_disable() after netif_device_detach() in order to >> avoid use-after-free of tx queues. However, there are two issues. >> >> 1) Its operation is redundant with netif_device_detach() in case the >> interface is running. >> 2) In case of the interface is not running before suspending and >> resuming, the tx does not get resumed by netif_device_attach(). >> This results in losing network connectivity. >> >> It is better to use netif_tx_lock_bh()/netif_tx_unlock_bh() instead for >> serializing tx routine during reset. This also preserves the symmetry >> of netif_device_detach() and netif_device_attach(). >> >> Fixes commit 713a98d90c5e ("virtio-net: serialize tx routine during reset") >> Signed-off-by: Ake Koomsin > > Acked-by: Michael S. Tsirkin > > Thanks a lot for debugging! > Seems like stable material to me, right? Yes. With this patch, we can avoid network connectivity lost because of tx not get re-enabled under some situation. Plus, it avoids redundant operation between netif_device_detach() and netif_tx_disable(). I tested the patch on Linux net-next and QEMU master by suspending/ resuming the virtual machine repeatedly. The network looks no problem and has no connectivity lost so far. I tested with both user-mode networking and tap interface. Best Regards >> --- >> drivers/net/virtio_net.c | 5 ++++- >> 1 file changed, 4 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c >> index 3f5aa59c37b7..3e2c041d76ac 100644 >> --- a/drivers/net/virtio_net.c >> +++ b/drivers/net/virtio_net.c >> @@ -2267,8 +2267,9 @@ static void virtnet_freeze_down(struct virtio_device *vdev) >> /* Make sure no work handler is accessing the device */ >> flush_work(&vi->config_work); >> >> + netif_tx_lock_bh(vi->dev); >> netif_device_detach(vi->dev); >> - netif_tx_disable(vi->dev); >> + netif_tx_unlock_bh(vi->dev); >> cancel_delayed_work_sync(&vi->refill); >> >> if (netif_running(vi->dev)) { >> @@ -2304,7 +2305,9 @@ static int virtnet_restore_up(struct virtio_device *vdev) >> } >> } >> >> + netif_tx_lock_bh(vi->dev); >> netif_device_attach(vi->dev); >> + netif_tx_unlock_bh(vi->dev); >> return err; >> } >> >> -- >> 2.19.1