[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] drivers/xen/hypervisor: Expose VM SIF flags to userspace


  • To: <linux-kernel@xxxxxxxxxxxxxxx>
  • From: Per Bilse <per.bilse@xxxxxxxxxx>
  • Date: Tue, 29 Nov 2022 15:00:57 +0000
  • Authentication-results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Per Bilse <per.bilse@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, "Stefano Stabellini" <sstabellini@xxxxxxxxxx>, Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>, Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, "moderated list:XEN HYPERVISOR INTERFACE" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 29 Nov 2022 15:12:21 +0000
  • Ironport-data: A9a23:sWt9j6354+v2TVIF5/bD5VVxkn2cJEfYwER7XKvMYLTBsI5bp2ZTy TMcDWqHb6zZNGb8Lot/bd6zo0MFvZXcmtNnTQtkpC1hF35El5HIVI+TRqvS04F+DeWYFR46s J9OAjXkBJppJpMJjk71atANlVEliefTAOK5ULSfUsxIbVcMYD87jh5+kPIOjIdtgNyoayuAo tq3qMDEULOf82cc3lk8tuTS9nuDgNyo4GlC5wVkNKgQ1LPjvyJ94Kw3dPnZw0TQGuG4LsbiL 87fwbew+H/u/htFIrtJRZ6iLyXm6paLVeS/oiI+t5qK23CulQRrukoPD9IOaF8/ttm8t4sZJ OOhF3CHYVxB0qXkwIzxWvTDes10FfUuFLTveRBTvSEPpqFvnrSFL/hGVSkL0YMkFulfJnl/+ +AaDA43SwGC3dqKg4iCGulRv5F2RCXrFNt3VnBIyDjYCbAtQIzZQrWM7thdtNsyrpkQR7CEP ZNfMGcxKkSbC/FMEg5/5JYWpOqywFP+dyZVgFmUubA28y7YywkZPL3FYIqOIozWH509ckCwq Wno8WX7WC0hNsHEyn3Y3nyPvtHItHauMG4VPOLhraM76LGJ/UQZDwcXTh28uuWjjVClWMN3L FYd8S4j66M18SSDTNPwQhm5q36spQMHVpxbFOhSwBGAzO/Y7hiUAkAATyVdc5o2uckuXzso2 1SV2dTzClRHt7mYSmmU8LuOmi+jIigeLWIEZigsQBMM5p/op4RbphbOSMtzVa24lNv4HRnuz D2Q6isznbMeiYgMzarT1VLImTW3vbDSUxU4oA7QWwqN9RhlbYSoY4ip71nz7vtaKoudCF6bs xA5d9O2tb5US8vXzWrUHbtLTOrBC+u53CP0pkZeEYUj0wqX3m+iJ7hsowtHdEdUC5NREdP2W 3P7tQRU7Z5VGXKla65rfo68Y/gXIbjc+cfNDa6NMIcXCnRlXErepXw1OxbMt4z4uBJ0+ZzTL 6t3ZipF4ZwyLa18hAS7SO4GuVPA7nBvnDiDLXwXIvnO7FZ/WJJ3Ye1dWLdtRrpjhE9hnOky2 4g3Cidy408DONASmwGOmWLpEXgELGIgGbf9oNFNe+iIL2JOQT9/WqGPmehwK9M6wcy5c9skG VnkCidlJKfX3yWbeW1mlFg8AF8QYXqPhS1iZnF9VbpZ83MifZyu/M8im2gfJNEaGBhY5acsF ZEtIpzQasmjvxybo1zxm7Gh9t09HPlq7CrSVxeYjM8XJcQ6GlSXpI+8I2MCNkAmV0KKiCf3m JX4viuzfHbJb1QzV646tNrHI4uNgEUg
  • Ironport-hdrordr: A9a23:2/a/mqlzZccVWZBw3+DcwPBe/xjpDfIg3DAbv31ZSRFFG/Fxl6 iV8sjzsiWE7Ar5OUtQ/+xoV5PhfZqxz/JICOoqTNKftWvdyQiVxehZhOOIqVDd8kXFh4lgPM xbEpSWZueeMbEDt7eZ3DWF
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

/proc/xen is a legacy pseudo filesystem which predates Xen support
getting merged into Linux.  It has largely been replaced with more
normal locations for data (/sys/hypervisor/ for info, /dev/xen/ for
user devices).  We want to compile xenfs support out of the dom0 kernel.

There is one item which only exists in /proc/xen, namely
/proc/xen/capabilities with "control_d" being the signal of "you're in
the control domain".  This ultimately comes from the SIF flags provided
at VM start.

This patch exposes all SIF flags in /sys/hypervisor/properties/flags,
which will coexist with /proc/xen while dependencies are being migrated.
Possible values are "privileged", "initdomain", "multiboot",
"mod_start_pfn", and "virtmap", with "initdomain" being the equivalent
of "control_d".

Signed-off-by: Per Bilse <per.bilse@xxxxxxxxxx>
---
 drivers/xen/sys-hypervisor.c | 26 ++++++++++++++++++++++++++
 include/xen/interface/xen.h  | 13 ++++++++-----
 2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/drivers/xen/sys-hypervisor.c b/drivers/xen/sys-hypervisor.c
index fcb0792f090e..7393e04bdb6d 100644
--- a/drivers/xen/sys-hypervisor.c
+++ b/drivers/xen/sys-hypervisor.c
@@ -379,6 +379,31 @@ static ssize_t buildid_show(struct hyp_sysfs_attr *attr, 
char *buffer)
 
 HYPERVISOR_ATTR_RO(buildid);
 
+static ssize_t flags_show(struct hyp_sysfs_attr *attr, char *buffer)
+{
+       static char const *const sifstr[SIFN_NUM_SIFN] = {
+               [SIFN_PRIV]  = "privileged",
+               [SIFN_INIT]  = "initdomain",
+               [SIFN_MULTI] = "multiboot",
+               [SIFN_PFN]   = "mod_start_pfn",
+               [SIFN_VIRT]  = "virtmap"
+       };
+       unsigned sifnum, sifmask;
+       ssize_t ret = 0;
+
+       sifmask = ~(~0U << SIFN_NUM_SIFN);  // ...0000111...
+       if (xen_domain() && (xen_start_flags & sifmask) != 0) {
+               for (sifnum = 0; sifnum != SIFN_NUM_SIFN; sifnum++) {
+                       if ((xen_start_flags & (1<<sifnum)) != 0)
+                               ret += sprintf(buffer+ret, "%s ", 
sifstr[sifnum]);
+               }
+               buffer[ret-1] = '\n';
+       }
+       return ret;
+}
+
+HYPERVISOR_ATTR_RO(flags);
+
 static struct attribute *xen_properties_attrs[] = {
        &capabilities_attr.attr,
        &changeset_attr.attr,
@@ -386,6 +411,7 @@ static struct attribute *xen_properties_attrs[] = {
        &pagesize_attr.attr,
        &features_attr.attr,
        &buildid_attr.attr,
+       &flags_attr.attr,
        NULL
 };
 
diff --git a/include/xen/interface/xen.h b/include/xen/interface/xen.h
index 0ca23eca2a9c..762a348abe3e 100644
--- a/include/xen/interface/xen.h
+++ b/include/xen/interface/xen.h
@@ -648,11 +648,14 @@ struct start_info {
 };
 
 /* These flags are passed in the 'flags' field of start_info_t. */
-#define SIF_PRIVILEGED      (1<<0)  /* Is the domain privileged? */
-#define SIF_INITDOMAIN      (1<<1)  /* Is this the initial control domain? */
-#define SIF_MULTIBOOT_MOD   (1<<2)  /* Is mod_start a multiboot module? */
-#define SIF_MOD_START_PFN   (1<<3)  /* Is mod_start a PFN? */
-#define SIF_VIRT_P2M_4TOOLS (1<<4)  /* Do Xen tools understand a virt. mapped 
*/
+/* Text strings are printed out in sys-hypervisor.c, we guard   */
+/* against mix-ups and errors by enumerating the flags.         */
+enum { SIFN_PRIV, SIFN_INIT, SIFN_MULTI, SIFN_PFN, SIFN_VIRT, SIFN_NUM_SIFN };
+#define SIF_PRIVILEGED      (1<<SIFN_PRIV)  /* Is the domain privileged? */
+#define SIF_INITDOMAIN      (1<<SIFN_INIT)  /* Is this the initial control 
domain? */
+#define SIF_MULTIBOOT_MOD   (1<<SIFN_MULTI) /* Is mod_start a multiboot 
module? */
+#define SIF_MOD_START_PFN   (1<<SIFN_PFN)   /* Is mod_start a PFN? */
+#define SIF_VIRT_P2M_4TOOLS (1<<SIFN_VIRT)  /* Do Xen tools understand a virt. 
mapped */
                                    /* P->M making the 3 level tree obsolete? */
 #define SIF_PM_MASK       (0xFF<<8) /* reserve 1 byte for xen-pm options */
 
-- 
2.31.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.