Blame SOURCES/0004-output-create_libvirt_xml-pick-virtio-transitional-m.patch

3156cb
From e4cf85bd3ad44aed28cf3e8d3bfd67fec38ebdab Mon Sep 17 00:00:00 2001
3156cb
From: Laszlo Ersek <lersek@redhat.com>
3156cb
Date: Thu, 6 Jan 2022 15:09:05 +0100
3156cb
Subject: [PATCH] output/create_libvirt_xml: pick "virtio-transitional" models
3156cb
 when needed
3156cb
3156cb
In the domain XML we generate, we do not assign PCI B/D/F addresses to
3156cb
devices; that job is left to libvirtd. When using the Q35 machine type,
3156cb
libvirtd places the virtio devices into PCI Express Root Ports. As a
3156cb
consequence, QEMU disables virtio-0.9.5 support on these devices, and so
3156cb
guest OSes without virtio-1.0 drivers cannot drive them.
3156cb
3156cb
Prevent QEMU from turning off the virtio-0.9.5 ("legacy") protocol by
3156cb
specifying the "virtio-transitional" (not "virtio") model for our virtio
3156cb
devices:
3156cb
3156cb
- For non-disk devices, simply change the value of the existent "model"
3156cb
  attribute.
3156cb
3156cb
- For disk devices, add the "model" attribute as a new one.
3156cb
3156cb
(In fact, libvirtd doesn't (only) add the "disable_legacy=off" QEMU device
3156cb
property for the "virtio-transitional" devices -- libvirtd even moves
3156cb
these devices from PCI Express Root Ports to a dedicated
3156cb
"pcie-to-pci-bridge". This has the same effect on QEMU.)
3156cb
3156cb
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1942325
3156cb
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
3156cb
Message-Id: <20220106140910.13695-5-lersek@redhat.com>
3156cb
Acked-by: Richard W.M. Jones <rjones@redhat.com>
3156cb
---
3156cb
 output/create_libvirt_xml.ml | 28 ++++++++++++++++++----------
3156cb
 1 file changed, 18 insertions(+), 10 deletions(-)
3156cb
3156cb
diff --git a/output/create_libvirt_xml.ml b/output/create_libvirt_xml.ml
3156cb
index 9413cc0b..87bfab17 100644
3156cb
--- a/output/create_libvirt_xml.ml
3156cb
+++ b/output/create_libvirt_xml.ml
3156cb
@@ -312,18 +312,26 @@ let create_libvirt_xml ?pool source inspect
3156cb
   (* The devices. *)
3156cb
   let devices = ref [] in
3156cb
 
3156cb
+  (* This will affect all of the virtio devices (if any). *)
3156cb
+  let virtio_transitional =
3156cb
+    guestcaps.gcaps_machine = Q35 && not guestcaps.gcaps_virtio_1_0 in
3156cb
+  let virtio_model =
3156cb
+    if virtio_transitional then "virtio-transitional" else "virtio" in
3156cb
+
3156cb
   (* Fixed and removable disks. *)
3156cb
   let () =
3156cb
-    let make_disk bus_name drive_prefix i = function
3156cb
+    let make_disk bus_name ?(viotrans = false) drive_prefix i = function
3156cb
     | BusSlotEmpty -> Comment (sprintf "%s slot %d is empty" bus_name i)
3156cb
 
3156cb
     | BusSlotDisk d ->
3156cb
        let outdisk = outdisk_name d.s_disk_id in
3156cb
 
3156cb
-        e "disk" [
3156cb
-          "type", if pool = None then "file" else "volume";
3156cb
-          "device", "disk"
3156cb
-        ] [
3156cb
+        e "disk" (
3156cb
+          [
3156cb
+            "type", if pool = None then "file" else "volume";
3156cb
+            "device", "disk"
3156cb
+          ] @ if (viotrans) then [ "model", "virtio-transitional" ] else []
3156cb
+        ) [
3156cb
           e "driver" [
3156cb
             "name", "qemu";
3156cb
             "type", output_format;
3156cb
@@ -364,7 +372,7 @@ let create_libvirt_xml ?pool source inspect
3156cb
     in
3156cb
 
3156cb
     List.push_back_list devices
3156cb
-      (List.mapi (make_disk "virtio" "vd")
3156cb
+      (List.mapi (make_disk "virtio" ~viotrans:virtio_transitional "vd")
3156cb
                  (Array.to_list target_buses.target_virtio_blk_bus));
3156cb
     let ide_disks =
3156cb
       match guestcaps.gcaps_machine with
3156cb
@@ -392,7 +400,7 @@ let create_libvirt_xml ?pool source inspect
3156cb
   let nics =
3156cb
     let net_model =
3156cb
       match guestcaps.gcaps_net_bus with
3156cb
-      | Virtio_net -> "virtio" | E1000 -> "e1000" | RTL8139 -> "rtl8139" in
3156cb
+      | Virtio_net -> virtio_model | E1000 -> "e1000" | RTL8139 -> "rtl8139" in
3156cb
     List.map (
3156cb
       fun { s_mac = mac; s_vnet_type = vnet_type; s_vnet = vnet } ->
3156cb
         let vnet_type_str =
3156cb
@@ -483,7 +491,7 @@ let create_libvirt_xml ?pool source inspect
3156cb
   (* Miscellaneous KVM devices. *)
3156cb
   if guestcaps.gcaps_virtio_rng then
3156cb
     List.push_back devices (
3156cb
-      e "rng" ["model", "virtio"] [
3156cb
+      e "rng" ["model", virtio_model] [
3156cb
         (* XXX Using /dev/urandom requires libvirt >= 1.3.4.  Libvirt
3156cb
          * was broken before that.
3156cb
          *)
3156cb
@@ -496,7 +504,7 @@ let create_libvirt_xml ?pool source inspect
3156cb
   List.push_back devices (
3156cb
     e "memballoon"
3156cb
       ["model",
3156cb
-       if guestcaps.gcaps_virtio_balloon then "virtio" else "none"]
3156cb
+       if guestcaps.gcaps_virtio_balloon then virtio_model else "none"]
3156cb
       []
3156cb
   );
3156cb
   if guestcaps.gcaps_isa_pvpanic then
3156cb
@@ -508,7 +516,7 @@ let create_libvirt_xml ?pool source inspect
3156cb
   List.push_back devices (
3156cb
     e "viosock"
3156cb
       ["model",
3156cb
-        if guestcaps.gcaps_virtio_socket then "virtio" else "none"]
3156cb
+        if guestcaps.gcaps_virtio_socket then virtio_model else "none"]
3156cb
        []
3156cb
   );
3156cb
 
3156cb
-- 
3156cb
2.31.1
3156cb