Commit c068e3f4 authored by Dexuan Cui's avatar Dexuan Cui Committed by Wei Liu

Drivers: hv: vmbus: Add /sys/bus/vmbus/hibernation

When a Linux VM runs on Hyper-V, if the host toolstack doesn't support
hibernation for the VM (this happens on old Hyper-V hosts like Windows
Server 2016, or new Hyper-V hosts if the admin or user doesn't declare
the hibernation intent for the VM), the VM is discouraged from trying
hibernation (because the host doesn't guarantee that the VM's virtual
hardware configuration will remain exactly the same across hibernation),
i.e. the VM should not try to set up the swap partition/file for
hibernation, etc.

x86 Hyper-V uses the presence of the virtual ACPI S4 state as the
indication of the host toolstack support for a VM. Currently there is
no easy and reliable way for the userspace to detect the presence of
the state (see https://lkml.org/lkml/2020/12/11/1097).  Add
/sys/bus/vmbus/hibernation for this purpose.
Signed-off-by: default avatarDexuan Cui <decui@microsoft.com>
Reviewed-by: default avatarMichael Kelley <mikelley@microsoft.com>
Link: https://lore.kernel.org/r/20210107014552.14234-1-decui@microsoft.comSigned-off-by: default avatarWei Liu <wei.liu@kernel.org>
parent e4d221b4
What: /sys/bus/vmbus/hibernation
Date: Jan 2021
KernelVersion: 5.12
Contact: Dexuan Cui <decui@microsoft.com>
Description: Whether the host supports hibernation for the VM.
Users: Daemon that sets up swap partition/file for hibernation.
What: /sys/bus/vmbus/devices/<UUID>/id What: /sys/bus/vmbus/devices/<UUID>/id
Date: Jul 2009 Date: Jul 2009
KernelVersion: 2.6.31 KernelVersion: 2.6.31
......
...@@ -678,6 +678,23 @@ static const struct attribute_group vmbus_dev_group = { ...@@ -678,6 +678,23 @@ static const struct attribute_group vmbus_dev_group = {
}; };
__ATTRIBUTE_GROUPS(vmbus_dev); __ATTRIBUTE_GROUPS(vmbus_dev);
/* Set up the attribute for /sys/bus/vmbus/hibernation */
static ssize_t hibernation_show(struct bus_type *bus, char *buf)
{
return sprintf(buf, "%d\n", !!hv_is_hibernation_supported());
}
static BUS_ATTR_RO(hibernation);
static struct attribute *vmbus_bus_attrs[] = {
&bus_attr_hibernation.attr,
NULL,
};
static const struct attribute_group vmbus_bus_group = {
.attrs = vmbus_bus_attrs,
};
__ATTRIBUTE_GROUPS(vmbus_bus);
/* /*
* vmbus_uevent - add uevent for our device * vmbus_uevent - add uevent for our device
* *
...@@ -1024,6 +1041,7 @@ static struct bus_type hv_bus = { ...@@ -1024,6 +1041,7 @@ static struct bus_type hv_bus = {
.uevent = vmbus_uevent, .uevent = vmbus_uevent,
.dev_groups = vmbus_dev_groups, .dev_groups = vmbus_dev_groups,
.drv_groups = vmbus_drv_groups, .drv_groups = vmbus_drv_groups,
.bus_groups = vmbus_bus_groups,
.pm = &vmbus_pm, .pm = &vmbus_pm,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment