All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: Start populating /sys/hypervisor with KVM entries
@ 2018-10-09  9:54 Filippo Sironi
  2018-10-09 10:41 ` Christian Borntraeger
                   ` (4 more replies)
  0 siblings, 5 replies; 77+ messages in thread
From: Filippo Sironi @ 2018-10-09  9:54 UTC (permalink / raw)
  To: sironi, linux-kernel, kvm

Start populating /sys/hypervisor with KVM entries when we're running on
KVM. This is to replicate functionality that's available when we're
running on Xen.

Let's start with /sys/hypervisor/uuid, which users prefer over
/sys/devices/virtual/dmi/id/product_uuid as a way to recognize a virtual
machine, since it's also available when running on Xen HVM and on Xen PV
and, on top of that doesn't require root privileges by default.

Signed-off-by: Filippo Sironi <sironi@amazon.de>
---
 drivers/Kconfig              |  2 ++
 drivers/Makefile             |  2 ++
 drivers/kvm/Kconfig          | 14 ++++++++++++++
 drivers/kvm/Makefile         |  1 +
 drivers/kvm/sys-hypervisor.c | 26 ++++++++++++++++++++++++++
 5 files changed, 45 insertions(+)
 create mode 100644 drivers/kvm/Kconfig
 create mode 100644 drivers/kvm/Makefile
 create mode 100644 drivers/kvm/sys-hypervisor.c

diff --git a/drivers/Kconfig b/drivers/Kconfig
index afc942c54814..597519c5f7c8 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -135,6 +135,8 @@ source "drivers/hv/Kconfig"
 
 source "drivers/xen/Kconfig"
 
+source "drivers/kvm/Kconfig"
+
 source "drivers/staging/Kconfig"
 
 source "drivers/platform/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index 1056f9699192..727205e287fc 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -47,6 +47,8 @@ obj-y				+= soc/
 obj-$(CONFIG_VIRTIO)		+= virtio/
 obj-$(CONFIG_XEN)		+= xen/
 
+obj-$(CONFIG_KVM_GUEST)		+= kvm/
+
 # regulators early, since some subsystems rely on them to initialize
 obj-$(CONFIG_REGULATOR)		+= regulator/
 
diff --git a/drivers/kvm/Kconfig b/drivers/kvm/Kconfig
new file mode 100644
index 000000000000..3fc041df7c11
--- /dev/null
+++ b/drivers/kvm/Kconfig
@@ -0,0 +1,14 @@
+menu "KVM driver support"
+        depends on KVM_GUEST
+
+config KVM_SYS_HYPERVISOR
+        bool "Create KVM entries under /sys/hypervisor"
+        depends on SYSFS
+        select SYS_HYPERVISOR
+        default y
+        help
+          Create KVM entries under /sys/hypervisor (e.g., uuid). When running
+          native or on another hypervisor, /sys/hypervisor may still be
+          present, but it will have no KVM entries.
+
+endmenu
diff --git a/drivers/kvm/Makefile b/drivers/kvm/Makefile
new file mode 100644
index 000000000000..73a43fc994b9
--- /dev/null
+++ b/drivers/kvm/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_KVM_SYS_HYPERVISOR) += sys-hypervisor.o
diff --git a/drivers/kvm/sys-hypervisor.c b/drivers/kvm/sys-hypervisor.c
new file mode 100644
index 000000000000..ef04ca65cf1a
--- /dev/null
+++ b/drivers/kvm/sys-hypervisor.c
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#include <asm/kvm_para.h>
+
+#include <linux/dmi.h>
+#include <linux/kobject.h>
+#include <linux/sysfs.h>
+
+static ssize_t uuid_show(struct kobject *obj,
+			 struct kobj_attribute *attr,
+			 char *buf)
+{
+	const char *uuid = dmi_get_system_info(DMI_PRODUCT_UUID);
+	return sprintf(buf, "%s\n", uuid);
+}
+
+static struct kobj_attribute uuid = __ATTR_RO(uuid);
+
+static int __init uuid_init(void)
+{
+	if (!kvm_para_available())
+		return 0;
+	return sysfs_create_file(hypervisor_kobj, &uuid.attr);
+}
+
+device_initcall(uuid_init);
-- 
2.7.4


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

end of thread, other threads:[~2019-05-31  9:39 UTC | newest]

Thread overview: 77+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-09  9:54 [PATCH] KVM: Start populating /sys/hypervisor with KVM entries Filippo Sironi
2018-10-09 10:41 ` Christian Borntraeger
2018-10-09 16:21   ` Boris Ostrovsky
2018-10-09 16:21   ` Boris Ostrovsky
2018-10-09 17:50     ` Cornelia Huck
2018-10-09 17:50     ` Cornelia Huck
2018-10-09 15:00 ` Konrad Rzeszutek Wilk
2018-10-10  5:19 ` kbuild test robot
2019-05-14 15:16 ` Filippo Sironi
2019-05-14 15:16   ` [Xen-devel] " Filippo Sironi
2019-05-14 15:16   ` [PATCH v2 1/2] " Filippo Sironi
2019-05-14 15:16     ` [Xen-devel] " Filippo Sironi
2019-05-14 15:26     ` Christian Borntraeger
2019-05-14 15:26       ` [Xen-devel] " Christian Borntraeger
2019-05-14 16:09       ` Sironi, Filippo
2019-05-14 16:09       ` Sironi, Filippo
2019-05-14 16:09         ` [Xen-devel] " Sironi, Filippo
2019-05-14 16:31         ` Christian Borntraeger
2019-05-14 16:31         ` Christian Borntraeger
2019-05-14 16:31           ` [Xen-devel] " Christian Borntraeger
2019-05-14 22:08         ` Sironi, Filippo
2019-05-14 22:08         ` Sironi, Filippo
2019-05-14 22:08           ` [Xen-devel] " Sironi, Filippo
2019-05-14 15:26     ` Christian Borntraeger
2019-05-16 13:50     ` Alexander Graf
2019-05-16 13:50       ` [Xen-devel] " Alexander Graf
2019-05-16 14:02       ` Andrew Cooper
2019-05-16 14:02         ` Andrew Cooper
2019-05-16 14:02         ` Andrew Cooper
2019-05-16 14:08         ` Alexander Graf
2019-05-16 14:08         ` [Xen-devel] " Alexander Graf
2019-05-16 14:08           ` Alexander Graf
2019-05-16 15:02           ` Boris Ostrovsky
2019-05-16 15:02             ` Boris Ostrovsky
2019-05-16 15:14             ` Sironi, Filippo
2019-05-16 15:14             ` [Xen-devel] " Sironi, Filippo
2019-05-16 15:14               ` Sironi, Filippo
2019-05-16 15:02           ` Boris Ostrovsky
2019-05-17 15:41       ` Sironi, Filippo
2019-05-17 15:41         ` [Xen-devel] " Sironi, Filippo
2019-05-31  9:06         ` Alexander Graf
2019-05-31  9:06           ` [Xen-devel] " Alexander Graf
2019-05-31  9:12           ` Raslan, KarimAllah
2019-05-31  9:12             ` [Xen-devel] " Raslan, KarimAllah
2019-05-31  9:26             ` Alexander Graf
2019-05-31  9:26               ` [Xen-devel] " Alexander Graf
2019-05-31  9:26             ` Alexander Graf
2019-05-31  9:38             ` Marc Zyngier
2019-05-31  9:38               ` [Xen-devel] " Marc Zyngier
2019-05-31  9:38             ` Marc Zyngier
2019-05-31  9:12           ` Raslan, KarimAllah
2019-05-31  9:06         ` Alexander Graf
2019-05-17 15:41       ` Sironi, Filippo
2019-05-16 13:50     ` Alexander Graf
2019-05-14 15:16   ` Filippo Sironi
2019-05-14 15:16   ` [PATCH v2 2/2] KVM: x86: Implement the arch-specific hook to report the VM UUID Filippo Sironi
2019-05-14 15:16     ` [Xen-devel] " Filippo Sironi
2019-05-16 13:56     ` Alexander Graf
2019-05-16 13:56       ` [Xen-devel] " Alexander Graf
2019-05-16 15:25       ` Sironi, Filippo
2019-05-16 15:25         ` [Xen-devel] " Sironi, Filippo
2019-05-16 15:33         ` Alexander Graf
2019-05-16 15:33           ` [Xen-devel] " Alexander Graf
2019-05-16 16:40           ` Boris Ostrovsky
2019-05-16 16:40             ` [Xen-devel] " Boris Ostrovsky
2019-05-16 17:41             ` Sironi, Filippo
2019-05-16 17:41               ` [Xen-devel] " Sironi, Filippo
2019-05-16 17:49               ` Alexander Graf
2019-05-16 17:49                 ` [Xen-devel] " Alexander Graf
2019-05-16 17:49               ` Alexander Graf
2019-05-16 17:41             ` Sironi, Filippo
2019-05-16 16:40           ` Boris Ostrovsky
2019-05-16 15:33         ` Alexander Graf
2019-05-16 15:25       ` Sironi, Filippo
2019-05-16 13:56     ` Alexander Graf
2019-05-14 15:16   ` Filippo Sironi
2019-05-14 15:16 ` KVM: Start populating /sys/hypervisor with KVM entries Filippo Sironi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.