diff mbox

[RFC,9/23] Tools/libxl: Inform device model to create a guest with a vIOMMU device

Message ID 1489750043-17260-10-git-send-email-tianyu.lan@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

lan,Tianyu March 17, 2017, 11:27 a.m. UTC
From: Chao Gao <chao.gao@intel.com>

A new device, xen_viommu, is added to qemu. In xen side, we can inform device
model to create a guest with a vIOMMU device through "-device xen_viommu" when
a viommu has been configurated in guest configuration file. Some specific
parameters are passed through xenstore. Qemu will create a dummy device to
preserve the address range and the dummy device will launch a viommu creation
and destruction throuth libxc interface.

Signed-off-by: Chao Gao <chao.gao@intel.com>
Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
---
 tools/libxl/libxl_create.c | 12 +++++++++++-
 tools/libxl/libxl_dm.c     |  9 +++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

Comments

Wei Liu March 28, 2017, 4:24 p.m. UTC | #1
On Fri, Mar 17, 2017 at 07:27:09PM +0800, Lan Tianyu wrote:
> From: Chao Gao <chao.gao@intel.com>
> 
> A new device, xen_viommu, is added to qemu. In xen side, we can inform device
> model to create a guest with a vIOMMU device through "-device xen_viommu" when
> a viommu has been configurated in guest configuration file. Some specific
> parameters are passed through xenstore. Qemu will create a dummy device to
> preserve the address range and the dummy device will launch a viommu creation
> and destruction throuth libxc interface.
> 
> Signed-off-by: Chao Gao <chao.gao@intel.com>
> Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>

The code looks fine, but the design needs to be agreed upon first.
diff mbox

Patch

diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index e741b9a..7954186 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -453,7 +453,7 @@  int libxl__domain_build(libxl__gc *gc,
         vments[4] = "start_time";
         vments[5] = GCSPRINTF("%lu.%02d", start_time.tv_sec,(int)start_time.tv_usec/10000);
 
-        localents = libxl__calloc(gc, 9, sizeof(char *));
+        localents = libxl__calloc(gc, 11, sizeof(char *));
         i = 0;
         localents[i++] = "platform/acpi";
         localents[i++] = libxl__acpi_defbool_val(info) ? "1" : "0";
@@ -472,6 +472,11 @@  int libxl__domain_build(libxl__gc *gc,
                                    info->u.hvm.mmio_hole_memkb << 10);
             }
         }
+        if (info->u.hvm.viommu.base_addr) {
+            localents[i++] = "viommu/base_addr";
+            localents[i++] =
+                GCSPRINTF("%"PRIu64, info->u.hvm.viommu.base_addr);
+        }
 
         break;
     case LIBXL_DOMAIN_TYPE_PV:
@@ -680,6 +685,11 @@  retry_transaction:
                     GCSPRINTF("%s/attr", dom_path),
                     rwperm, ARRAY_SIZE(rwperm));
 
+    if (info->type == LIBXL_DOMAIN_TYPE_HVM)
+        libxl__xs_mknod(gc, t,
+                        GCSPRINTF("%s/viommu", dom_path),
+                        noperm, ARRAY_SIZE(noperm));
+
     if (libxl_defbool_val(info->driver_domain)) {
         /*
          * Create a local "libxl" directory for each guest, since we might want
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index 281058d..f7fb81e 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -1252,6 +1252,15 @@  static int libxl__build_device_model_args_new(libxl__gc *gc,
             flexarray_append(dm_args, "-net");
             flexarray_append(dm_args, "none");
         }
+
+        if ( !libxl_defbool_is_default(b_info->u.hvm.viommu.intremap)
+             && libxl_defbool_val(b_info->u.hvm.viommu.intremap) )
+        {
+            flexarray_append(dm_args, "-device");
+            flexarray_append(dm_args,
+                             GCSPRINTF("xen_viommu,cap=%ld",
+                                       b_info->u.hvm.viommu.cap));
+        }
     } else {
         if (!sdl && !vnc) {
             flexarray_append(dm_args, "-nographic");