[PATCH 3/3] libxl: Support firmware autoselection

Jim Fehlig jfehlig at suse.com
Fri Jun 4 17:27:48 UTC 2021


Xen only supports one firmware, making autoselection easy to implement.
In fact, <os firmware='efi'> is probably preferable in the Xen driver,
where libxl supports a firmware setting with accepted values such as
bios, ovmf, uefi (currently same semantics as ovmf), seabios, etc.

Signed-off-by: Jim Fehlig <jfehlig at suse.com>
---
 src/libxl/libxl_conf.c   | 17 +++++++++++++++--
 src/libxl/libxl_domain.c | 22 ++++++++++++++++------
 2 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index fc4268db01..aef93fae53 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -627,15 +627,28 @@ libxlMakeDomBuildInfo(virDomainDef *def,
 
         /*
          * Currently libxl only allows specifying the type of BIOS.
-         * If the type is PFLASH, we assume OVMF and set libxl_bios_type
+         * If automatic firmware selection is enabled or the loader
+         * type is PFLASH, we assume OVMF and set libxl_bios_type
          * to LIBXL_BIOS_TYPE_OVMF. The path to the OVMF firmware is
          * configured when building Xen using '--with-system-ovmf='. If
          * not specified, LIBXL_FIRMWARE_DIR/ovmf.bin is used. In the
          * future, Xen will support a user-specified firmware path. See
          * https://lists.xenproject.org/archives/html/xen-devel/2016-03/msg01628.html
          */
-        if (virDomainDefHasOldStyleUEFI(def))
+        if (def->os.firmware == VIR_DOMAIN_OS_DEF_FIRMWARE_EFI) {
+            if (def->os.loader == NULL)
+                def->os.loader = g_new0(virDomainLoaderDef, 1);
+            if (def->os.loader->path == NULL)
+                def->os.loader->path = g_strdup(cfg->firmwares[0]->name);
+            if (def->os.loader->type == VIR_DOMAIN_LOADER_TYPE_NONE)
+                def->os.loader->type = VIR_DOMAIN_LOADER_TYPE_PFLASH;
+            if (def->os.loader->readonly == VIR_TRISTATE_BOOL_ABSENT)
+                def->os.loader->readonly = VIR_TRISTATE_BOOL_YES;
             b_info->u.hvm.bios = LIBXL_BIOS_TYPE_OVMF;
+            def->os.firmware = VIR_DOMAIN_OS_DEF_FIRMWARE_NONE;
+        } else if (virDomainDefHasOldStyleUEFI(def)) {
+            b_info->u.hvm.bios = LIBXL_BIOS_TYPE_OVMF;
+        }
 
         if (def->emulator) {
             if (!virFileExists(def->emulator)) {
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 14d000511a..59d26d5e2b 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -440,6 +440,7 @@ libxlDomainDefValidate(const virDomainDef *def,
 {
     libxlDriverPrivate *driver = opaque;
     g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
+    bool reqSecureBoot = false;
 
     if (!virCapabilitiesDomainSupported(cfg->caps, def->os.type,
                                         def->os.arch,
@@ -447,13 +448,20 @@ libxlDomainDefValidate(const virDomainDef *def,
         return -1;
 
     /* Xen+ovmf does not support secure boot */
+    if (def->os.firmware == VIR_DOMAIN_OS_DEF_FIRMWARE_EFI) {
+        if (def->os.firmwareFeatures &&
+            def->os.firmwareFeatures[VIR_DOMAIN_OS_DEF_FIRMWARE_FEATURE_SECURE_BOOT])
+            reqSecureBoot = true;
+    }
     if (virDomainDefHasOldStyleUEFI(def)) {
         if (def->os.loader &&
-            def->os.loader->secure == VIR_TRISTATE_BOOL_YES) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("Secure boot is not supported on Xen"));
-            return -1;
-        }
+            def->os.loader->secure == VIR_TRISTATE_BOOL_YES)
+            reqSecureBoot = true;
+    }
+    if (reqSecureBoot) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Secure boot is not supported on Xen"));
+        return -1;
     }
 
     return 0;
@@ -465,7 +473,9 @@ virDomainDefParserConfig libxlDomainDefParserConfig = {
     .devicesPostParseCallback = libxlDomainDeviceDefPostParse,
     .domainPostParseCallback = libxlDomainDefPostParse,
     .domainValidateCallback = libxlDomainDefValidate,
-    .features = VIR_DOMAIN_DEF_FEATURE_NET_MODEL_STRING,
+
+    .features = VIR_DOMAIN_DEF_FEATURE_FW_AUTOSELECT |
+                VIR_DOMAIN_DEF_FEATURE_NET_MODEL_STRING,
 };
 
 
-- 
2.31.1





More information about the libvir-list mailing list