Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2522197yba; Mon, 15 Apr 2019 13:30:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqzasqiEwY1TMtmO/txtck+KK7KDH4VIeft3cNMceKO+l5kVBvq38L1Qu0DQhRdlfAAc1cPl X-Received: by 2002:a63:8143:: with SMTP id t64mr70954171pgd.301.1555360225060; Mon, 15 Apr 2019 13:30:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555360225; cv=none; d=google.com; s=arc-20160816; b=0WlMRSInwceAW6g2LM4auD9a3+xb+5wu44UEM/f486qZQAY9mRHq+dxhAurmzoSP2x AwEYOvqQ0C14o3tsg4V1qicPZkfdTJxOejvXVi5MbxH2KZdWmqL7Be5iDK8DjakVxg/4 ZfhnVQCHGEft/b974ehRBp4W1gdclLCaA8r08Skr49f9we0DHzxEhyy58ez3Kd/S9RZa /ZrqaBcWFIEiHID8AAYtbwGsUg3lT/eXVzBysd8yaiM/DN8CBvoUq0X2BD00+eLKolr3 gRh95zibGuNACnbwKbieu+BGbRIKeINDgxy86QjHl7w8DpEqYIDSyBNBjDryKd9C/wHF W03g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PP8znEp7Hz3A8JfaB/Gw4ZTpmIP0s6YiNa+1BdDl7jk=; b=ORTkzl8ZNNYFxoPZNGyTHPN8VjR4iIiIKLmua0nQki9xnfM0KnD0g79QG/WgmUWp+5 SHF/UlfZxXA2GH2KNTj1/jaX7d+3Ld+6LTKwHfYqhl7A8pk0Ddum/36WReUXh7/PMuD6 +zO+AEdYbHh3L5uPZZ47GgnoEKxoED3fhyukfb4rrBvXDE+FXjrdKelBCxBGZfxdHV6W WkKteKPSm9kSpB9IaoPFsM0rWuR6qXziZDZXHCxoX7Q5cvn+xOeqs7e3ZWbSbHe5tTAm bTpG2nOHkEwbpx17uIiD2CzurtGmi56tL6rZ3LdcBs7CZPf87gYmG0P75ODdOsdDFJIL 6teQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="kkxKy/7l"; 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 w10si42965557plz.37.2019.04.15.13.30.08; Mon, 15 Apr 2019 13:30:25 -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=@kernel.org header.s=default header.b="kkxKy/7l"; 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 S1729157AbfDOTFF (ORCPT + 99 others); Mon, 15 Apr 2019 15:05:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:38506 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728276AbfDOTFE (ORCPT ); Mon, 15 Apr 2019 15:05:04 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BCD95218DA; Mon, 15 Apr 2019 19:05:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555355103; bh=w7aSaOuoA1FhkoVB4lx229H9iNUVi1cwmcPQ8Zbb0pc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kkxKy/7lk751a8HUyDAUCn/qEoHmcpwf6NCRZH2HrspZ2yrMmo1FTcJNrOFNkLIcH fKIbeZi56shnEFHomrF7Sqe1GB3go/bpExDWcfaH0a9xf/rmotuqMG2C/mjjwZDle0 KIQYSdIKdl6LnXBQ32HY2gl1agbJDQaGAdFjcO64= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mohammed Gamal , Haiyang Zhang , "David S. Miller" , Sasha Levin Subject: [PATCH 4.19 004/101] hv_netvsc: Fix unwanted wakeup after tx_disable Date: Mon, 15 Apr 2019 20:58:02 +0200 Message-Id: <20190415183740.578207548@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415183740.341577907@linuxfoundation.org> References: <20190415183740.341577907@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 1b704c4a1ba95574832e730f23817b651db2aa59 ] 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 Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- 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 42d284669b03..31d8d83c25ac 100644 --- a/drivers/net/hyperv/hyperv_net.h +++ b/drivers/net/hyperv/hyperv_net.h @@ -970,6 +970,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 1a942feab954..fb12b63439c6 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; @@ -716,7 +717,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); @@ -871,7 +872,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 c8320405c8f1..9d699bd5f715 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 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 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) { @@ -1899,7 +1919,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; } @@ -1909,7 +1929,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; @@ -1918,7 +1938,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); -- 2.19.1