From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: netdev@vger.kernel.org
Cc: devel@linuxdriverproject.org,
Haiyang Zhang <haiyangz@microsoft.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH 5/6] hv_netvsc: synchronize netvsc_change_mtu()/netvsc_set_channels() with netvsc_remove()
Date: Thu, 12 May 2016 14:49:37 +0200 [thread overview]
Message-ID: <1463057378-21118-6-git-send-email-vkuznets@redhat.com> (raw)
In-Reply-To: <1463057378-21118-1-git-send-email-vkuznets@redhat.com>
When netvsc device is removed during mtu change or channels setup we get
into troubles as both paths are trying to remove the device. Synchronize
them with start_remove flag and rtnl lock.
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
drivers/net/hyperv/netvsc_drv.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 393403a..71b9125 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -707,7 +707,7 @@ static int netvsc_set_channels(struct net_device *net,
int ret = 0;
bool recovering = false;
- if (!nvdev || nvdev->destroy)
+ if (net_device_ctx->start_remove || !nvdev || nvdev->destroy)
return -ENODEV;
num_chn = nvdev->num_chn;
@@ -855,7 +855,7 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu)
u32 num_chn;
int ret = 0;
- if (nvdev == NULL || nvdev->destroy)
+ if (ndevctx->start_remove || !nvdev || nvdev->destroy)
return -ENODEV;
if (nvdev->nvsp_version >= NVSP_PROTOCOL_VERSION_2)
@@ -1206,7 +1206,12 @@ static int netvsc_remove(struct hv_device *dev)
ndev_ctx = netdev_priv(net);
net_device = ndev_ctx->nvdev;
+ /* Avoid racing with netvsc_change_mtu()/netvsc_set_channels()
+ * removing the device.
+ */
+ rtnl_lock();
ndev_ctx->start_remove = true;
+ rtnl_unlock();
cancel_delayed_work_sync(&ndev_ctx->dwork);
cancel_work_sync(&ndev_ctx->work);
--
2.5.5
next prev parent reply other threads:[~2016-05-12 12:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-12 12:49 [PATCH 0/6] hv_netvsc: avoid races on mtu change/set channels Vitaly Kuznetsov
2016-05-12 12:49 ` [PATCH 1/6] hv_netvsc: move start_remove flag to net_device_context Vitaly Kuznetsov
2016-05-12 12:49 ` [PATCH 2/6] hv_netvsc: use start_remove flag to protect netvsc_link_change() Vitaly Kuznetsov
2016-05-12 12:49 ` [PATCH 3/6] hv_netvsc: untangle the pointer mess Vitaly Kuznetsov
2016-05-12 12:49 ` [PATCH 4/6] hv_netvsc: get rid of struct net_device pointer in struct netvsc_device Vitaly Kuznetsov
2016-05-12 12:49 ` Vitaly Kuznetsov [this message]
2016-05-12 12:49 ` [PATCH 6/6] hv_netvsc: set nvdev link after populating chn_table Vitaly Kuznetsov
2016-05-12 14:58 ` Aw: [PATCH 0/6] hv_netvsc: avoid races on mtu change/set channels Lino Sanfilippo
2016-05-12 15:09 ` Vitaly Kuznetsov
2016-05-12 16:19 ` Aw: " Lino Sanfilippo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1463057378-21118-6-git-send-email-vkuznets@redhat.com \
--to=vkuznets@redhat.com \
--cc=devel@linuxdriverproject.org \
--cc=haiyangz@microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).