Skip to content

Commit 1365388

Browse files
likebreathSebastien Boeuf
authored andcommitted
tests: Extend 'test_vfio' with block device passthrough
Fixes: cloud-hypervisor#2822 Signed-off-by: Bo Chen <[email protected]>
1 parent 73cc443 commit 1365388

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

test_data/cloud-init/ubuntu/user-data

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,18 @@ write_files:
3636
#!/bin/bash
3737

3838
mount /dev/vdc /mnt
39+
bash -c "echo 1af4 1042 > /sys/bus/pci/drivers/vfio-pci/new_id"
40+
bash -c "echo 0000:00:05.0 > /sys/bus/pci/devices/0000\:00\:05.0/driver/unbind"
41+
bash -c "echo 0000:00:05.0 > /sys/bus/pci/drivers/vfio-pci/bind"
3942
bash -c "echo 1af4 1041 > /sys/bus/pci/drivers/vfio-pci/new_id"
40-
bash -c "echo 0000:00:06.0 > /sys/bus/pci/devices/0000\:00\:06.0/driver/unbind"
41-
bash -c "echo 0000:00:06.0 > /sys/bus/pci/drivers/vfio-pci/bind"
4243
bash -c "echo 0000:00:07.0 > /sys/bus/pci/devices/0000\:00\:07.0/driver/unbind"
4344
bash -c "echo 0000:00:07.0 > /sys/bus/pci/drivers/vfio-pci/bind"
45+
bash -c "echo 0000:00:08.0 > /sys/bus/pci/devices/0000\:00\:08.0/driver/unbind"
46+
bash -c "echo 0000:00:08.0 > /sys/bus/pci/drivers/vfio-pci/bind"
4447
# 1G ram requires 512 pages
4548
echo 512 | sudo tee /proc/sys/vm/nr_hugepages
4649
sudo chmod a+rwX /dev/hugepages
47-
/mnt/cloud-hypervisor --kernel /mnt/vmlinux --cmdline "console=hvc0 reboot=k panic=1 nomodules root=/dev/vda1 VFIOTAG" --disk path=/mnt/focal-server-cloudimg-amd64-custom-20210609-0.qcow2 path=/mnt/cloudinit.img --cpus boot=1 --memory size=512M,hotplug_size=1G,hugepages=on --device path=/sys/bus/pci/devices/0000:00:06.0/ path=/sys/bus/pci/devices/0000:00:07.0/ --api-socket /tmp/ch_api.sock
50+
/mnt/cloud-hypervisor --kernel /mnt/vmlinux --cmdline "console=hvc0 reboot=k panic=1 nomodules root=/dev/vda1 VFIOTAG" --disk path=/mnt/focal-server-cloudimg-amd64-custom-20210609-0.qcow2 path=/mnt/cloudinit.img --cpus boot=1 --memory size=512M,hotplug_size=1G,hugepages=on --device path=/sys/bus/pci/devices/0000:00:05.0/ path=/sys/bus/pci/devices/0000:00:07.0/ path=/sys/bus/pci/devices/0000:00:08.0/ --api-socket /tmp/ch_api.sock
4851

4952
-
5053
path: /etc/systemd/system/notify-booted.service

tests/integration.rs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3238,6 +3238,8 @@ mod tests {
32383238
// line (We tag the command line from cloud-hypervisor for that purpose).
32393239
// The third device is added to validate that hotplug works correctly since
32403240
// it is being added to the L2 VM through hotplugging mechanism.
3241+
// Also, we pass-through a vitio-blk device to the L2 VM to test the 32-bit
3242+
// vfio device support
32413243
fn test_vfio() {
32423244
setup_vfio_network_interfaces();
32433245

@@ -3263,7 +3265,7 @@ mod tests {
32633265
)
32643266
.expect("copying of cloud-init disk failed");
32653267

3266-
let mut vfio_disk_path = workload_path;
3268+
let mut vfio_disk_path = workload_path.clone();
32673269
vfio_disk_path.push("vfio.img");
32683270

32693271
// Create the vfio disk image
@@ -3279,6 +3281,9 @@ mod tests {
32793281
panic!("mkfs.ext4 command generated an error");
32803282
}
32813283

3284+
let mut blk_file_path = workload_path;
3285+
blk_file_path.push("blk.img");
3286+
32823287
let vfio_tap0 = "vfio-tap0";
32833288
let vfio_tap1 = "vfio-tap1";
32843289
let vfio_tap2 = "vfio-tap2";
@@ -3301,6 +3306,7 @@ mod tests {
33013306
)
33023307
.as_str(),
33033308
format!("path={}", vfio_disk_path.to_str().unwrap()).as_str(),
3309+
format!("path={},iommu=on", blk_file_path.to_str().unwrap()).as_str(),
33043310
])
33053311
.args(&[
33063312
"--cmdline",
@@ -3374,27 +3380,38 @@ mod tests {
33743380
.trim()
33753381
.parse::<u32>()
33763382
.unwrap_or_default(),
3377-
7,
3383+
8,
3384+
);
3385+
3386+
// Check both if /dev/vdc exists and if the block size is 16M in L2 VM
3387+
assert_eq!(
3388+
guest
3389+
.ssh_command_l2_1("lsblk | grep vdc | grep -c 16M")
3390+
.unwrap()
3391+
.trim()
3392+
.parse::<u32>()
3393+
.unwrap_or_default(),
3394+
1
33783395
);
33793396

33803397
// Hotplug an extra virtio-net device through L2 VM.
33813398
guest.ssh_command_l1(
3382-
"echo 0000:00:08.0 | sudo tee /sys/bus/pci/devices/0000:00:08.0/driver/unbind",
3399+
"echo 0000:00:09.0 | sudo tee /sys/bus/pci/devices/0000:00:09.0/driver/unbind",
33833400
).unwrap();
33843401
guest
33853402
.ssh_command_l1(
3386-
"echo 0000:00:08.0 | sudo tee /sys/bus/pci/drivers/vfio-pci/bind",
3403+
"echo 0000:00:09.0 | sudo tee /sys/bus/pci/drivers/vfio-pci/bind",
33873404
)
33883405
.unwrap();
33893406
let vfio_hotplug_output = guest
33903407
.ssh_command_l1(
33913408
"sudo /mnt/ch-remote \
33923409
--api-socket=/tmp/ch_api.sock \
3393-
add-device path=/sys/bus/pci/devices/0000:00:08.0,id=vfio123",
3410+
add-device path=/sys/bus/pci/devices/0000:00:09.0,id=vfio123",
33943411
)
33953412
.unwrap();
33963413
assert!(
3397-
vfio_hotplug_output.contains("{\"id\":\"vfio123\",\"bdf\":\"0000:00:07.0\"}")
3414+
vfio_hotplug_output.contains("{\"id\":\"vfio123\",\"bdf\":\"0000:00:08.0\"}")
33983415
);
33993416

34003417
thread::sleep(std::time::Duration::new(10, 0));
@@ -3414,15 +3431,15 @@ mod tests {
34143431

34153432
// Check the amount of PCI devices appearing in L2 VM.
34163433
// There should be one more device than before, raising the count
3417-
// up to 8 PCI devices.
3434+
// up to 9 PCI devices.
34183435
assert_eq!(
34193436
guest
34203437
.ssh_command_l2_1("ls /sys/bus/pci/devices | wc -l")
34213438
.unwrap()
34223439
.trim()
34233440
.parse::<u32>()
34243441
.unwrap_or_default(),
3425-
8,
3442+
9,
34263443
);
34273444

34283445
// Let's now verify that we can correctly remove the virtio-net
@@ -3438,15 +3455,15 @@ mod tests {
34383455
thread::sleep(std::time::Duration::new(10, 0));
34393456

34403457
// Check the amount of PCI devices appearing in L2 VM is back down
3441-
// to 7 devices.
3458+
// to 8 devices.
34423459
assert_eq!(
34433460
guest
34443461
.ssh_command_l2_1("ls /sys/bus/pci/devices | wc -l")
34453462
.unwrap()
34463463
.trim()
34473464
.parse::<u32>()
34483465
.unwrap_or_default(),
3449-
7,
3466+
8,
34503467
);
34513468

34523469
// Perform memory hotplug in L2 and validate the memory is showing

0 commit comments

Comments
 (0)