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

[Xen-devel] [PATCH 2/2] xen/dom0: Add a dom0-iommu=none option



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 resonably 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) eagerly matches all options
which begin with "opt".

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Jan Beulich <JBeulich@xxxxxxxx>
CC: Wei Liu <wei.liu2@xxxxxxxxxx>
CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
CC: Stefano Stabellini <sstabellini@xxxxxxxxxx>
CC: Julien Grall <julien.grall@xxxxxxx>

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)
---
 docs/misc/xen-command-line.markdown |  8 +++++++-
 xen/common/kernel.c                 | 21 +++++++++++++++++++++
 xen/drivers/passthrough/iommu.c     |  6 +++++-
 xen/include/xen/lib.h               |  7 +++++++
 4 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/docs/misc/xen-command-line.markdown 
b/docs/misc/xen-command-line.markdown
index 94ee703..eb0a65e 100644
--- a/docs/misc/xen-command-line.markdown
+++ b/docs/misc/xen-command-line.markdown
@@ -663,7 +663,7 @@ Controls for how dom0 is constructed on x86 systems.
 
 ### dom0-iommu
 > `= List of [ passthrough=<bool>, strict=<bool>, map-inclusive=<bool>,
->              map-reserved=<bool> ]`
+>              map-reserved=<bool>, none ]`
 
 Controls for the dom0 IOMMU setup.
 
@@ -707,6 +707,12 @@ Controls for the dom0 IOMMU setup.
     This option is enabled by default on x86 Intel systems, disabled by
     default on other 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..fa2d9f3 100644
--- a/xen/common/kernel.c
+++ b/xen/common/kernel.c
@@ -4,6 +4,7 @@
  * Copyright (c) 2002-2005 K A Fraser
  */
 
+#include <xen/ctype.h>
 #include <xen/init.h>
 #include <xen/lib.h>
 #include <xen/errno.h>
@@ -271,6 +272,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 punctuation in 'frag' implies success. */
+            if ( *name == '\0' && ispunct(*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 ac62d7f..67efb10 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;
 
+bool __hwdom_initdata iommu_hwdom_none;
 bool __hwdom_initdata iommu_hwdom_strict;
 bool __read_mostly iommu_hwdom_passthrough;
 int8_t __hwdom_initdata iommu_hwdom_inclusive = -1;
@@ -158,6 +159,8 @@ static int __init parse_dom0_iommu_param(const char *s)
             iommu_hwdom_inclusive = 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;
 
@@ -189,7 +192,8 @@ static void __hwdom_init check_hwdom_reqs(struct domain *d)
     if ( !paging_mode_translate(d) )
         return;
 
-    arch_iommu_check_autotranslated_hwdom(d);
+    if ( !iommu_hwdom_none )
+        arch_iommu_check_autotranslated_hwdom(d);
 
     iommu_hwdom_passthrough = false;
     iommu_hwdom_strict = true;
diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h
index 972fc84..58a7ea9 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 punctuationin '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@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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