[PATCH RFC v3 83/88] KVM: selftests: Verify VFIO ioeventfd creation for igb device
From: Ackerley Tng via B4 Relay
Date: Fri Nov 06 2026 - 19:57:18 EST
From: Ackerley Tng <ackerleytng@xxxxxxxxxx>
Add a subtest to verify ioeventfd registration and unregistration on
the bound Intel 82576 device.
Allocate an eventfd and configure a VFIO_DEVICE_IOEVENTFD ioctl targeting
the scratch receive address low (RAL0) register in BAR0 with 4-byte width
and a test trigger value.
Assert that in direct mode registration succeeds and that unregistration
(passing fd = -1 with matching register criteria) succeeds cleanly.
In guest_memfd mode, verify that ioeventfd registration is rejected with
-EOPNOTSUPP.
Signed-off-by: Ackerley Tng <ackerleytng@xxxxxxxxxx>
---
.../selftests/kvm/x86/guest_memfd_vfio_test.c | 39 ++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/tools/testing/selftests/kvm/x86/guest_memfd_vfio_test.c b/tools/testing/selftests/kvm/x86/guest_memfd_vfio_test.c
index 46d325228bda3..dde249571ebc4 100644
--- a/tools/testing/selftests/kvm/x86/guest_memfd_vfio_test.c
+++ b/tools/testing/selftests/kvm/x86/guest_memfd_vfio_test.c
@@ -10,6 +10,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <sys/eventfd.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/types.h>
@@ -725,4 +726,42 @@ TEST_F(guest_memfd_vfio, dmabuf_creation)
free(feat);
}
+TEST_F(guest_memfd_vfio, ioeventfd_creation)
+{
+ struct vfio_device_ioeventfd ioeventfd = {};
+ struct vfio_region_info bar0_info = {};
+ int ret;
+ int efd;
+
+ bar0_info.argsz = sizeof(bar0_info);
+ bar0_info.index = VFIO_PCI_BAR0_REGION_INDEX;
+ ret = ioctl(self->vfio_fd, VFIO_DEVICE_GET_REGION_INFO, &bar0_info);
+ ASSERT_EQ(0, ret);
+
+ efd = eventfd(0, EFD_CLOEXEC);
+ ASSERT_GE(efd, 0);
+
+ /* Register ioeventfd on BAR0 targeting RAL0 with 4-byte width */
+ ioeventfd.argsz = sizeof(ioeventfd);
+ ioeventfd.flags = VFIO_DEVICE_IOEVENTFD_32;
+ ioeventfd.offset = bar0_info.offset + E1000_RAL0;
+ ioeventfd.data = 0xdeadbeef;
+ ioeventfd.fd = efd;
+
+ ret = ioctl(self->vfio_fd, VFIO_DEVICE_IOEVENTFD, &ioeventfd);
+ if (variant->use_gmem) {
+ ASSERT_LT(ret, 0);
+ ASSERT_EQ(EOPNOTSUPP, errno);
+ } else {
+ ASSERT_EQ(0, ret);
+
+ /* Unregister ioeventfd by passing fd = -1 with identical match criteria */
+ ioeventfd.fd = -1;
+ ret = ioctl(self->vfio_fd, VFIO_DEVICE_IOEVENTFD, &ioeventfd);
+ ASSERT_EQ(0, ret);
+ }
+
+ close(efd);
+}
+
TEST_HARNESS_MAIN
--
2.56.0.455.g6c5a503b38-goog