]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
bhyve: auto-assign PCI addresses for hostdevs
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Wed, 2 Apr 2025 11:20:11 +0000 (13:20 +0200)
committerRoman Bogorodskiy <bogorodskiy@gmail.com>
Sat, 8 Nov 2025 09:28:00 +0000 (10:28 +0100)
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/bhyve/bhyve_device.c
tests/bhyvexml2argvdata/bhyvexml2argv-passthru-multiple-devs.args [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-passthru-multiple-devs.ldargs [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-passthru-multiple-devs.xml [new file with mode: 0644]
tests/bhyvexml2argvtest.c
tests/bhyvexml2xmloutdata/bhyvexml2xmlout-passthru-multiple-devs.xml [new file with mode: 0644]
tests/bhyvexml2xmltest.c

index 49cfccaeba21f6d4baaf65a64ab4bf7c0145d824..ead52ae704743db847494294e859373a47144ebf 100644 (file)
@@ -196,6 +196,16 @@ bhyveAssignDevicePCISlots(virDomainDef *def,
             return -1;
     }
 
+    for (i = 0; i < def->nhostdevs; i++) {
+        if (!virDeviceInfoPCIAddressIsWanted(def->hostdevs[i]->info))
+            continue;
+        if (virDomainPCIAddressReserveNextAddr(addrs,
+                                               def->hostdevs[i]->info,
+                                               VIR_PCI_CONNECT_TYPE_PCI_DEVICE,
+                                               -1) < 0)
+            return -1;
+    }
+
     return 0;
 }
 
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-passthru-multiple-devs.args b/tests/bhyvexml2argvdata/bhyvexml2argv-passthru-multiple-devs.args
new file mode 100644 (file)
index 0000000..9764798
--- /dev/null
@@ -0,0 +1,12 @@
+bhyve \
+-c 1 \
+-m 214 \
+-S \
+-H \
+-P \
+-s 0:0,hostbridge \
+-s 2:0,ahci,hd:/tmp/freebsd.img \
+-s 7:1,passthru,3/0/4 \
+-s 3:0,passthru,4/0/0 \
+-s 4:0,passthru,5/2/0 \
+bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-passthru-multiple-devs.ldargs b/tests/bhyvexml2argvdata/bhyvexml2argv-passthru-multiple-devs.ldargs
new file mode 100644 (file)
index 0000000..5905f4b
--- /dev/null
@@ -0,0 +1,4 @@
+bhyveload \
+-m 214 \
+-d /tmp/freebsd.img \
+bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-passthru-multiple-devs.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-passthru-multiple-devs.xml
new file mode 100644 (file)
index 0000000..bcea7aa
--- /dev/null
@@ -0,0 +1,41 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <memoryBacking>
+    <locked/>
+  </memoryBacking>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type>hvm</type>
+  </os>
+  <clock offset='localtime'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>destroy</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <disk type='file'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/freebsd.img'/>
+      <target dev='hda' bus='sata'/>
+      <address type='drive' controller='0' bus='0' target='2' unit='0'/>
+    </disk>
+    <hostdev mode='subsystem' type='pci' managed='no'>
+      <source>
+        <address domain='0x0000' bus='0x03' slot='0x00' function='0x4'/>
+      </source>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x1'/>
+    </hostdev>
+    <hostdev mode='subsystem' type='pci' managed='no'>
+      <source>
+        <address domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
+      </source>
+    </hostdev>
+    <hostdev mode='subsystem' type='pci' managed='no'>
+      <source>
+        <address domain='0x0000' bus='0x05' slot='0x02' function='0x0'/>
+      </source>
+    </hostdev>
+  </devices>
+</domain>
index 5d234b39fa2aae3cdf7e28ef84019dd998dabaf3..f7411ee094f7270d74a4b4ea5c4dbd9589524ad6 100644 (file)
@@ -223,6 +223,7 @@ mymain(void)
     DO_TEST("localtime");
     DO_TEST("net-e1000");
     DO_TEST("passthru");
+    DO_TEST("passthru-multiple-devs");
     DO_TEST("uefi");
     DO_TEST("uefi-nvram");
     DO_TEST("uefi-nvram-template-set");
diff --git a/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-passthru-multiple-devs.xml b/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-passthru-multiple-devs.xml
new file mode 100644 (file)
index 0000000..dbb2a03
--- /dev/null
@@ -0,0 +1,48 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <memoryBacking>
+    <locked/>
+  </memoryBacking>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='localtime'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>destroy</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <disk type='file' device='disk'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/freebsd.img'/>
+      <target dev='hda' bus='sata'/>
+      <address type='drive' controller='0' bus='0' target='2' unit='0'/>
+    </disk>
+    <controller type='pci' index='0' model='pci-root'/>
+    <controller type='sata' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+    </controller>
+    <hostdev mode='subsystem' type='pci' managed='no'>
+      <source>
+        <address domain='0x0000' bus='0x03' slot='0x00' function='0x4'/>
+      </source>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x1'/>
+    </hostdev>
+    <hostdev mode='subsystem' type='pci' managed='no'>
+      <source>
+        <address domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
+      </source>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </hostdev>
+    <hostdev mode='subsystem' type='pci' managed='no'>
+      <source>
+        <address domain='0x0000' bus='0x05' slot='0x02' function='0x0'/>
+      </source>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
+    </hostdev>
+  </devices>
+</domain>
index 226eaccc6ad0d97914eabf0292484d08f3bc0f80..97c8647192c82b29c1878feb8d16111e5cd86a56 100644 (file)
@@ -119,6 +119,7 @@ mymain(void)
     DO_TEST_DIFFERENT("4-consoles");
     DO_TEST_DIFFERENT("nvme");
     DO_TEST_DIFFERENT("2-nvme-2-controllers");
+    DO_TEST_DIFFERENT("passthru-multiple-devs");
 
     /* Address allocation tests */
     DO_TEST_DIFFERENT("addr-single-sata-disk");