All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: "Stefano Stabellini" <sstabellini@kernel.org>,
	"Wei Liu" <wei.liu2@citrix.com>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Julien Grall" <julien.grall@arm.com>,
	"Jan Beulich" <JBeulich@suse.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [PATCH v2 4/4] xen/dom0: Add a dom0-iommu=none option
Date: Mon, 31 Dec 2018 15:16:23 +0000	[thread overview]
Message-ID: <1546269383-32166-5-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1546269383-32166-1-git-send-email-andrew.cooper3@citrix.com>

For development purposes, it is very convenient to boot Xen as a PVH guest,
with an XTF PV or PVH "dom0".  The edit-compile-go cycle is a matter of
seconds, and you can reasonably insert printk() debugging in places which
which would be completely infeasible when booting fully-fledged guests.

However, the PVH dom0 path insists on having a working IOMMU, which doesn't
exist when virtualised as a PVH guest, and isn't necessary for XTF anyway.

Introduce a developer mode to skip the IOMMU requirement.

To fix a corner case with command line parsing, cmdline_strcmp() is
introduced.  Because we no longer tokenise comma separated list with NUL's,
strcmp(line, "opt") doesn't work for a string in the middle of the comma
separated list, and strncmp("opt", s, ss - s) matches "o", "op" and "opt" on
the command line.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Julien Grall <julien.grall@arm.com>

Slightly RFC.  I've been carrying this patch locally for ages, but decided
that the approach is more likely to be accepted:

    diff --git a/xen/drivers/passthrough/x86/iommu.c b/xen/drivers/passthrough/x86/iommu.c
    index c68a722..87f0fd9 100644
    --- a/xen/drivers/passthrough/x86/iommu.c
    +++ b/xen/drivers/passthrough/x86/iommu.c
    @@ -117,8 +117,6 @@ int arch_iommu_populate_page_table(struct domain *d)

     void __hwdom_init arch_iommu_check_autotranslated_hwdom(struct domain *d)
     {
    -    if ( !iommu_enabled )
    -        panic("Presently, iommu must be enabled for PVH hardware domain\n");
     }

     int arch_iommu_domain_init(struct domain *d)

v2:
 * Retain `none` as opposed to repurposing `passthrough`.
 * Update cmdline_strcmp() to look only for commas.
---
 docs/misc/xen-command-line.markdown |  8 +++++++-
 xen/common/kernel.c                 | 20 ++++++++++++++++++++
 xen/drivers/passthrough/iommu.c     |  5 ++++-
 xen/include/xen/lib.h               |  7 +++++++
 4 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/docs/misc/xen-command-line.markdown b/docs/misc/xen-command-line.markdown
index 3a9af17..915d25c 100644
--- a/docs/misc/xen-command-line.markdown
+++ b/docs/misc/xen-command-line.markdown
@@ -664,7 +664,7 @@ Controls for how dom0 is constructed on x86 systems.
     hardware is not HAP-capable.
 
 ### dom0-iommu
-> `= List of [ passthrough=<bool>, strict=<bool>, map-reserved=<bool> ]`
+> `= List of [ passthrough=<bool>, strict=<bool>, map-reserved=<bool>, none ]`
 
 Controls for the dom0 IOMMU setup.
 
@@ -706,6 +706,12 @@ Controls for the dom0 IOMMU setup.
     This option is enabled by default on x86 systems, and invalid on ARM
     systems.
 
+*   The `none` option is intended for development purposes only, and skips
+    certain safety checks pertaining to the correct IOMMU configuration for
+    dom0 to boot.
+
+    Incorrect use of this option may result in a malfunctioning system.
+
 ### dom0\_ioports\_disable (x86)
 > `= List of <hex>-<hex>`
 
diff --git a/xen/common/kernel.c b/xen/common/kernel.c
index 5766a0f..af96850 100644
--- a/xen/common/kernel.c
+++ b/xen/common/kernel.c
@@ -271,6 +271,26 @@ int parse_boolean(const char *name, const char *s, const char *e)
     return -1;
 }
 
+int cmdline_strcmp(const char *frag, const char *name)
+{
+    while ( 1 )
+    {
+        int res = (*frag - *name);
+
+        if ( res || *name == '\0' )
+        {
+            /* NUL in 'name' matching a comma in 'frag' implies success. */
+            if ( *name == '\0' && *frag == ',' )
+                res = 0;
+
+            return res;
+        }
+
+        frag++;
+        name++;
+    }
+}
+
 unsigned int tainted;
 
 /**
diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c
index d2ee2ee..94b5f4c 100644
--- a/xen/drivers/passthrough/iommu.c
+++ b/xen/drivers/passthrough/iommu.c
@@ -59,6 +59,7 @@ bool_t __read_mostly iommu_snoop = 1;
 bool_t __read_mostly iommu_qinval = 1;
 bool_t __read_mostly iommu_intremap = 1;
 
+static bool __hwdom_initdata iommu_hwdom_none;
 bool __hwdom_initdata iommu_hwdom_strict;
 bool __read_mostly iommu_hwdom_passthrough;
 int8_t __hwdom_initdata iommu_hwdom_reserved = -1;
@@ -155,6 +156,8 @@ static int __init parse_dom0_iommu_param(const char *s)
             iommu_hwdom_strict = val;
         else if ( (val = parse_boolean("map-reserved", s, ss)) >= 0 )
             iommu_hwdom_reserved = val;
+        else if ( !cmdline_strcmp(s, "none") )
+            iommu_hwdom_none = true;
         else
             rc = -EINVAL;
 
@@ -183,7 +186,7 @@ int iommu_domain_init(struct domain *d)
 
 static void __hwdom_init check_hwdom_reqs(struct domain *d)
 {
-    if ( !paging_mode_translate(d) )
+    if ( iommu_hwdom_none || !paging_mode_translate(d) )
         return;
 
     arch_iommu_check_autotranslated_hwdom(d);
diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h
index 972fc84..1540fe0 100644
--- a/xen/include/xen/lib.h
+++ b/xen/include/xen/lib.h
@@ -79,6 +79,13 @@ int parse_bool(const char *s, const char *e);
  */
 int parse_boolean(const char *name, const char *s, const char *e);
 
+/**
+ * Very similar to strcmp(), but will declare a match if the NUL in 'name'
+ * lines up with comma in 'frag'.  Designed for picking exact string matches
+ * out of a comma-separated command line fragment.
+ */
+int cmdline_strcmp(const char *frag, const char *name);
+
 /*#define DEBUG_TRACE_DUMP*/
 #ifdef DEBUG_TRACE_DUMP
 extern void debugtrace_dump(void);
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2018-12-31 15:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-31 15:16 [PATCH v2 0/4] Functional and documentation improvements to dom0 setup Andrew Cooper
2018-12-31 15:16 ` [PATCH v2 1/4] xen/dom0: Improve documentation for dom0= and dom0-iommu= Andrew Cooper
2019-01-04 12:15   ` Roger Pau Monné
2018-12-31 15:16 ` [PATCH v2 2/4] x86/dom0: Improve dom0= useability Andrew Cooper
2019-01-04 12:17   ` Roger Pau Monné
2018-12-31 15:16 ` [PATCH v2 3/4] xen/dom0: Drop iommu_hwdom_inclusive entirely Andrew Cooper
2019-01-04 12:33   ` Roger Pau Monné
2019-01-04 12:46     ` Andrew Cooper
2019-01-04 12:54       ` Roger Pau Monné
2019-01-04 14:03   ` Roger Pau Monné
2018-12-31 15:16 ` Andrew Cooper [this message]
2019-01-04 12:38   ` [PATCH v2 4/4] xen/dom0: Add a dom0-iommu=none option Roger Pau Monné
2018-12-31 17:51 ` [PATCH v2 0/4] Functional and documentation improvements to dom0 setup Andrew Cooper

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=1546269383-32166-5-git-send-email-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=julien.grall@arm.com \
    --cc=roger.pau@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.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 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.