Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp803637ybb; Thu, 28 Mar 2019 12:29:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqx4z56s+bnhYVhgqLW5pYqGx7UgAOKHe6B8Ur7JSBBsz9lnQJo4/f597AjA2/BhIGP3NMIt X-Received: by 2002:a17:902:2848:: with SMTP id e66mr45531458plb.181.1553801391298; Thu, 28 Mar 2019 12:29:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553801391; cv=none; d=google.com; s=arc-20160816; b=j2hj/TbEU2hN5NxdAxqKWhCaC1EUqLbLCnroim2kjT0i2myxCJH6/r0r9YloVPDoCX 6UgrB+pWPxui8KKbI8tzjaA5i7DjDxPiuE/P+oSYySvNqPIuFum5/sWthMuGnSqrdwD4 mXyJhAQC/PIXDtkPRg3rwSTMqQzVvc5j6/L0GmbC35gthiTDJJP3NRU+Dqtuj3E4yR/9 YeOw7qknHKZuFQ3uwKsmecx5g0CtS4rTqUJgVztcBjXpjWm+3YomxGRQgH5zlTSlUOU/ GsfzF+98XuTtkDnJ0SJ87cCSm1CRXs6B7QYUR5y1/VDm02O/u0AVd0PAWekFVgyQzdAk vrgw== 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:mime-version :message-id:date:subject:cc:to:from; bh=zW2qcmTKEGciqpdBHgGa1wZoqJ8xKo71C+HexuoaIgo=; b=x7cag+4WUBZAWVEFXSkH67FuRsGfvBPpycDAXdrSSpnVaZ7YSRgGiCv+8Q8Eyq+aq0 7VJHjhwEjkKnBsmQ5pyTt1xoLuAtaA+hIe7pcjcC/Hy8zPGgbylqPZzYCR5FmHGELlc1 crTjf4vEnfVsrzjYDuwms3y12N06BknsbMCF3KhqIASwR/J4vaGIZy0q5DKSUiQebGhb 4Crlj60nczXUO/mK+vv3+xpiIbKptTyr86QzbbH+yJ3lxtop94OR0vPi3qfdhxnlJOG5 hKPENONOX5RuE8zdUnAa6kf6lEbY7yjSGpzCMbulhzSjtLE49Qv7HrIDjLgk1EFjylfx 14Tw== ARC-Authentication-Results: i=1; mx.google.com; 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 g136si6015370pfb.29.2019.03.28.12.29.35; Thu, 28 Mar 2019 12:29:51 -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; 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 S1726380AbfC1T27 (ORCPT + 99 others); Thu, 28 Mar 2019 15:28:59 -0400 Received: from a2nlsmtp01-05.prod.iad2.secureserver.net ([198.71.225.49]:57982 "EHLO a2nlsmtp01-05.prod.iad2.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725885AbfC1T26 (ORCPT ); Thu, 28 Mar 2019 15:28:58 -0400 X-Greylist: delayed 675 seconds by postgrey-1.27 at vger.kernel.org; Thu, 28 Mar 2019 15:28:58 EDT Received: from linuxonhyperv2.linuxonhyperv.com ([107.180.71.197]) by : HOSTING RELAY : with ESMTP id 9aW2hv8iAO8d99aW2hfRls; Thu, 28 Mar 2019 12:16:42 -0700 x-originating-ip: 107.180.71.197 Received: from haiyangz by linuxonhyperv2.linuxonhyperv.com with local (Exim 4.91) (envelope-from ) id 1h9aW2-0001kg-8E; Thu, 28 Mar 2019 12:16:42 -0700 From: Haiyang Zhang To: sashal@kernel.org, linux-hyperv@vger.kernel.org Cc: haiyangz@microsoft.com, kys@microsoft.com, sthemmin@microsoft.com, olaf@aepfle.de, vkuznets@redhat.com, davem@davemloft.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH hyperv-fixes,v2] hv_netvsc: Fix unwanted wakeup after tx_disable Date: Thu, 28 Mar 2019 19:16:37 +0000 Message-Id: <20190328191637.6698-1-haiyangz@linuxonhyperv.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4wfHnRjMqhpcL5yd3zLhFpxwp6QiyLwtVgV6++hxTnPSgFOJqcQzeJ11YqFaNJTPA9MBxNYjCgSrVYSngfFjELSUsHBokeiVIkAzAluOZW4TD9vsWdRBVH 9DRaAkMRClKGIkpYsjT++rQxerug1opm0RGhs5hRRK8N2Qw391veUT3+u3O0yoUw8MLDWAUvhM4n/wG7Px2407ttdlDxApmgiUC8b4cdQT5CvX8i8MntRs5G gR/lirCO5ib9g5I71FbFSoP2Ne9qpQlhkzhbdyoVu1PakuLHmZioNpJ6T5vPgayVXUyA5PvnBq2ObjdZSBjsqydcBd2DdFHdpbBZ2CFhSeaLxzaevu5d8b+y uVOIQKlIfbBBG5MomJNeJerc3AbE/0vqNTQzbDddNF9qS3Q6Nl+moWo48jMiJ5F7sXS3rsFNpqg/hxB49W70ROIlndXxlLvQW3q2PkyJHKm9hV9VKIuBzi28 aShPKi/WQ3t+ypGe7TGbYe84zTRKCsYTBHKR1O+ZEqSXshr69YeVttVSiQ4= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Haiyang Zhang After queue stopped, the wakeup mechanism may wake it up again when ring buffer usage is lower than a threshold. This may cause send path panic on NULL pointer when we stopped all tx queues in netvsc_detach and start removing the netvsc device. This patch fix it by adding a tx_disable flag to prevent unwanted queue wakeup. Fixes: 7b2ee50c0cd5 ("hv_netvsc: common detach logic") Reported-by: Mohammed Gamal Signed-off-by: Haiyang Zhang --- drivers/net/hyperv/hyperv_net.h | 1 + drivers/net/hyperv/netvsc.c | 6 ++++-- drivers/net/hyperv/netvsc_drv.c | 32 ++++++++++++++++++++++++++------ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h index e859ae2..49f41b6 100644 --- a/drivers/net/hyperv/hyperv_net.h +++ b/drivers/net/hyperv/hyperv_net.h @@ -987,6 +987,7 @@ struct netvsc_device { wait_queue_head_t wait_drain; bool destroy; + bool tx_disable; /* if true, do not wake up queue again */ /* Receive buffer allocated by us but manages by NetVSP */ void *recv_buf; diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c index 813d195..e0dce37 100644 --- a/drivers/net/hyperv/netvsc.c +++ b/drivers/net/hyperv/netvsc.c @@ -110,6 +110,7 @@ static struct netvsc_device *alloc_net_device(void) init_waitqueue_head(&net_device->wait_drain); net_device->destroy = false; + net_device->tx_disable = false; net_device->max_pkt = RNDIS_MAX_PKT_DEFAULT; net_device->pkt_align = RNDIS_PKT_ALIGN_DEFAULT; @@ -719,7 +720,7 @@ static void netvsc_send_tx_complete(struct net_device *ndev, } else { struct netdev_queue *txq = netdev_get_tx_queue(ndev, q_idx); - if (netif_tx_queue_stopped(txq) && + if (netif_tx_queue_stopped(txq) && !net_device->tx_disable && (hv_get_avail_to_write_percent(&channel->outbound) > RING_AVAIL_PERCENT_HIWATER || queue_sends < 1)) { netif_tx_wake_queue(txq); @@ -874,7 +875,8 @@ static inline int netvsc_send_pkt( } else if (ret == -EAGAIN) { netif_tx_stop_queue(txq); ndev_ctx->eth_stats.stop_queue++; - if (atomic_read(&nvchan->queue_sends) < 1) { + if (atomic_read(&nvchan->queue_sends) < 1 && + !net_device->tx_disable) { netif_tx_wake_queue(txq); ndev_ctx->eth_stats.wake_queue++; ret = -ENOSPC; diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c index 1a08679..ffb7922 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -109,6 +109,15 @@ static void netvsc_set_rx_mode(struct net_device *net) rcu_read_unlock(); } +static inline void netvsc_tx_enable(struct netvsc_device *nvscdev, + struct net_device *ndev) +{ + nvscdev->tx_disable = false; + virt_wmb(); /* ensure queue wake up mechanism is on */ + + netif_tx_wake_all_queues(ndev); +} + static int netvsc_open(struct net_device *net) { struct net_device_context *ndev_ctx = netdev_priv(net); @@ -129,7 +138,7 @@ static int netvsc_open(struct net_device *net) rdev = nvdev->extension; if (!rdev->link_state) { netif_carrier_on(net); - netif_tx_wake_all_queues(net); + netvsc_tx_enable(nvdev, net); } if (vf_netdev) { @@ -184,6 +193,17 @@ static int netvsc_wait_until_empty(struct netvsc_device *nvdev) } } +static inline void netvsc_tx_disable(struct netvsc_device *nvscdev, + struct net_device *ndev) +{ + if (nvscdev) { + nvscdev->tx_disable = true; + virt_wmb(); /* ensure txq will not wake up after stop */ + } + + netif_tx_disable(ndev); +} + static int netvsc_close(struct net_device *net) { struct net_device_context *net_device_ctx = netdev_priv(net); @@ -192,7 +212,7 @@ static int netvsc_close(struct net_device *net) struct netvsc_device *nvdev = rtnl_dereference(net_device_ctx->nvdev); int ret; - netif_tx_disable(net); + netvsc_tx_disable(nvdev, net); /* No need to close rndis filter if it is removed already */ if (!nvdev) @@ -918,7 +938,7 @@ static int netvsc_detach(struct net_device *ndev, /* If device was up (receiving) then shutdown */ if (netif_running(ndev)) { - netif_tx_disable(ndev); + netvsc_tx_disable(nvdev, ndev); ret = rndis_filter_close(nvdev); if (ret) { @@ -1906,7 +1926,7 @@ static void netvsc_link_change(struct work_struct *w) if (rdev->link_state) { rdev->link_state = false; netif_carrier_on(net); - netif_tx_wake_all_queues(net); + netvsc_tx_enable(net_device, net); } else { notify = true; } @@ -1916,7 +1936,7 @@ static void netvsc_link_change(struct work_struct *w) if (!rdev->link_state) { rdev->link_state = true; netif_carrier_off(net); - netif_tx_stop_all_queues(net); + netvsc_tx_disable(net_device, net); } kfree(event); break; @@ -1925,7 +1945,7 @@ static void netvsc_link_change(struct work_struct *w) if (!rdev->link_state) { rdev->link_state = true; netif_carrier_off(net); - netif_tx_stop_all_queues(net); + netvsc_tx_disable(net_device, net); event->event = RNDIS_STATUS_MEDIA_CONNECT; spin_lock_irqsave(&ndev_ctx->lock, flags); list_add(&event->list, &ndev_ctx->reconfig_events); -- 1.8.3.1