netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] netvsc: transparent VF related cleanups
@ 2017-08-31 23:16 Stephen Hemminger
  2017-08-31 23:16 ` [PATCH net-next 1/2] netvsc: cleanup datapath switch Stephen Hemminger
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Stephen Hemminger @ 2017-08-31 23:16 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin; +Cc: devel, netdev

The first gets rid of unnecessary ref counting, and second
allows removing hv_netvsc driver even if VF present.

Stephen Hemminger (2):
  netvsc: cleanup datapath switch
  netvsc: allow driver to be removed even if VF is present

 drivers/net/hyperv/netvsc_drv.c | 55 ++++++++++++-----------------------------
 1 file changed, 16 insertions(+), 39 deletions(-)

-- 
2.11.0

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net-next 1/2] netvsc: cleanup datapath switch
  2017-08-31 23:16 [PATCH net-next 0/2] netvsc: transparent VF related cleanups Stephen Hemminger
@ 2017-08-31 23:16 ` Stephen Hemminger
  2017-08-31 23:16 ` [PATCH net-next 2/2] netvsc: allow driver to be removed even if VF is present Stephen Hemminger
  2017-09-02  3:31 ` [PATCH net-next 0/2] netvsc: transparent VF related cleanups David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2017-08-31 23:16 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin; +Cc: devel, netdev

Use one routine for datapath up/down. Don't need to reopen
the rndis layer.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
---
 drivers/net/hyperv/netvsc_drv.c | 38 +++++++-------------------------------
 1 file changed, 7 insertions(+), 31 deletions(-)

diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index fac44c5c8d0d..128165e49c9a 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -1842,11 +1842,13 @@ static int netvsc_register_vf(struct net_device *vf_netdev)
 	return NOTIFY_OK;
 }
 
-static int netvsc_vf_up(struct net_device *vf_netdev)
+/* VF up/down change detected, schedule to change data path */
+static int netvsc_vf_changed(struct net_device *vf_netdev)
 {
 	struct net_device_context *net_device_ctx;
 	struct netvsc_device *netvsc_dev;
 	struct net_device *ndev;
+	bool vf_is_up = netif_running(vf_netdev);
 
 	ndev = get_netvsc_byref(vf_netdev);
 	if (!ndev)
@@ -1857,34 +1859,9 @@ static int netvsc_vf_up(struct net_device *vf_netdev)
 	if (!netvsc_dev)
 		return NOTIFY_DONE;
 
-	/* Bump refcount when datapath is acvive - Why? */
-	rndis_filter_open(netvsc_dev);
-
-	/* notify the host to switch the data path. */
-	netvsc_switch_datapath(ndev, true);
-	netdev_info(ndev, "Data path switched to VF: %s\n", vf_netdev->name);
-
-	return NOTIFY_OK;
-}
-
-static int netvsc_vf_down(struct net_device *vf_netdev)
-{
-	struct net_device_context *net_device_ctx;
-	struct netvsc_device *netvsc_dev;
-	struct net_device *ndev;
-
-	ndev = get_netvsc_byref(vf_netdev);
-	if (!ndev)
-		return NOTIFY_DONE;
-
-	net_device_ctx = netdev_priv(ndev);
-	netvsc_dev = rtnl_dereference(net_device_ctx->nvdev);
-	if (!netvsc_dev)
-		return NOTIFY_DONE;
-
-	netvsc_switch_datapath(ndev, false);
-	netdev_info(ndev, "Data path switched from VF: %s\n", vf_netdev->name);
-	rndis_filter_close(netvsc_dev);
+	netvsc_switch_datapath(ndev, vf_is_up);
+	netdev_info(ndev, "Data path switched %s VF: %s\n",
+		    vf_is_up ? "to" : "from", vf_netdev->name);
 
 	return NOTIFY_OK;
 }
@@ -2094,9 +2071,8 @@ static int netvsc_netdev_event(struct notifier_block *this,
 	case NETDEV_UNREGISTER:
 		return netvsc_unregister_vf(event_dev);
 	case NETDEV_UP:
-		return netvsc_vf_up(event_dev);
 	case NETDEV_DOWN:
-		return netvsc_vf_down(event_dev);
+		return netvsc_vf_changed(event_dev);
 	default:
 		return NOTIFY_DONE;
 	}
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net-next 2/2] netvsc: allow driver to be removed even if VF is present
  2017-08-31 23:16 [PATCH net-next 0/2] netvsc: transparent VF related cleanups Stephen Hemminger
  2017-08-31 23:16 ` [PATCH net-next 1/2] netvsc: cleanup datapath switch Stephen Hemminger
@ 2017-08-31 23:16 ` Stephen Hemminger
  2017-09-02  3:31 ` [PATCH net-next 0/2] netvsc: transparent VF related cleanups David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2017-08-31 23:16 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin; +Cc: devel, netdev

If VF is attached then can still allow netvsc driver module to
be removed. Just have to make sure and do the cleanup.

Also, avoid extra rtnl round trip when calling unregister.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
---
 drivers/net/hyperv/netvsc_drv.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 128165e49c9a..97ed4bdc439f 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -1834,9 +1834,6 @@ static int netvsc_register_vf(struct net_device *vf_netdev)
 
 	netdev_info(ndev, "VF registering: %s\n", vf_netdev->name);
 
-	/* Prevent this module from being unloaded while VF is registered */
-	try_module_get(THIS_MODULE);
-
 	dev_hold(vf_netdev);
 	rcu_assign_pointer(net_device_ctx->vf_netdev, vf_netdev);
 	return NOTIFY_OK;
@@ -1880,10 +1877,11 @@ static int netvsc_unregister_vf(struct net_device *vf_netdev)
 
 	netdev_info(ndev, "VF unregistering: %s\n", vf_netdev->name);
 
+	netdev_rx_handler_unregister(vf_netdev);
 	netdev_upper_dev_unlink(vf_netdev, ndev);
 	RCU_INIT_POINTER(net_device_ctx->vf_netdev, NULL);
 	dev_put(vf_netdev);
-	module_put(THIS_MODULE);
+
 	return NOTIFY_OK;
 }
 
@@ -1987,11 +1985,11 @@ static int netvsc_probe(struct hv_device *dev,
 
 static int netvsc_remove(struct hv_device *dev)
 {
-	struct net_device *net;
 	struct net_device_context *ndev_ctx;
+	struct net_device *vf_netdev;
+	struct net_device *net;
 
 	net = hv_get_drvdata(dev);
-
 	if (net == NULL) {
 		dev_err(&dev->device, "No net device to remove\n");
 		return 0;
@@ -2008,12 +2006,15 @@ static int netvsc_remove(struct hv_device *dev)
 	 * removed. Also blocks mtu and channel changes.
 	 */
 	rtnl_lock();
+	vf_netdev = rtnl_dereference(ndev_ctx->vf_netdev);
+	if (vf_netdev)
+		netvsc_unregister_vf(vf_netdev);
+
 	rndis_filter_device_remove(dev,
 				   rtnl_dereference(ndev_ctx->nvdev));
+	unregister_netdevice(net);
 	rtnl_unlock();
 
-	unregister_netdev(net);
-
 	hv_set_drvdata(dev, NULL);
 
 	free_percpu(ndev_ctx->vf_stats);
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next 0/2] netvsc: transparent VF related cleanups
  2017-08-31 23:16 [PATCH net-next 0/2] netvsc: transparent VF related cleanups Stephen Hemminger
  2017-08-31 23:16 ` [PATCH net-next 1/2] netvsc: cleanup datapath switch Stephen Hemminger
  2017-08-31 23:16 ` [PATCH net-next 2/2] netvsc: allow driver to be removed even if VF is present Stephen Hemminger
@ 2017-09-02  3:31 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2017-09-02  3:31 UTC (permalink / raw)
  To: stephen; +Cc: kys, haiyangz, sthemmin, devel, netdev

From: Stephen Hemminger <stephen@networkplumber.org>
Date: Thu, 31 Aug 2017 16:16:11 -0700

> The first gets rid of unnecessary ref counting, and second
> allows removing hv_netvsc driver even if VF present.

Series applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-09-02  3:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-31 23:16 [PATCH net-next 0/2] netvsc: transparent VF related cleanups Stephen Hemminger
2017-08-31 23:16 ` [PATCH net-next 1/2] netvsc: cleanup datapath switch Stephen Hemminger
2017-08-31 23:16 ` [PATCH net-next 2/2] netvsc: allow driver to be removed even if VF is present Stephen Hemminger
2017-09-02  3:31 ` [PATCH net-next 0/2] netvsc: transparent VF related cleanups David Miller

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).