[PATCH] bhyve: improve loader handling on arm64

Roman Bogorodskiy posted 1 patch 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20260125065455.41476-1-bogorodskiy@gmail.com
There is a newer version of this series
src/bhyve/bhyve_domain.c                      | 22 +++++++++++++++++++
.../aarch64/bhyvexml2argv-base.args           |  1 +
.../aarch64/bhyvexml2argv-base.ldargs         |  8 +------
.../aarch64/bhyvexml2argv-console.args        |  1 +
.../aarch64/bhyvexml2argv-console.ldargs      |  8 +------
tests/bhyvexml2argvmock.c                     | 20 ++++++++++++++++-
.../aarch64/bhyvexml2xmlout-base.xml          |  1 +
.../aarch64/bhyvexml2xmlout-console.xml       |  1 +
8 files changed, 47 insertions(+), 15 deletions(-)
[PATCH] bhyve: improve loader handling on arm64
Posted by Roman Bogorodskiy 1 week ago
Bhyve on arm64 does not have the bhyveload(8) tool.
That means that it cannot be used as a default if the loader is not
configured for the domain.

To prevent users from getting unusable configurations, handle loader
configuration on arm64 like that:

 - if loader is specified in the domain XML, just use it
 - if not specified, try to check whether the default uboot loader
   is available on the system. In case it is, set is as the loader,
   otherwise fail with the error.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
---
 src/bhyve/bhyve_domain.c                      | 22 +++++++++++++++++++
 .../aarch64/bhyvexml2argv-base.args           |  1 +
 .../aarch64/bhyvexml2argv-base.ldargs         |  8 +------
 .../aarch64/bhyvexml2argv-console.args        |  1 +
 .../aarch64/bhyvexml2argv-console.ldargs      |  8 +------
 tests/bhyvexml2argvmock.c                     | 20 ++++++++++++++++-
 .../aarch64/bhyvexml2xmlout-base.xml          |  1 +
 .../aarch64/bhyvexml2xmlout-console.xml       |  1 +
 8 files changed, 47 insertions(+), 15 deletions(-)

diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c
index df0a008ecd..733bacc8c1 100644
--- a/src/bhyve/bhyve_domain.c
+++ b/src/bhyve/bhyve_domain.c
@@ -27,11 +27,14 @@
 #include "bhyve_domain.h"
 #include "bhyve_capabilities.h"
 #include "viralloc.h"
+#include "virfile.h"
 #include "virlog.h"
 #include "virutil.h"
 
 #define VIR_FROM_THIS VIR_FROM_BHYVE
 
+#define UBOOT_BHYVE DATADIR "/u-boot/u-boot-bhyve-arm64/u-boot.bin"
+
 VIR_LOG_INIT("bhyve.bhyve_domain");
 
 static void *
@@ -112,6 +115,25 @@ bhyveDomainDefPostParse(virDomainDef *def,
         !(bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_RTC_UTC))
         def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME;
 
+    /* bhyve/arm64 does not provide the bhyveload(8) tool,
+     * so if the loader is not specified and we cannot fall back to the
+     * default one, then this results in an usable configuration. */
+    if (ARCH_IS_ARM(def->os.arch)) {
+        if (def->os.loader == NULL) {
+            if (virFileExists(UBOOT_BHYVE)) {
+                def->os.loader = virDomainLoaderDefNew();
+                def->os.loader->path = g_strdup(UBOOT_BHYVE);
+                def->os.loader->readonly = true;
+                def->os.loader->type = VIR_DOMAIN_LOADER_TYPE_PFLASH;
+            } else {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("loader is not specified and the default loader (%1$s) not found"),
+                               UBOOT_BHYVE);
+                return -1;
+            }
+        }
+    }
+
     return 0;
 }
 
diff --git a/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-base.args b/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-base.args
index aef3ebd017..1079beee52 100644
--- a/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-base.args
+++ b/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-base.args
@@ -2,6 +2,7 @@ bhyve \
 -c 1 \
 -m 214 \
 -s 0:0,hostbridge \
+-o bootrom=/usr/local/share/u-boot/u-boot-bhyve-arm64/u-boot.bin \
 -s 3:0,virtio-net,faketapdev,mac=52:54:00:b9:94:02 \
 -s 2:0,virtio-blk,/tmp/freebsd.img \
 bhyve
diff --git a/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-base.ldargs b/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-base.ldargs
index 264ae48441..421376db9e 100644
--- a/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-base.ldargs
+++ b/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-base.ldargs
@@ -1,7 +1 @@
-timeout \
---foreground \
---verbose \
--k 20s 300s bhyveload \
--m 214 \
--d /tmp/freebsd.img \
-bhyve
+dummy
diff --git a/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.args b/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.args
index 4a031afb71..ea2cc15713 100644
--- a/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.args
+++ b/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.args
@@ -2,6 +2,7 @@ bhyve \
 -c 1 \
 -m 214 \
 -s 0:0,hostbridge \
+-o bootrom=/usr/local/share/u-boot/u-boot-bhyve-arm64/u-boot.bin \
 -s 3:0,virtio-net,faketapdev,mac=52:54:00:b9:94:02 \
 -s 2:0,virtio-blk,/tmp/freebsd.img \
 -o console=/dev/nmdm0A \
diff --git a/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.ldargs b/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.ldargs
index 264ae48441..421376db9e 100644
--- a/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.ldargs
+++ b/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.ldargs
@@ -1,7 +1 @@
-timeout \
---foreground \
---verbose \
--k 20s 300s bhyveload \
--m 214 \
--d /tmp/freebsd.img \
-bhyve
+dummy
diff --git a/tests/bhyvexml2argvmock.c b/tests/bhyvexml2argvmock.c
index fe76564d51..f4271563d7 100644
--- a/tests/bhyvexml2argvmock.c
+++ b/tests/bhyvexml2argvmock.c
@@ -2,7 +2,9 @@
 
 #include <dirent.h>
 
+#include "configmake.h"
 #include "viralloc.h"
+#include "virfile.h"
 #include "virstring.h"
 #include "virnetdev.h"
 #include "virnetdevtap.h"
@@ -12,11 +14,16 @@
 #define VIR_FROM_THIS VIR_FROM_BHYVE
 
 static DIR * (*real_opendir)(const char *name);
+static bool (*real_virFileExists)(const char *path);
 
 static void
 init_syms(void)
 {
-    VIR_MOCK_REAL_INIT(opendir);
+    if (!real_opendir)
+        VIR_MOCK_REAL_INIT(opendir);
+
+    if (!real_virFileExists)
+        VIR_MOCK_REAL_INIT(virFileExists);
 }
 
 #define FAKEFIRMWAREDIR abs_srcdir "/bhyvefirmwaredata/three_firmwares"
@@ -89,3 +96,14 @@ int bind(int sockfd G_GNUC_UNUSED,
 {
     return 0;
 }
+
+bool
+virFileExists(const char *path)
+{
+    init_syms();
+
+    if (STREQ(path, DATADIR "/u-boot/u-boot-bhyve-arm64/u-boot.bin"))
+        return true;
+
+    return real_virFileExists(path);
+}
diff --git a/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-base.xml b/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-base.xml
index ee72370047..d6c9caa225 100644
--- a/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-base.xml
+++ b/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-base.xml
@@ -6,6 +6,7 @@
   <vcpu placement='static'>1</vcpu>
   <os>
     <type arch='aarch64'>hvm</type>
+    <loader readonly='yes' type='pflash'>/usr/local/share/u-boot/u-boot-bhyve-arm64/u-boot.bin</loader>
     <boot dev='hd'/>
   </os>
   <clock offset='localtime'/>
diff --git a/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-console.xml b/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-console.xml
index d43ce8fd6f..d694ecfb8d 100644
--- a/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-console.xml
+++ b/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-console.xml
@@ -6,6 +6,7 @@
   <vcpu placement='static'>1</vcpu>
   <os>
     <type arch='aarch64'>hvm</type>
+    <loader readonly='yes' type='pflash'>/usr/local/share/u-boot/u-boot-bhyve-arm64/u-boot.bin</loader>
     <boot dev='hd'/>
   </os>
   <clock offset='localtime'/>
-- 
2.52.0
Re: [PATCH] bhyve: improve loader handling on arm64
Posted by Michal Prívozník via Devel 6 days, 18 hours ago
On 1/25/26 07:54, Roman Bogorodskiy wrote:
> Bhyve on arm64 does not have the bhyveload(8) tool.
> That means that it cannot be used as a default if the loader is not
> configured for the domain.
> 
> To prevent users from getting unusable configurations, handle loader
> configuration on arm64 like that:
> 
>  - if loader is specified in the domain XML, just use it
>  - if not specified, try to check whether the default uboot loader
>    is available on the system. In case it is, set is as the loader,
>    otherwise fail with the error.
> 
> Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
> ---
>  src/bhyve/bhyve_domain.c                      | 22 +++++++++++++++++++
>  .../aarch64/bhyvexml2argv-base.args           |  1 +
>  .../aarch64/bhyvexml2argv-base.ldargs         |  8 +------
>  .../aarch64/bhyvexml2argv-console.args        |  1 +
>  .../aarch64/bhyvexml2argv-console.ldargs      |  8 +------
>  tests/bhyvexml2argvmock.c                     | 20 ++++++++++++++++-
>  .../aarch64/bhyvexml2xmlout-base.xml          |  1 +
>  .../aarch64/bhyvexml2xmlout-console.xml       |  1 +
>  8 files changed, 47 insertions(+), 15 deletions(-)

You'll need to regenerate tests too. Squash this in:


diff --git i/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-base.args w/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-base.args
index 1079beee52..d01f62ff5c 100644
--- i/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-base.args
+++ w/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-base.args
@@ -2,7 +2,7 @@ bhyve \
 -c 1 \
 -m 214 \
 -s 0:0,hostbridge \
--o bootrom=/usr/local/share/u-boot/u-boot-bhyve-arm64/u-boot.bin \
+-o bootrom=/usr/share/u-boot/u-boot-bhyve-arm64/u-boot.bin \
 -s 3:0,virtio-net,faketapdev,mac=52:54:00:b9:94:02 \
 -s 2:0,virtio-blk,/tmp/freebsd.img \
 bhyve
diff --git i/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.args w/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.args
index ea2cc15713..069ecf3425 100644
--- i/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.args
+++ w/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.args
@@ -2,7 +2,7 @@ bhyve \
 -c 1 \
 -m 214 \
 -s 0:0,hostbridge \
--o bootrom=/usr/local/share/u-boot/u-boot-bhyve-arm64/u-boot.bin \
+-o bootrom=/usr/share/u-boot/u-boot-bhyve-arm64/u-boot.bin \
 -s 3:0,virtio-net,faketapdev,mac=52:54:00:b9:94:02 \
 -s 2:0,virtio-blk,/tmp/freebsd.img \
 -o console=/dev/nmdm0A \
diff --git i/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-base.xml w/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-base.xml
index d6c9caa225..eb28be7dfd 100644
--- i/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-base.xml
+++ w/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-base.xml
@@ -6,7 +6,7 @@
   <vcpu placement='static'>1</vcpu>
   <os>
     <type arch='aarch64'>hvm</type>
-    <loader readonly='yes' type='pflash'>/usr/local/share/u-boot/u-boot-bhyve-arm64/u-boot.bin</loader>
+    <loader readonly='yes' type='pflash'>/usr/share/u-boot/u-boot-bhyve-arm64/u-boot.bin</loader>
     <boot dev='hd'/>
   </os>
   <clock offset='localtime'/>
diff --git i/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-console.xml w/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-console.xml
index d694ecfb8d..dc358cbaab 100644
--- i/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-console.xml
+++ w/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-console.xml
@@ -6,7 +6,7 @@
   <vcpu placement='static'>1</vcpu>
   <os>
     <type arch='aarch64'>hvm</type>
-    <loader readonly='yes' type='pflash'>/usr/local/share/u-boot/u-boot-bhyve-arm64/u-boot.bin</loader>
+    <loader readonly='yes' type='pflash'>/usr/share/u-boot/u-boot-bhyve-arm64/u-boot.bin</loader>
     <boot dev='hd'/>
   </os>
   <clock offset='localtime'/>



Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal
Re: [PATCH] bhyve: improve loader handling on arm64
Posted by Roman Bogorodskiy 6 days, 14 hours ago
  Michal Prívozník wrote:

> On 1/25/26 07:54, Roman Bogorodskiy wrote:
> > Bhyve on arm64 does not have the bhyveload(8) tool.
> > That means that it cannot be used as a default if the loader is not
> > configured for the domain.
> > 
> > To prevent users from getting unusable configurations, handle loader
> > configuration on arm64 like that:
> > 
> >  - if loader is specified in the domain XML, just use it
> >  - if not specified, try to check whether the default uboot loader
> >    is available on the system. In case it is, set is as the loader,
> >    otherwise fail with the error.
> > 
> > Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
> > ---
> >  src/bhyve/bhyve_domain.c                      | 22 +++++++++++++++++++
> >  .../aarch64/bhyvexml2argv-base.args           |  1 +
> >  .../aarch64/bhyvexml2argv-base.ldargs         |  8 +------
> >  .../aarch64/bhyvexml2argv-console.args        |  1 +
> >  .../aarch64/bhyvexml2argv-console.ldargs      |  8 +------
> >  tests/bhyvexml2argvmock.c                     | 20 ++++++++++++++++-
> >  .../aarch64/bhyvexml2xmlout-base.xml          |  1 +
> >  .../aarch64/bhyvexml2xmlout-console.xml       |  1 +
> >  8 files changed, 47 insertions(+), 15 deletions(-)
> 
> You'll need to regenerate tests too. Squash this in:
> 
> 
> diff --git i/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-base.args w/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-base.args
> index 1079beee52..d01f62ff5c 100644
> --- i/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-base.args
> +++ w/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-base.args
> @@ -2,7 +2,7 @@ bhyve \
>  -c 1 \
>  -m 214 \
>  -s 0:0,hostbridge \
> --o bootrom=/usr/local/share/u-boot/u-boot-bhyve-arm64/u-boot.bin \
> +-o bootrom=/usr/share/u-boot/u-boot-bhyve-arm64/u-boot.bin \

Oh, I guess it's because DATADIR on your system resolves to /usr/share
and on my system it is /usr/local/share.

Should make tests not depend on that.

>  -s 3:0,virtio-net,faketapdev,mac=52:54:00:b9:94:02 \
>  -s 2:0,virtio-blk,/tmp/freebsd.img \
>  bhyve
> diff --git i/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.args w/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.args
> index ea2cc15713..069ecf3425 100644
> --- i/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.args
> +++ w/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.args
> @@ -2,7 +2,7 @@ bhyve \
>  -c 1 \
>  -m 214 \
>  -s 0:0,hostbridge \
> --o bootrom=/usr/local/share/u-boot/u-boot-bhyve-arm64/u-boot.bin \
> +-o bootrom=/usr/share/u-boot/u-boot-bhyve-arm64/u-boot.bin \
>  -s 3:0,virtio-net,faketapdev,mac=52:54:00:b9:94:02 \
>  -s 2:0,virtio-blk,/tmp/freebsd.img \
>  -o console=/dev/nmdm0A \
> diff --git i/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-base.xml w/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-base.xml
> index d6c9caa225..eb28be7dfd 100644
> --- i/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-base.xml
> +++ w/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-base.xml
> @@ -6,7 +6,7 @@
>    <vcpu placement='static'>1</vcpu>
>    <os>
>      <type arch='aarch64'>hvm</type>
> -    <loader readonly='yes' type='pflash'>/usr/local/share/u-boot/u-boot-bhyve-arm64/u-boot.bin</loader>
> +    <loader readonly='yes' type='pflash'>/usr/share/u-boot/u-boot-bhyve-arm64/u-boot.bin</loader>
>      <boot dev='hd'/>
>    </os>
>    <clock offset='localtime'/>
> diff --git i/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-console.xml w/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-console.xml
> index d694ecfb8d..dc358cbaab 100644
> --- i/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-console.xml
> +++ w/tests/bhyvexml2xmloutdata/aarch64/bhyvexml2xmlout-console.xml
> @@ -6,7 +6,7 @@
>    <vcpu placement='static'>1</vcpu>
>    <os>
>      <type arch='aarch64'>hvm</type>
> -    <loader readonly='yes' type='pflash'>/usr/local/share/u-boot/u-boot-bhyve-arm64/u-boot.bin</loader>
> +    <loader readonly='yes' type='pflash'>/usr/share/u-boot/u-boot-bhyve-arm64/u-boot.bin</loader>
>      <boot dev='hd'/>
>    </os>
>    <clock offset='localtime'/>
> 
> 
> 
> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
> 
> Michal
> 
Re: [PATCH] bhyve: improve loader handling on arm64
Posted by Michal Prívozník via Devel 6 days, 14 hours ago
On 1/26/26 14:46, Roman Bogorodskiy wrote:
>   Michal Prívozník wrote:
> 
>> On 1/25/26 07:54, Roman Bogorodskiy wrote:
>>> Bhyve on arm64 does not have the bhyveload(8) tool.
>>> That means that it cannot be used as a default if the loader is not
>>> configured for the domain.
>>>
>>> To prevent users from getting unusable configurations, handle loader
>>> configuration on arm64 like that:
>>>
>>>  - if loader is specified in the domain XML, just use it
>>>  - if not specified, try to check whether the default uboot loader
>>>    is available on the system. In case it is, set is as the loader,
>>>    otherwise fail with the error.
>>>
>>> Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
>>> ---
>>>  src/bhyve/bhyve_domain.c                      | 22 +++++++++++++++++++
>>>  .../aarch64/bhyvexml2argv-base.args           |  1 +
>>>  .../aarch64/bhyvexml2argv-base.ldargs         |  8 +------
>>>  .../aarch64/bhyvexml2argv-console.args        |  1 +
>>>  .../aarch64/bhyvexml2argv-console.ldargs      |  8 +------
>>>  tests/bhyvexml2argvmock.c                     | 20 ++++++++++++++++-
>>>  .../aarch64/bhyvexml2xmlout-base.xml          |  1 +
>>>  .../aarch64/bhyvexml2xmlout-console.xml       |  1 +
>>>  8 files changed, 47 insertions(+), 15 deletions(-)
>>
>> You'll need to regenerate tests too. Squash this in:
>>
>>
>> diff --git i/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-base.args w/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-base.args
>> index 1079beee52..d01f62ff5c 100644
>> --- i/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-base.args
>> +++ w/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-base.args
>> @@ -2,7 +2,7 @@ bhyve \
>>  -c 1 \
>>  -m 214 \
>>  -s 0:0,hostbridge \
>> --o bootrom=/usr/local/share/u-boot/u-boot-bhyve-arm64/u-boot.bin \
>> +-o bootrom=/usr/share/u-boot/u-boot-bhyve-arm64/u-boot.bin \
> 
> Oh, I guess it's because DATADIR on your system resolves to /usr/share
> and on my system it is /usr/local/share.
> 
> Should make tests not depend on that.

Indeed. So post that patch first, I'll review it and then merge this one?

Michal