diff mbox

[v4,27/28] tools/libxl: create vIOMMU during domain construction

Message ID 1510899755-40237-28-git-send-email-chao.gao@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Chao Gao Nov. 17, 2017, 6:22 a.m. UTC
If guest is configured to have a vIOMMU, create it during domain construction.

Signed-off-by: Chao Gao <chao.gao@intel.com>
Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>

---
v4:
 - s/LOGED/LOGD
v3:
 - Remove the process of querying capabilities.
---
 tools/libxl/libxl_x86.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
diff mbox

Patch

diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c
index cb2f494..394c70f 100644
--- a/tools/libxl/libxl_x86.c
+++ b/tools/libxl/libxl_x86.c
@@ -343,8 +343,25 @@  int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config,
     if (d_config->b_info.type != LIBXL_DOMAIN_TYPE_PV) {
         unsigned long shadow = DIV_ROUNDUP(d_config->b_info.shadow_memkb,
                                            1024);
+        unsigned int i;
+
         xc_shadow_control(ctx->xch, domid, XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION,
                           NULL, 0, &shadow, 0, NULL);
+
+        for (i = 0; i < d_config->b_info.num_viommus; i++) {
+            uint32_t id;
+            libxl_viommu_info *viommu = &d_config->b_info.viommu[i];
+
+            if (viommu->type == LIBXL_VIOMMU_TYPE_INTEL_VTD) {
+                ret = xc_viommu_create(ctx->xch, domid, VIOMMU_TYPE_INTEL_VTD,
+                                       viommu->base_addr, viommu->cap, &id);
+                if (ret) {
+                    LOGD(ERROR, domid, "create vIOMMU fail (%d)", ret);
+                    ret = ERROR_FAIL;
+                    goto out;
+                }
+            }
+        }
     }
 
     if (d_config->c_info.type == LIBXL_DOMAIN_TYPE_PV &&