Skip to contentSkip to conversation

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

PATCH Superseded Dexuan Cui 2 participants 2 messages Jan 6, 2021

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Dexuan Cui

author maintainer
#0 lore raw

PATCH v2 1/1 Drivers: hv: vmbus: Add /sys/bus/vmbus/supported_features

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/supported_features for this purpose.

---

Change in v2:
Added a "Values:" section
Updated "Date:"

 Documentation/ABI/stable/sysfs-bus-vmbus |  9 +++++++++
 drivers/hv/vmbus_drv.c                   | 20 ++++++++++++++++++++
 2 files changed, 29 insertions(+)
Documentation/ABI/stable/sysfs-bus-vmbus +9 -0
index c27b7b89477c..c8d56389b7be 100644
@@ -1,3 +1,12 @@
+What:		/sys/bus/vmbus/supported_features
+Date:		Jan 2021
+KernelVersion:	5.11
+Contact:	Dexuan Cui <[email protected]>
+Description:	Features specific to VMs running on Hyper-V
+Values:		A list of strings.
+		hibernation: the host toolstack 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
drivers/hv/vmbus_drv.c +20 -0
index d491fdcee61f..958487a40a18 100644
@@ -678,6 +678,25 @@ static const struct attribute_group vmbus_dev_group = {
 };
 __ATTRIBUTE_GROUPS(vmbus_dev);
 
+/* Set up bus attribute(s) for /sys/bus/vmbus/supported_features */
+static ssize_t supported_features_show(struct bus_type *bus, char *buf)
+{
+	bool hb = hv_is_hibernation_supported();
+
+	return sprintf(buf, "%s\n", hb ? "hibernation" : "");
+}
+
+static BUS_ATTR_RO(supported_features);
+
+static struct attribute *vmbus_bus_attrs[] = {
+	&bus_attr_supported_features.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 +1043,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,
 };
 
Signature · 1 line
2.19.1
maintainer
#1 lore raw
Quoted 9 lines · 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.

Quoted 7 lines

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/supported_features for this purpose.

LGTM. I will wait a bit for others to comment.

Quoted 68 lines

---

Change in v2:
Added a "Values:" section
Updated "Date:"

 Documentation/ABI/stable/sysfs-bus-vmbus |  9 +++++++++
 drivers/hv/vmbus_drv.c                   | 20 ++++++++++++++++++++
 2 files changed, 29 insertions(+)
Documentation/ABI/stable/sysfs-bus-vmbus +9 -0
index c27b7b89477c..c8d56389b7be 100644
@@ -1,3 +1,12 @@
+What:		/sys/bus/vmbus/supported_features
+Date:		Jan 2021
+KernelVersion:	5.11
+Contact:	Dexuan Cui <[email protected]>
+Description:	Features specific to VMs running on Hyper-V
+Values:		A list of strings.
+		hibernation: the host toolstack 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
drivers/hv/vmbus_drv.c +20 -0
index d491fdcee61f..958487a40a18 100644
@@ -678,6 +678,25 @@ static const struct attribute_group vmbus_dev_group = {
 };
 __ATTRIBUTE_GROUPS(vmbus_dev);
 
+/* Set up bus attribute(s) for /sys/bus/vmbus/supported_features */
+static ssize_t supported_features_show(struct bus_type *bus, char *buf)
+{
+	bool hb = hv_is_hibernation_supported();
+
+	return sprintf(buf, "%s\n", hb ? "hibernation" : "");
+}
+
+static BUS_ATTR_RO(supported_features);
+
+static struct attribute *vmbus_bus_attrs[] = {
+	&bus_attr_supported_features.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 +1043,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,
 };
 
Signature · 1 line
2.19.1