linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/2] Basic /sys/hypervisor information for Hyper-V
@ 2019-07-26 23:17 Nuno Das Neves
  2019-07-26 23:17 ` [RFC PATCH 1/2] sys-hypervisor: /sys/hypervisor/type " Nuno Das Neves
  2019-07-26 23:17 ` [RFC PATCH 2/2] sys-hypervisor: version information " Nuno Das Neves
  0 siblings, 2 replies; 4+ messages in thread
From: Nuno Das Neves @ 2019-07-26 23:17 UTC (permalink / raw)
  To: nudasnev, gregkh, sthemmin, Alexander.Levin, haiyangz, kys, mikelley
  Cc: linux-kernel

These patches populate /sys/hypervisor with some basic information when running
on Hyper-V. The first patch just introduces /sys/hypervisor/type which contains
"Hyper-V", and the second introduces /sys/hypervisor/version/ which contains a
file for each piece of hypervisor version information.

Nuno Das Neves (2):
  sys-hypervisor: /sys/hypervisor/type for Hyper-V
  sys-hypervisor: version information for Hyper-V

 .../ABI/stable/sysfs-hypervisor-hyperv        |  61 ++++++++
 drivers/hv/Kconfig                            |  10 ++
 drivers/hv/Makefile                           |   7 +-
 drivers/hv/sys-hypervisor.c                   | 143 ++++++++++++++++++
 4 files changed, 218 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/ABI/stable/sysfs-hypervisor-hyperv
 create mode 100644 drivers/hv/sys-hypervisor.c

-- 
2.17.1


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

* [RFC PATCH 1/2] sys-hypervisor: /sys/hypervisor/type for Hyper-V
  2019-07-26 23:17 [RFC PATCH 0/2] Basic /sys/hypervisor information for Hyper-V Nuno Das Neves
@ 2019-07-26 23:17 ` Nuno Das Neves
       [not found]   ` <MN2PR21MB1216DBB3BD918B6DCC738E30CCC30@MN2PR21MB1216.namprd21.prod.outlook.com>
  2019-07-26 23:17 ` [RFC PATCH 2/2] sys-hypervisor: version information " Nuno Das Neves
  1 sibling, 1 reply; 4+ messages in thread
From: Nuno Das Neves @ 2019-07-26 23:17 UTC (permalink / raw)
  To: nudasnev, gregkh, sthemmin, Alexander.Levin, haiyangz, kys, mikelley
  Cc: linux-kernel

Populate /sys/hypervisor with entries for Hyper-V.
This patch adds /sys/hypervisor/type which contains "Hyper-V".

Signed-off-by: Nuno Das Neves <nudasnev@microsoft.com>
---
 .../ABI/stable/sysfs-hypervisor-hyperv        |  7 ++++
 drivers/hv/Kconfig                            | 10 +++++
 drivers/hv/Makefile                           |  7 ++--
 drivers/hv/sys-hypervisor.c                   | 41 +++++++++++++++++++
 4 files changed, 62 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/ABI/stable/sysfs-hypervisor-hyperv
 create mode 100644 drivers/hv/sys-hypervisor.c

diff --git a/Documentation/ABI/stable/sysfs-hypervisor-hyperv b/Documentation/ABI/stable/sysfs-hypervisor-hyperv
new file mode 100644
index 000000000000..58380ea81315
--- /dev/null
+++ b/Documentation/ABI/stable/sysfs-hypervisor-hyperv
@@ -0,0 +1,7 @@
+What:		/sys/hypervisor/type
+Date:		July 2019
+KernelVersion:	5.2.1
+Contact:	linux-hyperv@vger.kernel.org
+Description:	If running under Hyper-V:
+		Type of hypervisor:
+		"Hyper-V": Hyper-V hypervisor
diff --git a/drivers/hv/Kconfig b/drivers/hv/Kconfig
index 1c1a2514d6f3..e693adf0b77f 100644
--- a/drivers/hv/Kconfig
+++ b/drivers/hv/Kconfig
@@ -25,4 +25,14 @@ config HYPERV_BALLOON
 	help
 	  Select this option to enable Hyper-V Balloon driver.
 
+config HYPERV_SYS_HYPERVISOR
+	bool "Create Hyper-V entries under /sys/hypervisor"
+	depends on HYPERV && SYSFS
+	select SYS_HYPERVISOR
+	default y
+	help
+	  Create Hyper-V entries under /sys/hypervisor (e.g., type). When running
+	  native or on another hypervisor, /sys/hypervisor may still be
+	  present, but it will have no Hyper-V entries.
+
 endmenu
diff --git a/drivers/hv/Makefile b/drivers/hv/Makefile
index a1eec7177c2d..87f569659555 100644
--- a/drivers/hv/Makefile
+++ b/drivers/hv/Makefile
@@ -1,7 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0
-obj-$(CONFIG_HYPERV)		+= hv_vmbus.o
-obj-$(CONFIG_HYPERV_UTILS)	+= hv_utils.o
-obj-$(CONFIG_HYPERV_BALLOON)	+= hv_balloon.o
+obj-$(CONFIG_HYPERV)			+= hv_vmbus.o
+obj-$(CONFIG_HYPERV_UTILS)		+= hv_utils.o
+obj-$(CONFIG_HYPERV_BALLOON)		+= hv_balloon.o
+obj-$(CONFIG_HYPERV_SYS_HYPERVISOR)	+= sys-hypervisor.o
 
 CFLAGS_hv_trace.o = -I$(src)
 CFLAGS_hv_balloon.o = -I$(src)
diff --git a/drivers/hv/sys-hypervisor.c b/drivers/hv/sys-hypervisor.c
new file mode 100644
index 000000000000..eb3d2a6502c4
--- /dev/null
+++ b/drivers/hv/sys-hypervisor.c
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * Copyright (C) 2019, Microsoft, Inc.
+ *
+ * Authored by: Nuno Das Neves <nudasnev@microsoft.com>
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/kobject.h>
+#include <linux/err.h>
+
+#include <asm/hypervisor.h>
+
+static ssize_t type_show(struct kobject *obj,
+			struct kobj_attribute *attr,
+			char *buf)
+{
+	return sprintf(buf, "Hyper-V\n");
+}
+
+static struct kobj_attribute type_attr = __ATTR_RO(type);
+
+static int __init hyperv_sysfs_type_init(void)
+{
+	return sysfs_create_file(hypervisor_kobj, &type_attr.attr);
+}
+
+static int __init hyper_sysfs_init(void)
+{
+	int ret;
+
+	if (!hypervisor_is_type(X86_HYPER_MS_HYPERV))
+		return -ENODEV;
+
+	ret = hyperv_sysfs_type_init();
+
+	return ret;
+}
+device_initcall(hyper_sysfs_init);
-- 
2.17.1


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

* [RFC PATCH 2/2] sys-hypervisor: version information for Hyper-V
  2019-07-26 23:17 [RFC PATCH 0/2] Basic /sys/hypervisor information for Hyper-V Nuno Das Neves
  2019-07-26 23:17 ` [RFC PATCH 1/2] sys-hypervisor: /sys/hypervisor/type " Nuno Das Neves
@ 2019-07-26 23:17 ` Nuno Das Neves
  1 sibling, 0 replies; 4+ messages in thread
From: Nuno Das Neves @ 2019-07-26 23:17 UTC (permalink / raw)
  To: nudasnev, gregkh, sthemmin, Alexander.Levin, haiyangz, kys, mikelley
  Cc: linux-kernel

This patch introduces the /sys/hypervisor/version directory, which contains
files with version information about the underlying Windows hypervisor, namely:
major, minor, build_number, service_number, service_pack, service_branch

Signed-off-by: Nuno Das Neves <nudasnev@microsoft.com>
---
 .../ABI/stable/sysfs-hypervisor-hyperv        |  54 ++++++++++
 drivers/hv/sys-hypervisor.c                   | 102 ++++++++++++++++++
 2 files changed, 156 insertions(+)

diff --git a/Documentation/ABI/stable/sysfs-hypervisor-hyperv b/Documentation/ABI/stable/sysfs-hypervisor-hyperv
index 58380ea81315..9bb50e37b083 100644
--- a/Documentation/ABI/stable/sysfs-hypervisor-hyperv
+++ b/Documentation/ABI/stable/sysfs-hypervisor-hyperv
@@ -5,3 +5,57 @@ Contact:	linux-hyperv@vger.kernel.org
 Description:	If running under Hyper-V:
 		Type of hypervisor:
 		"Hyper-V": Hyper-V hypervisor
+
+What:		/sys/hypervisor/version/major
+Date:		July 2019
+KernelVersion:	5.2.1
+Contact:	linux-hyperv@vger.kernel.org
+Description:	If running under Hyper-V:
+		The Hyper-V version is in the format:
+		<major>.<minor>.<build_number>.<service_number>-<service_pack>-<service_branch>
+		This is the <major> part of it.
+
+What:		/sys/hypervisor/version/minor
+Date:		July 2019
+KernelVersion:	5.2.1
+Contact:	linux-hyperv@vger.kernel.org
+Description:	If running under Hyper-V:
+		The Hyper-V version is in the format:
+		<major>.<minor>.<build_number>.<service_number>-<service_pack>-<service_branch>
+		This is the <minor> part of it.
+
+What:		/sys/hypervisor/version/build_number
+Date:		July 2019
+KernelVersion:	5.2.1
+Contact:	linux-hyperv@vger.kernel.org
+Description:	If running under Hyper-V:
+		The Hyper-V version is in the format:
+		<major>.<minor>.<build_number>.<service_number>-<service_pack>-<service_branch>
+		This is the <build_number> part of it.
+
+What:		/sys/hypervisor/version/service_number
+Date:		July 2019
+KernelVersion:	5.2.1
+Contact:	linux-hyperv@vger.kernel.org
+Description:	If running under Hyper-V:
+		The Hyper-V version is in the format:
+		<major>.<minor>.<build_number>.<service_number>-<service_pack>-<service_branch>
+		This is the <service_number> part of it.
+
+What:		/sys/hypervisor/version/service_pack
+Date:		July 2019
+KernelVersion:	5.2.1
+Contact:	linux-hyperv@vger.kernel.org
+Description:	If running under Hyper-V:
+		The Hyper-V version is in the format:
+		<major>.<minor>.<build_number>.<service_number>-<service_pack>-<service_branch>
+		This is the <service_pack> part of it.
+
+What:		/sys/hypervisor/version/service_branch
+Date:		July 2019
+KernelVersion:	5.2.1
+Contact:	linux-hyperv@vger.kernel.org
+Description:	If running under Hyper-V:
+		The Hyper-V version is in the format:
+		<major>.<minor>.<build_number>.<service_number>-<service_pack>-<service_branch>
+		This is the <service_branch> part of it.
diff --git a/drivers/hv/sys-hypervisor.c b/drivers/hv/sys-hypervisor.c
index eb3d2a6502c4..d157636c2db9 100644
--- a/drivers/hv/sys-hypervisor.c
+++ b/drivers/hv/sys-hypervisor.c
@@ -10,7 +10,9 @@
 #include <linux/init.h>
 #include <linux/kobject.h>
 #include <linux/err.h>
+#include <linux/processor.h>
 
+#include <asm/hyperv-tlfs.h>
 #include <asm/hypervisor.h>
 
 static ssize_t type_show(struct kobject *obj,
@@ -27,6 +29,95 @@ static int __init hyperv_sysfs_type_init(void)
 	return sysfs_create_file(hypervisor_kobj, &type_attr.attr);
 }
 
+/* version info */
+
+static ssize_t major_show(struct kobject *obj,
+			struct kobj_attribute *attr,
+			char *buf)
+{
+	unsigned int hv_host_info_ebx = cpuid_ebx(HYPERV_CPUID_VERSION);
+
+	return sprintf(buf, "%u\n", hv_host_info_ebx >> 16);
+}
+
+static struct kobj_attribute major_attr = __ATTR_RO(major);
+
+static ssize_t minor_show(struct kobject *obj,
+			struct kobj_attribute *attr,
+			char *buf)
+{
+	unsigned int hv_host_info_ebx = cpuid_ebx(HYPERV_CPUID_VERSION);
+
+	return sprintf(buf, "%u\n", hv_host_info_ebx & 0xFFFF);
+}
+
+static struct kobj_attribute minor_attr = __ATTR_RO(minor);
+
+static ssize_t build_number_show(struct kobject *obj,
+			struct kobj_attribute *attr,
+			char *buf)
+{
+	unsigned int hv_host_info_eax = cpuid_eax(HYPERV_CPUID_VERSION);
+
+	return sprintf(buf, "%u\n", hv_host_info_eax);
+}
+
+static struct kobj_attribute build_number_attr = __ATTR_RO(build_number);
+
+static ssize_t service_number_show(struct kobject *obj,
+			struct kobj_attribute *attr,
+			char *buf)
+{
+	unsigned int hv_host_info_edx = cpuid_edx(HYPERV_CPUID_VERSION);
+
+	return sprintf(buf, "%u\n", hv_host_info_edx & 0xFFFFFF);
+}
+
+static struct kobj_attribute service_number_attr = __ATTR_RO(service_number);
+
+static ssize_t service_pack_show(struct kobject *obj,
+			struct kobj_attribute *attr,
+			char *buf)
+{
+	unsigned int hv_host_info_ecx = cpuid_ecx(HYPERV_CPUID_VERSION);
+
+	return sprintf(buf, "%u\n", hv_host_info_ecx);
+}
+
+static struct kobj_attribute service_pack_attr = __ATTR_RO(service_pack);
+
+static ssize_t service_branch_show(struct kobject *obj,
+			struct kobj_attribute *attr,
+			char *buf)
+{
+	unsigned int hv_host_info_edx = cpuid_edx(HYPERV_CPUID_VERSION);
+
+	return sprintf(buf, "%u\n", hv_host_info_edx >> 24);
+}
+
+static struct kobj_attribute service_branch_attr = __ATTR_RO(service_branch);
+
+static struct attribute *version_attrs[] = {
+	&major_attr.attr,
+	&minor_attr.attr,
+	&build_number_attr.attr,
+	&service_number_attr.attr,
+	&service_pack_attr.attr,
+	&service_branch_attr.attr,
+	NULL
+};
+
+static const struct attribute_group version_group = {
+	.name = "version",
+	.attrs = version_attrs,
+};
+
+static int __init hyperv_sysfs_version_init(void)
+{
+	return sysfs_create_group(hypervisor_kobj, &version_group);
+}
+
+
 static int __init hyper_sysfs_init(void)
 {
 	int ret;
@@ -35,7 +126,18 @@ static int __init hyper_sysfs_init(void)
 		return -ENODEV;
 
 	ret = hyperv_sysfs_type_init();
+	if (ret)
+		goto out;
+
+	ret = hyperv_sysfs_version_init();
+	if (ret)
+		goto version_out;
+
+	goto out;
 
+version_out:
+	sysfs_remove_file(hypervisor_kobj, &type_attr.attr);
+out:
 	return ret;
 }
 device_initcall(hyper_sysfs_init);
-- 
2.17.1


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

* Re: [RFC PATCH 1/2] sys-hypervisor: /sys/hypervisor/type for Hyper-V
       [not found]     ` <MWHPR21MB07015125F311AF5E2A8D813883DD0@MWHPR21MB0701.namprd21.prod.outlook.com>
@ 2019-08-05 16:58       ` Nuno Das Neves
  0 siblings, 0 replies; 4+ messages in thread
From: Nuno Das Neves @ 2019-08-05 16:58 UTC (permalink / raw)
  To: Nuno Das Neves <Nuno.Das@microsoft.com>; Nuno Das Neves
	<Nuno.Das@microsoft.com>; gregkh@linuxfoundation.org
	<gregkh@linuxfoundation.org>; Sasha Levin
	<Alexander.Levin@microsoft.com>; Haiyang Zhang
	<haiyangz@microsoft.com>; KY Srinivasan
	<kys@microsoft.com>; Michael Kelley
  Cc: linux-kernel

On 7/29/2019 3:54 PM, Nuno Das Neves wrote:
> *From:*Stephen Hemminger <sthemmin@microsoft.com>
> *Sent:* Friday, 26 July 2019 5:43 PM
> *To:* Nuno Das Neves <Nuno.Das@microsoft.com>; Nuno Das Neves <Nuno.Das@microsoft.com>; gregkh@linuxfoundation.org <gregkh@linuxfoundation.org>; Sasha Levin <Alexander.Levin@microsoft.com>; Haiyang Zhang <haiyangz@microsoft.com>; KY Srinivasan <kys@microsoft.com>; Michael Kelley <mikelley@microsoft.com>
> *Cc:* linux-kernel@vger.kernel.org <linux-kernel@vger.kernel.org>
> *Subject:* Re: [RFC PATCH 1/2] sys-hypervisor: /sys/hypervisor/type for Hyper-V
>  
> I am not sure about this. 
> The existing tools like lscpu just use CPUID. What is does this addition add?
> 
The main motivation is to replicate functionality available on Xen.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> *From:* Nuno Das Neves <nudasnev@microsoft.com>
> *Sent:* Friday, July 26, 2019 4:17 PM
> *To:* Nuno Das Neves <Nuno.Das@microsoft.com>; gregkh@linuxfoundation.org <gregkh@linuxfoundation.org>; Stephen Hemminger <sthemmin@microsoft.com>; Sasha Levin <Alexander.Levin@microsoft.com>; Haiyang Zhang <haiyangz@microsoft.com>; KY Srinivasan <kys@microsoft.com>; Michael Kelley <mikelley@microsoft.com>
> *Cc:* linux-kernel@vger.kernel.org <linux-kernel@vger.kernel.org>
> *Subject:* [RFC PATCH 1/2] sys-hypervisor: /sys/hypervisor/type for Hyper-V
>  
> Populate /sys/hypervisor with entries for Hyper-V.
> This patch adds /sys/hypervisor/type which contains "Hyper-V".
> 
> Signed-off-by: Nuno Das Neves <nudasnev@microsoft.com>
> ---
>  .../ABI/stable/sysfs-hypervisor-hyperv        |  7 ++++
>  drivers/hv/Kconfig                            | 10 +++++
>  drivers/hv/Makefile                           |  7 ++--
>  drivers/hv/sys-hypervisor.c                   | 41 +++++++++++++++++++
>  4 files changed, 62 insertions(+), 3 deletions(-)
>  create mode 100644 Documentation/ABI/stable/sysfs-hypervisor-hyperv
>  create mode 100644 drivers/hv/sys-hypervisor.c
> 
> diff --git a/Documentation/ABI/stable/sysfs-hypervisor-hyperv b/Documentation/ABI/stable/sysfs-hypervisor-hyperv
> new file mode 100644
> index 000000000000..58380ea81315
> --- /dev/null
> +++ b/Documentation/ABI/stable/sysfs-hypervisor-hyperv
> @@ -0,0 +1,7 @@
> +What:          /sys/hypervisor/type
> +Date:          July 2019
> +KernelVersion: 5.2.1
> +Contact:       linux-hyperv@vger.kernel.org
> +Description:   If running under Hyper-V:
> +               Type of hypervisor:
> +               "Hyper-V": Hyper-V hypervisor
> diff --git a/drivers/hv/Kconfig b/drivers/hv/Kconfig
> index 1c1a2514d6f3..e693adf0b77f 100644
> --- a/drivers/hv/Kconfig
> +++ b/drivers/hv/Kconfig
> @@ -25,4 +25,14 @@ config HYPERV_BALLOON
>          help
>            Select this option to enable Hyper-V Balloon driver.
>  
> +config HYPERV_SYS_HYPERVISOR
> +       bool "Create Hyper-V entries under /sys/hypervisor"
> +       depends on HYPERV && SYSFS
> +       select SYS_HYPERVISOR
> +       default y
> +       help
> +         Create Hyper-V entries under /sys/hypervisor (e.g., type). When running
> +         native or on another hypervisor, /sys/hypervisor may still be
> +         present, but it will have no Hyper-V entries.
> +
>  endmenu
> diff --git a/drivers/hv/Makefile b/drivers/hv/Makefile
> index a1eec7177c2d..87f569659555 100644
> --- a/drivers/hv/Makefile
> +++ b/drivers/hv/Makefile
> @@ -1,7 +1,8 @@
>  # SPDX-License-Identifier: GPL-2.0
> -obj-$(CONFIG_HYPERV)           += hv_vmbus.o
> -obj-$(CONFIG_HYPERV_UTILS)     += hv_utils.o
> -obj-$(CONFIG_HYPERV_BALLOON)   += hv_balloon.o
> +obj-$(CONFIG_HYPERV)                   += hv_vmbus.o
> +obj-$(CONFIG_HYPERV_UTILS)             += hv_utils.o
> +obj-$(CONFIG_HYPERV_BALLOON)           += hv_balloon.o
> +obj-$(CONFIG_HYPERV_SYS_HYPERVISOR)    += sys-hypervisor.o
>  
>  CFLAGS_hv_trace.o = -I$(src)
>  CFLAGS_hv_balloon.o = -I$(src)
> diff --git a/drivers/hv/sys-hypervisor.c b/drivers/hv/sys-hypervisor.c
> new file mode 100644
> index 000000000000..eb3d2a6502c4
> --- /dev/null
> +++ b/drivers/hv/sys-hypervisor.c
> @@ -0,0 +1,41 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +/*
> + * Copyright (C) 2019, Microsoft, Inc.
> + *
> + * Authored by: Nuno Das Neves <nudasnev@microsoft.com>
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/init.h>
> +#include <linux/kobject.h>
> +#include <linux/err.h>
> +
> +#include <asm/hypervisor.h>
> +
> +static ssize_t type_show(struct kobject *obj,
> +                       struct kobj_attribute *attr,
> +                       char *buf)
> +{
> +       return sprintf(buf, "Hyper-V\n");
> +}
> +
> +static struct kobj_attribute type_attr = __ATTR_RO(type);
> +
> +static int __init hyperv_sysfs_type_init(void)
> +{
> +       return sysfs_create_file(hypervisor_kobj, &type_attr.attr);
> +}
> +
> +static int __init hyper_sysfs_init(void)
> +{
> +       int ret;
> +
> +       if (!hypervisor_is_type(X86_HYPER_MS_HYPERV))
> +               return -ENODEV;
> +
> +       ret = hyperv_sysfs_type_init();
> +
> +       return ret;
> +}
> +device_initcall(hyper_sysfs_init);
> -- 
> 2.17.1
> 

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

end of thread, other threads:[~2019-08-05 16:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-26 23:17 [RFC PATCH 0/2] Basic /sys/hypervisor information for Hyper-V Nuno Das Neves
2019-07-26 23:17 ` [RFC PATCH 1/2] sys-hypervisor: /sys/hypervisor/type " Nuno Das Neves
     [not found]   ` <MN2PR21MB1216DBB3BD918B6DCC738E30CCC30@MN2PR21MB1216.namprd21.prod.outlook.com>
     [not found]     ` <MWHPR21MB07015125F311AF5E2A8D813883DD0@MWHPR21MB0701.namprd21.prod.outlook.com>
2019-08-05 16:58       ` Nuno Das Neves
2019-07-26 23:17 ` [RFC PATCH 2/2] sys-hypervisor: version information " Nuno Das Neves

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