linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2][PATCH net] hv_netvsc: Add the support of hibernation
@ 2019-09-25 22:04 Dexuan Cui
  2019-09-25 22:23 ` Haiyang Zhang
  2019-09-27  4:17 ` kbuild test robot
  0 siblings, 2 replies; 5+ messages in thread
From: Dexuan Cui @ 2019-09-25 22:04 UTC (permalink / raw)
  To: KY Srinivasan, Haiyang Zhang, Stephen Hemminger, sashal, davem,
	linux-hyperv, netdev, linux-kernel, Michael Kelley
  Cc: Dexuan Cui

The existing netvsc_detach() and netvsc_attach() APIs make it easy to
implement the suspend/resume callbacks.

Signed-off-by: Dexuan Cui <decui@microsoft.com>
---

This patch is basically a pure Hyper-V specific change. I request this
patch should go through Sasha's Hyper-V tree rather than the net tree.

Sasha's Hyper-V tree is here:
https://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux.git

Previously there was a dependency on the commit 271b2224d42f ("Drivers:
hv: vmbus: Implement suspend/resume for VSC drivers for hibernation"),
which was only on Sasha Levin's Hyper-V tree's hyperv-next branch:
https://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux.git/log/?h=hyperv-next
. Now the patch has been merged into Linus's master tree, but as of now,
the patch (271b2224d42f) has not appeared in the net.git tree, so IMO
it's better for this patch to go through the Hyper-V tree. The added
code in this patch is unlikely to cause a conflict.

In v2:
    Removed the superfluous "cancel_work_sync(&nvdev->subchan_work)".

    Changed the [PATCH net-next] to [PATCH net] in the Subject, because
    IMO this is more of a bug fix rather than a new feaure.

    No other change.

 drivers/net/hyperv/hyperv_net.h |  3 ++
 drivers/net/hyperv/netvsc_drv.c | 57 +++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index ecc9af050387..b8763ee4c0d0 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -952,6 +952,9 @@ struct net_device_context {
 	u32 vf_alloc;
 	/* Serial number of the VF to team with */
 	u32 vf_serial;
+
+	/* Used to temporarily save the config info across hibernation */
+	struct netvsc_device_info *saved_netvsc_dev_info;
 };
 
 /* Per channel data */
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index afdcc5664ea6..53a9451a58a7 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -2392,6 +2392,61 @@ static int netvsc_remove(struct hv_device *dev)
 	return 0;
 }
 
+static int netvsc_suspend(struct hv_device *dev)
+{
+	struct net_device_context *ndev_ctx;
+	struct net_device *vf_netdev, *net;
+	struct netvsc_device *nvdev;
+	int ret;
+
+	net = hv_get_drvdata(dev);
+
+	ndev_ctx = netdev_priv(net);
+	cancel_delayed_work_sync(&ndev_ctx->dwork);
+
+	rtnl_lock();
+
+	nvdev = rtnl_dereference(ndev_ctx->nvdev);
+	if (nvdev == NULL) {
+		ret = -ENODEV;
+		goto out;
+	}
+
+	vf_netdev = rtnl_dereference(ndev_ctx->vf_netdev);
+	if (vf_netdev)
+		netvsc_unregister_vf(vf_netdev);
+
+	/* Save the current config info */
+	ndev_ctx->saved_netvsc_dev_info = netvsc_devinfo_get(nvdev);
+
+	ret = netvsc_detach(net, nvdev);
+out:
+	rtnl_unlock();
+
+	return ret;
+}
+
+static int netvsc_resume(struct hv_device *dev)
+{
+	struct net_device *net = hv_get_drvdata(dev);
+	struct net_device_context *net_device_ctx;
+	struct netvsc_device_info *device_info;
+	int ret;
+
+	rtnl_lock();
+
+	net_device_ctx = netdev_priv(net);
+	device_info = net_device_ctx->saved_netvsc_dev_info;
+
+	ret = netvsc_attach(net, device_info);
+
+	rtnl_unlock();
+
+	kfree(device_info);
+	net_device_ctx->saved_netvsc_dev_info = NULL;
+
+	return ret;
+}
 static const struct hv_vmbus_device_id id_table[] = {
 	/* Network guid */
 	{ HV_NIC_GUID, },
@@ -2406,6 +2461,8 @@ static struct  hv_driver netvsc_drv = {
 	.id_table = id_table,
 	.probe = netvsc_probe,
 	.remove = netvsc_remove,
+	.suspend = netvsc_suspend,
+	.resume = netvsc_resume,
 	.driver = {
 		.probe_type = PROBE_FORCE_SYNCHRONOUS,
 	},
-- 
2.19.1


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

* RE: [PATCH v2][PATCH net] hv_netvsc: Add the support of hibernation
  2019-09-25 22:04 [PATCH v2][PATCH net] hv_netvsc: Add the support of hibernation Dexuan Cui
@ 2019-09-25 22:23 ` Haiyang Zhang
  2019-10-01 18:59   ` Sasha Levin
  2019-09-27  4:17 ` kbuild test robot
  1 sibling, 1 reply; 5+ messages in thread
From: Haiyang Zhang @ 2019-09-25 22:23 UTC (permalink / raw)
  To: Dexuan Cui, KY Srinivasan, Stephen Hemminger, sashal, davem,
	linux-hyperv, netdev, linux-kernel, Michael Kelley



> -----Original Message-----
> From: Dexuan Cui <decui@microsoft.com>
> Sent: Wednesday, September 25, 2019 6:04 PM
> To: KY Srinivasan <kys@microsoft.com>; Haiyang Zhang
> <haiyangz@microsoft.com>; Stephen Hemminger
> <sthemmin@microsoft.com>; sashal@kernel.org; davem@davemloft.net;
> linux-hyperv@vger.kernel.org; netdev@vger.kernel.org; linux-
> kernel@vger.kernel.org; Michael Kelley <mikelley@microsoft.com>
> Cc: Dexuan Cui <decui@microsoft.com>
> Subject: [PATCH v2][PATCH net] hv_netvsc: Add the support of hibernation
> 
> The existing netvsc_detach() and netvsc_attach() APIs make it easy to
> implement the suspend/resume callbacks.
> 
> Signed-off-by: Dexuan Cui <decui@microsoft.com>

Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com>

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

* Re: [PATCH v2][PATCH net] hv_netvsc: Add the support of hibernation
  2019-09-25 22:04 [PATCH v2][PATCH net] hv_netvsc: Add the support of hibernation Dexuan Cui
  2019-09-25 22:23 ` Haiyang Zhang
@ 2019-09-27  4:17 ` kbuild test robot
  2019-09-27  4:39   ` Dexuan Cui
  1 sibling, 1 reply; 5+ messages in thread
From: kbuild test robot @ 2019-09-27  4:17 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: kbuild-all, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
	sashal, davem, linux-hyperv, netdev, linux-kernel,
	Michael Kelley, Dexuan Cui

[-- Attachment #1: Type: text/plain, Size: 2030 bytes --]

Hi Dexuan,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net/master]

url:    https://github.com/0day-ci/linux/commits/Dexuan-Cui/hv_netvsc-Add-the-support-of-hibernation/20190926-061258
config: x86_64-rhel-7.6 (attached as .config)
compiler: gcc-7 (Debian 7.4.0-13) 7.4.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>):

>> drivers/net/hyperv/netvsc_drv.c:2486:3: error: 'struct hv_driver' has no member named 'suspend'
     .suspend = netvsc_suspend,
      ^~~~~~~
>> drivers/net/hyperv/netvsc_drv.c:2486:13: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
     .suspend = netvsc_suspend,
                ^~~~~~~~~~~~~~
   drivers/net/hyperv/netvsc_drv.c:2486:13: note: (near initialization for 'netvsc_drv.shutdown')
>> drivers/net/hyperv/netvsc_drv.c:2487:3: error: 'struct hv_driver' has no member named 'resume'; did you mean 'remove'?
     .resume = netvsc_resume,
      ^~~~~~
      remove
>> drivers/net/hyperv/netvsc_drv.c:2487:12: warning: excess elements in struct initializer
     .resume = netvsc_resume,
               ^~~~~~~~~~~~~
   drivers/net/hyperv/netvsc_drv.c:2487:12: note: (near initialization for 'netvsc_drv')
   cc1: some warnings being treated as errors

vim +2486 drivers/net/hyperv/netvsc_drv.c

  2479	
  2480	/* The one and only one */
  2481	static struct  hv_driver netvsc_drv = {
  2482		.name = KBUILD_MODNAME,
  2483		.id_table = id_table,
  2484		.probe = netvsc_probe,
  2485		.remove = netvsc_remove,
> 2486		.suspend = netvsc_suspend,
> 2487		.resume = netvsc_resume,
  2488		.driver = {
  2489			.probe_type = PROBE_FORCE_SYNCHRONOUS,
  2490		},
  2491	};
  2492	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 48169 bytes --]

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

* RE: [PATCH v2][PATCH net] hv_netvsc: Add the support of hibernation
  2019-09-27  4:17 ` kbuild test robot
@ 2019-09-27  4:39   ` Dexuan Cui
  0 siblings, 0 replies; 5+ messages in thread
From: Dexuan Cui @ 2019-09-27  4:39 UTC (permalink / raw)
  To: kbuild test robot
  Cc: kbuild-all, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
	sashal, davem, linux-hyperv, netdev, linux-kernel,
	Michael Kelley

> From: linux-hyperv-owner@vger.kernel.org
> <linux-hyperv-owner@vger.kernel.org> On Behalf Of kbuild test robot
> Sent: Thursday, September 26, 2019 9:18 PM
> 
> Hi Dexuan,
> 
> Thank you for the patch! Yet something to improve:
> 
> [auto build test ERROR on net/master]
> 
> 'netvsc_drv.shutdown')
> >> drivers/net/hyperv/netvsc_drv.c:2487:3: error: 'struct hv_driver' has no
> member named 'resume'; did you mean 'remove'?
>      .resume = netvsc_resume,
>       ^~~~~~

This is a false alarm. Your code base needs to be merged with the latest 
Linus's tree, which has the prerequisite patch:
271b2224d42f ("Drivers: hv: vmbus: Implement suspend/resume for VSC drivers for hibernation")

Thanks,
-- Dexuan

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

* Re: [PATCH v2][PATCH net] hv_netvsc: Add the support of hibernation
  2019-09-25 22:23 ` Haiyang Zhang
@ 2019-10-01 18:59   ` Sasha Levin
  0 siblings, 0 replies; 5+ messages in thread
From: Sasha Levin @ 2019-10-01 18:59 UTC (permalink / raw)
  To: Haiyang Zhang
  Cc: Dexuan Cui, KY Srinivasan, Stephen Hemminger, davem,
	linux-hyperv, netdev, linux-kernel, Michael Kelley

On Wed, Sep 25, 2019 at 10:23:28PM +0000, Haiyang Zhang wrote:
>
>
>> -----Original Message-----
>> From: Dexuan Cui <decui@microsoft.com>
>> Sent: Wednesday, September 25, 2019 6:04 PM
>> To: KY Srinivasan <kys@microsoft.com>; Haiyang Zhang
>> <haiyangz@microsoft.com>; Stephen Hemminger
>> <sthemmin@microsoft.com>; sashal@kernel.org; davem@davemloft.net;
>> linux-hyperv@vger.kernel.org; netdev@vger.kernel.org; linux-
>> kernel@vger.kernel.org; Michael Kelley <mikelley@microsoft.com>
>> Cc: Dexuan Cui <decui@microsoft.com>
>> Subject: [PATCH v2][PATCH net] hv_netvsc: Add the support of hibernation
>>
>> The existing netvsc_detach() and netvsc_attach() APIs make it easy to
>> implement the suspend/resume callbacks.
>>
>> Signed-off-by: Dexuan Cui <decui@microsoft.com>
>
>Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com>

Queued up for hyperv-next, thanks!

--
Thanks,
Sasha

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

end of thread, other threads:[~2019-10-01 18:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-25 22:04 [PATCH v2][PATCH net] hv_netvsc: Add the support of hibernation Dexuan Cui
2019-09-25 22:23 ` Haiyang Zhang
2019-10-01 18:59   ` Sasha Levin
2019-09-27  4:17 ` kbuild test robot
2019-09-27  4:39   ` Dexuan Cui

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