Linux-HyperV Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] Input: hyperv-keyboard: Add the support of hibernation
@ 2019-11-20  7:14 Dexuan Cui
  2019-11-24 20:31 ` Michael Kelley
  0 siblings, 1 reply; 2+ messages in thread
From: Dexuan Cui @ 2019-11-20  7:14 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, sashal, dmitry.torokhov, linux-hyperv,
	linux-input, linux-kernel, mikelley, Alexander.Levin
  Cc: Dexuan Cui

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

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

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

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

This patch is basically a pure Hyper-V specific change. I suggest it should
go through the Hyper-V tree:
https://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux.git/log/?h=hyperv-next

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/input/serio/hyperv-keyboard.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/drivers/input/serio/hyperv-keyboard.c b/drivers/input/serio/hyperv-keyboard.c
index e486a8a74c40..df4e9f6f4529 100644
--- a/drivers/input/serio/hyperv-keyboard.c
+++ b/drivers/input/serio/hyperv-keyboard.c
@@ -259,6 +259,8 @@ static int hv_kbd_connect_to_vsp(struct hv_device *hv_dev)
 	u32 proto_status;
 	int error;
 
+	reinit_completion(&kbd_dev->wait_event);
+
 	request = &kbd_dev->protocol_req;
 	memset(request, 0, sizeof(struct synth_kbd_protocol_request));
 	request->header.type = __cpu_to_le32(SYNTH_KBD_PROTOCOL_REQUEST);
@@ -380,6 +382,29 @@ static int hv_kbd_remove(struct hv_device *hv_dev)
 	return 0;
 }
 
+static int hv_kbd_suspend(struct hv_device *hv_dev)
+{
+	vmbus_close(hv_dev->channel);
+
+	return 0;
+}
+
+static int hv_kbd_resume(struct hv_device *hv_dev)
+{
+	int ret;
+
+	ret = vmbus_open(hv_dev->channel,
+			 KBD_VSC_SEND_RING_BUFFER_SIZE,
+			 KBD_VSC_RECV_RING_BUFFER_SIZE,
+			 NULL, 0,
+			 hv_kbd_on_channel_callback,
+			 hv_dev);
+	if (ret == 0)
+		ret = hv_kbd_connect_to_vsp(hv_dev);
+
+	return ret;
+}
+
 static const struct hv_vmbus_device_id id_table[] = {
 	/* Keyboard guid */
 	{ HV_KBD_GUID, },
@@ -393,6 +418,8 @@ static struct  hv_driver hv_kbd_drv = {
 	.id_table = id_table,
 	.probe = hv_kbd_probe,
 	.remove = hv_kbd_remove,
+	.suspend = hv_kbd_suspend,
+	.resume = hv_kbd_resume,
 	.driver = {
 		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
 	},
-- 
2.19.1


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

* RE: [PATCH v2] Input: hyperv-keyboard: Add the support of hibernation
  2019-11-20  7:14 [PATCH v2] Input: hyperv-keyboard: Add the support of hibernation Dexuan Cui
@ 2019-11-24 20:31 ` Michael Kelley
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Kelley @ 2019-11-24 20:31 UTC (permalink / raw)
  To: Dexuan Cui, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
	sashal, dmitry.torokhov, linux-hyperv, linux-input, linux-kernel,
	Sasha Levin

From: Dexuan Cui <decui@microsoft.com> Sent: Tuesday, November 19, 2019 11:14 PM
> 
> During the suspend process and resume process, if there is any keyboard
> event, there is a small chance the suspend and the resume process can be
> aborted because of hv_kbd_on_receive() -> pm_wakeup_hard_event().
> 
> This behavior can be avoided by disabling the Hyper-V keyboard device as
> a wakeup source:
> 
> echo disabled > /sys/bus/vmbus/drivers/hyperv_keyboard/XXX/power/wakeup
> (XXX is the device's GUID).

I'd like to see a more descriptive commit message, along the lines of:

Add suspend() and resume() functions so the Hyper-V virtual keyboard
can participate in VM hibernation.

Note that the keyboard is a "wakeup" device that could abort an in-progress
hibernation if there is keyboard event.  No attempt is made to suppress this
behavior.  If desired, a sysadmin can disable the keyboard as a wakeup device
using standard mechanisms such as:

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

> 
> Signed-off-by: Dexuan Cui <decui@microsoft.com>
> ---
> 
> This patch is basically a pure Hyper-V specific change. I suggest it should
> go through the Hyper-V tree:
> https://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux.git/log/?h=hyperv-next
> 
> 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/input/serio/hyperv-keyboard.c | 27 +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)
> 

Notwithstanding the suggestion on the commit message,

Reviewed-by:  Michael Kelley <mikelley@microsoft.com>



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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-20  7:14 [PATCH v2] Input: hyperv-keyboard: Add the support of hibernation Dexuan Cui
2019-11-24 20:31 ` Michael Kelley

Linux-HyperV Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-hyperv/0 linux-hyperv/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-hyperv linux-hyperv/ https://lore.kernel.org/linux-hyperv \
		linux-hyperv@vger.kernel.org
	public-inbox-index linux-hyperv

Example config snippet for mirrors

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


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