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

Commit 73871b1

Browse files
committed
vfio: Fix default port assignment
Fix default port assignment with an explicit value in the TOML It was implicit before and now the runtime will bail out if we did not set it explicitly. Update the configuration and set it. This will make the intent more clear. Fixes: #5726 Signed-off-by: Zvonko Kaiser <[email protected]>
1 parent 5102a2d commit 73871b1

File tree

1 file changed

+63
-8
lines changed

1 file changed

+63
-8
lines changed

functional/vfio/run.sh

Lines changed: 63 additions & 8 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
@@ -189,12 +197,28 @@ setup_configuration_file() {
189197
if [ "$HYPERVISOR" = "qemu" ]; then
190198
sed -i 's|^machine_type.*|machine_type = "'${MACHINE_TYPE}'"|g' "${kata_config_file}"
191199
# Make sure we have set hot_plug_vfio to a reasonable value
200+
<<<<<<< HEAD
192201
sudo 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}"
202+
=======
203+
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}"
204+
>>>>>>> 933bbc1f (vfio: Fix default port assignment)
193205
else
194206
warn "Variable machine_type only applies to qemu. It will be ignored"
195207
fi
196208
fi
197209

210+
if [ "${VFIO_HOTPLUG}" != "bridge-port" ]; then
211+
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}"
212+
cat "${kata_config_file}" | grep -v '#' | grep -v '^$'
213+
fi
214+
215+
if [ "${VFIO_COLDPLUG}" != "bridge-port" ]; then
216+
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}"
217+
cat "${kata_config_file}" | grep -v '#' | grep -v '^$'
218+
fi
219+
220+
221+
198222
if [ -n "${SANDBOX_CGROUP_ONLY}" ]; then
199223
sed -i 's|^sandbox_cgroup_only.*|sandbox_cgroup_only='${SANDBOX_CGROUP_ONLY}'|g' "${kata_config_file}"
200224
fi
@@ -288,7 +312,7 @@ main() {
288312
#
289313
# Get the device ready on the host
290314
#
291-
setup_configuration_file
315+
#setup_configuration_file
292316

293317
restart_containerd_service
294318
sudo modprobe vfio
@@ -318,6 +342,37 @@ main() {
318342
# Run the tests
319343
#
320344

345+
# First test hot_plug_vfio="bridge-port"
346+
export VFIO_HOTPLUG="bridge-port"
347+
348+
setup_configuration_file
349+
350+
# test for guest-kernel mode
351+
guest_kernel_cid="vfio-guest-kernel-${RANDOM}"
352+
run_test_container "${guest_kernel_cid}" \
353+
"${tmp_data_dir}/vfio-guest-kernel" \
354+
"${script_path}/guest-kernel.json.in" \
355+
"${host_pci}"
356+
check_guest_kernel "${guest_kernel_cid}"
357+
358+
# Remove the container so we can re-use the device for the next test
359+
clean_env_ctr
360+
361+
# test for vfio mode
362+
vfio_cid="vfio-vfio-${RANDOM}"
363+
run_test_container "${vfio_cid}" \
364+
"${tmp_data_dir}/vfio-vfio" \
365+
"${script_path}/vfio.json.in" \
366+
"${host_pci}"
367+
check_vfio "${vfio_cid}"
368+
369+
370+
371+
# Now test cold_plug_vfio="bridge-port"
372+
export VFIO_COLDPLUG="bridge-port"
373+
374+
setup_configuration_file
375+
321376
# test for guest-kernel mode
322377
guest_kernel_cid="vfio-guest-kernel-${RANDOM}"
323378
run_test_container "${guest_kernel_cid}" \
@@ -338,4 +393,4 @@ main() {
338393
check_vfio "${vfio_cid}"
339394
}
340395

341-
main $@
396+
main "$@"

0 commit comments

Comments
 (0)