xen: add sysfs node for guest type
authorJuergen Gross <jgross@suse.com>
Wed, 14 Jun 2017 15:12:45 +0000 (17:12 +0200)
committerJuergen Gross <jgross@suse.com>
Thu, 15 Jun 2017 06:50:32 +0000 (08:50 +0200)
Currently there is no reliable user interface inside a Xen guest to
determine its type (e.g. HVM, PV or PVH). Instead of letting user mode
try to determine this by various rather hacky mechanisms (parsing of
boot messages before they are gone, trying to make use of known subtle
differences in behavior of some instructions), add a sysfs node
/sys/hypervisor/guest_type to explicitly deliver this information as
it is known to the kernel.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
Documentation/ABI/testing/sysfs-hypervisor-pmu [deleted file]
Documentation/ABI/testing/sysfs-hypervisor-xen [new file with mode: 0644]
MAINTAINERS
drivers/xen/sys-hypervisor.c

diff --git a/Documentation/ABI/testing/sysfs-hypervisor-pmu b/Documentation/ABI/testing/sysfs-hypervisor-pmu
deleted file mode 100644 (file)
index 224faa1..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-What:          /sys/hypervisor/pmu/pmu_mode
-Date:          August 2015
-KernelVersion: 4.3
-Contact:       Boris Ostrovsky <boris.ostrovsky@oracle.com>
-Description:
-               Describes mode that Xen's performance-monitoring unit (PMU)
-               uses. Accepted values are
-                       "off"  -- PMU is disabled
-                       "self" -- The guest can profile itself
-                       "hv"   -- The guest can profile itself and, if it is
-                                 privileged (e.g. dom0), the hypervisor
-                       "all" --  The guest can profile itself, the hypervisor
-                                 and all other guests. Only available to
-                                 privileged guests.
-
-What:           /sys/hypervisor/pmu/pmu_features
-Date:           August 2015
-KernelVersion:  4.3
-Contact:        Boris Ostrovsky <boris.ostrovsky@oracle.com>
-Description:
-               Describes Xen PMU features (as an integer). A set bit indicates
-               that the corresponding feature is enabled. See
-               include/xen/interface/xenpmu.h for available features
diff --git a/Documentation/ABI/testing/sysfs-hypervisor-xen b/Documentation/ABI/testing/sysfs-hypervisor-xen
new file mode 100644 (file)
index 0000000..c0edb3f
--- /dev/null
@@ -0,0 +1,34 @@
+What:          /sys/hypervisor/guest_type
+Date:          May 2017
+KernelVersion: 4.13
+Contact:       xen-devel@lists.xenproject.org
+Description:   If running under Xen:
+               Type of guest:
+               "Xen": standard guest type on arm
+               "HVM": fully virtualized guest (x86)
+               "PV": paravirtualized guest (x86)
+               "PVH": fully virtualized guest without legacy emulation (x86)
+
+What:          /sys/hypervisor/pmu/pmu_mode
+Date:          August 2015
+KernelVersion: 4.3
+Contact:       Boris Ostrovsky <boris.ostrovsky@oracle.com>
+Description:   If running under Xen:
+               Describes mode that Xen's performance-monitoring unit (PMU)
+               uses. Accepted values are
+                       "off"  -- PMU is disabled
+                       "self" -- The guest can profile itself
+                       "hv"   -- The guest can profile itself and, if it is
+                                 privileged (e.g. dom0), the hypervisor
+                       "all" --  The guest can profile itself, the hypervisor
+                                 and all other guests. Only available to
+                                 privileged guests.
+
+What:           /sys/hypervisor/pmu/pmu_features
+Date:           August 2015
+KernelVersion:  4.3
+Contact:        Boris Ostrovsky <boris.ostrovsky@oracle.com>
+Description:   If running under Xen:
+               Describes Xen PMU features (as an integer). A set bit indicates
+               that the corresponding feature is enabled. See
+               include/xen/interface/xenpmu.h for available features
index 730245ac2c1840ed365d1a69c7c2b2c4ee1ac0f2..c3ce334414e9ec8d2ee51d0b2824da4074ea4d45 100644 (file)
@@ -13984,7 +13984,7 @@ F:      arch/x86/include/asm/xen/
 F:     include/xen/
 F:     include/uapi/xen/
 F:     Documentation/ABI/stable/sysfs-hypervisor-xen
-F:     Documentation/ABI/testing/sysfs-hypervisor-pmu
+F:     Documentation/ABI/testing/sysfs-hypervisor-xen
 
 XEN HYPERVISOR ARM
 M:     Stefano Stabellini <sstabellini@kernel.org>
index 84106f9c456cd14a3798fd72893b05f1042f3873..2f78f84a31e90649ee9be7500795fa5f8de54d5f 100644 (file)
@@ -50,6 +50,35 @@ static int __init xen_sysfs_type_init(void)
        return sysfs_create_file(hypervisor_kobj, &type_attr.attr);
 }
 
+static ssize_t guest_type_show(struct hyp_sysfs_attr *attr, char *buffer)
+{
+       const char *type;
+
+       switch (xen_domain_type) {
+       case XEN_NATIVE:
+               /* ARM only. */
+               type = "Xen";
+               break;
+       case XEN_PV_DOMAIN:
+               type = "PV";
+               break;
+       case XEN_HVM_DOMAIN:
+               type = xen_pvh_domain() ? "PVH" : "HVM";
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return sprintf(buffer, "%s\n", type);
+}
+
+HYPERVISOR_ATTR_RO(guest_type);
+
+static int __init xen_sysfs_guest_type_init(void)
+{
+       return sysfs_create_file(hypervisor_kobj, &guest_type_attr.attr);
+}
+
 /* xen version attributes */
 static ssize_t major_show(struct hyp_sysfs_attr *attr, char *buffer)
 {
@@ -471,6 +500,9 @@ static int __init hyper_sysfs_init(void)
        ret = xen_sysfs_type_init();
        if (ret)
                goto out;
+       ret = xen_sysfs_guest_type_init();
+       if (ret)
+               goto guest_type_out;
        ret = xen_sysfs_version_init();
        if (ret)
                goto version_out;
@@ -502,6 +534,8 @@ uuid_out:
 comp_out:
        sysfs_remove_group(hypervisor_kobj, &version_group);
 version_out:
+       sysfs_remove_file(hypervisor_kobj, &guest_type_attr.attr);
+guest_type_out:
        sysfs_remove_file(hypervisor_kobj, &type_attr.attr);
 out:
        return ret;