hv_netvsc: Fix unwanted wakeup after tx_disable
PATCH v2 1/1 hv_netvsc: Fix unwanted wakeup after tx_disable
From: Haiyang Zhang <[email protected]>
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.
--- 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(-)
drivers/net/hyperv/hyperv_net.h +1 -0
@@ -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;
drivers/net/hyperv/netvsc.c +4 -2
@@ -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 ;
drivers/net/hyperv/netvsc_drv.c +26 -6
@@ -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);
Signature · 1 line
1.8.3.1
David Miller
maintainerFrom: Haiyang Zhang <[email protected]>
Date: Thu, 28 Mar 2019 19:16:37 +0000
Quoted 7 lines
From: Haiyang Zhang <[email protected]>
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_detachand start removing the netvsc device.
Quoted 6 lines
This patch fix it by adding a
tx_disableflag to prevent unwanted queue wakeup.Fixes 7b2ee50c0cd5 ("hv_netvsc: common detach logic")Reported-by Mohammed Gamal <[email protected]>Signed-off-by Haiyang Zhang <[email protected]>
Still need to fix the inline issues I mentioned in v1.
David Miller
maintainerAlso, your email bounces:
<[email protected]>: host mail.linuxonhyperv.com[107.180.71.197] said:
550 No Such User Here (in reply to RCPT TO command)
Haiyang Zhang
maintainerQuoted 25 lines
-----Original Message-----
From: [email protected] <linux-hyperv- [email protected]> On Behalf Of David Miller
Sent: Thursday, March 28, 2019 3:22 PM
To: [email protected]
Cc: [email protected]; [email protected]; Haiyang Zhang <[email protected]>; KY Srinivasan <[email protected]>; Stephen Hemminger <[email protected]>; [email protected]; vkuznets <[email protected]>; [email protected]; linux- [email protected]
Subject: Re: [PATCH hyperv-fixes,v2]hv_netvsc: Fix unwanted wakeup aftertx_disableFrom: Haiyang Zhang <[email protected]>
Date: Thu, 28 Mar 2019 19:16:37 +0000Quoted 7 lines
From: Haiyang Zhang <[email protected]>
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_detachand start removing the netvsc device.
Quoted 8 lines
Quoted 6 lines
This patch fix it by adding a
tx_disableflag to prevent unwanted queue wakeup.Fixes 7b2ee50c0cd5 ("hv_netvsc: common detach logic")Reported-by Mohammed Gamal <[email protected]>Signed-off-by Haiyang Zhang <[email protected]>Still need to fix the inline issues I mentioned in v1.
I will fix the inline issues.
The [email protected] cannot receive emails. My regular email is in the reply-to: field.
Also, linuxonhyperv.com is being replaced by a new system soon.
Thanks.
- Haiyang