mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@nvidia.com>
To: kvm <kvm@vger.kernel.org>, Alex Williamson <alex@shazbot.org>
Cc: Alex Williamson <alex.williamson@nvidia.com>,
	skhawaja@google.com, Jason Gunthorpe <jgg@ziepe.ca>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Kevin Tian <kevin.tian@intel.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	linux-pci <linux-pci@vger.kernel.org>
Subject: [RFC PATCH 5/5] vfio/pci: Use pci_reset_supported() in place of reset_works
Date: Tue, 11 Aug 2026 22:53:23 -0600	[thread overview]
Message-ID: <20260812045325.2733631-6-alex.williamson@nvidia.com> (raw)
In-Reply-To: <20260812045325.2733631-1-alex.williamson@nvidia.com>

vfio-pci latches whether pci_reset_function() works at open device and
makes decisions based on this latched value at runtime.  With the
introduction of the reset_method pci-sysfs attribute, this flag can
be made stale at runtime by administrative action.  Further, with the
SR-IOV active VFs gating of pci_reset_function(), the flag can be made
stale via more subtle dependencies.

Drop the latched flag and rely on pci_reset_supported() to indicate
whether reset methods exist for the device.  This is no guarantee that
those reset methods work, nor has the RESET flag in struct
vfio_device_info ever been a guarantee of VFIO_DEVICE_RESET success.
It's only a guarantee that there are reset methods that are
applicable to the device at the instant it's called.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Alex Williamson <alex.williamson@nvidia.com>
---
 drivers/vfio/pci/vfio_pci_core.c | 9 ++++-----
 include/linux/vfio_pci_core.h    | 1 -
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index 956a05ca12e5..8e42342d56d3 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -609,7 +609,6 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev)
 	if (ret == -EAGAIN)
 		goto out_disable_device;
 
-	vdev->reset_works = !ret;
 	pci_save_state(pdev);
 	vdev->pci_saved_state = pci_store_saved_state(pdev);
 	if (!vdev->pci_saved_state)
@@ -766,7 +765,7 @@ void vfio_pci_core_disable(struct vfio_pci_core_device *vdev)
 	if (pci_load_and_free_saved_state(pdev, &vdev->pci_saved_state)) {
 		pci_info(pdev, "%s: Couldn't reload saved state\n", __func__);
 
-		if (!vdev->reset_works)
+		if (!pci_reset_supported(pdev))
 			goto out;
 
 		pci_save_state(pdev);
@@ -785,7 +784,7 @@ void vfio_pci_core_disable(struct vfio_pci_core_device *vdev)
 	 * We can not use the "try" reset interface here, which will
 	 * overwrite the previously restored configuration information.
 	 */
-	if (vdev->reset_works) {
+	if (pci_reset_supported(pdev)) {
 		bridge = pci_upstream_bridge(pdev);
 		if (bridge && !pci_dev_trylock(bridge))
 			goto out_restore_state;
@@ -1098,7 +1097,7 @@ static int vfio_pci_ioctl_get_info(struct vfio_pci_core_device *vdev,
 
 	info.flags = VFIO_DEVICE_FLAGS_PCI;
 
-	if (vdev->reset_works)
+	if (pci_reset_supported(vdev->pdev))
 		info.flags |= VFIO_DEVICE_FLAGS_RESET;
 
 	info.num_regions = VFIO_PCI_NUM_REGIONS + vdev->num_regions;
@@ -1330,7 +1329,7 @@ static int vfio_pci_ioctl_reset(struct vfio_pci_core_device *vdev,
 {
 	int ret;
 
-	if (!vdev->reset_works)
+	if (!pci_reset_supported(vdev->pdev))
 		return -EINVAL;
 
 	vfio_pci_zap_and_down_write_memory_lock(vdev);
diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h
index 9a1674c152aa..6fb599ec2919 100644
--- a/include/linux/vfio_pci_core.h
+++ b/include/linux/vfio_pci_core.h
@@ -121,7 +121,6 @@ struct vfio_pci_core_device {
 	/* Flags only modified on setup/release - bitfield ok */
 	bool			has_dyn_msix:1;
 	bool			pci_2_3:1;
-	bool			reset_works:1;
 	bool			extended_caps:1;
 	bool			has_vga:1;
 	bool			nointx:1;
-- 
2.53.0


  parent reply	other threads:[~2026-08-12  4:53 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-12  4:53 [RFC PATCH 0/5] PCI/vfio-pci: Guard resets against active SR-IOV VFs Alex Williamson
2026-08-12  4:53 ` [RFC PATCH 1/5] PCI: Refuse function reset of an SR-IOV PF with enabled VFs Alex Williamson
2026-08-13 23:22   ` Samiullah Khawaja
2026-08-14 14:37     ` Alex Williamson
2026-08-14 15:54       ` Samiullah Khawaja
2026-08-17 12:18       ` Jason Gunthorpe
2026-08-18  7:07         ` Tian, Kevin
2026-08-18 14:03           ` Jason Gunthorpe
2026-08-18 20:39             ` Alex Williamson
2026-08-20 22:38               ` Samiullah Khawaja
2026-08-20 23:37                 ` Jason Gunthorpe
2026-08-21  2:20                   ` Samiullah Khawaja
2026-09-04 19:06                     ` Jason Gunthorpe
2026-08-27  5:35               ` Tian, Kevin
2026-09-22  1:47                 ` Samiullah Khawaja
2026-08-25 23:55   ` Samiullah Khawaja
2026-08-12  4:53 ` [RFC PATCH 2/5] PCI: Add pci_reset_bus_cond() for a caller-gated slot or bus reset Alex Williamson
2026-08-12  4:53 ` [RFC PATCH 3/5] vfio/pci: Refuse to reset an SR-IOV PF with enabled VFs Alex Williamson
2026-08-12  4:53 ` [RFC PATCH 4/5] PCI: Export pci_reset_supported() Alex Williamson
2026-08-12  4:53 ` Alex Williamson [this message]
2026-08-12 21:45 ` [RFC PATCH 0/5] PCI/vfio-pci: Guard resets against active SR-IOV VFs Bjorn Helgaas
2026-08-12 22:53   ` Alex Williamson
2026-08-17 20:23   ` Tony Nguyen
2026-08-13 22:30 ` Samiullah Khawaja

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=20260812045325.2733631-6-alex.williamson@nvidia.com \
    --to=alex.williamson@nvidia.com \
    --cc=alex@shazbot.org \
    --cc=bhelgaas@google.com \
    --cc=jgg@ziepe.ca \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=skhawaja@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

all inboxes | Powered by JetHome®