From nobody Fri Oct 2 05:30:33 2026 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3271036195B for ; Wed, 5 Aug 2026 00:21:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.69 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785889265; cv=none; b=HckyjLcmx5xIjsJsEd722N2FQLz/xBMAm0A1TT/GRgiQk9s/gVZugcjWCg0f7pyiXOoCw3bew07tCUasKTcSqwdNXj4RtwjcxFwAqiLj/pPxXlvM8zlm8Hcj1WaZwZMkdsQ0eY3vsQM17qyL3CO7zvJ9fokBMAW27KN8X4zfqw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785889265; c=relaxed/simple; bh=/s/WutWgBkDkoqWk1gtwHnk/Af6S+Dr8yUYiF5uC5uE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tY58baIrKdrYXP3YOYUXIhAJebYYP1UPMNx9Sk+ctQ1fP13EZeJB2oTebfl1CatZsF5Pr3WNbWPFKPKYnK1ymbgDhCyyhYL2O8CyVS1k7n0XyDgtI4TIg52k3HRgTbndfPQ/bUYWR/SHlzarhMDF0A1dIc4m4aR0bHDTJA2l/sw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jrhilke.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Jm8j/9CR; arc=none smtp.client-ip=209.85.216.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jrhilke.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Jm8j/9CR" Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-38e475f83a2so580913a91.1 for ; Tue, 04 Aug 2026 17:21:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785889263; x=1786494063; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=siogvW8DGq9Kjt0WBylwgP+rzy7WuNyV/ARa/oJc9U4=; b=Jm8j/9CRg7TQ5nmacWlytTIjQ9N4ScPxlmdobKjSweEJXKiiYRWn86yhfN3tYp91Wj WhmffRz5zY9IQW8hjC5hAhyk9r6hPAa4YQkD1PYIKPJfCoYfNpkYulsh4ucwnc3K0LnR ZHwutDRP22R8QYCipmvOYMlgbuVMDj9qiEooXmTlipTTuKeiid9wV1HE4ExWrCpmycgH t173JdS+s4Ix4qVu4ca88c2DfY4MfN3e9yrMX3W1WG50jLx6vyRmUASnauVh5STsuHST 7CW0MZIOzv/GdGIkoMhDF+QQxbuVi1gYsPNNdSAFRaKJJbfxP25y96/1MQ0TruOEZXuV SJBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785889263; x=1786494063; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=siogvW8DGq9Kjt0WBylwgP+rzy7WuNyV/ARa/oJc9U4=; b=DXSOrAOSVtcktAQZEjRkJL8p+n4P9hoAPiM1B3NTdit/muJnVTcl/wkhzXPLN/6C4u lngqHm5orDv3E08nHJgcSjSFiKzlu9bcIXBdTgXstOOJUiW/JO2ie++dxwHIm1NHarhL 4PDInbM/8VceNaV88kA+Z8mCicigzhsbjjzU0FiGnk62Tc0dvUMKtrDBbosOczageljb xOpzH3MowRJ33vGxUabY3h5gLkQC9ax97rpOpC65PN/Yhf7TYy60rtMoG2FQWoWNUrgU ntLjUOexGChDWf9754WZploqJvxTFQvFnxEhVcK1TbtB90WegnNhZDmcLTyoP4mYVsPa 61JQ== X-Forwarded-Encrypted: i=1; AHgh+RrVxArx2syERBNb44jePVJ185h2/pFuJBcMfdiEM751Xqy+38xJ9adYEFFNLw7lQsTA9aAAi13ui7qjDNw=@vger.kernel.org X-Gm-Message-State: AOJu0YzWyv4UZrZ8wOko2aEbSeZE11nfWVWTzVBU9oIY5JqEG26iKpzf 1p88v+xkh2LvMWX9QoHb/LkVgIa9mthFV+BjGY0CCyXcjaClX2/IMUo72IIVWd3Up8YQfeMa/qP pQbNPII3h X-Received: from pjcc15.prod.google.com ([2002:a17:90b:574f:b0:384:f6e1:ff87]) (user=jrhilke job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3a8d:b0:38e:57a3:f218 with SMTP id 98e67ed59e1d1-3903c5b9f70mr2337359a91.13.1785889263273; Tue, 04 Aug 2026 17:21:03 -0700 (PDT) Date: Wed, 05 Aug 2026 00:20:58 +0000 In-Reply-To: <20260805-igb_v3_b4-v10-0-9c86dc849c0d@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260805-igb_v3_b4-v10-0-9c86dc849c0d@google.com> X-Developer-Key: i=jrhilke@google.com; a=ed25519; pk=cK+Urrh214DoCHywJiTwhMP+zcs1ofpGrewToO/i/3A= X-Developer-Signature: v=1; a=ed25519-sha256; t=1785889261; l=4427; i=jrhilke@google.com; s=20260710; h=from:subject:message-id; bh=MlKUyD/iWnX4HMtGpIO1fGxO+tR5jQHpAHxHPe4ktOs=; b=YP1lLaWRuUfua8sT8yiH96WEn4Jt3QeI9RmH5Gtd6f+QJuJXSb04Hgv7aeu24lvoH9nFaKwvz pdEMFnQdUSLAAHO3op5B83LCSfitMvmUc/32CQVhI+y89c08qVwQhh6 X-Mailer: b4 0.14.3 Message-ID: <20260805-igb_v3_b4-v10-1-9c86dc849c0d@google.com> Subject: [PATCH v10 1/3] vfio: selftests: Add helpers to re-enable interrupts From: Josh Hilke To: David Matlack , Alex Williamson Cc: Shuah Khan , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma , Josh Hilke , Alex Williamson Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Alex Williamson 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. Assisted-by: Claude:claude-opus-4-7 Signed-off-by: Alex Williamson Reviewed-by: David Matlack Acked-by: David Matlack --- .../vfio/lib/include/libvfio/vfio_pci_device.h | 14 ++++++++++++++ tools/testing/selftests/vfio/lib/vfio_pci_device.c | 22 ++++++++++++++++++= ++++ 2 files changed, 36 insertions(+) diff --git a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_devi= ce.h b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h index 59acef381d05..89a039ab3075 100644 --- a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h +++ b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h @@ -84,6 +84,8 @@ static inline void vfio_pci_cmd_clear(struct vfio_pci_dev= ice *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 v= ector); =20 static inline void fcntl_set_nonblock(int fd) @@ -108,6 +110,12 @@ static inline void vfio_pci_msi_disable(struct vfio_pc= i_device *device) vfio_pci_irq_disable(device, VFIO_PCI_MSI_IRQ_INDEX); } =20 +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_p= ci_device *device) vfio_pci_irq_disable(device, VFIO_PCI_MSIX_IRQ_INDEX); } =20 +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, i= ova_t *iova) { return __iommu_hva2iova(device->iommu, vaddr, iova); diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/tes= ting/selftests/vfio/lib/vfio_pci_device.c index 28868343f2ab..65a4fffb480c 100644 --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c @@ -105,6 +105,28 @@ void vfio_pci_irq_disable(struct vfio_pci_device *devi= ce, u32 index) vfio_pci_irq_set(device, index, 0, 0, NULL); } =20 +/* + * 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 =3D 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 + vec= tor); +} + static void vfio_pci_irq_get(struct vfio_pci_device *device, u32 index, struct vfio_irq_info *irq_info) { --=20 2.55.0.571.g244d577d93-goog From nobody Fri Oct 2 05:30:33 2026 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 650A9361940 for ; Wed, 5 Aug 2026 00:21:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785889267; cv=none; b=HRaICEJ2noDBV/fI2uIyj2W3/CjVEuqkjv7F9hA2tfx+iJoRoHfge6IW0ay7wDqzCWgZfS+IZHNOHq/3Pb0FdXsWSQh0hFKyGYMLzK+r9Gbzp5EFu1WCO1XPtSfyNQ5uG7b7gh/mZCp7p5GwsF6rVBLJVfgYwMxIoNX8j5ayniQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785889267; c=relaxed/simple; bh=T71iOqyVmFY/MGsmZht8xB3dYyQ3zRiPgT9cXGe6XUQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JLTFsd3SAIIlimEgPWkAahSEolpyU1rZ3+09oV+d/QfgfHXzUP0JgpL3drUu0Ho2j0yw5X+CVuJcdbUcNNOOhwlJJPtljWQ4ffJRKKAtR55K9r2UOgee9+sYaTWxLTzMMvJxrQO+FfJdvPykH5BYFE/mOgWlk9myPUFGgJUS3qc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jrhilke.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=PALQ+z03; arc=none smtp.client-ip=209.85.216.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jrhilke.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PALQ+z03" Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-38ecc48b3c2so516160a91.1 for ; Tue, 04 Aug 2026 17:21:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785889265; x=1786494065; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=kQa1LdCTelcrIgQEyZfGOjiJ3/AvuOT6kbHPsy1D0H8=; b=PALQ+z03Oe9r91Pw2rX/RlD+G11yuwSeErClaF+5OzUFJVIW7a92AGxlQFiWK1rFl5 1GHEjTCBRqWCTQJFpBSm5A14iyIxISNsUuH//rFix5Rb6/dRhg1qR5o87M0nwXMlHPZ0 koHPy13/HFDyM6Vo5WWGWHhGJ190okXoxclZsaxFpnJ0vAAppJWCDoScPat3vF4r4zsd HgpxnejdQQPbo5wIR1X0sHlgBI57K3+lLb7cLTOiHT6ScdcDu3Yp0PZBeb0jGj5jRjhg XitYozG86Pbw4UZx9zI4O2EHBi2plzF4le7znXYGyHzeUf73vGIlGTd/eqTqovyIXkQ2 RiJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785889265; x=1786494065; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=kQa1LdCTelcrIgQEyZfGOjiJ3/AvuOT6kbHPsy1D0H8=; b=XdBICqGSssT7MIRfJXd6a5s+X3VSSxqHOlsky1lVTZpiyj1Qea73Ue6/v9lgh6mXzi 34KYy7i8hy2Gdhkw4/0DewsQJlfZ0lKhqs9DqUeJdpOZKJrsRmBdTshD2YZPb6sPS86Q la7jIIcmW/XvFkKNBsxwV3ATkFLFjQTg+8Wo17XJqtbqus6XsYlm6wLkKo0Nyy2Vxx/g 4k7MvHKyplBarzATof227el1gmnuOoBd5w6x9pgNhKmlPlCiTzlg7FY18nyQ2l9R4ZSR y5uF4Jfw67j8PB1YNeYuy/cWQ/v/dD1+WehJzeXK8YjwN5RcnT7hltc0Nv5X88a3hUQH JzQg== X-Forwarded-Encrypted: i=1; AHgh+Rqieeulo1mvjWOEL+OI4nXfsYr0/jQn2NrwLndUbNbght+5fQzb/0eAQvAnA7WCTNDCR2BhwmVE55i1qaY=@vger.kernel.org X-Gm-Message-State: AOJu0YycrGb+2N7fVJaUB82oYHyBEWNCKyrQCm24VgFxyaXYO1acpTs7 hEloj6xVhi0Cju0VF6Tefiu3NMnVjQcfGvAKIULcKq3PU4LTsszsJsubrj4t+T5bnINafLB5e9Z AUSa7ZaQU X-Received: from pjij10.prod.google.com ([2002:a17:90a:588a:b0:38e:a556:bb27]) (user=jrhilke job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2245:b0:36b:bec8:94c5 with SMTP id 98e67ed59e1d1-3903c5a6abbmr1882084a91.10.1785889264240; Tue, 04 Aug 2026 17:21:04 -0700 (PDT) Date: Wed, 05 Aug 2026 00:20:59 +0000 In-Reply-To: <20260805-igb_v3_b4-v10-0-9c86dc849c0d@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260805-igb_v3_b4-v10-0-9c86dc849c0d@google.com> X-Developer-Key: i=jrhilke@google.com; a=ed25519; pk=cK+Urrh214DoCHywJiTwhMP+zcs1ofpGrewToO/i/3A= X-Developer-Signature: v=1; a=ed25519-sha256; t=1785889261; l=25046; i=jrhilke@google.com; s=20260710; h=from:subject:message-id; bh=T71iOqyVmFY/MGsmZht8xB3dYyQ3zRiPgT9cXGe6XUQ=; b=Eqw7ao1XyvKN8LTq15oc+x9E3C4C4BswluaXkB66xtCCficTNr03IpmxZ3o99/pGgVS8k+XIJ zQzCDZcCoQcC15u62lvH8E86GDp/ORYfUzeNU63A3BmStkFCMtx/f2N X-Mailer: b4 0.14.3 Message-ID: <20260805-igb_v3_b4-v10-2-9c86dc849c0d@google.com> Subject: [PATCH v10 2/3] vfio: selftests: igb: Add driver for Intel 82576 device From: Josh Hilke To: David Matlack , Alex Williamson Cc: Shuah Khan , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma , Josh Hilke , Alex Williamson Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Add 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=3D"-M q35,accel=3Dkvm,kernel-irqchip=3Dsplit" \ --qemu-opts=3D"-device intel-iommu,intremap=3Don,caching-mode=3Don,device-i= otlb=3Don" \ --qemu-opts=3D"-netdev user,id=3Dnet0 -device igb,netdev=3Dnet0,addr=3D09.0= " \ --append "console=3DttyS0 earlyprintk=3DttyS0 intel_iommu=3Don iommu=3Dpt" \ --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/v= fio/vfio_pci_driver_test" Assisted-by: Claude:claude-opus-4-7 Assisted-by: Gemini:gemini-3.1-pro-preview Co-developed-by: Alex Williamson Signed-off-by: Alex Williamson Signed-off-by: Josh Hilke Acked-by: David Matlack --- .../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(-) diff --git a/tools/testing/selftests/vfio/lib/drivers/igb/e1000_82575.h b/t= ools/testing/selftests/vfio/lib/drivers/igb/e1000_82575.h new file mode 120000 index 000000000000..b84affdec559 --- /dev/null +++ b/tools/testing/selftests/vfio/lib/drivers/igb/e1000_82575.h @@ -0,0 +1 @@ +../../../../../../../drivers/net/ethernet/intel/igb/e1000_82575.h \ No newline at end of file diff --git a/tools/testing/selftests/vfio/lib/drivers/igb/e1000_defines.h b= /tools/testing/selftests/vfio/lib/drivers/igb/e1000_defines.h new file mode 120000 index 000000000000..9f97f4330086 --- /dev/null +++ b/tools/testing/selftests/vfio/lib/drivers/igb/e1000_defines.h @@ -0,0 +1 @@ +../../../../../../../drivers/net/ethernet/intel/igb/e1000_defines.h \ No newline at end of file diff --git a/tools/testing/selftests/vfio/lib/drivers/igb/e1000_regs.h b/to= ols/testing/selftests/vfio/lib/drivers/igb/e1000_regs.h new file mode 120000 index 000000000000..c733634171bb --- /dev/null +++ b/tools/testing/selftests/vfio/lib/drivers/igb/e1000_regs.h @@ -0,0 +1 @@ +../../../../../../../drivers/net/ethernet/intel/igb/e1000_regs.h \ No newline at end of file diff --git a/tools/testing/selftests/vfio/lib/drivers/igb/igb.c b/tools/tes= ting/selftests/vfio/lib/drivers/igb/igb.c new file mode 100644 index 000000000000..fd9e05d77ea4 --- /dev/null +++ b/tools/testing/selftests/vfio/lib/drivers/igb/igb.c @@ -0,0 +1,585 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "e1000_regs.h" +#include "e1000_defines.h" +#include "e1000_82575.h" + +#define PCI_DEVICE_ID_INTEL_82576 0x10C9 +#define IGB_MAX_CHUNK_SIZE 1024 +#define MSIX_VECTOR 0 +#define MSIX_VECTOR_MASK (1 << MSIX_VECTOR) +#define RING_SIZE 4096 /* Number of descriptors in ring */ + +struct igb_tx_desc { + union { + struct { + u64 buffer_addr; /* Address of descriptor's data buffer */ + u32 cmd_type_len; /* Command/Type/Length */ + u32 olinfo_status; /* Context/Buffer info */ + } read; + + struct { + u64 rsvd; /* Reserved */ + u32 nxtseq_seed; /* Next sequence seed */ + u32 status; /* Descriptor status */ + } wb; + }; +}; + +struct igb_rx_desc { + union { + struct { + u64 pkt_addr; /* Packet buffer address */ + u64 hdr_addr; /* Header buffer address */ + } read; + struct { + u16 pkt_info; /* RSS type, Packet type */ + u16 hdr_info; /* Split Head, buf len */ + u32 rss; /* RSS Hash */ + u32 status_error; /* ext status/error */ + u16 length; /* Packet length */ + u16 vlan; /* VLAN tag */ + } wb; /* writeback */ + }; +}; + +struct igb { + void *bar0; + u32 tx_tail; + u32 rx_tail; + struct igb_tx_desc tx_ring[RING_SIZE] __attribute__((aligned(128))); + struct igb_rx_desc rx_ring[RING_SIZE] __attribute__((aligned(128))); +}; + +static inline struct igb *to_igb_state(struct vfio_pci_device *device) +{ + return (struct igb *)device->driver.region.vaddr; +} + +static inline void igb_write32(struct igb *igb, u32 reg, u32 val) +{ + writel(val, igb->bar0 + reg); +} + +static inline u32 igb_read32(struct igb *igb, u32 reg) +{ + return readl(igb->bar0 + reg); +} + +static int igb_write_phy(struct igb *igb, u32 offset, u16 data) +{ + u32 mdic; + int i; + + /* + * Write a PHY register over MDIO. + * + * A production driver would hold the SW/FW semaphore (SWSM.SWESMBI + the + * SW_FW_SYNC PHY bit) across the MDIO transaction to serialize against t= he + * device's management firmware. The selftest owns the assigned function + * exclusively on a dedicated test device with no active manageability + * contending for the PHY, so the sync is omitted; it should be added here + * if this ever needs to run on a manageability-enabled NIC. + */ + mdic =3D (((u32)data) | + (offset << E1000_MDIC_REG_SHIFT) | + (1 << E1000_MDIC_PHY_SHIFT) | + E1000_MDIC_OP_WRITE); + + igb_write32(igb, E1000_MDIC, mdic); + + for (i =3D 0; i < 1000; i++) { + usleep(50); + mdic =3D igb_read32(igb, E1000_MDIC); + if (mdic & E1000_MDIC_READY) + break; + } + + if (!(mdic & E1000_MDIC_READY)) + return -1; + + if (mdic & E1000_MDIC_ERROR) + return -1; + + return 0; +} + +/* + * Configure the device for PHY internal loopback per 82576 datasheet + * section 3.5.6.3.1. Force the PHY to 1Gb/s full duplex with loopback + * enabled, then force the MAC link state to match. Internal loopback + * wraps data at the end of the PHY datapath (section 3.5.6.3), so the + * physical link state is irrelevant. + * + * Section 3.5.6.1 directs to "Use PHY Loopback instead of MAC Loopback + * on the 82576", and section 3.5.6.2 states "MAC Loopback is not used + * on this device." RCTL.LBM_MAC is still set elsewhere as a QEMU-only + * accommodation; see the RCTL programming in the caller for the + * rationale. + */ +static void igb_setup_loopback(struct igb *igb) +{ + u32 ctrl; + int ret; + + /* + * Kick the autoneg machinery solely to bring STATUS.LU up under + * QEMU's igb emulation: QEMU only updates STATUS.LU via its + * autoneg-done timer, and without LU set its receive path + * (e1000x_hw_rx_enabled) drops every loopback frame. On real + * hardware autoneg cannot complete before the next PHY write + * below clears the autoneg-enable bit, so this is effectively a + * no-op there. + */ + (void)igb_write_phy(igb, MII_BMCR, + BMCR_ANENABLE | BMCR_ANRESTART); + + /* PHY control: loopback + 1Gb/s full duplex, autoneg disabled. */ + ret =3D igb_write_phy(igb, MII_BMCR, + BMCR_LOOPBACK | + BMCR_SPEED1000 | + BMCR_FULLDPLX); + VFIO_ASSERT_EQ(ret, 0, "Failed to write PHY control register"); + + /* + * Brief delay before forcing the MAC, mirroring the kernel ethtool + * selftest in igb_integrated_phy_loopback(). Not specified by the + * datasheet, but empirically required by the kernel driver. + */ + usleep(50000); + + /* + * Force the MAC to 1Gb/s full duplex with link up. Without forcing + * the link state the descriptor engine does not run, since the chip + * normally waits for a real negotiated link. + */ + ctrl =3D igb_read32(igb, E1000_CTRL); + ctrl &=3D ~E1000_CTRL_SPD_SEL; + ctrl |=3D E1000_CTRL_FRCSPD | + E1000_CTRL_FRCDPX | + E1000_CTRL_SPD_1000 | + E1000_CTRL_FD | + E1000_CTRL_SLU; + igb_write32(igb, E1000_CTRL, ctrl); + + /* + * Settling delay matching the kernel ethtool selftest's msleep(500) + * at the tail of igb_integrated_phy_loopback(). Not specified by + * the datasheet; empirical, and inherited from the kernel driver. + */ + usleep(500000); +} + +static int igb_probe(struct vfio_pci_device *device) +{ + if (!vfio_pci_device_match(device, PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INT= EL_82576)) + return -EINVAL; + + return 0; +} + +static void igb_reset(struct igb *igb) +{ + int retries =3D 20; + + igb_write32(igb, E1000_CTRL, igb_read32(igb, E1000_CTRL) | E1000_CTRL_RST= ); + /* + * Must wait at least 1 millisecond after setting the reset bit before + * checking if this device is ready to be used (82576 datasheet section + * 4.2.1.6.1). The delay also ensures the reset has taken effect and + * cleared EECD.AUTO_RD before it is polled below. + */ + usleep(1000); + + /* + * Poll NVM Auto Read Done rather than CTRL.RST, matching + * igb_get_auto_rd_done() in the igb driver: AUTO_RD implies both that + * the reset completed and that the device finished re-reading its + * configuration from NVM, which is what actually makes it usable. + */ + while (retries-- > 0 && !(igb_read32(igb, E1000_EECD) & E1000_EECD_AUTO_R= D)) + usleep(1000); + + /* + * QEMU's igb emulation does not set E1000_EECD_AUTO_RD. If we timed out, + * check if CTRL.RST is cleared, which is what QEMU uses to signal reset + * completion. + */ + if (retries < 0) { + VFIO_ASSERT_EQ(igb_read32(igb, E1000_CTRL) & E1000_CTRL_RST, 0, + "Device reset did not complete (CTRL.RST not cleared)"); + } + + igb_write32(igb, E1000_IMC, 0xFFFFFFFF); +} + +/* + * Program the device into a usable state. Split out of igb_init() so it + * can be reused after a device reset to re-program the registers that + * CTRL.RST clears. Expects bar0 to be mapped and MSI-X already enabled + * via VFIO. + */ +static void igb_hw_init(struct vfio_pci_device *device) +{ + struct igb *igb =3D to_igb_state(device); + u64 iova_tx, iova_rx; + u32 ctrl, rctl; + u16 cmd_reg; + int retries; + + iova_tx =3D to_iova(device, igb->tx_ring); + iova_rx =3D to_iova(device, igb->rx_ring); + + + + /* Signal that the driver is loaded */ + ctrl =3D igb_read32(igb, E1000_CTRL_EXT); + ctrl |=3D E1000_CTRL_EXT_DRV_LOAD; + ctrl &=3D ~E1000_CTRL_EXT_LINK_MODE_MASK; + igb_write32(igb, E1000_CTRL_EXT, ctrl); + + /* Enable PCI Bus Master. */ + cmd_reg =3D vfio_pci_config_readw(device, PCI_COMMAND); + if ((cmd_reg & (PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY)) !=3D + (PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY)) { + cmd_reg |=3D (PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY); + vfio_pci_config_writew(device, PCI_COMMAND, cmd_reg); + } + + /* Configure PHY internal loopback for testing. */ + igb_setup_loopback(igb); + + /* + * Disable DMA re-send on PCIe completion timeout (82576 datasheet + * section 8.6.1, GCR.Completion_Timeout_Resend, bit 16). The + * mix_and_match test intentionally submits descriptors targeting + * unmapped IOVAs; with the default (set) value, the device keeps + * retrying the failed read indefinitely, which keeps PCIe AER and + * IOMMU error handling busy and interferes with reset recovery. + */ + ctrl =3D igb_read32(igb, E1000_GCR); + ctrl &=3D ~E1000_GCR_CMPL_TMOUT_RESEND; + igb_write32(igb, E1000_GCR, ctrl); + + /* Configure TX and RX descriptor rings */ + igb_write32(igb, E1000_TDBAL(0), (u32)iova_tx); + igb_write32(igb, E1000_TDBAH(0), (u32)(iova_tx >> 32)); + igb_write32(igb, E1000_TDLEN(0), RING_SIZE * sizeof(struct igb_tx_desc)); + igb_write32(igb, E1000_TDH(0), 0); + igb_write32(igb, E1000_TDT(0), 0); + igb_write32(igb, E1000_TXDCTL(0), E1000_TXDCTL_QUEUE_ENABLE); + + igb_write32(igb, E1000_RDBAL(0), (u32)iova_rx); + igb_write32(igb, E1000_RDBAH(0), (u32)(iova_rx >> 32)); + igb_write32(igb, E1000_RDLEN(0), RING_SIZE * sizeof(struct igb_rx_desc)); + igb_write32(igb, E1000_RDH(0), 0); + igb_write32(igb, E1000_RDT(0), 0); + + /* + * Select the advanced one-buffer descriptor format. Per 82576 + * datasheet section 7.1.5.2: "SRRCTL[n].DESCTYPE must be set to a + * value other than 000b for the 82576 to write back the special + * descriptors." struct igb_rx_desc matches the advanced one-buffer + * writeback layout (section 7.1.5.2), so polling rx.wb.status_error + * requires this format. Section 8.10.2 specifies DESCTYPE[27:25]. + * + * The direct write also zeroes SRRCTL.BSIZEPACKET, which is + * intentional: per section 7.1.3.1 a zero BSIZEPACKET falls back to + * the RCTL.BSIZE buffer size, whose reset default (00b) is 2048 + * bytes -- ample for the loopback frames here. + */ + igb_write32(igb, E1000_SRRCTL(0), E1000_SRRCTL_DESCTYPE_ADV_ONEBUF); + + igb_write32(igb, E1000_RXDCTL(0), E1000_RXDCTL_QUEUE_ENABLE); + + /* + * Enable Receiver and Transmitter. RCTL.LBM_MAC is set in addition + * to PHY loopback as a QEMU-only accommodation: QEMU's emulated igb + * does not honor PHY register 0 bit 14 (PHY internal loopback) and + * relies on RCTL.LBM_MAC to wrap TX descriptors back to the RX + * queue. Datasheet 8.10.1 (RCTL register) advises "When using the + * internal PHY, LBM should remain set to 00b", so setting LBM_MAC + * here deviates from datasheet guidance; empirically the bit has + * no observable effect on real 82576 hardware because MAC loopback + * is not implemented (datasheet 3.5.6.2). Setting both lets the + * selftest work on both real hardware and QEMU without conditional + * code paths. + */ + rctl =3D E1000_RCTL_EN | /* Receiver Enable */ + E1000_RCTL_UPE | /* Unicast Promiscuous (for dummy MAC) */ + E1000_RCTL_MPE | /* Multicast Promiscuous */ + E1000_RCTL_BAM | /* Broadcast Accept Mode */ + E1000_RCTL_LBM_MAC | /* MAC Loopback - for QEMU emulation only */ + E1000_RCTL_SECRC; /* Strip CRC (needed for memcmp) */ + igb_write32(igb, E1000_RCTL, rctl); + igb_write32(igb, E1000_TCTL, E1000_TCTL_EN | E1000_TCTL_PSP); + + /* + * Wait for TX and RX queues to be enabled. Per the RXDCTL/TXDCTL + * register definitions (8.10.10/8.12.13), the per-queue enable bit + * "remains zero" until the global RCTL.RXEN/TCTL.TXEN are set, so + * E1000_RCTL_EN and E1000_TCTL_EN must already be written above. + */ + retries =3D 2000; + while (retries-- > 0) { + if ((igb_read32(igb, E1000_TXDCTL(0)) & E1000_TXDCTL_QUEUE_ENABLE) && + (igb_read32(igb, E1000_RXDCTL(0)) & E1000_RXDCTL_QUEUE_ENABLE)) + break; + usleep(10); + } + VFIO_ASSERT_GE(retries, 0); + + /* + * Program MSI-X interrupt routing per 82576 datasheet: + * + * GPIE (section 7.3.2.11, Table 7-47): set Multiple_MSIX (bit 4) to + * route interrupt causes through IVAR mapping, and EIAME (bit 30) + * to apply EIAM on MSI-X assertion (without EIAME, EIAM only + * applies on EICR read/write). + * + * EIAC (section 8.8.5): enable auto-clear of EICR for vector 0. + * Without auto-clear the cause stays set after delivery and the + * test can see spurious interrupts on the next memcpy batch. + * + * EIAM (section 8.8.6): enable auto-mask of EIMS for vector 0 on + * MSI-X assertion (effective because EIAME is set). + * + * IVAR (section 7.3.1.2, register definition in 8.8.13): map RX + * cause 0 to MSI-X vector 0 and mark the entry valid. + */ + igb_write32(igb, E1000_GPIE, E1000_GPIE_MSIX_MODE | E1000_GPIE_EIAME); + igb_write32(igb, E1000_EIAC, MSIX_VECTOR_MASK); + igb_write32(igb, E1000_EIAM, MSIX_VECTOR_MASK); + + /* Map vector 0 to interrupt cause 0 and mark it valid */ + igb_write32(igb, E1000_IVAR0, E1000_IVAR_VALID); + + /* Enable interrupts on vector 0 */ + igb_write32(igb, E1000_EIMS, MSIX_VECTOR_MASK); + + /* Initialize driver state and capability limits */ + igb->tx_tail =3D 0; + igb->rx_tail =3D 0; + + device->driver.max_memcpy_size =3D IGB_MAX_CHUNK_SIZE; + device->driver.max_memcpy_count =3D RING_SIZE - 1; + device->driver.msi =3D MSIX_VECTOR; +} + +static void igb_init(struct vfio_pci_device *device) +{ + struct igb *igb =3D to_igb_state(device); + + VFIO_ASSERT_GE(device->driver.region.size, sizeof(struct igb)); + + igb->bar0 =3D device->bars[0].vaddr; + + igb_reset(igb); + + /* + * Enable MSI-X via VFIO before device-side register programming. + * vfio_pci_msix_enable() only touches the VFIO IRQ machinery and the + * PCI MSI-X capability via config space; it has no ordering + * dependency on the device-side writes performed by igb_hw_init(). + * Placing it here keeps igb_hw_init() reusable from the reset + * recovery path (which calls vfio_pci_irq_reenable() instead). + */ + vfio_pci_msix_enable(device, MSIX_VECTOR, 1); + + igb_hw_init(device); +} + +static void igb_remove(struct vfio_pci_device *device) +{ + struct igb *igb =3D to_igb_state(device); + + igb_write32(igb, E1000_RCTL, 0); + igb_write32(igb, E1000_TCTL, 0); + igb_reset(igb); + + vfio_pci_msix_disable(device); +} + +static void igb_irq_disable(struct igb *igb) +{ + igb_write32(igb, E1000_EIMC, MSIX_VECTOR_MASK); +} + +static void igb_irq_enable(struct igb *igb) +{ + igb_write32(igb, E1000_EIMS, MSIX_VECTOR_MASK); +} + +static void igb_irq_clear(struct igb *igb) +{ + /* + * Use write-to-clear (datasheet 7.3.4.2). In MSI-X mode with EIAC + * programmed, section 8.8.5 explicitly states "If any bits are set + * in EIAC, the EICR register should not be read", which rules out + * the read-to-clear path in 7.3.4.3. Bits not in EIAC are still + * cleared by writing 1. + */ + igb_write32(igb, E1000_EICR, 0xFFFFFFFF); +} + +static void igb_memcpy_start(struct vfio_pci_device *device, iova_t src, + iova_t dst, u64 size, u64 count) +{ + struct igb *igb =3D to_igb_state(device); + struct igb_rx_desc *rx; + struct igb_tx_desc *tx; + u32 i; + + VFIO_ASSERT_GE(size, 60, + "IGB driver requires memcpy size to be at least 60 bytes (Etherne= t minimum payload size)"); + + igb_irq_disable(igb); + + for (i =3D 0; i < count; i++) { + tx =3D &igb->tx_ring[igb->tx_tail]; + rx =3D &igb->rx_ring[igb->rx_tail]; + + memset(tx, 0, sizeof(struct igb_tx_desc)); + memset(rx, 0, sizeof(struct igb_rx_desc)); + + rx->read.pkt_addr =3D cpu_to_le64(dst); + rx->read.hdr_addr =3D cpu_to_le64(0); + + tx->read.buffer_addr =3D cpu_to_le64(src); + /* + * Build an advanced data descriptor per 82576 datasheet + * section 7.2.2.3. DEXT marks the descriptor as advanced + * (required by hardware); DTYP=3Ddata selects the data + * descriptor; IFCS asks the MAC to append the Ethernet + * FCS (without it the frame is dropped as malformed); + * EOP marks end of packet. DTALEN is the buffer length + * in bits 15:0 of cmd_type_len. + */ + tx->read.cmd_type_len =3D cpu_to_le32((uint32_t)size | + E1000_ADVTXD_DTYP_DATA | + E1000_ADVTXD_DCMD_DEXT | + E1000_ADVTXD_DCMD_IFCS | + E1000_ADVTXD_DCMD_EOP); + /* + * PAYLEN (section 7.2.2.3.11) is the total payload size + * in olinfo_status[31:14]. + */ + tx->read.olinfo_status =3D + cpu_to_le32((uint32_t)size << E1000_ADVTXD_PAYLEN_SHIFT); + + igb->tx_tail =3D (igb->tx_tail + 1) % RING_SIZE; + igb->rx_tail =3D (igb->rx_tail + 1) % RING_SIZE; + } + + igb_write32(igb, E1000_RDT(0), igb->rx_tail); + igb_write32(igb, E1000_TDT(0), igb->tx_tail); +} + +/* + * Reset the device via VFIO_DEVICE_RESET (PCIe FLR on the 82576) and + * re-program it. VFIO_DEVICE_RESET tears down the kernel-side MSI-X + * trigger but leaves user-side eventfds intact, so re-arm the trigger + * via vfio_pci_irq_reenable() before reprogramming so any caller-cached + * eventfd remains valid. + * + * FLR clears device-side state to power-on reset values (datasheet + * 4.2.1.5.1: a PF FLR is "equivalent to a D0->D3->D0 transition"), so + * EIMS and EICR come back as 0 from their register-defined initial + * values, and igb_hw_init() resets tx_tail/rx_tail to 0. The next + * igb_memcpy_start() will memset each descriptor it touches before + * submission, so no explicit IMC/EICR writes or ring memsets are + * needed here. + */ +static void igb_error_reset_and_reinit(struct vfio_pci_device *device) +{ + vfio_pci_device_reset(device); + vfio_pci_msix_reenable(device, MSIX_VECTOR, 1); + igb_hw_init(device); +} + +static int igb_memcpy_wait(struct vfio_pci_device *device) +{ + struct igb *igb =3D to_igb_state(device); + struct igb_rx_desc *rx; + u32 status =3D 0; + u32 prev_tail; + int retries; + + prev_tail =3D (igb->rx_tail + RING_SIZE - 1) % RING_SIZE; + rx =3D &igb->rx_ring[prev_tail]; + + /* + * Real 82576 hardware processes the descriptor ring at line rate. + * max_memcpy_size =3D (RING_SIZE - 1) * IGB_MAX_CHUNK_SIZE ~=3D 4 MB, + * split into 4095 1 KB frames. At 1 Gb/s (~125 MB/s) the worst + * valid memcpy takes ~32 ms on the wire, plus per-frame preamble, + * SFD, IFG and FCS overhead (~3%) and descriptor fetch/writeback + * latency. Wait up to ~200 ms before declaring the device hung; + * ~6x the line-rate floor leaves comfortable headroom for host + * scheduling jitter while keeping the intentional invalid-DMA + * tests bounded. + */ + retries =3D 200; + while (retries-- > 0) { + status =3D le32_to_cpu(READ_ONCE(rx->wb.status_error)); + if (status & 1) + break; + usleep(1000); + } + + if (status & 1) + /* + * Ensure the test code doesn't speculatively read the DMA + * destination buffer before we have verified that the + * descriptor writeback is complete. + */ + rmb(); + + igb_irq_clear(igb); + + igb_irq_enable(igb); + + if (status & 1) + return 0; + + /* + * The descriptor never completed. On real 82576 hardware this + * typically follows a DMA-read fault from one of the intentional + * unmapped-IOVA tests; the fault leaves the descriptor engine + * unable to service subsequent valid descriptors. CTRL.RST alone + * reinitializes the queue registers but leaves the engine wedged + * for the current process, so a broader VFIO_DEVICE_RESET (FLR) + * is required. + */ + igb_error_reset_and_reinit(device); + + return -ETIMEDOUT; +} + +static void igb_send_msi(struct vfio_pci_device *device) +{ + struct igb *igb =3D to_igb_state(device); + + igb_write32(igb, E1000_EICS, MSIX_VECTOR_MASK); +} + +const struct vfio_pci_driver_ops igb_ops =3D { + .name =3D "igb", + .probe =3D igb_probe, + .init =3D igb_init, + .remove =3D igb_remove, + .memcpy_start =3D igb_memcpy_start, + .memcpy_wait =3D igb_memcpy_wait, + .send_msi =3D igb_send_msi, +}; diff --git a/tools/testing/selftests/vfio/lib/libvfio.mk b/tools/testing/se= lftests/vfio/lib/libvfio.mk index 82132b648744..bcfa74ae040e 100644 --- a/tools/testing/selftests/vfio/lib/libvfio.mk +++ b/tools/testing/selftests/vfio/lib/libvfio.mk @@ -16,6 +16,7 @@ LIBVFIO_C +=3D drivers/dsa/dsa.c endif =20 LIBVFIO_C +=3D drivers/nv_falcon/nv_falcon.c +LIBVFIO_C +=3D drivers/igb/igb.c =20 LIBVFIO_OUTPUT :=3D $(OUTPUT)/libvfio =20 diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_driver.c b/tools/tes= ting/selftests/vfio/lib/vfio_pci_driver.c index 153bf4a7a19f..5e65434d2318 100644 --- a/tools/testing/selftests/vfio/lib/vfio_pci_driver.c +++ b/tools/testing/selftests/vfio/lib/vfio_pci_driver.c @@ -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; =20 static struct vfio_pci_driver_ops *driver_ops[] =3D { #ifdef __x86_64__ @@ -15,6 +15,7 @@ static struct vfio_pci_driver_ops *driver_ops[] =3D { &ioat_ops, #endif &nv_falcon_ops, + &igb_ops, }; =20 void vfio_pci_driver_probe(struct vfio_pci_device *device) --=20 2.55.0.571.g244d577d93-goog From nobody Fri Oct 2 05:30:33 2026 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B5EE3672B0 for ; Wed, 5 Aug 2026 00:21:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785889269; cv=none; b=BK3292R2G04gO/u6hWClfQtJq3hdd0RYJpNOJPNOO3hRxIGTTas946t6crP8Zl3Q2stj4C6t2JMdfkPaoQs4OS4/IBMJaq49/QVyn+BwyOTv3Yp8hJWf82o3NjoJv13wN36HuEds8Cps8KoyMUKJfAGoA9DmW4r4TvnON5c1jB0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785889269; c=relaxed/simple; bh=PaA5xATJY2tarwGeOfuU6ZPqAxPaqiRO99xxmsojGYU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=obFAiIa4B08TeJ+8FdKUuFXgqMOyJh4tm30jgr98gdFGdAYTSUUKYNino1Da1RIX9rBYW5T0jF2kvEV4QFcpQPAf/2+ZeB5uZfyezicKVQqPq1E698kXBl1D8xIOgywWM+Tu/Mzc3fC1wUIDItRqHVgi13P1Hq7nQ4clB64uR2Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jrhilke.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=MXsQwzJo; arc=none smtp.client-ip=209.85.215.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jrhilke.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MXsQwzJo" Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-cb11535e6a1so292828a12.0 for ; Tue, 04 Aug 2026 17:21:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785889265; x=1786494065; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=0WzAE8+0oSntfgPoTyIg9F5/lTZKO08wQsoVqeitm2o=; b=MXsQwzJoUduA5mbQgG5IBkMD/ELiL8fmyeh1bAqV2z+xBcMVuiAFTWti5hTW4lPlGU P7nUdZ9Mdyls+I8BOlpWVB4Gr2ibKjfWr8AnAunqEred8NwEli0QIkcIbAcDTLR++23o Bk1yK3yWV9W3MiHIeX5jvAz2QwjPLm1Ylc/wQoRjNrmrSEgiXbPdiuWvK7X9+Gux/VxH mDEgBLapZAULBJleOZ3CGDi68MQlI1KxmrusMGKFXfjG8ZmwWxIgpoDRHFeHi4eBmH60 jAhocwjbPE/hIXDXaL6EaUOLGVm/qUWnVwHT2W8UV7IWdhNctrAntRtNXuwVwECHKimm +ySA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785889265; x=1786494065; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=0WzAE8+0oSntfgPoTyIg9F5/lTZKO08wQsoVqeitm2o=; b=OMc39q5dXtI2hAeOCB5wQx1hh8QzeCsc2yIqxC3ajE8es/p6NMmuy4xBiou9380I8V R8Lp8zC0jRwXvbvkEorHITvY5UhslqieHPdNGUBp284GvZG2/ALpi4KpatUykVv7elSu Akq57hbWaZa/j0HBkPG5LI2awgzrY/6d4BqaUDmoVjNsdZL+V/GIns+Xu+dAjv4BgjJV LRUrqJhsCHMQN5Bh/d92NhMuIM+6ItDngl5Qu0uIB/7HCrnSZjoqOeCMfizpHI1ztCBJ sIDc7OPPeh7pyOHA3TkKNv51lZdM24gAc6MABHzi5QrZo4ts134CBHx4r6UscmrmePbz 1ybA== X-Forwarded-Encrypted: i=1; AHgh+RppdIRyKrWJgegBe6MWut57vlb1wQyS9xQnS7/PDYl21fdHmPbsPK9oeZkkKcDcWZvZvIxCj80qjMEtAms=@vger.kernel.org X-Gm-Message-State: AOJu0Yxwsyzna6oRKqGh+ETmlbqrSMsHot45TCkosrZv6ICkaU5lBgKq oYYOJJsv4WHJf8DnVDkX3pwnQPSe1Yx/8FGxgMuXnhaeFsWkthNcuBtErcKNgVxEoIk4u4Yg+5r fvnue2k99 X-Received: from pgig16.prod.google.com ([2002:a63:f410:0:b0:c92:11a5:bbce]) (user=jrhilke job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:329c:b0:3c3:8315:80b7 with SMTP id adf61e73a8af0-3cb85e9757amr2768382637.9.1785889265238; Tue, 04 Aug 2026 17:21:05 -0700 (PDT) Date: Wed, 05 Aug 2026 00:21:00 +0000 In-Reply-To: <20260805-igb_v3_b4-v10-0-9c86dc849c0d@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260805-igb_v3_b4-v10-0-9c86dc849c0d@google.com> X-Developer-Key: i=jrhilke@google.com; a=ed25519; pk=cK+Urrh214DoCHywJiTwhMP+zcs1ofpGrewToO/i/3A= X-Developer-Signature: v=1; a=ed25519-sha256; t=1785889261; l=2483; i=jrhilke@google.com; s=20260710; h=from:subject:message-id; bh=PaA5xATJY2tarwGeOfuU6ZPqAxPaqiRO99xxmsojGYU=; b=WQihD4RIUN91QasTX1wDfR2ED1EYJ6Vbpp52klVawbVUvTBINt/qIOwjZmtVwS32okKw9NzMD FCGOdcWDsjFDdDmS5r6eotUTc812uVG3XUSio8b3qDklhTcMvebhS9X X-Mailer: b4 0.14.3 Message-ID: <20260805-igb_v3_b4-v10-3-9c86dc849c0d@google.com> Subject: [PATCH v10 3/3] vfio: selftests: Retry on EAGAIN during device reset From: Josh Hilke To: David Matlack , Alex Williamson Cc: Shuah Khan , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma , Josh Hilke Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Add 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. Suggested-by: David Matlack Signed-off-by: Josh Hilke Acked-by: David Matlack --- .../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(-) diff --git a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_devi= ce.h b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h index 89a039ab3075..e19bd94b8dd2 100644 --- a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h +++ b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h @@ -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); =20 +int __vfio_pci_device_reset(struct vfio_pci_device *device); void vfio_pci_device_reset(struct vfio_pci_device *device); =20 void vfio_pci_config_access(struct vfio_pci_device *device, bool write, diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/tes= ting/selftests/vfio/lib/vfio_pci_device.c index 65a4fffb480c..4063a0e2b3df 100644 --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only #include +#include #include #include #include @@ -259,9 +260,26 @@ void vfio_pci_config_access(struct vfio_pci_device *de= vice, bool write, write ? "write to" : "read from", config); } =20 +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 =3D 20; + int r; + + do { + r =3D __vfio_pci_device_reset(device); + if (r =3D=3D -EAGAIN) + usleep(10000); + } while (r =3D=3D -EAGAIN && retries-- > 0); + + VFIO_ASSERT_EQ(r, 0, "ioctl(device->fd, VFIO_DEVICE_RESET) failed\n"); } =20 void vfio_pci_group_setup(struct vfio_pci_device *device, const char *bdf) --=20 2.55.0.571.g244d577d93-goog