linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] Drivers: hv: vmbus: Add /sys/bus/vmbus/hibernation
@ 2021-01-07  1:45 Dexuan Cui
  2021-01-07 18:08 ` Michael Kelley
  0 siblings, 1 reply; 3+ messages in thread
From: Dexuan Cui @ 2021-01-07  1:45 UTC (permalink / raw)
  To: wei.liu, kys, haiyangz, sthemmin, linux-hyperv, linux-kernel,
	mikelley, vkuznets, marcelo.cerri
  Cc: Dexuan Cui

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: Dexuan Cui <decui@microsoft.com>
---

This v3 is similar to v1, and the changes are:
  Updated the documentation changes.
  Updated the commit log.
  /sys/bus/vmbus/supported_features -> /sys/bus/vmbus/hibernation

The patch is targeted at the Hyper-V tree's hyperv-next branch.

 Documentation/ABI/stable/sysfs-bus-vmbus |  7 +++++++
 drivers/hv/vmbus_drv.c                   | 18 ++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/Documentation/ABI/stable/sysfs-bus-vmbus b/Documentation/ABI/stable/sysfs-bus-vmbus
index c27b7b89477c..42599d9fa161 100644
--- a/Documentation/ABI/stable/sysfs-bus-vmbus
+++ b/Documentation/ABI/stable/sysfs-bus-vmbus
@@ -1,3 +1,10 @@
+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
 Date:		Jul 2009
 KernelVersion:	2.6.31
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index d491fdcee61f..4c544473b1d9 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -678,6 +678,23 @@ static const struct attribute_group vmbus_dev_group = {
 };
 __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
  *
@@ -1024,6 +1041,7 @@ static struct bus_type  hv_bus = {
 	.uevent =		vmbus_uevent,
 	.dev_groups =		vmbus_dev_groups,
 	.drv_groups =		vmbus_drv_groups,
+	.bus_groups =		vmbus_bus_groups,
 	.pm =			&vmbus_pm,
 };
 
-- 
2.19.1


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

* RE: [PATCH v3] Drivers: hv: vmbus: Add /sys/bus/vmbus/hibernation
  2021-01-07  1:45 [PATCH v3] Drivers: hv: vmbus: Add /sys/bus/vmbus/hibernation Dexuan Cui
@ 2021-01-07 18:08 ` Michael Kelley
  2021-01-11 11:05   ` Wei Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Kelley @ 2021-01-07 18:08 UTC (permalink / raw)
  To: Dexuan Cui, wei.liu, KY Srinivasan, Haiyang Zhang,
	Stephen Hemminger, linux-hyperv, linux-kernel, vkuznets,
	marcelo.cerri

From: Dexuan Cui <decui@microsoft.com> Sent: Wednesday, January 6, 2021 5:46 PM
> 
> 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: Dexuan Cui <decui@microsoft.com>
> ---
> 
> This v3 is similar to v1, and the changes are:
>   Updated the documentation changes.
>   Updated the commit log.
>   /sys/bus/vmbus/supported_features -> /sys/bus/vmbus/hibernation
> 
> The patch is targeted at the Hyper-V tree's hyperv-next branch.
> 
>  Documentation/ABI/stable/sysfs-bus-vmbus |  7 +++++++
>  drivers/hv/vmbus_drv.c                   | 18 ++++++++++++++++++
>  2 files changed, 25 insertions(+)
> 
> diff --git a/Documentation/ABI/stable/sysfs-bus-vmbus
> b/Documentation/ABI/stable/sysfs-bus-vmbus
> index c27b7b89477c..42599d9fa161 100644
> --- a/Documentation/ABI/stable/sysfs-bus-vmbus
> +++ b/Documentation/ABI/stable/sysfs-bus-vmbus
> @@ -1,3 +1,10 @@
> +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
>  Date:		Jul 2009
>  KernelVersion:	2.6.31
> diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
> index d491fdcee61f..4c544473b1d9 100644
> --- a/drivers/hv/vmbus_drv.c
> +++ b/drivers/hv/vmbus_drv.c
> @@ -678,6 +678,23 @@ static const struct attribute_group vmbus_dev_group = {
>  };
>  __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
>   *
> @@ -1024,6 +1041,7 @@ static struct bus_type  hv_bus = {
>  	.uevent =		vmbus_uevent,
>  	.dev_groups =		vmbus_dev_groups,
>  	.drv_groups =		vmbus_drv_groups,
> +	.bus_groups =		vmbus_bus_groups,
>  	.pm =			&vmbus_pm,
>  };
> 
> --
> 2.19.1

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


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

* Re: [PATCH v3] Drivers: hv: vmbus: Add /sys/bus/vmbus/hibernation
  2021-01-07 18:08 ` Michael Kelley
@ 2021-01-11 11:05   ` Wei Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Wei Liu @ 2021-01-11 11:05 UTC (permalink / raw)
  To: Michael Kelley
  Cc: Dexuan Cui, wei.liu, KY Srinivasan, Haiyang Zhang,
	Stephen Hemminger, linux-hyperv, linux-kernel, vkuznets,
	marcelo.cerri

On Thu, Jan 07, 2021 at 06:08:51PM +0000, Michael Kelley wrote:
> From: Dexuan Cui <decui@microsoft.com> Sent: Wednesday, January 6, 2021 5:46 PM
> > 
> > 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: Dexuan Cui <decui@microsoft.com>
[...]
> 
> Reviewed-by: Michael Kelley <mikelley@microsoft.com>

Queued for hyperv-next. Thanks.

Wei.

> 

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

end of thread, other threads:[~2021-01-11 11:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-07  1:45 [PATCH v3] Drivers: hv: vmbus: Add /sys/bus/vmbus/hibernation Dexuan Cui
2021-01-07 18:08 ` Michael Kelley
2021-01-11 11:05   ` Wei Liu

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