Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: David Matlack <dmatlack@google.com>
To: Josh Hilke <jrhilke@google.com>
Cc: Alex Williamson <alex@shazbot.org>,
	Vipin Sharma <vipinsh@google.com>, Shuah Khan <shuah@kernel.org>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org,
	Alex Williamson <alex.williamson@nvidia.com>
Subject: Re: [PATCH v2 07/10] selftests/vfio: Add vfio_pci_irq_reenable() helper
Date: Mon, 6 Jul 2026 21:03:01 +0000	[thread overview]
Message-ID: <akwYBagw3pFsN0Mt@google.com> (raw)
In-Reply-To: <20260526235417.2058313-8-jrhilke@google.com>

On 2026-05-26 11:54 PM, Josh Hilke wrote:
> From: Alex Williamson <alex.williamson@nvidia.com>
> 
> 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().
> 
> Assisted-by: Claude:claude-opus-4-7
> Signed-off-by: Alex Williamson <alex.williamson@nvidia.com>
> ---
>  .../lib/include/libvfio/vfio_pci_device.h     |  2 ++
>  .../selftests/vfio/lib/vfio_pci_device.c      | 22 +++++++++++++++++++
>  2 files changed, 24 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 2858885a89bb..a362e2b2bfda 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
> @@ -68,6 +68,8 @@ void vfio_pci_config_access(struct vfio_pci_device *device, bool write,
>  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);

Let's add vfio_pci_msi{,x}_reenable() static inline wrappers below
alongside the existing enable/disable wrappers. And use the msix helper
in the next driver patch for consistency.

>  void vfio_pci_irq_trigger(struct vfio_pci_device *device, u32 index, u32 vector);
>  
>  static inline void fcntl_set_nonblock(int fd)
> diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> index fc75e04ef010..7b8394d0ac50 100644
> --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> @@ -106,6 +106,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.54.0.794.g4f17f83d09-goog
> 

  reply	other threads:[~2026-07-06 21:03 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-26 23:54 [PATCH v2 00/10] selftests/vfio: igb: Add driver for Intel Josh Hilke
2026-05-26 23:54 ` [PATCH v2 01/10] selftests/vfio: igb: Add driver for IGB QEMU device Josh Hilke
2026-05-27  0:32   ` sashiko-bot
2026-07-06 20:30     ` David Matlack
2026-05-26 23:54 ` [PATCH v2 02/10] selftests/vfio: igb: Use PHY internal loopback on 82576 Josh Hilke
2026-05-26 23:54 ` [PATCH v2 03/10] selftests/vfio: igb: Use advanced TX and RX descriptors Josh Hilke
2026-05-27  0:14   ` sashiko-bot
2026-05-29 20:24     ` Alex Williamson
2026-05-26 23:54 ` [PATCH v2 04/10] selftests/vfio: igb: Program MSI-X interrupt routing Josh Hilke
2026-05-27  0:19   ` sashiko-bot
2026-05-29 20:24     ` Alex Williamson
2026-05-26 23:54 ` [PATCH v2 05/10] selftests/vfio: igb: Extend memcpy completion timeout for line-rate hardware Josh Hilke
2026-05-26 23:54 ` [PATCH v2 06/10] selftests/vfio: igb: Disable PCIe completion timeout retries Josh Hilke
2026-05-26 23:54 ` [PATCH v2 07/10] selftests/vfio: Add vfio_pci_irq_reenable() helper Josh Hilke
2026-07-06 21:03   ` David Matlack [this message]
2026-05-26 23:54 ` [PATCH v2 08/10] selftests/vfio: igb: Factor hardware programming into igb_hw_init() Josh Hilke
2026-07-06 21:16   ` David Matlack
2026-05-26 23:54 ` [PATCH v2 09/10] selftests/vfio: igb: Recover after DMA-read faults Josh Hilke
2026-07-06 21:16   ` David Matlack
2026-05-26 23:54 ` [PATCH v2 10/10] selftests/vfio: igb: Use offical IGB headers in selftest driver Josh Hilke
2026-05-27  2:40   ` sashiko-bot
2026-07-06 20:49   ` David Matlack
2026-07-06 20:55 ` [PATCH v2 00/10] selftests/vfio: igb: Add driver for Intel David Matlack

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=akwYBagw3pFsN0Mt@google.com \
    --to=dmatlack@google.com \
    --cc=alex.williamson@nvidia.com \
    --cc=alex@shazbot.org \
    --cc=jrhilke@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=vipinsh@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox