Skip to contentSkip to conversation

libxl: check nesthvm and altp2m in libxl level

PATCH Superseded Wei Liu 3 participants 4 messages Jul 24, 2015 – Jul 27, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

PATCH 1/1 libxl: check nesthvm and altp2m in libxl level

In ea214001 ("x86/altp2m: add altp2mhvm HVM domain parameter"), a check was added to ensure nestedhvm and altp2m cannot be enabled at the same time. That check was added in xl, but in fact it should be in libxl because it should be the entity that decides whether the provided configuration is valid.

This patch moves the check to libxl. The code snippet is moved after calling libxl__domain_build_info_setdefault so that we can:
1. remove libxl_defbool_is_default in `if()';
2. detect mistake in libxl__domain_build_info_setdefault.

---
Cc: Ed White <[email protected]>
Cc: "Sahita, Ravi" <[email protected]>

I said I discovered an issue during review but also volunteered to fix it after the series is merged. Here is the patch to do that.

---
 tools/libxl/libxl_create.c | 6 ++++++
 tools/libxl/xl_cmdimpl.c   | 8 --------
 2 files changed, 6 insertions(+), 8 deletions(-)
tools/libxl/libxl_create.c +6 -0
index 855b42c..de536ba 100644
@@ -883,6 +883,12 @@ static void initiate_domain_create(libxl__egc *egc,
         goto error_out;
     }
 
+    if (libxl_defbool_val(d_config->b_info.u.hvm.nested_hvm) &&
+        libxl_defbool_val(d_config->b_info.u.hvm.altp2m)) {
+        LOG(ERROR, "nestedhvm and altp2mhvm cannot be used together");
+        goto error_out;
+    }
+
     for (i = 0; i < d_config->num_disks; i++) {
         ret = libxl__device_disk_setdefault(gc, &d_config->disks[i]);
         if (ret) {
tools/libxl/xl_cmdimpl.c +0 -8
index d0bf0cb..9755d55 100644
@@ -1568,14 +1568,6 @@ static void parse_config_data(const char *config_source,
 
         xlu_cfg_get_defbool(config, "altp2mhvm", &b_info->u.hvm.altp2m, 0);
 
-        if (!libxl_defbool_is_default(b_info->u.hvm.nested_hvm) &&
-            libxl_defbool_val(b_info->u.hvm.nested_hvm) &&
-            !libxl_defbool_is_default(b_info->u.hvm.altp2m) &&
-            libxl_defbool_val(b_info->u.hvm.altp2m)) {
-            fprintf(stderr, "ERROR: nestedhvm and altp2mhvm cannot be used together\n");
-            exit(1);
-        }
-
         xlu_cfg_replace_string(config, "smbios_firmware",
                                &b_info->u.hvm.smbios_firmware, 0);
         xlu_cfg_replace_string(config, "acpi_firmware",
Signature · 1 line
2.1.4
#1 lore raw
Quoted 63 lines

From: Wei Liu [mailto:[email protected]]
Sent: Friday, July 24, 2015 8:40 AM

In ea214001 ("x86/altp2m: add altp2mhvm HVM domain parameter"), a check was added to ensure nestedhvm and altp2m cannot be enabled at the same time. That check was added in xl, but in fact it should be in libxl because it should be the entity that decides whether the provided configuration is valid.

This patch moves the check to libxl. The code snippet is moved after calling libxl__domain_build_info_setdefault so that we can:
1. remove libxl_defbool_is_default in `if()'; 2. detect mistake in libxl__domain_build_info_setdefault.

---
Cc: Ed White <[email protected]>
Cc: "Sahita, Ravi" <[email protected]>

I said I discovered an issue during review but also volunteered to fix it after the series is merged. Here is the patch to do that.
---
tools/libxl/libxl_create.c | 6 ++++++
tools/libxl/xl_cmdimpl.c | 8 --------

2 files changed, 6 insertions(+), 8 deletions(-)
tools/libxl/libxl_create.c index renamed from tools/libxl/libxl_create.c +0 -0

855b42c..de536ba 100644

tools/libxl/libxl_create.c +6 -0
@@ -883,6 +883,12 @@ static void initiate_domain_create(libxl__egc *egc,
        goto error_out;
    }
 
+    if (libxl_defbool_val(d_config->b_info.u.hvm.nested_hvm) &&
+        libxl_defbool_val(d_config->b_info.u.hvm.altp2m)) {
+        LOG(ERROR, "nestedhvm and altp2mhvm cannot be used together");
+        goto error_out;
+    }
+
    for (i = 0; i < d_config->num_disks; i++) {
        ret = libxl__device_disk_setdefault(gc, &d_config->disks[i]);
        if (ret) {
tools/libxl/xl_cmdimpl.c index renamed from tools/libxl/xl_cmdimpl.c +0 -0

d0bf0cb..9755d55 100644

tools/libxl/xl_cmdimpl.c +0 -8
@@ -1568,14 +1568,6 @@ static void parse_config_data(const char
 *config_source,
 
        xlu_cfg_get_defbool(config, "altp2mhvm", &b_info->u.hvm.altp2m, 0);
 
-        if (!libxl_defbool_is_default(b_info->u.hvm.nested_hvm) &&
-            libxl_defbool_val(b_info->u.hvm.nested_hvm) &&
-            !libxl_defbool_is_default(b_info->u.hvm.altp2m) &&
-            libxl_defbool_val(b_info->u.hvm.altp2m)) {
-            fprintf(stderr, "ERROR: nestedhvm and altp2mhvm cannot be used
 together\n");
-            exit(1);
-        }
-
        xlu_cfg_replace_string(config, "smbios_firmware",
                               &b_info->u.hvm.smbios_firmware, 0);
        xlu_cfg_replace_string(config, "acpi_firmware",
Quoted 2 lines

--
2.1.4

Thanks Wei

Ravi

#2 lore raw
In reply to Wei Liu

Hi Wei,

Quoted 28 lines · Wei Liu

In ea214001 ("x86/altp2m: add altp2mhvm HVM domain parameter"), a check was added to ensure nestedhvm and altp2m cannot be enabled at the same time. That check was added in xl, but in fact it should be in libxl because it should be the entity that decides whether the provided configuration is valid.

This patch moves the check to libxl. The code snippet is moved after calling libxl__domain_build_info_setdefault so that we can:
1. remove libxl_defbool_is_default in `if()';
2. detect mistake in libxl__domain_build_info_setdefault.

---
Cc: Ed White <[email protected]>
Cc: "Sahita, Ravi" <[email protected]>

I said I discovered an issue during review but also volunteered to fix it after the series is merged. Here is the patch to do that.

---
 tools/libxl/libxl_create.c | 6 ++++++
 tools/libxl/xl_cmdimpl.c   | 8 --------
 2 files changed, 6 insertions(+), 8 deletions(-)
tools/libxl/libxl_create.c +0 -0
index 855b42c..de536ba 100644

tools/libxl/libxl_create.c static void initiate_domain_create(libxl__egc *egc, · line 891

Quoted 9 lines
tools/libxl/libxl_create.c +6 -0
@@ -883,6 +883,12 @@ static void initiate_domain_create(libxl__egc *egc,
         goto error_out;
     }
 
+    if (libxl_defbool_val(d_config->b_info.u.hvm.nested_hvm) &&
+        libxl_defbool_val(d_config->b_info.u.hvm.altp2m)) {
+        LOG(ERROR, "nestedhvm and altp2mhvm cannot be used together");
+        goto error_out;
+    }
+

The u.hvm.{nested_hvm,altp2m} can only be checked when the created domain is an HVM.

But initiate_domain_create is called with either a PV or HVM domain. So you may need to check if we are creating a HVM one.

Regards,

Signature · 1 line
Julien Grall
author
#3 lore raw
Quoted 44 lines · Julien Grall

Hi Wei,

Quoted 28 lines · Wei Liu

In ea214001 ("x86/altp2m: add altp2mhvm HVM domain parameter"), a check was added to ensure nestedhvm and altp2m cannot be enabled at the same time. That check was added in xl, but in fact it should be in libxl because it should be the entity that decides whether the provided configuration is valid.

This patch moves the check to libxl. The code snippet is moved after calling libxl__domain_build_info_setdefault so that we can:
1. remove libxl_defbool_is_default in `if()';
2. detect mistake in libxl__domain_build_info_setdefault.

---
Cc: Ed White <[email protected]>
Cc: "Sahita, Ravi" <[email protected]>

I said I discovered an issue during review but also volunteered to fix it after the series is merged. Here is the patch to do that.

---
 tools/libxl/libxl_create.c | 6 ++++++
 tools/libxl/xl_cmdimpl.c   | 8 --------
 2 files changed, 6 insertions(+), 8 deletions(-)
tools/libxl/libxl_create.c +0 -0
index 855b42c..de536ba 100644

tools/libxl/libxl_create.c static void initiate_domain_create(libxl__egc *egc, · line 891

Quoted 9 lines
tools/libxl/libxl_create.c +6 -0
@@ -883,6 +883,12 @@ static void initiate_domain_create(libxl__egc *egc,
         goto error_out;
     }
 
+    if (libxl_defbool_val(d_config->b_info.u.hvm.nested_hvm) &&
+        libxl_defbool_val(d_config->b_info.u.hvm.altp2m)) {
+        LOG(ERROR, "nestedhvm and altp2mhvm cannot be used together");
+        goto error_out;
+    }
+

The u.hvm.{nested_hvm,altp2m} can only be checked when the created domain is an HVM.

Quoted 3 lines

But initiate_domain_create is called with either a PV or HVM domain. So you may need to check if we are creating a HVM one.

Good point. I will respin.

Wei.

Quoted 4 lines

Regards,

Signature · 1 line
Julien Grall