linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] HID: hyperv: Add the support of hibernation
@ 2019-09-11 23:35 Dexuan Cui
  2019-09-25 19:53 ` Dexuan Cui
  0 siblings, 1 reply; 8+ messages in thread
From: Dexuan Cui @ 2019-09-11 23:35 UTC (permalink / raw)
  To: KY Srinivasan, Haiyang Zhang, Stephen Hemminger, sashal, jikos,
	benjamin.tissoires, linux-hyperv, linux-input, linux-kernel,
	Michael Kelley
  Cc: Dexuan Cui

We need mousevsc_pm_notify() to make sure the pm_wakeup_hard_event() call
does not prevent the system from entering hibernation: the hibernation
is a relatively long process, which can be aborted by the call
pm_wakeup_hard_event(), which is invoked upon mouse events.

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

This patch is basically a pure Hyper-V specific change and it has a
build dependency on the commit 271b2224d42f ("Drivers: hv: vmbus: Implement
suspend/resume for VSC drivers for hibernation"), which is 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

I request this patch should go through Sasha's tree rather than the
input subsystem's tree.

Hi Jiri, Benjamin, can you please Ack?

 drivers/hid/hid-hyperv.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 69 insertions(+), 2 deletions(-)

diff --git a/drivers/hid/hid-hyperv.c b/drivers/hid/hid-hyperv.c
index cc5b09b8..e798740 100644
--- a/drivers/hid/hid-hyperv.c
+++ b/drivers/hid/hid-hyperv.c
@@ -12,6 +12,7 @@
 #include <linux/hid.h>
 #include <linux/hiddev.h>
 #include <linux/hyperv.h>
+#include <linux/suspend.h>
 
 
 struct hv_input_dev_info {
@@ -150,6 +151,9 @@ struct mousevsc_dev {
 	struct hv_input_dev_info hid_dev_info;
 	struct hid_device       *hid_device;
 	u8			input_buf[HID_MAX_BUFFER_SIZE];
+
+	struct notifier_block	pm_nb;
+	bool			hibernation_in_progress;
 };
 
 
@@ -192,6 +196,9 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
 	if (desc->bLength == 0)
 		goto cleanup;
 
+	/* The pointer is not NULL when we resume from hibernation */
+	if (input_device->hid_desc != NULL)
+		kfree(input_device->hid_desc);
 	input_device->hid_desc = kmemdup(desc, desc->bLength, GFP_ATOMIC);
 
 	if (!input_device->hid_desc)
@@ -203,6 +210,9 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
 		goto cleanup;
 	}
 
+	/* The pointer is not NULL when we resume from hibernation */
+	if (input_device->report_desc != NULL)
+		kfree(input_device->report_desc);
 	input_device->report_desc = kzalloc(input_device->report_desc_size,
 					  GFP_ATOMIC);
 
@@ -243,7 +253,7 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
 }
 
 static void mousevsc_on_receive(struct hv_device *device,
-				struct vmpacket_descriptor *packet)
+				const struct vmpacket_descriptor *packet)
 {
 	struct pipe_prt_msg *pipe_msg;
 	struct synthhid_msg *hid_msg;
@@ -301,7 +311,8 @@ static void mousevsc_on_receive(struct hv_device *device,
 		hid_input_report(input_dev->hid_device, HID_INPUT_REPORT,
 				 input_dev->input_buf, len, 1);
 
-		pm_wakeup_hard_event(&input_dev->device->device);
+		if (!input_dev->hibernation_in_progress)
+			pm_wakeup_hard_event(&input_dev->device->device);
 
 		break;
 	default:
@@ -378,6 +389,8 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
 	struct mousevsc_prt_msg *request;
 	struct mousevsc_prt_msg *response;
 
+	reinit_completion(&input_dev->wait_event);
+
 	request = &input_dev->protocol_req;
 	memset(request, 0, sizeof(struct mousevsc_prt_msg));
 
@@ -475,6 +488,29 @@ static int mousevsc_hid_raw_request(struct hid_device *hid,
 
 static struct hid_driver mousevsc_hid_driver;
 
+static int mousevsc_pm_notify(struct notifier_block *nb,
+			      unsigned long val, void *ign)
+{
+	struct mousevsc_dev *input_dev;
+
+	input_dev = container_of(nb, struct mousevsc_dev, pm_nb);
+
+	switch (val) {
+	case PM_HIBERNATION_PREPARE:
+	case PM_RESTORE_PREPARE:
+		input_dev->hibernation_in_progress = true;
+		return NOTIFY_OK;
+
+	case PM_POST_HIBERNATION:
+	case PM_POST_RESTORE:
+		input_dev->hibernation_in_progress = false;
+		return NOTIFY_OK;
+
+	default:
+		return NOTIFY_DONE;
+	}
+}
+
 static int mousevsc_probe(struct hv_device *device,
 			const struct hv_vmbus_device_id *dev_id)
 {
@@ -549,6 +585,9 @@ static int mousevsc_probe(struct hv_device *device,
 	input_dev->connected = true;
 	input_dev->init_complete = true;
 
+	input_dev->pm_nb.notifier_call = mousevsc_pm_notify;
+	register_pm_notifier(&input_dev->pm_nb);
+
 	return ret;
 
 probe_err2:
@@ -568,6 +607,8 @@ static int mousevsc_remove(struct hv_device *dev)
 {
 	struct mousevsc_dev *input_dev = hv_get_drvdata(dev);
 
+	unregister_pm_notifier(&input_dev->pm_nb);
+
 	device_init_wakeup(&dev->device, false);
 	vmbus_close(dev->channel);
 	hid_hw_stop(input_dev->hid_device);
@@ -577,6 +618,30 @@ static int mousevsc_remove(struct hv_device *dev)
 	return 0;
 }
 
+static int mousevsc_suspend(struct hv_device *dev)
+{
+	vmbus_close(dev->channel);
+
+	return 0;
+}
+
+static int mousevsc_resume(struct hv_device *dev)
+{
+	int ret;
+
+	ret = vmbus_open(dev->channel,
+			 INPUTVSC_SEND_RING_BUFFER_SIZE,
+			 INPUTVSC_RECV_RING_BUFFER_SIZE,
+			 NULL, 0,
+			 mousevsc_on_channel_callback,
+			 dev);
+	if (ret)
+		return ret;
+
+	ret = mousevsc_connect_to_vsp(dev);
+	return ret;
+}
+
 static const struct hv_vmbus_device_id id_table[] = {
 	/* Mouse guid */
 	{ HV_MOUSE_GUID, },
@@ -590,6 +655,8 @@ static int mousevsc_remove(struct hv_device *dev)
 	.id_table = id_table,
 	.probe = mousevsc_probe,
 	.remove = mousevsc_remove,
+	.suspend = mousevsc_suspend,
+	.resume = mousevsc_resume,
 	.driver = {
 		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
 	},
-- 
1.8.3.1


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

* RE: [PATCH] HID: hyperv: Add the support of hibernation
  2019-09-11 23:35 [PATCH] HID: hyperv: Add the support of hibernation Dexuan Cui
@ 2019-09-25 19:53 ` Dexuan Cui
  2019-09-26 13:22   ` Jiri Kosina
  0 siblings, 1 reply; 8+ messages in thread
From: Dexuan Cui @ 2019-09-25 19:53 UTC (permalink / raw)
  To: Dexuan Cui, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
	sashal, jikos, benjamin.tissoires, linux-hyperv, linux-input,
	linux-kernel, Michael Kelley

> From: Dexuan Cui <decui@microsoft.com>
> Sent: Wednesday, September 11, 2019 4:36 PM
> 
> We need mousevsc_pm_notify() to make sure the pm_wakeup_hard_event()
> call
> does not prevent the system from entering hibernation: the hibernation
> is a relatively long process, which can be aborted by the call
> pm_wakeup_hard_event(), which is invoked upon mouse events.
> 
> Signed-off-by: Dexuan Cui <decui@microsoft.com>
> ---
> 
> This patch is basically a pure Hyper-V specific change and it has a
> build dependency on the commit 271b2224d42f ("Drivers: hv: vmbus:
> Implement
> suspend/resume for VSC drivers for hibernation"), which is on Sasha Levin's
> Hyper-V tree's hyperv-next branch [ ... snipped ...]
> 
> I request this patch should go through Sasha's tree rather than the
> input subsystem's tree.
> 
> Hi Jiri, Benjamin, can you please Ack?

Hi Jiri, Benjamin,
Can you please take a look at the patch?

Thanks,
-- Dexuan

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

* RE: [PATCH] HID: hyperv: Add the support of hibernation
  2019-09-25 19:53 ` Dexuan Cui
@ 2019-09-26 13:22   ` Jiri Kosina
  2019-09-26 13:23     ` Jiri Kosina
  0 siblings, 1 reply; 8+ messages in thread
From: Jiri Kosina @ 2019-09-26 13:22 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: KY Srinivasan, Haiyang Zhang, Stephen Hemminger, sashal,
	benjamin.tissoires, linux-hyperv, linux-input, linux-kernel,
	Michael Kelley

On Wed, 25 Sep 2019, Dexuan Cui wrote:

> > We need mousevsc_pm_notify() to make sure the pm_wakeup_hard_event() 
> > call does not prevent the system from entering hibernation: the 
> > hibernation is a relatively long process, which can be aborted by the 
> > call pm_wakeup_hard_event(), which is invoked upon mouse events.
> > 
> > Signed-off-by: Dexuan Cui <decui@microsoft.com>
> > ---
> > 
> > This patch is basically a pure Hyper-V specific change and it has a
> > build dependency on the commit 271b2224d42f ("Drivers: hv: vmbus:
> > Implement
> > suspend/resume for VSC drivers for hibernation"), which is on Sasha Levin's
> > Hyper-V tree's hyperv-next branch [ ... snipped ...]
> > 
> > I request this patch should go through Sasha's tree rather than the
> > input subsystem's tree.
> > 
> > Hi Jiri, Benjamin, can you please Ack?
> 
> Hi Jiri, Benjamin,
> Can you please take a look at the patch?

Hi Dexuan,

I am planning to process it once 5.4 merge window is over and thus hid.git 
is open again for 5.5 material.

Thanks,

-- 
Jiri Kosina
SUSE Labs


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

* RE: [PATCH] HID: hyperv: Add the support of hibernation
  2019-09-26 13:22   ` Jiri Kosina
@ 2019-09-26 13:23     ` Jiri Kosina
  2019-09-27  5:42       ` Dexuan Cui
  0 siblings, 1 reply; 8+ messages in thread
From: Jiri Kosina @ 2019-09-26 13:23 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: KY Srinivasan, Haiyang Zhang, Stephen Hemminger, sashal,
	benjamin.tissoires, linux-hyperv, linux-input, linux-kernel,
	Michael Kelley

On Thu, 26 Sep 2019, Jiri Kosina wrote:

> > > We need mousevsc_pm_notify() to make sure the pm_wakeup_hard_event() 
> > > call does not prevent the system from entering hibernation: the 
> > > hibernation is a relatively long process, which can be aborted by the 
> > > call pm_wakeup_hard_event(), which is invoked upon mouse events.
> > > 
> > > Signed-off-by: Dexuan Cui <decui@microsoft.com>
> > > ---
> > > 
> > > This patch is basically a pure Hyper-V specific change and it has a
> > > build dependency on the commit 271b2224d42f ("Drivers: hv: vmbus:
> > > Implement
> > > suspend/resume for VSC drivers for hibernation"), which is on Sasha Levin's
> > > Hyper-V tree's hyperv-next branch [ ... snipped ...]
> > > 
> > > I request this patch should go through Sasha's tree rather than the
> > > input subsystem's tree.
> > > 
> > > Hi Jiri, Benjamin, can you please Ack?
> > 
> > Hi Jiri, Benjamin,
> > Can you please take a look at the patch?
> 
> Hi Dexuan,
> 
> I am planning to process it once 5.4 merge window is over and thus hid.git 
> is open again for 5.5 material.

Ah, now I see you asked for this go through hyperv tree. For that, feel 
free to add

	Acked-by: Jiri Kosina <jkosina@suse.cz>

Thanks,

-- 
Jiri Kosina
SUSE Labs


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

* RE: [PATCH] HID: hyperv: Add the support of hibernation
  2019-09-26 13:23     ` Jiri Kosina
@ 2019-09-27  5:42       ` Dexuan Cui
  2019-09-27 12:05         ` Sasha Levin
  0 siblings, 1 reply; 8+ messages in thread
From: Dexuan Cui @ 2019-09-27  5:42 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: KY Srinivasan, Haiyang Zhang, Stephen Hemminger, sashal,
	benjamin.tissoires, linux-hyperv, linux-input, linux-kernel,
	Michael Kelley

> From: Jiri Kosina <jikos@kernel.org>
> Sent: Thursday, September 26, 2019 6:23 AM
> To: Dexuan Cui <decui@microsoft.com>
> 
> On Thu, 26 Sep 2019, Jiri Kosina wrote:
> 
> > > > This patch is basically a pure Hyper-V specific change and it has a
> > > > build dependency on the commit 271b2224d42f ("Drivers: hv: vmbus:
> > > > Implement
> > > > suspend/resume for VSC drivers for hibernation"), which is on Sasha
> Levin's
> > > > Hyper-V tree's hyperv-next branch [ ... snipped ...]
> > > >
> > > > I request this patch should go through Sasha's tree rather than the
> > > > input subsystem's tree.
> > > >
> > > > Hi Jiri, Benjamin, can you please Ack?
> > >
> > > Hi Jiri, Benjamin,
> > > Can you please take a look at the patch?
> >
> > Hi Dexuan,
> >
> > I am planning to process it once 5.4 merge window is over and thus hid.git
> > is open again for 5.5 material.
> 
> Ah, now I see you asked for this go through hyperv tree. For that, feel
> free to add
> 	Acked-by: Jiri Kosina <jkosina@suse.cz>
> Jiri Kosina

Thanks for the Ack, Jiri!

I have a bunch of patches, including this one, to support Linux VM's hibernation
when the VM runs on Hyper-V. I just feel it would be better for all of them to
go through the Hyper-V tree. :-)

Thanks,
-- Dexuan

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

* Re: [PATCH] HID: hyperv: Add the support of hibernation
  2019-09-27  5:42       ` Dexuan Cui
@ 2019-09-27 12:05         ` Sasha Levin
  2019-09-29 17:44           ` Dexuan Cui
  0 siblings, 1 reply; 8+ messages in thread
From: Sasha Levin @ 2019-09-27 12:05 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: Jiri Kosina, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
	benjamin.tissoires, linux-hyperv, linux-input, linux-kernel,
	Michael Kelley

On Fri, Sep 27, 2019 at 05:42:31AM +0000, Dexuan Cui wrote:
>> From: Jiri Kosina <jikos@kernel.org>
>> Sent: Thursday, September 26, 2019 6:23 AM
>> To: Dexuan Cui <decui@microsoft.com>
>>
>> On Thu, 26 Sep 2019, Jiri Kosina wrote:
>>
>> > > > This patch is basically a pure Hyper-V specific change and it has a
>> > > > build dependency on the commit 271b2224d42f ("Drivers: hv: vmbus:
>> > > > Implement
>> > > > suspend/resume for VSC drivers for hibernation"), which is on Sasha
>> Levin's
>> > > > Hyper-V tree's hyperv-next branch [ ... snipped ...]
>> > > >
>> > > > I request this patch should go through Sasha's tree rather than the
>> > > > input subsystem's tree.
>> > > >
>> > > > Hi Jiri, Benjamin, can you please Ack?
>> > >
>> > > Hi Jiri, Benjamin,
>> > > Can you please take a look at the patch?
>> >
>> > Hi Dexuan,
>> >
>> > I am planning to process it once 5.4 merge window is over and thus hid.git
>> > is open again for 5.5 material.
>>
>> Ah, now I see you asked for this go through hyperv tree. For that, feel
>> free to add
>> 	Acked-by: Jiri Kosina <jkosina@suse.cz>
>> Jiri Kosina
>
>Thanks for the Ack, Jiri!
>
>I have a bunch of patches, including this one, to support Linux VM's hibernation
>when the VM runs on Hyper-V. I just feel it would be better for all of them to
>go through the Hyper-V tree. :-)

Thank Dexuan, Jiri,

Dexuan, I've been silently ignoring your patches for the past few weeks
for the same reason as Jiri has mentioned. I'll pick them all up once
the 5.4 merge window closes in a few days.

--
Thanks,
Sasha

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

* RE: [PATCH] HID: hyperv: Add the support of hibernation
  2019-09-27 12:05         ` Sasha Levin
@ 2019-09-29 17:44           ` Dexuan Cui
  2019-10-01 18:40             ` Sasha Levin
  0 siblings, 1 reply; 8+ messages in thread
From: Dexuan Cui @ 2019-09-29 17:44 UTC (permalink / raw)
  To: Sasha Levin
  Cc: Jiri Kosina, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
	benjamin.tissoires, linux-hyperv, linux-input, linux-kernel,
	Michael Kelley

> From: Sasha Levin <sashal@kernel.org>
> Sent: Friday, September 27, 2019 5:05 AM
> To: Dexuan Cui <decui@microsoft.com>
> Cc: Jiri Kosina <jikos@kernel.org>; KY Srinivasan <kys@microsoft.com>;
> Haiyang Zhang <haiyangz@microsoft.com>; Stephen Hemminger
> <sthemmin@microsoft.com>; benjamin.tissoires@redhat.com;
> linux-hyperv@vger.kernel.org; linux-input@vger.kernel.org;
> linux-kernel@vger.kernel.org; Michael Kelley <mikelley@microsoft.com>
> Subject: Re: [PATCH] HID: hyperv: Add the support of hibernation
> 
> On Fri, Sep 27, 2019 at 05:42:31AM +0000, Dexuan Cui wrote:
> >> From: Jiri Kosina <jikos@kernel.org>
> >> Sent: Thursday, September 26, 2019 6:23 AM
> >> To: Dexuan Cui <decui@microsoft.com>
> >>
> >> On Thu, 26 Sep 2019, Jiri Kosina wrote:
> >>
> >> > > > This patch is basically a pure Hyper-V specific change and it has a
> >> > > > build dependency on the commit 271b2224d42f ("Drivers: hv: vmbus:
> >> > > > Implement
> >> > > > suspend/resume for VSC drivers for hibernation"), which is on Sasha
> >> Levin's
> >> > > > Hyper-V tree's hyperv-next branch [ ... snipped ...]
> >> > > >
> >> > > > I request this patch should go through Sasha's tree rather than the
> >> > > > input subsystem's tree.
> >> > > >
> >> > > > Hi Jiri, Benjamin, can you please Ack?
> >> > >
> >> > > Hi Jiri, Benjamin,
> >> > > Can you please take a look at the patch?
> >> >
> >> > Hi Dexuan,
> >> >
> >> > I am planning to process it once 5.4 merge window is over and thus hid.git
> >> > is open again for 5.5 material.
> >>
> >> Ah, now I see you asked for this go through hyperv tree. For that, feel
> >> free to add
> >> 	Acked-by: Jiri Kosina <jkosina@suse.cz>
> >> Jiri Kosina
> >
> >Thanks for the Ack, Jiri!
> >
> >I have a bunch of patches, including this one, to support Linux VM's
> hibernation
> >when the VM runs on Hyper-V. I just feel it would be better for all of them to
> >go through the Hyper-V tree. :-)
> 
> Thank Dexuan, Jiri,
> 
> Dexuan, I've been silently ignoring your patches for the past few weeks
> for the same reason as Jiri has mentioned. I'll pick them all up once
> the 5.4 merge window closes in a few days.
> 
> Thanks,
> Sasha

Thanks, Sasha!

BTW, I'll post a v2 for this patch, as IMO I may be able to get rid of the
mousevsc_pm_notify in this patch by disabling the channel callback
in the suspend function.

Thanks,
-- Dexuan

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

* Re: [PATCH] HID: hyperv: Add the support of hibernation
  2019-09-29 17:44           ` Dexuan Cui
@ 2019-10-01 18:40             ` Sasha Levin
  0 siblings, 0 replies; 8+ messages in thread
From: Sasha Levin @ 2019-10-01 18:40 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: Jiri Kosina, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
	benjamin.tissoires, linux-hyperv, linux-input, linux-kernel,
	Michael Kelley

On Sun, Sep 29, 2019 at 05:44:09PM +0000, Dexuan Cui wrote:
>> From: Sasha Levin <sashal@kernel.org>
>> Dexuan, I've been silently ignoring your patches for the past few weeks
>> for the same reason as Jiri has mentioned. I'll pick them all up once
>> the 5.4 merge window closes in a few days.
>
>Thanks, Sasha!
>
>BTW, I'll post a v2 for this patch, as IMO I may be able to get rid of the
>mousevsc_pm_notify in this patch by disabling the channel callback
>in the suspend function.

Okay, I'm ignoring this patch for now then.

--
Thanks,
Sasha

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

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

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-11 23:35 [PATCH] HID: hyperv: Add the support of hibernation Dexuan Cui
2019-09-25 19:53 ` Dexuan Cui
2019-09-26 13:22   ` Jiri Kosina
2019-09-26 13:23     ` Jiri Kosina
2019-09-27  5:42       ` Dexuan Cui
2019-09-27 12:05         ` Sasha Levin
2019-09-29 17:44           ` Dexuan Cui
2019-10-01 18:40             ` Sasha Levin

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