From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (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 89AC643B6EF for ; Mon, 6 Jul 2026 21:03:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783371786; cv=none; b=Abug53xF0RDW13cZoOzEata2pOrrfbSYz9tLEs3LMIDKEMmEu8+xx8mHVv/sBjU3mHNcmxxXFTp2BAh1hUJ5UEELe+O+AUZSXPZh/esqEaNtb9nB4IqqrzWNgWGyfNY5trSvJ3D0uG923JL5+JnnPYrDCFMKjkoUgMwTkN9/deg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783371786; c=relaxed/simple; bh=fRwVRAmzazXUDn32KSeqZ5ViQIt0hag1CTDsltSIb9Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=svPeQwMMQXQwxO5OEoYRy4duMXe/UD3alS6et9FfFmd0S+tibUpsAf8ecPF29KN/7qLD0oOSAlGcqDs+js9cue6sOBlnhmNsk/2zPvmQW+Mf6u2foGp3/rMPkPeckud21WQjzD9G50QrWJBjN4Gs3ZtvAf6SBN7qVVtgB0qS7vk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=MlXmPUlh; arc=none smtp.client-ip=209.85.216.54 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=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MlXmPUlh" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-3825c406ffeso2625837a91.0 for ; Mon, 06 Jul 2026 14:03:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783371785; x=1783976585; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=/hCewW54bhoxJS9ZE+EEQyKSlMWHdo4kMqBhJSyC7fA=; b=MlXmPUlh7T/7eHjYWGaQKg1x+NzDbGjz4dz7mfnPDvUzomAuE4pxpvcgIlDFgsAYK6 67hq0dav7zTfuMzXIagQaZ24xabqkLGA8L64j9YFU9YeVItYE6gXDdKY4TvgBw8XlfCE Sjhg/1nucr0v6xCG5C5RPZEdVd2N0cdaLUNuR5Cth3w701lKafM6oFM9YUowGtFpZcnb NeS+8mtDxJ9lCHNLOlw/KH9sJutei6PUGf2ymiOGQB9+t2FYnwp1g1cmDxnA6n8KUX5t PPUTlTtzQiCeIQV0qsdgswIEPzlmgh87rFgrFC2BSPRSmuQdluqUzvntVB4h7vGYVeck FKqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783371785; x=1783976585; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/hCewW54bhoxJS9ZE+EEQyKSlMWHdo4kMqBhJSyC7fA=; b=miV22SFI2Fb28FFtUWHJLOskwqZ6nLM4rEG843kzUJA5jrSHYawQw2gEMztYlAAwC6 v6yu2d3wz9KT+SCySacLH0zKeti5SleQH4iIQdomfJ2E54+Nfhj3vStDTL6lY56lLRCA FL0cIvwrO6DalFl9+sr3o/Ko9QOxi3GtugulO6KZy9CQdFSJ16LdfXpbpLA3IMSV6JT4 dIja+GDUanYGBAmyAFfyrT94jnT8CE35n98Wg2ZsUsqiZt9U0aGDBcltdixtHnk+31WH afA3D+UhmSMUnI6kyQMFsmaQt/Zqdrm6tC1qqkJWSRNgOglmhtfl4xnqCDqrRyJgytCq cXFQ== X-Forwarded-Encrypted: i=1; AHgh+RqiU4JxeLIHS0fOcdgGcu4ytCu9AoHGXnYfn0xEJsgxa0kaXbSiv4UPRTlFhOa/UP+LJdAR7y5+p5K6/ZQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwDn6Mx13jwm0MVQLOlekIbtFjaVPCaJGXDBMgNWplBcpAOKSJj VMg0KOmGm9jzPkZQoGNeHBklYBhfiQid10MgMN+9zt2KSrJBbdGlaGTZCmuCnoidww== X-Gm-Gg: AfdE7cnNiRl28khd+dxAqMtayTcUjPwaAh018uRHvtZ2XCRncAogYVdPlsnmlVK+0Fu 2U7e4jLAauL/bvMBSO+Oc/EGQyo9oRhZE6hXRbLE7q4ZXDD90virQQodIXwJPDCQz2Tn9jEFtYX nOsLdJ1V5xDFY3okQehwCAHdLmUBoNMMicATfWAlK7gifVsPKN2eMLVlQAuJbPB55lF06qZh2VQ sQb2jD/W0jsmvxTSRMegxgrSk7MTdFZ5x2XAVhTaPBH7CRE+O/Zt0mtEg+rmNvFXyIoJKGTrJf9 UYUyam4a/VKnUCjwJ5MbLmdHcusHYK7tRUtAtBN7HV8fDc94B2ZVUZ0n6GEDNRzTtMAnEfTvBgO ppSwjolEMzFxGXlEcQpmhFeEr1G3n/Kto4jB/5KghAH6/ODl94EG5rgkVEmEfEcfToJwwoCtKBL zLYIJFccHHEro+GY7/uTC/xgSvjRkuBxN4EKDjkJg8OZZyH5CTjJU= X-Received: by 2002:a17:90b:51cf:b0:37f:eda5:5169 with SMTP id 98e67ed59e1d1-38755d40263mr2591393a91.13.1783371784418; Mon, 06 Jul 2026 14:03:04 -0700 (PDT) Received: from google.com (56.149.168.34.bc.googleusercontent.com. [34.168.149.56]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-387d3d66036sm146a91.17.2026.07.06.14.03.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 14:03:03 -0700 (PDT) Date: Mon, 6 Jul 2026 21:03:01 +0000 From: David Matlack To: Josh Hilke Cc: Alex Williamson , Vipin Sharma , Shuah Khan , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Alex Williamson Subject: Re: [PATCH v2 07/10] selftests/vfio: Add vfio_pci_irq_reenable() helper Message-ID: References: <20260526235417.2058313-1-jrhilke@google.com> <20260526235417.2058313-8-jrhilke@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260526235417.2058313-8-jrhilke@google.com> On 2026-05-26 11:54 PM, Josh Hilke wrote: > 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(). > > Assisted-by: Claude:claude-opus-4-7 > Signed-off-by: Alex Williamson > --- > .../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 >