It is used to pass a PCI device from the host to a bhyve guest
Signed-off-by: Alexander Shursha <kekek2(a)ya.ru>
---
src/bhyve/bhyve_command.c | 24 ++++++++++++++++
.../bhyvexml2argv-passthru.args | 9 ++++++
.../bhyvexml2argv-passthru.ldargs | 4 +++
.../bhyvexml2argv-passthru.xml | 28 +++++++++++++++++++
tests/bhyvexml2argvtest.c | 1 +
5 files changed, 66 insertions(+)
create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-passthru.args
create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-passthru.ldargs
create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-passthru.xml
diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index bc287307c8..23bb2cdcf4 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -2,6 +2,7 @@
* bhyve_command.c: bhyve command generation
*
* Copyright (C) 2014 Roman Bogorodskiy
+ * Copyright (C) 2024-2025 Future Crew, LLC
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -152,6 +153,26 @@ bhyveBuildConsoleArgStr(const virDomainDef *def, virCommand *cmd)
return 0;
}
+static int
+bhyveBuildHostdevArgStr(const virDomainDef *def, virCommand *cmd)
+{
+ size_t i;
+
+ for (i = 0; i < def->nhostdevs; i++) {
+ virDomainHostdevDef *hostdev = def->hostdevs[i];
+ virDomainHostdevSubsys *subsys = &hostdev->source.subsys;
+
+ if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
+ subsys->type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
+ continue;
+ virCommandAddArg(cmd, "-s");
+ virCommandAddArgFormat(cmd, "%d,passthru,%d/%d/%d",
+ hostdev->info->addr.pci.slot, subsys->u.pci.addr.bus,
+ subsys->u.pci.addr.slot, subsys->u.pci.addr.function);
+ }
+ return 0;
+}
+
static int
bhyveBuildAHCIControllerArgStr(const virDomainDef *def,
virDomainControllerDef *controller,
@@ -819,6 +840,9 @@ virBhyveProcessBuildBhyveCmd(struct _bhyveConn *driver, virDomainDef
*def,
virCommandAddArg(cmd, bhyvecmd->args[i]);
}
+ if (bhyveBuildHostdevArgStr(def, cmd) < 0)
+ return NULL;
+
virCommandAddArg(cmd, def->name);
return g_steal_pointer(&cmd);
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-passthru.args
b/tests/bhyvexml2argvdata/bhyvexml2argv-passthru.args
new file mode 100644
index 0000000000..ec17756d36
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-passthru.args
@@ -0,0 +1,9 @@
+bhyve \
+-c 1 \
+-m 214 \
+-H \
+-P \
+-s 0:0,hostbridge \
+-s 2:0,ahci,hd:/tmp/freebsd.img \
+-s 7,passthru,3/0/0 \
+bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-passthru.ldargs
b/tests/bhyvexml2argvdata/bhyvexml2argv-passthru.ldargs
new file mode 100644
index 0000000000..5905f4b3e6
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-passthru.ldargs
@@ -0,0 +1,4 @@
+bhyveload \
+-m 214 \
+-d /tmp/freebsd.img \
+bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-passthru.xml
b/tests/bhyvexml2argvdata/bhyvexml2argv-passthru.xml
new file mode 100644
index 0000000000..9845587f1e
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-passthru.xml
@@ -0,0 +1,28 @@
+<domain type='bhyve'>
+ <name>bhyve</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>219136</memory>
+ <currentMemory unit='KiB'>219136</currentMemory>
+ <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='0x0'/>
+ </source>
+ <address type='pci' domain='0x0000' bus='0x00'
slot='0x07' function='0x0'/>
+ </hostdev>
+ </devices>
+</domain>
diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c
index cdaa32f65c..c1da8a1a17 100644
--- a/tests/bhyvexml2argvtest.c
+++ b/tests/bhyvexml2argvtest.c
@@ -217,6 +217,7 @@ mymain(void)
DO_TEST("serial-grub");
DO_TEST("localtime");
DO_TEST("net-e1000");
+ DO_TEST("passthru");
DO_TEST("uefi");
DO_TEST("vnc");
DO_TEST("vnc-vgaconf-on");
--
2.46.1