From: Per Bilse <per.bilse@citrix.com>
To: <linux-kernel@vger.kernel.org>
Cc: Per Bilse <per.bilse@citrix.com>, Juergen Gross <jgross@suse.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>,
Boris Ostrovsky <boris.ostrovsky@oracle.com>,
Jan Beulich <jbeulich@suse.com>,
"moderated list:XEN HYPERVISOR INTERFACE"
<xen-devel@lists.xenproject.org>
Subject: [PATCH] drivers/xen/hypervisor: Expose VM SIF flags to userspace
Date: Tue, 29 Nov 2022 15:00:57 +0000 [thread overview]
Message-ID: <20221129150058.266943-1-per.bilse@citrix.com> (raw)
/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@citrix.com>
---
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
next reply other threads:[~2022-11-29 15:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-29 15:00 Per Bilse [this message]
2022-11-29 15:27 ` Juergen Gross
2022-11-29 16:41 ` Andrew Cooper
2022-11-29 17:38 ` Per Bilse (3P)
2022-11-29 16:29 ` Boris Ostrovsky
2022-11-29 16:46 ` Per Bilse (3P)
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=20221129150058.266943-1-per.bilse@citrix.com \
--to=per.bilse@citrix.com \
--cc=boris.ostrovsky@oracle.com \
--cc=jbeulich@suse.com \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oleksandr_tyshchenko@epam.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/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®