Linux Input Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] HID: hyperv: Add the support of hibernation
@ 2019-11-20  7:14 Dexuan Cui
  2019-11-21 14:34 ` Jiri Kosina
  0 siblings, 1 reply; 3+ messages in thread
From: Dexuan Cui @ 2019-11-20  7:14 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, sashal, jikos, benjamin.tissoires,
	linux-hyperv, linux-input, linux-kernel, mikelley,
	Alexander.Levin
  Cc: Dexuan Cui

During the suspend process and resume process, if there is any mouse
event, there is a small chance the suspend and the resume process can be
aborted because of mousevsc_on_receive() -> pm_wakeup_hard_event().

This behavior can be avoided by disabling the Hyper-V mouse device as
a wakeup source:

echo disabled > /sys/bus/vmbus/drivers/hid_hyperv/XXX/power/wakeup
(XXX is the device's GUID).

Signed-off-by: Dexuan Cui <decui@microsoft.com>
Acked-by: Jiri Kosina <jkosina@suse.cz>
---

Changes in v2:
  Removed the "struct notifier_block pm_nb;" after the discussion
with Dmitry Torokhov:
  https://lore.kernel.org/lkml/PU1P153MB016914A7C827CA35D7FEB66ABF8B0@PU1P153MB0169.APCP153.PROD.OUTLOOK.COM/T/#m8948c711301220a36a1a413eead74cd2fb6dcac1

 drivers/hid/hid-hyperv.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/drivers/hid/hid-hyperv.c b/drivers/hid/hid-hyperv.c
index 79a28fc91521..dddfca555df9 100644
--- a/drivers/hid/hid-hyperv.c
+++ b/drivers/hid/hid-hyperv.c
@@ -192,6 +192,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 +206,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);
 
@@ -342,6 +348,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));
 
@@ -541,6 +549,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, },
@@ -554,6 +586,8 @@ static struct  hv_driver mousevsc_drv = {
 	.id_table = id_table,
 	.probe = mousevsc_probe,
 	.remove = mousevsc_remove,
+	.suspend = mousevsc_suspend,
+	.resume = mousevsc_resume,
 	.driver = {
 		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
 	},
-- 
2.19.1


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

* Re: [PATCH v2] HID: hyperv: Add the support of hibernation
  2019-11-20  7:14 [PATCH v2] HID: hyperv: Add the support of hibernation Dexuan Cui
@ 2019-11-21 14:34 ` Jiri Kosina
  2019-11-22  0:26   ` Sasha Levin
  0 siblings, 1 reply; 3+ messages in thread
From: Jiri Kosina @ 2019-11-21 14:34 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: kys, haiyangz, sthemmin, sashal, benjamin.tissoires,
	linux-hyperv, linux-input, linux-kernel, mikelley,
	Alexander.Levin

On Tue, 19 Nov 2019, Dexuan Cui wrote:

> During the suspend process and resume process, if there is any mouse
> event, there is a small chance the suspend and the resume process can be
> aborted because of mousevsc_on_receive() -> pm_wakeup_hard_event().
> 
> This behavior can be avoided by disabling the Hyper-V mouse device as
> a wakeup source:
> 
> echo disabled > /sys/bus/vmbus/drivers/hid_hyperv/XXX/power/wakeup
> (XXX is the device's GUID).
> 
> Signed-off-by: Dexuan Cui <decui@microsoft.com>
> Acked-by: Jiri Kosina <jkosina@suse.cz>

My Ack still holds for v2. Sasha, this is going to be merged through your 
tree, right?

Thanks,

-- 
Jiri Kosina
SUSE Labs


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

* Re: [PATCH v2] HID: hyperv: Add the support of hibernation
  2019-11-21 14:34 ` Jiri Kosina
@ 2019-11-22  0:26   ` Sasha Levin
  0 siblings, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2019-11-22  0:26 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: Dexuan Cui, kys, haiyangz, sthemmin, benjamin.tissoires,
	linux-hyperv, linux-input, linux-kernel, mikelley,
	Alexander.Levin

On Thu, Nov 21, 2019 at 03:34:10PM +0100, Jiri Kosina wrote:
>On Tue, 19 Nov 2019, Dexuan Cui wrote:
>
>> During the suspend process and resume process, if there is any mouse
>> event, there is a small chance the suspend and the resume process can be
>> aborted because of mousevsc_on_receive() -> pm_wakeup_hard_event().
>>
>> This behavior can be avoided by disabling the Hyper-V mouse device as
>> a wakeup source:
>>
>> echo disabled > /sys/bus/vmbus/drivers/hid_hyperv/XXX/power/wakeup
>> (XXX is the device's GUID).
>>
>> Signed-off-by: Dexuan Cui <decui@microsoft.com>
>> Acked-by: Jiri Kosina <jkosina@suse.cz>
>
>My Ack still holds for v2. Sasha, this is going to be merged through your
>tree, right?

Yup, queued up for hyperv-next, thanks!

-- 
Thanks,
Sasha

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-20  7:14 [PATCH v2] HID: hyperv: Add the support of hibernation Dexuan Cui
2019-11-21 14:34 ` Jiri Kosina
2019-11-22  0:26   ` Sasha Levin

Linux Input Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-input/0 linux-input/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-input linux-input/ https://lore.kernel.org/linux-input \
		linux-input@vger.kernel.org
	public-inbox-index linux-input

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-input


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git