[RFC PATCH 5/5] vfio/pci: Use pci_reset_supported() in place of reset_works

Alex Williamson <[email protected]>
Newsgroups org.kernel.vger.linux-pci,org.kernel.vger.kvm,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
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 <[email protected]>
---
 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.