Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

Commit 9ae8a41

Browse files
committed
vfio: Extend VFIO test
Extend the VFIO test to check for any VFIO device not only for network devices. Fixes: #5728 Signed-off-by: Zvonko Kaiser <[email protected]>
1 parent e45aea4 commit 9ae8a41

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

functional/vfio/run.sh

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,23 @@ HYPERVISOR=
2525
MACHINE_TYPE=
2626
IMAGE_TYPE=
2727

28+
# Option to choose an alternative PCI device for the VFIO test
29+
VFIO_PCI_CLASS=${VFIO_PCI_CLASS:-"Ethernet controller"}
30+
VFIO_PCI_NAME=${VFIO_PCI_NAME:-"Virtio.*network device"}
31+
VFIO_CHECK_GUEST_KERNEL=${VFIO_CHECK_GUEST_KERNEL:-"ip a | grep \"eth\" || die \"Missing VFIO network interface\""}
32+
VFIO_HOTPLUG=${VFIO_HOTPLUG:-"bridge-port"}
33+
VFIO_COLDPLUG=${VFIO_COLDPLUG:-"bridge-port"}
34+
VFIO_CHECK_NUM_DEVICES=${VFIO_CHECK_NUM_DEVICES:-"2"}
35+
2836
cleanup() {
2937
clean_env_ctr
3038
sudo rm -rf "${tmp_data_dir}"
31-
32-
[ -n "${host_pci}" ] && sudo driverctl unset-override "${host_pci}"
39+
# some devices fail if no previous driver being bound
40+
[ -n "${host_pci}" ] && sudo driverctl --noprobe unset-override "${host_pci}"
3341
}
3442

3543
host_pci_addr() {
36-
lspci -D | grep "Ethernet controller" | grep "Virtio.*network device" | tail -1 | cut -d' ' -f1
44+
lspci -D | grep "${VFIO_PCI_CLASS}" | grep "${VFIO_PCI_NAME}" | tail -1 | cut -d' ' -f1
3745
}
3846

3947
get_vfio_path() {
@@ -87,7 +95,7 @@ check_guest_kernel() {
8795
# For vfio_mode=guest-kernel, the device should be bound to
8896
# the guest kernel's native driver. To check this has worked,
8997
# we look for an ethernet device named 'eth*'
90-
get_ctr_cmd_output "${container_id}" ip a | grep "eth" || die "Missing VFIO network interface"
98+
get_ctr_cmd_output "${container_id}" ash -c "${VFIO_CHECK_GUEST_KERNEL}"
9199
}
92100

93101
check_vfio() {
@@ -113,8 +121,8 @@ check_vfio() {
113121
# There should be two devices in the IOMMU group: the ethernet
114122
# device we care about, plus the PCIe to PCI bridge device
115123
devs="$(get_ctr_cmd_output "${cid}" ls /sys/kernel/iommu_groups/"${group}"/devices)"
116-
if [ $(echo "${devs}" | wc -w) != "2" ] ; then
117-
die "Expected exactly two devices got: ${devs}"
124+
if [ $(echo "${devs}" | wc -w) != ${VFIO_CHECK_NUM_DEVICES} ] ; then
125+
die "Expected exactly ${VFIO_CHECK_NUM_DEVICES} device(s) got: ${devs}"
118126
fi
119127

120128
# The bridge device will always sort first, because it is on
@@ -188,11 +196,25 @@ setup_configuration_file() {
188196
if [ -n "$MACHINE_TYPE" ]; then
189197
if [ "$HYPERVISOR" = "qemu" ]; then
190198
sed -i 's|^machine_type.*|machine_type = "'${MACHINE_TYPE}'"|g' "${kata_config_file}"
199+
# Make sure we have set hot_plug_vfio to a reasonable value
200+
sed -i -e 's|^#hot_plug_vfio =.*$|hot_plug_vfio = "bridge-port"|' -e 's|^hot_plug_vfio =.*$|hot_plug_vfio = "bridge-port"|' "${kata_config_file}"
191201
else
192202
warn "Variable machine_type only applies to qemu. It will be ignored"
193203
fi
194204
fi
195205

206+
if [ "${VFIO_HOTPLUG}" != "bridge-port" ]; then
207+
sed -i -e "s|^#hot_plug_vfio =.*$|hot_plug_vfio = \"${VFIO_HOTPLUG}\"|" -e "s|^hot_plug_vfio =.*$|hot_plug_vfio = \"${VFIO_HOTPLUG}\"|" "${kata_config_file}"
208+
cat "${kata_config_file}" | grep -v '#' | grep -v '^$'
209+
fi
210+
211+
if [ "${VFIO_COLDPLUG}" != "bridge-port" ]; then
212+
sed -i -e "s|^#cold_plug_vfio =.*$|cold_plug_vfio = \"${VFIO_HOTPLUG}\"|" -e "s|^cold_plug_vfio =.*$|cold_plug_vfio = \"${VFIO_HOTPLUG}\"|" "${kata_config_file}"
213+
cat "${kata_config_file}" | grep -v '#' | grep -v '^$'
214+
fi
215+
216+
217+
196218
if [ -n "${SANDBOX_CGROUP_ONLY}" ]; then
197219
sed -i 's|^sandbox_cgroup_only.*|sandbox_cgroup_only='${SANDBOX_CGROUP_ONLY}'|g' "${kata_config_file}"
198220
fi

0 commit comments

Comments
 (0)