vfio: selftests: Add driver for Intel Ethernet Gigabit Controller (IGB)
Subsystems (4)
v10 cover vfio: selftests: Add driver for Intel Ethernet Gigabit Controller (IGB)
This v10 of a series which adds a VFIO selftest driver for the Intel Gigabit Ethernet controller (IGB), specifically targeting the 82576 device. IGB is fully virtualized in QEMU, making it suitable for running VFIO selftests without specialized hardware.
v9: https://lore.kernel.org/kvm/[email protected]/
Version 10 adds an assert in the IGB driver to prevent DMA transfers smaller than 60 bytes, avoiding out-of-bounds DMA writes caused by hardware padding on short transfers, and squashes the recovery logic (previously Patch 5) into the main driver patch to keep the driver self-contained. Also add some logic from Alex to correct the ordering of Tx/Rx queue setup.
This series applies on top of linux-next, but the VFIO selftests don't build without this patch which fixes a compile error for the test fixture:
https://lore.kernel.org/linux-kselftest/[email protected]/
Testing
=======
- VFIO selftests builds clean at every commit
- vfio_pci_driver_test passes using IGB driver + QEMU. Use the following command to run the tests:
vng \
--run arch/x86/boot/bzImage \
--user root \
--disable-microvm \
--memory 32G \
--cpus 8 \
--qemu-opts="-M q35,accel=kvm,kernel-irqchip=split" \
--qemu-opts="-device intel-iommu,intremap=on,caching-mode=on,device-iotlb=on" \
--qemu-opts="-netdev user,id=net0 -device igb,netdev=net0,addr=09.0" \
--append "console=ttyS0 earlyprintk=ttyS0 intel_iommu=on iommu=pt" \
--exec "modprobe vfio-pci && \
./tools/testing/selftests/vfio/scripts/setup.sh 0000:00:09.0 && \
./tools/testing/selftests/vfio/scripts/run.sh ./tools/testing/selftests/vfio/vfio_pci_driver_test"--------
Changelog:
v9 -> v10:
- Add assert in IGB driver to prevent DMA transfers < 60 bytes (Ethernet minimum payload size) to avoid memory corruption from hardware padding. (Sashiko)
- Squash recovery logic into the main driver patch to make the driver self-contained.
- Set per-queue enable bits _after_ enabling global queue bits (Alex)
v8 -> v9:
- Enable Pad Short Packets (PSP) in TCTL to support transfers < 60 bytes. (Sashiko)
- Correct misleading comment about interrupt delivery in Patch 1. (Sashiko)
v7 -> v8:
- Rebase onto linux-next branch. (Alex)
- Implement retry limit in vfio_pci_device_reset(). (Alex)
- Carry David's reviewed-by tag onto the patches that haven't been touched since v6.
v6 -> v7:
- Allow the driver to be used on any architecture. (Alex)
- Fix regression in reset logic for the physical device. (Alex)
v5 -> v6:
- Retry on EAGAIN during device reset to handle transient lock contention (Sashiko).
v4 -> v5:
- Reordered igb_remove() to reset the device before disabling MSI-X (Sashiko)
- Refactored hardware reset logic into igb_reset() helper.
- Simplified reset completion check to usleep + assertion instead of retry loop (Sashiko).
- Allow arbitrary test data by enabling Multicast Promiscuous (MPE)
and Broadcast Accept (BAM) modes (Sashiko).
- Fixed igb_send_msi() to use MSIX_VECTOR_MASK instead of magic number (Sashiko).
v3 -> v4
- Enable MSI-X mode in GPIE (Sashiko)
- Fix hardware initilization order to avoid race conditions (Alex/Sashiko)
- Add memory barrier to prevent speculative reads (Alex/Sashiko)
- Clean up stale references in commit messages and comments (Alex/Sashiko)
- Add a comment to address software/firmware semaphore (Alex/Sashiko)
v2 -> v3
- Poll reset bit and document the required wait time (David/Sashiko)
- Fix the logic for enabling PCI_COMMAND_MEMORY (David/Sashiko)
- Fail the test if autonegotation fails (David/Sashiko)
- Handle endianness conversions (David/Sashiko)
- Use real IGB headers at the start of the series (David)
- Add E1000_TXD_CMD_IFCS to the TX descriptor command word (Sashiko)
v1 -> v2
- Removed the chunking loop in igb_memcpy_start() (David)
- Removed redundant writes to status_error and hdr_addr (David)
- Include official IGB header files (David)
---
Alex Williamson (1):
vfio: selftests: Add helpers to re-enable interrupts
Josh Hilke (2):
vfio: selftests: igb: Add driver for Intel 82576 device
vfio: selftests: Retry on EAGAIN during device reset
.../selftests/vfio/lib/drivers/igb/e1000_82575.h | 1 + .../selftests/vfio/lib/drivers/igb/e1000_defines.h | 1 + .../selftests/vfio/lib/drivers/igb/e1000_regs.h | 1 + tools/testing/selftests/vfio/lib/drivers/igb/igb.c | 585 +++++++++++++++++++++ .../vfio/lib/include/libvfio/vfio_pci_device.h | 15 + tools/testing/selftests/vfio/lib/libvfio.mk | 1 + tools/testing/selftests/vfio/lib/vfio_pci_device.c | 42 +- tools/testing/selftests/vfio/lib/vfio_pci_driver.c | 3 +- 8 files changed, 647 insertions(+), 2 deletions(-)
---
base-commit: 0f6da28aab51b16762ed82e8fdeaa5042da45b08
change-id: 20260707-igb_v3_b4-49194c14373c
Best regards,
Signature · 1 line
Josh Hilke <[email protected]>
PATCH v10 1/3 vfio: selftests: Add helpers to re-enable interrupts
From: Alex Williamson <[email protected]>
Selftest drivers that recover from a fault by issuing VFIO_DEVICE_RESET need to re-arm device interrupts afterwards. VFIO_DEVICE_RESET tears down the kernel-side IRQ trigger so a subsequent VFIO_DEVICE_SET_IRQS is required, but the user-side eventfds (and any fd cached in a test fixture) are still valid and must be preserved.
vfio_pci_irq_enable() refuses to be called for vectors that already have an eventfd (VFIO_ASSERT_LT), and vfio_pci_irq_disable() closes all eventfds before resetting the trigger, so neither is suitable.
Add vfio_pci_irq_reenable(device, index, vector, count) which asserts that the requested range has existing eventfds and re-issues VFIO_DEVICE_SET_IRQS using them. Signature mirrors vfio_pci_irq_enable().
Add vfio_pci_msi{,x}_reenable() wrappers around vfio_pci_irq_reenable() for additional ease of use and readability.
--- .../vfio/lib/include/libvfio/vfio_pci_device.h | 14 ++++++++++++++ tools/testing/selftests/vfio/lib/vfio_pci_device.c | 22 ++++++++++++++++++++++ 2 files changed, 36 insertions(+)
tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h +14 -0
@@ -84,6 +84,8 @@ static inline void vfio_pci_cmd_clear(struct vfio_pci_device *device, u16 bits)void vfio_pci_irq_enable (struct vfio_pci_device *device,u32 index,u32 vector,int count);void vfio_pci_irq_disable (struct vfio_pci_device *device,u32 index); +void vfio_pci_irq_reenable (struct vfio_pci_device *device,u32 index, +u32 vector,int count);void vfio_pci_irq_trigger (struct vfio_pci_device *device,u32 index,u32 vector);static inline void fcntl_set_nonblock (int fd)
@@ -108,6 +110,12 @@ static inline void vfio_pci_msi_disable(struct vfio_pci_device *device)vfio_pci_irq_disable (device,VFIO_PCI_MSI_IRQ_INDEX ); } +static inline void vfio_pci_msi_reenable (struct vfio_pci_device *device, +u32 vector,int count) +{ +vfio_pci_irq_reenable (device,VFIO_PCI_MSI_IRQ_INDEX , vector, count); +} +static inline void vfio_pci_msix_enable (struct vfio_pci_device *device,u32 vector,int count) {
@@ -119,6 +127,12 @@ static inline void vfio_pci_msix_disable(struct vfio_pci_device *device)vfio_pci_irq_disable (device,VFIO_PCI_MSIX_IRQ_INDEX ); } +static inline void vfio_pci_msix_reenable (struct vfio_pci_device *device, +u32 vector,int count) +{ +vfio_pci_irq_reenable (device,VFIO_PCI_MSIX_IRQ_INDEX , vector, count); +} +static inline int __to_iova (struct vfio_pci_device *device,void *vaddr,iova_t *iova) {return __iommu_hva2iova (device->iommu, vaddr, iova);
tools/testing/selftests/vfio/lib/vfio_pci_device.c +22 -0
@@ -105,6 +105,28 @@ void vfio_pci_irq_disable(struct vfio_pci_device *device, u32 index)vfio_pci_irq_set (device, index,0 ,0 ,NULL ); } +/* +* Re-issue VFIO_DEVICE_SET_IRQS for an already-enabled vector range using +* the existing eventfds. Intended for drivers that need to re-arm device +* interrupts after a VFIO_DEVICE_RESET, which tears down the kernel-side +* IRQ trigger but leaves user-side eventfds intact. Recreating the +* eventfds would invalidate any test-fixture cache of the fd, so this +* helper deliberately preserves them. +*/ +void vfio_pci_irq_reenable (struct vfio_pci_device *device,u32 index, +u32 vector,int count) +{ +int i; + +check_supported_irq_index (index); + +for (i = vector; i < vector + count; i++) +VFIO_ASSERT_GE (device->msi_eventfds[i],0 , +"vector %d eventfd not allocated\n" , i); + +vfio_pci_irq_set (device, index, vector, count, device->msi_eventfds + vector); +} +static void vfio_pci_irq_get (struct vfio_pci_device *device,u32 index,struct vfio_irq_info *irq_info) {
Signature · 1 line
2.55.0.571.g244d577d93-goog
PATCH v10 2/3 vfio: selftests: igb: Add driver for Intel 82576 device
In reply to Josh HilkeAdd a VFIO selftest driver for the Intel Gigabit Ethernet controller (IGB), specifically targeting the 82576 device. IGB is fully virtualized in QEMU which makes it easy to run VFIO selftests without needing any specific hardware.
Since IGB is an Ethernet device, it cannot support DMA transfers smaller than the minimum Ethernet payload size (60 bytes) without hardware padding corrupting adjacent memory. The driver asserts that the transfer size is at least 60 bytes to prevent this.
All VFIO selftest drivers must implement DMA/memcpy operations, but IGB doesn't have a native memcpy feature, so the loopback feature (described in section 3.5.6.3 of IGB specification) is used to implement it. To support testing on both QEMU and physical hardware, the driver uses PHY internal loopback with some QEMU-specific fallbacks. The driver also supports MSI-X routing and interrupt management, and disables PCIe completion timeout retries to ensure clean recovery during invalid-DMA tests.
Users can verify the driver works in QEMU by building the kernel, building VFIO selftests, and then running the vfio_pci_driver_test using this command:
vng \
--run arch/x86/boot/bzImage \
--user root \
--disable-microvm \
--memory 32G \
--cpus 8 \
--qemu-opts="-M q35,accel=kvm,kernel-irqchip=split" \
--qemu-opts="-device intel-iommu,intremap=on,caching-mode=on,device-iotlb=on" \
--qemu-opts="-netdev user,id=net0 -device igb,netdev=net0,addr=09.0" \
--append "console=ttyS0 earlyprintk=ttyS0 intel_iommu=on iommu=pt" \
--exec "modprobe vfio-pci && \
./tools/testing/selftests/vfio/scripts/setup.sh 0000:00:09.0 && \
./tools/testing/selftests/vfio/scripts/run.sh ./tools/testing/selftests/vfio/vfio_pci_driver_test"
--- .../selftests/vfio/lib/drivers/igb/e1000_82575.h | 1 + .../selftests/vfio/lib/drivers/igb/e1000_defines.h | 1 + .../selftests/vfio/lib/drivers/igb/e1000_regs.h | 1 + tools/testing/selftests/vfio/lib/drivers/igb/igb.c | 585 +++++++++++++++++++++ tools/testing/selftests/vfio/lib/libvfio.mk | 1 + tools/testing/selftests/vfio/lib/vfio_pci_driver.c | 3 +- 6 files changed, 591 insertions(+), 1 deletion(-)
tools/testing/selftests/vfio/lib/drivers/igb/e1000_82575.h new file +1 -0
@@ -0,0 +1 @@ +../../../../../../../drivers/net/ethernet/intel/igb/e1000_82575.h
tools/testing/selftests/vfio/lib/drivers/igb/e1000_defines.h new file +1 -0
@@ -0,0 +1 @@ +../../../../../../../drivers/net/ethernet/intel/igb/e1000_defines.h
tools/testing/selftests/vfio/lib/drivers/igb/e1000_regs.h new file +1 -0
@@ -0,0 +1 @@ +../../../../../../../drivers/net/ethernet/intel/igb/e1000_regs.h
tools/testing/selftests/vfio/lib/drivers/igb/igb.c new file +585 -0
585 lines not on this page · raw message
tools/testing/selftests/vfio/lib/libvfio.mk +1 -0
@@ -16,6 +16,7 @@ LIBVFIO_C += drivers/dsa/dsa.c endif LIBVFIO_C += drivers/nv_falcon/nv_falcon.c +LIBVFIO_C += drivers/igb/igb.c LIBVFIO_OUTPUT := $(OUTPUT)/libvfio
tools/testing/selftests/vfio/lib/vfio_pci_driver.c +2 -1
@@ -6,8 +6,8 @@extern struct vfio_pci_driver_ops dsa_ops;extern struct vfio_pci_driver_ops ioat_ops;#endif -extern struct vfio_pci_driver_ops nv_falcon_ops; +extern struct vfio_pci_driver_ops igb_ops; static struct vfio_pci_driver_ops *driver_ops[] = {#ifdef __x86_64__
@@ -15,6 +15,7 @@ static struct vfio_pci_driver_ops *driver_ops[] = { &ioat_ops, #endif &nv_falcon_ops, + &igb_ops, };void vfio_pci_driver_probe (struct vfio_pci_device *device)
Signature · 1 line
2.55.0.571.g244d577d93-goog
PATCH v10 3/3 vfio: selftests: Retry on EAGAIN during device reset
In reply to Josh HilkeAdd retry logic to vfio_pci_device_reset() to handle the case where PCI resets fail due to lock contention, in which case pci_try_reset_function() returns -EAGAIN.
--- .../vfio/lib/include/libvfio/vfio_pci_device.h | 1 + tools/testing/selftests/vfio/lib/vfio_pci_device.c | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-)
tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h +1 -0
@@ -43,6 +43,7 @@ void vfio_pci_device_free(struct vfio_pci_device *device);struct vfio_pci_device *vfio_pci_device_init (const char *bdf,struct iommu *iommu);void vfio_pci_device_cleanup (struct vfio_pci_device *device); +int __vfio_pci_device_reset (struct vfio_pci_device *device);void vfio_pci_device_reset (struct vfio_pci_device *device); void vfio_pci_config_access(struct vfio_pci_device *device, bool write,
tools/testing/selftests/vfio/lib/vfio_pci_device.c +19 -1
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0-only #include <dirent.h> +#include <errno.h> #include <fcntl.h> #include <libgen.h> #include <stdint.h>
@@ -259,9 +260,26 @@ void vfio_pci_config_access(struct vfio_pci_device *device, bool write, write ? "write to" : "read from", config); } +int __vfio_pci_device_reset (struct vfio_pci_device *device) +{ +if (ioctl (device->fd,VFIO_DEVICE_RESET ,NULL )) +return -errno; + +return 0 ; +} +void vfio_pci_device_reset (struct vfio_pci_device *device) { -ioctl_assert (device->fd,VFIO_DEVICE_RESET ,NULL ); +int retries =20 ; +int r; + +do { + r =__vfio_pci_device_reset (device); +if (r == -EAGAIN ) +usleep (10000 ); + }while (r == -EAGAIN && retries-- >0 ); + +VFIO_ASSERT_EQ (r,0 ,"ioctl(device->fd, VFIO_DEVICE_RESET) failed\n" ); }void vfio_pci_group_setup (struct vfio_pci_device *device,const char *bdf)
Signature · 1 line
2.55.0.571.g244d577d93-goog
Alex Williamson
maintainerQuoted 4 lines · On Wed, 05 Aug 2026 00:20:57 +0000 Josh Hilke <[email protected]> wrote:
This v10 of a series which adds a VFIO selftest driver for the Intel Gigabit Ethernet controller (IGB), specifically targeting the 82576 device. IGB is fully virtualized in QEMU, making it suitable for running VFIO selftests without specialized hardware.
LGTM, passes on physical NIC. Thanks for the re-spins.
David, do you want to double check and provide an Ack? Thanks,
Alex
Quoted 110 lines
v9: https://lore.kernel.org/kvm/[email protected]/
Version 10 adds an assert in the IGB driver to prevent DMA transfers smaller than 60 bytes, avoiding out-of-bounds DMA writes caused by hardware padding on short transfers, and squashes the recovery logic (previously Patch 5) into the main driver patch to keep the driver self-contained. Also add some logic from Alex to correct the ordering of Tx/Rx queue setup.
This series applies on top of linux-next, but the VFIO selftests don't build without this patch which fixes a compile error for the test fixture:
https://lore.kernel.org/linux-kselftest/[email protected]/Testing
=======
- VFIO selftests builds clean at every commit
-vfio_pci_driver_testpasses using IGB driver + QEMU. Use the following command to run the tests:vng \
--runarch/x86/boot/bzImage\
--user root \
--disable-microvm \
--memory 32G \
--cpus 8 \
--qemu-opts="-M q35,accel=kvm,kernel-irqchip=split" \
--qemu-opts="-device intel-iommu,intremap=on,caching-mode=on,device-iotlb=on" \
--qemu-opts="-netdev user,id=net0 -device igb,netdev=net0,addr=09.0" \
--append "console=ttyS0 earlyprintk=ttyS0 intel_iommu=on iommu=pt" \--exec "modprobe vfio-pci && \ ./tools/testing/selftests/vfio/scripts/setup.sh 0000:00:09.0 && \ ./tools/testing/selftests/vfio/scripts/run.sh ./tools/testing/selftests/vfio/vfio_pci_driver_test"--------
Changelog:v9 -> v10:
- Add assert in IGB driver to prevent DMA transfers < 60 bytes (Ethernet minimum payload size) to avoid memory corruption from hardware padding. (Sashiko)
- Squash recovery logic into the main driver patch to make the driver self-contained.
- Set per-queue enable bits _after_ enabling global queue bits (Alex)v8 -> v9:
- Enable Pad Short Packets (PSP) in TCTL to support transfers < 60 bytes. (Sashiko)
- Correct misleading comment about interrupt delivery in Patch 1. (Sashiko)v7 -> v8:
- Rebase onto linux-next branch. (Alex)
- Implement retry limit invfio_pci_device_reset(). (Alex)
- Carry David's reviewed-by tag onto the patches that haven't been touched since v6.v6 -> v7:
- Allow the driver to be used on any architecture. (Alex)
- Fix regression in reset logic for the physical device. (Alex)v5 -> v6:
- Retry on EAGAIN during device reset to handle transient lock contention (Sashiko).v4 -> v5:
- Reorderedigb_remove()to reset the device before disabling MSI-X (Sashiko)
- Refactored hardware reset logic intoigb_reset()helper.
- Simplified reset completion check to usleep + assertion instead of retry loop (Sashiko).
- Allow arbitrary test data by enabling Multicast Promiscuous (MPE)
and Broadcast Accept (BAM) modes (Sashiko).
- Fixedigb_send_msi()to useMSIX_VECTOR_MASKinstead of magic number (Sashiko).v3 -> v4
- Enable MSI-X mode in GPIE (Sashiko)
- Fix hardware initilization order to avoid race conditions (Alex/Sashiko)
- Add memory barrier to prevent speculative reads (Alex/Sashiko)
- Clean up stale references in commit messages and comments (Alex/Sashiko)
- Add a comment to address software/firmware semaphore (Alex/Sashiko)v2 -> v3
- Poll reset bit and document the required wait time (David/Sashiko)
- Fix the logic for enablingPCI_COMMAND_MEMORY(David/Sashiko)
- Fail the test if autonegotation fails (David/Sashiko)
- Handle endianness conversions (David/Sashiko)
- Use real IGB headers at the start of the series (David)
- AddE1000_TXD_CMD_IFCSto the TX descriptor command word (Sashiko)v1 -> v2
- Removed the chunking loop inigb_memcpy_start()(David)
- Removed redundant writes tostatus_errorandhdr_addr(David)
- Include official IGB header files (David)Signed-off-by Josh Hilke <[email protected]>---
Alex Williamson (1):
vfio: selftests: Add helpers to re-enable interruptsJosh Hilke (2):
vfio: selftests: igb: Add driver for Intel 82576 device
vfio: selftests: Retry on EAGAIN during device reset.../selftests/vfio/lib/drivers/igb/e1000_82575.h | 1 + .../selftests/vfio/lib/drivers/igb/e1000_defines.h | 1 + .../selftests/vfio/lib/drivers/igb/e1000_regs.h | 1 + tools/testing/selftests/vfio/lib/drivers/igb/igb.c | 585 +++++++++++++++++++++ .../vfio/lib/include/libvfio/vfio_pci_device.h | 15 + tools/testing/selftests/vfio/lib/libvfio.mk | 1 + tools/testing/selftests/vfio/lib/vfio_pci_device.c | 42 +- tools/testing/selftests/vfio/lib/vfio_pci_driver.c | 3 +- 8 files changed, 647 insertions(+), 2 deletions(-)---
base-commit:0f6da28aab51b16762ed82e8fdeaa5042da45b08
change-id: 20260707-igb_v3_b4-49194c14373cBest regards,
Quoted 8 lines · Alex Williamson
Quoted 4 lines · On Wed, 05 Aug 2026 00:20:57 +0000 Josh Hilke <[email protected]> wrote:
This v10 of a series which adds a VFIO selftest driver for the Intel Gigabit Ethernet controller (IGB), specifically targeting the 82576 device. IGB is fully virtualized in QEMU, making it suitable for running VFIO selftests without specialized hardware.
Quoted 5 lines
LGTM, passes on physical NIC. Thanks for the re-spins.
David, do you want to double check and provide an Ack? Thanks,
Alex
Quoted 38 lines · On Wed, 05 Aug 2026 00:20:57 +0000 Josh Hilke <[email protected]> wrote:
This v10 of a series which adds a VFIO selftest driver for the Intel Gigabit Ethernet controller (IGB), specifically targeting the 82576 device. IGB is fully virtualized in QEMU, making it suitable for running VFIO selftests without specialized hardware.
v9: https://lore.kernel.org/kvm/[email protected]/
Version 10 adds an assert in the IGB driver to prevent DMA transfers smaller than 60 bytes, avoiding out-of-bounds DMA writes caused by hardware padding on short transfers, and squashes the recovery logic (previously Patch 5) into the main driver patch to keep the driver self-contained. Also add some logic from Alex to correct the ordering of Tx/Rx queue setup.
This series applies on top of linux-next, but the VFIO selftests don't build without this patch which fixes a compile error for the test fixture:
https://lore.kernel.org/linux-kselftest/[email protected]/Testing
=======
- VFIO selftests builds clean at every commit
-vfio_pci_driver_testpasses using IGB driver + QEMU. Use the following command to run the tests:vng \
--runarch/x86/boot/bzImage\
--user root \
--disable-microvm \
--memory 32G \
--cpus 8 \
--qemu-opts="-M q35,accel=kvm,kernel-irqchip=split" \
--qemu-opts="-device intel-iommu,intremap=on,caching-mode=on,device-iotlb=on" \
--qemu-opts="-netdev user,id=net0 -device igb,netdev=net0,addr=09.0" \
--append "console=ttyS0 earlyprintk=ttyS0 intel_iommu=on iommu=pt" \--exec "modprobe vfio-pci && \ ./tools/testing/selftests/vfio/scripts/setup.sh 0000:00:09.0 && \ ./tools/testing/selftests/vfio/scripts/run.sh ./tools/testing/selftests/vfio/vfio_pci_driver_test"
Quoted 8 lines
--------
Changelog:v9 -> v10:
- Add assert in IGB driver to prevent DMA transfers < 60 bytes (Ethernet minimum payload size) to avoid memory corruption from hardware padding. (Sashiko)
- Squash recovery logic into the main driver patch to make the driver self-contained.
- Set per-queue enable bits _after_ enabling global queue bits (Alex)
Applied to vfio next branch for v7.3. Thanks,
Alex