[Libguestfs] [PATCH v2v 2/3] -o libvirt: Always use host-model unless overridden by source hypervisor

Richard W.M. Jones rjones at redhat.com
Wed Feb 15 14:12:04 UTC 2023


In the case where the source hypervisor doesn't specify a CPU model,
previously we chose qemu64 (qemu's most basic model), except for a few
guests that we know won't work on qemu64, eg. RHEL 9 requires
x86_64-v2 where we use <cpu mode='host-model'/>

However we recently encountered an obscure KVM bug related to this
(https://bugzilla.redhat.com/show_bug.cgi?id=2168082).  Windows 11
thinks the qemu64 CPU model when booted on real AMD Milan is an AMD
Phenom and tried to apply an ancient erratum to it.  Since KVM didn't
emulate the correct MSRs for this it caused the guest to fail to boot.

After discussion upstream we can't see any reason not to give all
guests host-model.  This should fix the bug above and also generally
improve performance by allowing the guest to exploit all host
features.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=2168082#c19
Related: https://listman.redhat.com/archives/libguestfs/2023-February/030624.html
Thanks: Dr. David Alan Gilbert, Daniel Berrangé
---
 output/create_libvirt_xml.ml | 7 ++++---
 tests/test-v2v-i-ova.xml     | 1 +
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/output/create_libvirt_xml.ml b/output/create_libvirt_xml.ml
index e9c6c8c150..6eb66f2dcb 100644
--- a/output/create_libvirt_xml.ml
+++ b/output/create_libvirt_xml.ml
@@ -185,15 +185,13 @@ let create_libvirt_xml ?pool source inspect
   ];
 
   if source.s_cpu_model <> None ||
-     guestcaps.gcaps_arch_min_version >= 1 ||
      source.s_cpu_topology <> None then (
     let cpu_attrs = ref []
     and cpu = ref [] in
 
     (match source.s_cpu_model with
      | None ->
-         if guestcaps.gcaps_arch_min_version >= 1 then
-           List.push_back cpu_attrs ("mode", "host-model");
+        List.push_back cpu_attrs ("mode", "host-model");
      | Some model ->
          List.push_back cpu_attrs ("match", "minimum");
          if model = "qemu64" then
@@ -217,6 +215,9 @@ let create_libvirt_xml ?pool source inspect
     );
 
     List.push_back_list body [ e "cpu" !cpu_attrs !cpu ]
+  )
+  else (
+    List.push_back_list body [ e "cpu" [ "mode", "host-model" ] [] ]
   );
 
   let uefi_firmware =
diff --git a/tests/test-v2v-i-ova.xml b/tests/test-v2v-i-ova.xml
index da1db473e5..e5907ea1cc 100644
--- a/tests/test-v2v-i-ova.xml
+++ b/tests/test-v2v-i-ova.xml
@@ -10,6 +10,7 @@
   <memory unit='KiB'>2097152</memory>
   <currentMemory unit='KiB'>2097152</currentMemory>
   <vcpu>1</vcpu>
+  <cpu mode='host-model'/>
   <features>
     <acpi/>
     <apic/>
-- 
2.39.0



More information about the Libguestfs mailing list