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

[Xen-devel] [PATCH v1] libxl: fix device_model_version related assert



In commit 3802ecbaa9 ("libxl: add helper function to set
device_model_version") an assert was added to
libxl__domain_build_info_setdefault to make sure callers provide
complete info to this function. This unveiled a flaw in the way how
libxl_domain_build_info is passed to libxl. The public API
libxl_domain_need_memory passes an incomplete libxl_domain_build_info to
libxl__domain_build_info_setdefault, which triggers the assert. Prior to
the change above, device_model_version was hardcoded to QEMU_XEN which
lead to the bugs described in that changeset.

A new libxl API would need to be created to fully populate
libxl_domain_build_info with missing defaults. For existing, unchanged
consumers of libxl the assumption about QEMU_XEN needs to be restored
within this function to properly populate the amount of required memory.

Signed-off-by: Olaf Hering <olaf@xxxxxxxxx>
Reported-by: Juergen Gross <jgross@xxxxxxxx>
---
 tools/libxl/libxl_create.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 89f99f7f44..030851fb28 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -123,6 +123,7 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
                                         libxl_domain_build_info *b_info)
 {
     int i, rc;
+    libxl_device_model_version device_model_version;
 
     if (b_info->type != LIBXL_DOMAIN_TYPE_HVM &&
         b_info->type != LIBXL_DOMAIN_TYPE_PV &&
@@ -131,7 +132,9 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
         return ERROR_INVAL;
     }
 
-    assert(b_info->device_model_version);
+    device_model_version = b_info->device_model_version;
+    if (!device_model_version)
+        device_model_version = LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN;
 
     /* Copy deprecated options to it's new position. */
     rc = libxl__domain_build_info_copy_deprecated(CTX, b_info);
@@ -149,7 +152,7 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
 
     if (b_info->type == LIBXL_DOMAIN_TYPE_HVM) {
         if (!b_info->u.hvm.bios)
-            switch (b_info->device_model_version) {
+            switch (device_model_version) {
             case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL:
                 b_info->u.hvm.bios = LIBXL_BIOS_TYPE_ROMBIOS; break;
             case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
@@ -160,7 +163,7 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
             }
 
         /* Enforce BIOS<->Device Model version relationship */
-        switch (b_info->device_model_version) {
+        switch (device_model_version) {
         case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL:
             if (b_info->u.hvm.bios != LIBXL_BIOS_TYPE_ROMBIOS) {
                 LOG(ERROR, "qemu-xen-traditional requires bios=rombios.");
@@ -186,7 +189,7 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
     }
 
     if (b_info->type == LIBXL_DOMAIN_TYPE_HVM &&
-        b_info->device_model_version !=
+        device_model_version !=
             LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL &&
         libxl_defbool_val(b_info->device_model_stubdomain)) {
         LOG(ERROR,
@@ -259,7 +262,7 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
         if (!b_info->u.hvm.hdtype)
             b_info->u.hvm.hdtype = LIBXL_HDTYPE_IDE;
 
-        switch (b_info->device_model_version) {
+        switch (device_model_version) {
         case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL:
             switch (b_info->u.hvm.vga.kind) {
             case LIBXL_VGA_INTERFACE_TYPE_NONE:

_______________________________________________
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®.