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

[Xen-devel] [RFC PATCH V2 10/26] libxl: create vIOMMU during domain construction



From: Chao Gao <chao.gao@xxxxxxxxx>

If guest is configured to have a vIOMMU, create it during domain construction.

Signed-off-by: Chao Gao <chao.gao@xxxxxxxxx>
Signed-off-by: Lan Tianyu <tianyu.lan@xxxxxxxxx>
---
 tools/libxl/libxl_arch.h   |  5 +++++
 tools/libxl/libxl_arm.c    |  7 +++++++
 tools/libxl/libxl_create.c |  4 ++++
 tools/libxl/libxl_x86.c    | 24 ++++++++++++++++++++++++
 4 files changed, 40 insertions(+)

diff --git a/tools/libxl/libxl_arch.h b/tools/libxl/libxl_arch.h
index 5e1fc60..7f9fc9a 100644
--- a/tools/libxl/libxl_arch.h
+++ b/tools/libxl/libxl_arch.h
@@ -71,6 +71,11 @@ int libxl__arch_extra_memory(libxl__gc *gc,
                              const libxl_domain_build_info *info,
                              uint64_t *out);
 
+_hidden
+int libxl__arch_create_viommu(libxl__gc *gc,
+                              const libxl_domain_config *d_config,
+                              uint32_t domid);
+
 #if defined(__i386__) || defined(__x86_64__)
 
 #define LAPIC_BASE_ADDRESS  0xfee00000
diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index d842d88..f5bf5dd 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -1065,6 +1065,13 @@ void libxl__arch_domain_build_info_acpi_setdefault(
     libxl_defbool_setdefault(&b_info->acpi, false);
 }
 
+int libxl__arch_create_viommu(libxl__gc *gc,
+                         const libxl_domain_config *d_config,
+                         uint32_t domid)
+{
+    return 0;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index bffbc45..fd9bfb8 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -557,6 +557,10 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config 
*d_config,
         }
     }
 
+    rc = libxl__arch_create_viommu(gc, d_config, *domid);
+    if (rc < 0)
+        goto out;
+
     rc = libxl__arch_domain_save_config(gc, d_config, xc_config);
     if (rc < 0)
         goto out;
diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c
index 455f6f0..819ee0a 100644
--- a/tools/libxl/libxl_x86.c
+++ b/tools/libxl/libxl_x86.c
@@ -2,6 +2,7 @@
 #include "libxl_arch.h"
 
 #include <xc_dom.h>
+#include <xen/viommu.h>
 
 int libxl__arch_domain_prepare_config(libxl__gc *gc,
                                       libxl_domain_config *d_config,
@@ -587,6 +588,29 @@ void libxl__arch_domain_build_info_acpi_setdefault(
     libxl_defbool_setdefault(&b_info->acpi, true);
 }
 
+int libxl__arch_create_viommu(libxl__gc *gc,
+                              const libxl_domain_config *d_config,
+                              uint32_t domid)
+{
+    int rc = 0;
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+    libxl_viommu_info viommu = d_config->b_info.u.hvm.viommu;
+
+    if (viommu.type == VIOMMU_TYPE_INTEL_VTD) {
+        uint32_t id;
+        uint64_t cap;
+
+        rc = xc_viommu_query_cap(ctx->xch, domid, viommu.type, &cap);
+        if (rc || ((cap & viommu.cap) != cap))
+            return rc;
+
+        rc = xc_viommu_create(ctx->xch, domid, viommu.type,
+                              viommu.base_addr, viommu.length, viommu.cap, 
&id);
+    }
+
+    return rc;
+}
+
 /*
  * Local variables:
  * mode: C
-- 
1.8.3.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

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