Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

vfio: selftests: Enable asserting MSI eventfds not firing

Make it possible to assert that a given MSI eventfd did _not_ fire by
adding a helper to mark an eventfd non-blocking. Demonstrate this in
vfio_pci_device_test by asserting the MSI eventfd did not fire before
vfio_pci_irq_trigger().

Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: David Matlack <dmatlack@google.com>
Link: https://lore.kernel.org/r/20250822212518.4156428-11-dmatlack@google.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

authored by

David Matlack and committed by
Alex Williamson
92494780 346cd58f

+21 -1
+12
tools/testing/selftests/vfio/lib/include/vfio_util.h
··· 2 2 #ifndef SELFTESTS_VFIO_LIB_INCLUDE_VFIO_UTIL_H 3 3 #define SELFTESTS_VFIO_LIB_INCLUDE_VFIO_UTIL_H 4 4 5 + #include <fcntl.h> 5 6 #include <string.h> 6 7 #include <linux/vfio.h> 7 8 #include <linux/list.h> ··· 130 129 u32 vector, int count); 131 130 void vfio_pci_irq_disable(struct vfio_pci_device *device, u32 index); 132 131 void vfio_pci_irq_trigger(struct vfio_pci_device *device, u32 index, u32 vector); 132 + 133 + static inline void fcntl_set_nonblock(int fd) 134 + { 135 + int r; 136 + 137 + r = fcntl(fd, F_GETFL, 0); 138 + VFIO_ASSERT_NE(r, -1, "F_GETFL failed for fd %d\n", fd); 139 + 140 + r = fcntl(fd, F_SETFL, r | O_NONBLOCK); 141 + VFIO_ASSERT_NE(r, -1, "F_SETFL O_NONBLOCK failed for fd %d\n", fd); 142 + } 133 143 134 144 static inline void vfio_pci_msi_enable(struct vfio_pci_device *device, 135 145 u32 vector, int count)
+9 -1
tools/testing/selftests/vfio/vfio_pci_device_test.c
··· 129 129 TEST_F(vfio_pci_irq_test, enable_trigger_disable) 130 130 { 131 131 bool msix = variant->irq_index == VFIO_PCI_MSIX_IRQ_INDEX; 132 + int msi_eventfd; 132 133 u32 count; 133 134 u64 value; 134 135 int i; ··· 148 147 printf("MSI%s: enabled %d interrupts\n", msix ? "-x" : "", count); 149 148 150 149 for (i = 0; i < count; i++) { 150 + msi_eventfd = self->device->msi_eventfds[i]; 151 + 152 + fcntl_set_nonblock(msi_eventfd); 153 + ASSERT_EQ(-1, read(msi_eventfd, &value, 8)); 154 + ASSERT_EQ(EAGAIN, errno); 155 + 151 156 vfio_pci_irq_trigger(self->device, variant->irq_index, i); 152 - ASSERT_EQ(8, read(self->device->msi_eventfds[i], &value, 8)); 157 + 158 + ASSERT_EQ(8, read(msi_eventfd, &value, 8)); 153 159 ASSERT_EQ(1, value); 154 160 } 155 161