From: Nuno Das Neves <nudasnev@microsoft.com>
To: nudasnev@microsoft.com, gregkh@linuxfoundation.org,
sthemmin@microsoft.com, Alexander.Levin@microsoft.com,
haiyangz@microsoft.com, kys@microsoft.com,
mikelley@microsoft.com
Cc: linux-kernel@vger.kernel.org
Subject: [RFC PATCH 1/2] sys-hypervisor: /sys/hypervisor/type for Hyper-V
Date: Fri, 26 Jul 2019 16:17:25 -0700 [thread overview]
Message-ID: <1564183046-128211-2-git-send-email-nudasnev@microsoft.com> (raw)
In-Reply-To: <1564183046-128211-1-git-send-email-nudasnev@microsoft.com>
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
next prev parent reply other threads:[~2019-07-26 23:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-26 23:17 [RFC PATCH 0/2] Basic /sys/hypervisor information " Nuno Das Neves
2019-07-26 23:17 ` Nuno Das Neves [this message]
[not found] ` <MN2PR21MB1216DBB3BD918B6DCC738E30CCC30@MN2PR21MB1216.namprd21.prod.outlook.com>
[not found] ` <MWHPR21MB07015125F311AF5E2A8D813883DD0@MWHPR21MB0701.namprd21.prod.outlook.com>
2019-08-05 16:58 ` [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
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=1564183046-128211-2-git-send-email-nudasnev@microsoft.com \
--to=nudasnev@microsoft.com \
--cc=Alexander.Levin@microsoft.com \
--cc=gregkh@linuxfoundation.org \
--cc=haiyangz@microsoft.com \
--cc=kys@microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mikelley@microsoft.com \
--cc=sthemmin@microsoft.com \
/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
all inboxes | Powered by JetHome®