From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (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 58E264432FF for ; Wed, 29 Jul 2026 22:27:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785364031; cv=none; b=EMDWCFUfY6rAS9ZXDdHVtmwQ3vwlCOko5O0we0Xp7apuRzljRb7LCCLDjmUjvcCDrpe7GvEunQfXh9s0hSqIg21dZCDWTa5eC0Zb7+FYvM5w9/MSNdUMPS7O2uA0SgSo1i8VePcHyzRHrI4iyb4GEP2tPbml6DiVNsnK7NZN0s4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785364031; c=relaxed/simple; bh=ublbwVHLjHuOf8bVYVmCdOrHqxq2uRZG3/nm81yew10=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GN5BkCo0x5hOJZO1wC3T7M4THnV5S+K6NT5CCdByznMDwoUf1uD+Ag1FZtlj3xvfH2KlTjyqLKFFW/SPv0XjqOeMN3HPH7kJrAYxJsmM2wayKTpcvmb09DJfKV7X+jDB5OEv9VaC45yOWbIOQUDeMrezB+ab6kZH8RDEzN9TBBQ= 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=CVqLRo4G; arc=none smtp.client-ip=209.85.210.197 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="CVqLRo4G" Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-84e3d575d6eso2622999b3a.3 for ; Wed, 29 Jul 2026 15:27:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785364028; x=1785968828; 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=Nlzv4T5EPdxCuqpzeUzIfaHaVhUbOQL/hylAagCwky0=; b=CVqLRo4GLRAPqwlM0iMzG+X2XF87j1Fk4A5GagzxbN7Oi80ncpeByHlaQ1VrpqtJeY nyLq7iRstApPbGR7lS2mGvbIbPkNaoAWfRIrfV33YF7i05xser5ZrnsaawP0AsZE+pSq iHcn7NNc1HADRBqlatOzvtL9+m4Hc8Q6EH0BI7ruWN6C+tH6f84w/ftT/KcmXSQ518C3 AX0C6jacnRHl5TQQK+Ndgr9qTf2H7S1/DfR7thA48QEUb+5d1QPC4OYEoiEPpWxW+MsF wOxTGYFP1mc+lwSg/PIX8aH9TsSMDpil1h19QevQtq422TwLM1Bi6Js9EGBbhz8NIMV6 h3hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785364028; x=1785968828; 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=Nlzv4T5EPdxCuqpzeUzIfaHaVhUbOQL/hylAagCwky0=; b=B/DiZhXOFlyLnWMno/LCzt//dJADpxUZ81FUxSVl8U8tMz+mPXOP/csB9SPMKobeGO Y1aIgUrZEgwDikZAZna+UgoNlReRkDjhEDbN8dDkC9ZkXvVW6nnd9zYc+u/n+OR/MVTm cKCzkk/tZgcumt5gQEO4dNmuD+woogPBT2PyWzxu+df9TnM8YDBKZ4nSiHogIHwdrckb 3AtggK8n+VQ+iAaOQV4ztl/BTNm3NXEEXfrYpGH6EkkXXAOtfcJLScAsILLtBU34UUap nD/oSLiJOgQWTC6TzncX0q0yuWnIFyGOmiLRoJknZYdCo5MKD7bJfdlqexuy1Fpw9Lnz A6bg== X-Forwarded-Encrypted: i=1; AHgh+Rq3GaBZXCFuOaQsr9Ltd/OgeAASaVh2RpgZBAa9L66rQ+U5VswNy1J9HttzwmeBw/nq/06piPdETvULtCs=@vger.kernel.org X-Gm-Message-State: AOJu0YwJHA9GFJQFcVX1zY+mFHOHTLWEhparvZoFzEzHpYm4iIP2dDgj jcLHrWiF9Sl6jwWABzCHwlBP+J9RBbTaSLjzQarWpMRGkpve0BoZn9QdmiG/sZd4MrLyLjN04gb 66fSm0FwE X-Received: from pfes15.prod.google.com ([2002:aa7:8d4f:0:b0:846:5d01:2319]) (user=jrhilke job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:3491:b0:84e:5e4:b9a2 with SMTP id d2e1a72fcca58-84ebc424a22mr152132b3a.36.1785364028454; Wed, 29 Jul 2026 15:27:08 -0700 (PDT) Date: Wed, 29 Jul 2026 22:26:58 +0000 In-Reply-To: <20260729-igb_v3_b4-v8-0-3ed236272b4e@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260729-igb_v3_b4-v8-0-3ed236272b4e@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=1785364025; l=4427; i=jrhilke@google.com; s=20260710; h=from:subject:message-id; bh=B6453uAm0x21xn2hczpE7cBMG1HF/KExFh4AJ1PCGzA=; b=jLx0sNOYJzSxbt9SSqJVUMG8VZvlF+cSD27JDsjw2JFZeP/BuufOxxvul+vBueCE57jH8/w+P etAQGF5Q8hkABHtEdmJmzXg9QMLC5qTNsROW9pC5cVouYiYwqkm6ivW X-Mailer: b4 0.14.3 Message-ID: <20260729-igb_v3_b4-v8-3-3ed236272b4e@google.com> Subject: [PATCH v8 3/6] 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" 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 --- .../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_device.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_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); diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/testing/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 *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) { -- 2.55.0.508.g3f0d502094-goog