]> www.infradead.org Git - users/hch/misc.git/commitdiff
vfio: selftests: Add test to reset vfio device.
authorJosh Hilke <jrhilke@google.com>
Fri, 22 Aug 2025 21:24:53 +0000 (21:24 +0000)
committerAlex Williamson <alex.williamson@redhat.com>
Wed, 27 Aug 2025 18:14:03 +0000 (12:14 -0600)
Add a test to vfio_pci_device_test which resets the device. If reset is
not supported by the device, the test is skipped.

Signed-off-by: Josh Hilke <jrhilke@google.com>
Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: David Matlack <dmatlack@google.com>
Link: https://lore.kernel.org/r/20250822212518.4156428-7-dmatlack@google.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
tools/testing/selftests/vfio/lib/include/vfio_util.h
tools/testing/selftests/vfio/lib/vfio_pci_device.c
tools/testing/selftests/vfio/vfio_pci_device_test.c

index b7d2bb8c18ba6e7457aa5977dcf4dfa272c9b8ea..234403b442af2ca1f295acace275b0ed71ad9f05 100644 (file)
@@ -83,6 +83,7 @@ const char *vfio_selftests_get_bdf(int *argc, char *argv[]);
 
 struct vfio_pci_device *vfio_pci_device_init(const char *bdf, int iommu_type);
 void vfio_pci_device_cleanup(struct vfio_pci_device *device);
+void vfio_pci_device_reset(struct vfio_pci_device *device);
 
 void vfio_pci_dma_map(struct vfio_pci_device *device, u64 iova, u64 size,
                      void *vaddr);
index 76adb1841f16d3f32381d752a8f6d315dc3804c3..98cce0a6ecd732c6f92715d4e7d8e3d06d785e28 100644 (file)
@@ -202,6 +202,11 @@ void vfio_pci_config_access(struct vfio_pci_device *device, bool write,
                       write ? "write to" : "read from", config);
 }
 
+void vfio_pci_device_reset(struct vfio_pci_device *device)
+{
+       ioctl_assert(device->fd, VFIO_DEVICE_RESET, NULL);
+}
+
 static unsigned int vfio_pci_get_group_from_dev(const char *bdf)
 {
        char dev_iommu_group_path[PATH_MAX] = {0};
index a2e41398d184c4c28c0b72ccbff25d88340527f3..82e3c947f45d35f32141c3b3c7ed85b5d9fec5eb 100644 (file)
@@ -155,6 +155,14 @@ TEST_F(vfio_pci_irq_test, enable_trigger_disable)
        vfio_pci_irq_disable(self->device, variant->irq_index);
 }
 
+TEST_F(vfio_pci_device_test, reset)
+{
+       if (!(self->device->info.flags & VFIO_DEVICE_FLAGS_RESET))
+               SKIP(return, "Device does not support reset\n");
+
+       vfio_pci_device_reset(self->device);
+}
+
 int main(int argc, char *argv[])
 {
        device_bdf = vfio_selftests_get_bdf(&argc, argv);