linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dexuan Cui <decui@microsoft.com>
To: kys@microsoft.com, haiyangz@microsoft.com,
	sthemmin@microsoft.com, wei.liu@kernel.org,
	linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org,
	mikelley@microsoft.com, vkuznets@redhat.com
Cc: Dexuan Cui <decui@microsoft.com>
Subject: [PATCH] Drivers: hv: vmbus: Disallow the freeze PM operation
Date: Tue,  7 Apr 2020 15:01:47 -0700	[thread overview]
Message-ID: <1586296907-53744-1-git-send-email-decui@microsoft.com> (raw)

Before the hibernation patchset (e.g. f53335e3289f), a Linux VM on Hyper-V
can run "echo freeze > /sys/power/state" (or "systemctl suspend")
to freeze the system. The user can press the keyboard or move the mouse
to wake up the VM. Note: the two aforementioned commands are equivalent
here, because Hyper-V doesn't support the guest ACPI S3 state.

With the hibernation patchset, a Linux VM on Hyper-V can hibernate to disk
and resume back; however, the 'freeze' operation is broken for Hyper-V
Generation-2 VM (which doesn't have a legacy keyboard/mouse): when the
vmbus devices are suspended, the VM can not receive any interrupt from
the synthetic keyboard/mouse devices, so there is no way to wake up the
VM. This is not an issue for Generaton-1 VM, because it looks the legacy
keyboard/mouse devices can still be used to wake up the VM in my test.

IMO 'freeze' in a Linux VM on Hyper-V is not really useful in practice,
so let's disallow the operation for both Gen-1 and Gen-2 VMs, even if
it's not an issue for Gen-1 VMs.

Fixes: f53335e3289f ("Drivers: hv: vmbus: Suspend/resume the vmbus itself for hibernation")
Signed-off-by: Dexuan Cui <decui@microsoft.com>
---
 drivers/hv/vmbus_drv.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 029378c..82a4327 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -28,6 +28,7 @@
 #include <linux/notifier.h>
 #include <linux/ptrace.h>
 #include <linux/screen_info.h>
+#include <linux/suspend.h>
 #include <linux/kdebug.h>
 #include <linux/efi.h>
 #include <linux/random.h>
@@ -2357,6 +2358,23 @@ static void hv_synic_resume(void)
 	.resume = hv_synic_resume,
 };
 
+/*
+ * Note: "freeze/suspend" here means "systemctl suspend".
+ * "systemctl hibernate" is still supported.
+ */
+static int hv_pm_notify(struct notifier_block *nb,
+			unsigned long val, void *ign)
+{
+	if (val == PM_SUSPEND_PREPARE) {
+		pr_info("freeze/suspend is not supported\n");
+		return NOTIFY_BAD;
+	}
+
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block hv_pm_nb;
+
 static int __init hv_acpi_init(void)
 {
 	int ret, t;
@@ -2389,6 +2407,8 @@ static int __init hv_acpi_init(void)
 	hv_setup_crash_handler(hv_crash_handler);
 
 	register_syscore_ops(&hv_synic_syscore_ops);
+	hv_pm_nb.notifier_call = hv_pm_notify;
+	register_pm_notifier(&hv_pm_nb);
 
 	return 0;
 
@@ -2402,6 +2422,7 @@ static void __exit vmbus_exit(void)
 {
 	int cpu;
 
+	unregister_pm_notifier(&hv_pm_nb);
 	unregister_syscore_ops(&hv_synic_syscore_ops);
 
 	hv_remove_kexec_handler();
-- 
1.8.3.1


             reply	other threads:[~2020-04-07 22:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-07 22:01 Dexuan Cui [this message]
2020-04-08 15:47 ` [PATCH] Drivers: hv: vmbus: Disallow the freeze PM operation Vitaly Kuznetsov
2020-04-08 17:43   ` Dexuan Cui
2020-04-08 19:24     ` Vitaly Kuznetsov
2020-04-08 19:42       ` Dexuan Cui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1586296907-53744-1-git-send-email-decui@microsoft.com \
    --to=decui@microsoft.com \
    --cc=haiyangz@microsoft.com \
    --cc=kys@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikelley@microsoft.com \
    --cc=sthemmin@microsoft.com \
    --cc=vkuznets@redhat.com \
    --cc=wei.liu@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).