Skip to contentSkip to conversation

PCI/vfio-pci: Guard resets against active SR-IOV VFs

RFC PATCH In review Alex Williamson 8 participants 32 messages Aug 12 – Nov 18

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover PCI/vfio-pci: Guard resets against active SR-IOV VFs

It's recently been found[1] that vfio-pci doesn't restrict resets on PFs while SR-IOV is enabled. This can not only result in an uncoordinated disruption of the use of the associated VFs, but the ongoing use of and access to the VF has the potential to result in machine checks.

This series proposes that this gap is largely an oversight of pci_reset_function() to recognize that a PF reset affecting SR-IOV VFs violates the scope boundary of the pci_reset_function() API.

Patch 1 introduces guards in the common wrappers where we can hold device_lock to prevent .sriov_configure races. This covers locking conformant use cases. __pci_reset_function_locked() can't be gated in PCI-core; it runs after the potentially destructive .reset_prepare. Therefore its callers must provide the gating, along with the locking and state manipulation the interface already demands. The vfio-pci change is included as an example and known use case here.

Patch 2 introduces a callback to pci_reset_bus() which allows a lock dependent callback to be evaluated after locking the physical hierarchy and before initiating the actual reset. This allows use cases such as in the following patch to evaluate the SR-IOV PF configuration without racing.

Patch 3 implements exactly that test in vfio-pci-core, such that the hot-reset ioctl can be blocked when SR-IOV VFs are present on a bus/slot affected PF. This completes the lockdown of resets induced on behalf of the vfio-pci in-kernel or userspace drivers.

Patch 4 exports pci_reset_supported, which allows patch 5 to remove the latched reset_works flag, which already had the potential to become stale due to reset_method manipulation through sysfs, but now may also become stale due to the SR-IOV state of the PF.

This is RFC to capture the discussion of [1] while it's active but requires testing before formal proposal. This effectively side-steps the feasibility and security question of the operating model in use by the referenced thread by generically gating resets affecting PFs with active SR-IOV. Please review and comment. Thanks,

Alex

[1]https://lore.kernel.org/all/[email protected]/

Alex Williamson (5):
PCI: Refuse function reset of an SR-IOV PF with enabled VFs
PCI: Add pci_reset_bus_cond() for a caller-gated slot or bus reset vfio/pci: Refuse to reset an SR-IOV PF with enabled VFs
PCI: Export pci_reset_supported()
vfio/pci: Use pci_reset_supported() in place of reset_works

 drivers/pci/pci.c                | 117 +++++++++++++++++++++++++++----
 drivers/pci/pci.h                |   1 -
 drivers/vfio/pci/vfio_pci_core.c |  28 +++++---
 include/linux/pci.h              |   4 ++
 include/linux/vfio_pci_core.h    |   1 -
 include/uapi/linux/vfio.h        |   3 +
 6 files changed, 129 insertions(+), 25 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

RFC PATCH 1/5 PCI: Refuse function reset of an SR-IOV PF with enabled VFs

pci_reset_function() and its locked and try variants are intended to provide a function-scoped reset. The bus and slot methods supporting this interface refuse when sibling or subordinate devices are present. SR-IOV VFs however, are not currently considered in this scope.

Correct this oversight by testing for non-zero VF count in calls through the pci_reset_function() interfaces. This test needs to occur under device_lock to avoid races with .sriov_configure. It should also occur before pci_dev_save_and_disable() to avoid calling potentially destructive reset hooks. Tests are therefore added to each of pci_reset_function(), pci_reset_function_locked(), and pci_try_reset_function().

The __pci_reset_function_locked() interface remains a low-level primitive depending on the caller to perform such tests as necessary. The vfio_pci_core use case of __pci_reset_function_locked() is pulled through with this test. Other use cases, such as xen-pciback, that don't obviously support or prevent binding to SR-IOV enabled PFs will need to decide whether VFs are possible and can be preserved. Additionally, direct callers of sriov_enable() that do not hold device_lock (lpfc) are considered a preexisting, non-compliance issue.

Fixes dd7cc44d0bce ("PCI: add SR-IOV API for Physical Function driver")
Assisted-by Claude:claude-opus-4-8
---
 drivers/pci/pci.c                | 19 +++++++++++++++++++
 drivers/vfio/pci/vfio_pci_core.c |  4 +++-
 2 files changed, 22 insertions(+), 1 deletion(-)
drivers/pci/pci.c +19 -0
index 77b17b13ee61..b40b00c0c0c9 100644
@@ -5222,11 +5222,22 @@ int pci_reset_function(struct pci_dev *dev)
 		pci_dev_lock(bridge);
 
 	pci_dev_lock(dev);
+
+	/*
+	 * Reset of an SR-IOV PF necessarily resets any active VFs.  Such resets are
+	 * beyond the scope advertised for pci_reset_function() and variants, refuse.
+	 */
+	if (pci_num_vf(dev) > 0) {
+		rc = -ENOTTY;
+		goto unlock;
+	}
+
 	pci_dev_save_and_disable(dev);
 
 	rc = __pci_reset_function_locked(dev);
 
 	pci_dev_restore(dev);
+unlock:
 	pci_dev_unlock(dev);
 
 	if (bridge)
@@ -5264,6 +5275,9 @@ int pci_reset_function_locked(struct pci_dev *dev)
 	if (!pci_reset_supported(dev))
 		return -ENOTTY;
 
+	if (pci_num_vf(dev) > 0)
+		return -ENOTTY;
+
 	pci_dev_save_and_disable(dev);
 
 	rc = __pci_reset_function_locked(dev);
@@ -5290,6 +5304,11 @@ int pci_try_reset_function(struct pci_dev *dev)
 	if (!pci_dev_trylock(dev))
 		return -EAGAIN;
 
+	if (pci_num_vf(dev) > 0) {
+		pci_dev_unlock(dev);
+		return -ENOTTY;
+	}
+
 	pci_dev_save_and_disable(dev);
 	rc = __pci_reset_function_locked(dev);
 	pci_dev_restore(dev);
drivers/vfio/pci/vfio_pci_core.c +3 -1
index 3f11a9624b9c..9757b171791c 100644
@@ -790,7 +790,9 @@ void vfio_pci_core_disable(struct vfio_pci_core_device *vdev)
 		if (bridge && !pci_dev_trylock(bridge))
 			goto out_restore_state;
 		if (pci_dev_trylock(pdev)) {
-			if (!__pci_reset_function_locked(pdev))
+			/* Enforce function scope under lock for SR-IOV PFs */
+			if (!pci_num_vf(pdev) &&
+			    !__pci_reset_function_locked(pdev))
 				vdev->needs_reset = false;
 			pci_dev_unlock(pdev);
 		}
Signature · 1 line
2.53.0
#2 lore raw

Re: [RFC PATCH 1/5] PCI: Refuse function reset of an SR-IOV PF with enabled VFs

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 22 lines

pci_reset_function() and its locked and try variants are intended to provide a function-scoped reset. The bus and slot methods supporting this interface refuse when sibling or subordinate devices are present. SR-IOV VFs however, are not currently considered in this scope.

Correct this oversight by testing for non-zero VF count in calls through the pci_reset_function() interfaces. This test needs to occur under device_lock to avoid races with .sriov_configure. It should also occur before pci_dev_save_and_disable() to avoid calling potentially destructive reset hooks. Tests are therefore added to each of pci_reset_function(), pci_reset_function_locked(), and pci_try_reset_function().

The __pci_reset_function_locked() interface remains a low-level primitive depending on the caller to perform such tests as necessary. The vfio_pci_core use case of __pci_reset_function_locked() is pulled through with this test. Other use cases, such as xen-pciback, that don't obviously support or prevent binding to SR-IOV enabled PFs will need to decide whether VFs are possible and can be preserved. Additionally, direct callers of sriov_enable() that do not hold device_lock (lpfc) are considered a preexisting, non-compliance issue.

Quoted 4 lines
Fixes dd7cc44d0bce ("PCI: add SR-IOV API for Physical Function driver")
Assisted-by Claude:claude-opus-4-8

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [RFC PATCH 1/5] PCI: Refuse function reset of an SR-IOV PF with enabled VFs

In reply to Alex Williamson
Quoted 69 lines · Alex Williamson

pci_reset_function() and its locked and try variants are intended to provide a function-scoped reset. The bus and slot methods supporting this interface refuse when sibling or subordinate devices are present. SR-IOV VFs however, are not currently considered in this scope.

Correct this oversight by testing for non-zero VF count in calls through the pci_reset_function() interfaces. This test needs to occur under device_lock to avoid races with .sriov_configure. It should also occur before pci_dev_save_and_disable() to avoid calling potentially destructive reset hooks. Tests are therefore added to each of pci_reset_function(), pci_reset_function_locked(), and pci_try_reset_function().

The __pci_reset_function_locked() interface remains a low-level primitive depending on the caller to perform such tests as necessary. The vfio_pci_core use case of __pci_reset_function_locked() is pulled through with this test. Other use cases, such as xen-pciback, that don't obviously support or prevent binding to SR-IOV enabled PFs will need to decide whether VFs are possible and can be preserved. Additionally, direct callers of sriov_enable() that do not hold device_lock (lpfc) are considered a preexisting, non-compliance issue.

Fixes dd7cc44d0bce ("PCI: add SR-IOV API for Physical Function driver")
Assisted-by Claude:claude-opus-4-8

---
drivers/pci/pci.c | 19 +++++++++++++++++++
drivers/vfio/pci/vfio_pci_core.c | 4 +++-

2 files changed, 22 insertions(+), 1 deletion(-)
drivers/pci/pci.c +14 -0
index 77b17b13ee61..b40b00c0c0c9 100644
@@ -5222,11 +5222,22 @@ int pci_reset_function(struct pci_dev *dev)
 		pci_dev_lock(bridge);
 
 	pci_dev_lock(dev);
+
+	/*
+	 * Reset of an SR-IOV PF necessarily resets any active VFs.  Such resets are
+	 * beyond the scope advertised for pci_reset_function() and variants, refuse.
+	 */
+	if (pci_num_vf(dev) > 0) {
+		rc = -ENOTTY;
+		goto unlock;
+	}
+
 	pci_dev_save_and_disable(dev);
 
 	rc = __pci_reset_function_locked(dev);
 
 	pci_dev_restore(dev);
+unlock:
 	pci_dev_unlock(dev);
 
 	if (bridge)
@@ -5264,6 +5275,9 @@ int pci_reset_function_locked(struct pci_dev *dev)
 	if (!pci_reset_supported(dev))
 		return -ENOTTY;
 
+	if (pci_num_vf(dev) > 0)
+		return -ENOTTY;
+
 	pci_dev_save_and_disable(dev);
 
 	rc = __pci_reset_function_locked(dev);

drivers/pci/pci.c int pci_try_reset_function(struct pci_dev *dev) · line 5310

Quoted 7 lines
drivers/pci/pci.c +4 -0
@@ -5290,6 +5304,11 @@ int pci_try_reset_function(struct pci_dev *dev)
 	if (!pci_dev_trylock(dev))
 		return -EAGAIN;
 
+	if (pci_num_vf(dev) > 0) {
+		pci_dev_unlock(dev);
+		return -ENOTTY;
+	}

I am wondering whether we should return EAGAIN from here, since this function is used by vfio_pci_core_enable() during open and it doesn't fail the open on ENOTTY. Basically whether we should allow the user to reopen the device if the reset was skipped previously? In the previous instance of open, the device was setup with vfio/iommufd and the vfio fd was abruptly closed and the reset was skipped. But the device went back to the IOMMU default domain and that is probably an Identity domain. If we allow the device to be opened and re-enable busmaster without a reset, is there a chance that device would continue to DMA based on its previous setup/context? Probably unlikely?

Note this is different from the current vfio-pci behaviour where device is always reset during close.

Maybe thinking with too much paranoia about it :D.

Thanks,
Sami

#4 lore raw

Re: [RFC PATCH 1/5] PCI: Refuse function reset of an SR-IOV PF with enabled VFs

Quoted 89 lines · On Thu, 13 Aug 2026 23:22:33 +0000 Samiullah Khawaja <[email protected]>…
Quoted 69 lines · Alex Williamson

pci_reset_function() and its locked and try variants are intended to provide a function-scoped reset. The bus and slot methods supporting this interface refuse when sibling or subordinate devices are present. SR-IOV VFs however, are not currently considered in this scope.

Correct this oversight by testing for non-zero VF count in calls through the pci_reset_function() interfaces. This test needs to occur under device_lock to avoid races with .sriov_configure. It should also occur before pci_dev_save_and_disable() to avoid calling potentially destructive reset hooks. Tests are therefore added to each of pci_reset_function(), pci_reset_function_locked(), and pci_try_reset_function().

The __pci_reset_function_locked() interface remains a low-level primitive depending on the caller to perform such tests as necessary. The vfio_pci_core use case of __pci_reset_function_locked() is pulled through with this test. Other use cases, such as xen-pciback, that don't obviously support or prevent binding to SR-IOV enabled PFs will need to decide whether VFs are possible and can be preserved. Additionally, direct callers of sriov_enable() that do not hold device_lock (lpfc) are considered a preexisting, non-compliance issue.

Fixes dd7cc44d0bce ("PCI: add SR-IOV API for Physical Function driver")
Assisted-by Claude:claude-opus-4-8

---
drivers/pci/pci.c | 19 +++++++++++++++++++
drivers/vfio/pci/vfio_pci_core.c | 4 +++-

2 files changed, 22 insertions(+), 1 deletion(-)
drivers/pci/pci.c +14 -0
index 77b17b13ee61..b40b00c0c0c9 100644
@@ -5222,11 +5222,22 @@ int pci_reset_function(struct pci_dev *dev)
 		pci_dev_lock(bridge);
 
 	pci_dev_lock(dev);
+
+	/*
+	 * Reset of an SR-IOV PF necessarily resets any active VFs.  Such resets are
+	 * beyond the scope advertised for pci_reset_function() and variants, refuse.
+	 */
+	if (pci_num_vf(dev) > 0) {
+		rc = -ENOTTY;
+		goto unlock;
+	}
+
 	pci_dev_save_and_disable(dev);
 
 	rc = __pci_reset_function_locked(dev);
 
 	pci_dev_restore(dev);
+unlock:
 	pci_dev_unlock(dev);
 
 	if (bridge)
@@ -5264,6 +5275,9 @@ int pci_reset_function_locked(struct pci_dev *dev)
 	if (!pci_reset_supported(dev))
 		return -ENOTTY;
 
+	if (pci_num_vf(dev) > 0)
+		return -ENOTTY;
+
 	pci_dev_save_and_disable(dev);
 
 	rc = __pci_reset_function_locked(dev);

drivers/pci/pci.c int pci_try_reset_function(struct pci_dev *dev) · line 5310

Quoted 7 lines
drivers/pci/pci.c +4 -0
@@ -5290,6 +5304,11 @@ int pci_try_reset_function(struct pci_dev *dev)
 	if (!pci_dev_trylock(dev))
 		return -EAGAIN;
 
+	if (pci_num_vf(dev) > 0) {
+		pci_dev_unlock(dev);
+		return -ENOTTY;
+	}  

I am wondering whether we should return EAGAIN from here, since this function is used by vfio_pci_core_enable() during open and it doesn't fail the open on ENOTTY. Basically whether we should allow the user to reopen the device if the reset was skipped previously? In the previous instance of open, the device was setup with vfio/iommufd and the vfio fd was abruptly closed and the reset was skipped. But the device went back to the IOMMU default domain and that is probably an Identity domain. If we allow the device to be opened and re-enable busmaster without a reset, is there a chance that device would continue to DMA based on its previous setup/context? Probably unlikely?

Quoted 4 lines

Note this is different from the current vfio-pci behaviour where device is always reset during close.

Maybe thinking with too much paranoia about it :D.

Devices are only ever opened into a user owned domain, the IOMMU context switch happens before this and regardless of the reset. Close also disables bus-master regardless of reset, so there's no risk of ongoing DMA if the device is placed into an identity domain between close and re-open.

Actually, I think -ENOTTY is a leftover from a previous iteration where this test was pushed into the individual reset methods. -ENOTTY allows continuing to the next reset method. With the test guarding all the reset methods in this version, we should probably use -EBUSY. -EAGAIN would conflate the try-lock contention error, which is actually a usage race, versus the PF is not in a state to handle the request.

If the user owns the PF, as evidenced by them being able to get to vfio_pci_core_enable(), and reset is blocked by the SR-IOV state of the PF, I think there are arguments both that the user implicitly opted in to the best-effort reset, as well as a use case that allows the PF driver to fail and re-open the PF demands this behavior.

Further, the PF requires vf-token authentication if VFs are open within the vfio ecosystem. If the VFs are instead bound to in-kernel drivers, they've already been opted out of that security barrier. Thanks,

Alex

#5 lore raw

Re: [RFC PATCH 1/5] PCI: Refuse function reset of an SR-IOV PF with enabled VFs

Quoted 4 lines · Alex Williamson
Quoted 1 line · On Thu, 13 Aug 2026 23:22:33 +0000 Samiullah Khawaja <[email protected]>…
Quoted 1 line

[snip]

Quoted 16 lines
Quoted 16 lines

drivers/pci/pci.c int pci_try_reset_function(struct pci_dev *dev) · line 5310

Quoted 4 lines
drivers/pci/pci.c +4 -0
+	if (pci_num_vf(dev) > 0) {
+		pci_dev_unlock(dev);
+		return -ENOTTY;
+	}

I am wondering whether we should return EAGAIN from here, since this function is used by vfio_pci_core_enable() during open and it doesn't fail the open on ENOTTY. Basically whether we should allow the user to reopen the device if the reset was skipped previously? In the previous instance of open, the device was setup with vfio/iommufd and the vfio fd was abruptly closed and the reset was skipped. But the device went back to the IOMMU default domain and that is probably an Identity domain. If we allow the device to be opened and re-enable busmaster without a reset, is there a chance that device would continue to DMA based on its previous setup/context? Probably unlikely?

Quoted 8 lines
Quoted 4 lines

Note this is different from the current vfio-pci behaviour where device is always reset during close.

Maybe thinking with too much paranoia about it :D.

Devices are only ever opened into a user owned domain, the IOMMU context switch happens before this and regardless of the reset. Close also disables bus-master regardless of reset, so there's no risk of

Yes the close side makes sense, I was more concerned about the reopen.

Quoted 9 lines

ongoing DMA if the device is placed into an identity domain between close and re-open.

Actually, I think -ENOTTY is a leftover from a previous iteration where this test was pushed into the individual reset methods. -ENOTTY allows continuing to the next reset method. With the test guarding all the reset methods in this version, we should probably use -EBUSY. -EAGAIN would conflate the try-lock contention error, which is actually a usage race, versus the PF is not in a state to handle the request.

This sounds good to me.

Quoted 6 lines

If the user owns the PF, as evidenced by them being able to get to vfio_pci_core_enable(), and reset is blocked by the SR-IOV state of the PF, I think there are arguments both that the user implicitly opted in to the best-effort reset, as well as a use case that allows the PF driver to fail and re-open the PF demands this behavior.

That is fair.

Thanks for clarifying.

Sami

#6 lore raw

Re: [RFC PATCH 1/5] PCI: Refuse function reset of an SR-IOV PF with enabled VFs

In reply to Alex Williamson
Quoted 5 lines · Alex Williamson

Devices are only ever opened into a user owned domain, the IOMMU context switch happens before this and regardless of the reset. Close also disables bus-master regardless of reset, so there's no risk of ongoing DMA if the device is placed into an identity domain between close and re-open.

I've been told by HW people that bus-master isn't actually a strong fence for stopping DMA on most real HW. More of a 'dma will eventually stop' kind of thing.

It does reliably prevent DMA during the post-FLR phase only.

If the device hasn't been reset it should be kept on a blocking domain.

Quoted 3 lines

PF, I think there are arguments both that the user implicitly opted in to the best-effort reset, as well as a use case that allows the PF driver to fail and re-open the PF demands this behavior.

I really think we cannot alow a device to be returned back to the kernel without a reset. VFIO should be keeping things attached to a blocking domain as long as the driver is bound. It should force a reset during unbinding as well if the device FD was ever closed without a reset..

Jason

#7 lore raw

RE: [RFC PATCH 1/5] PCI: Refuse function reset of an SR-IOV PF with enabled VFs

Quoted 24 lines

From: Jason Gunthorpe <[email protected]>
Sent: Monday, August 17, 2026 8:18 PM

Quoted 5 lines · Alex Williamson

Devices are only ever opened into a user owned domain, the IOMMU context switch happens before this and regardless of the reset. Close also disables bus-master regardless of reset, so there's no risk of ongoing DMA if the device is placed into an identity domain between close and re-open.

I've been told by HW people that bus-master isn't actually a strong fence for stopping DMA on most real HW. More of a 'dma will eventually stop' kind of thing.

It does reliably prevent DMA during the post-FLR phase only.

If the device hasn't been reset it should be kept on a blocking domain.

Quoted 3 lines

PF, I think there are arguments both that the user implicitly opted in to the best-effort reset, as well as a use case that allows the PF driver to fail and re-open the PF demands this behavior.

Quoted 6 lines

I really think we cannot alow a device to be returned back to the kernel without a reset. VFIO should be keeping things attached to a blocking domain as long as the driver is bound. It should force a reset during unbinding as well if the device FD was ever closed without a reset..

hmm so we have several resetting categories:

1) reset a hanging PF or for administrative purpose (sysfs, vfio open/close etc.)

This series avoids uncoordinated disruptive impact on associated VFs by rejecting the request. User can reinitiate the resetting request after disabling SR-IOV.

2) resetting a erroneous PF in the AER path

The link to the PF is down. pci_{slot|bus}_reset() is called by pci core to recover the error condition. VFs are impacted inevitably as the cmd to disable sriov may not reach the PF at all.

Not sure any enhancement can be done to relax disruptive on associated VFs, but so far this series doesn't change this path.

3) resetting a PF due to ad-hoc FW error

e.g. pdsc_check_pci_health() calls pci_reset_function() when FW reports broken PCI. Sounds a similar condition to AER.

but as it calls pci_reset_function() this series causes a regression in case of active VFs. Is it desired?

4) Jason's suggestion to force a reset upon unbinding

sounds reasonable and clean as long as reset is done post disabling sriov, which is the 1st action in vfio_pci_core_unregister_device(). Then it's just a normal reset w/o concerning any active VFs.

#8 lore raw

Re: [RFC PATCH 1/5] PCI: Refuse function reset of an SR-IOV PF with enabled VFs

Quoted 7 lines · Kevin

3) resetting a PF due to ad-hoc FW error

e.g. pdsc_check_pci_health() calls pci_reset_function() when FW reports broken PCI. Sounds a similar condition to AER.

but as it calls pci_reset_function() this series causes a regression in case of active VFs. Is it desired?

mlx5 does something similar. RAS flows require detecting the PF has blown up and resetting it to bring it back.

This has to work while VFs exist and bound to kernel drivers or vfio.

In the VFIO KVM case I would expect the VM to experiance a RAS error on its vPCI device and trigger a VF flr

But we have to sort all this out through the hypervisor to not crash the machine or otherwise :)

Jason

#9 lore raw

Re: [RFC PATCH 1/5] PCI: Refuse function reset of an SR-IOV PF with enabled VFs

Quoted 9 lines · On Tue, 18 Aug 2026 11:03:04 -0300 Jason Gunthorpe <[email protected]> wrote:
Quoted 7 lines · Kevin

3) resetting a PF due to ad-hoc FW error

e.g. pdsc_check_pci_health() calls pci_reset_function() when FW reports broken PCI. Sounds a similar condition to AER.

but as it calls pci_reset_function() this series causes a regression in case of active VFs. Is it desired?

Quoted 7 lines

mlx5 does something similar. RAS flows require detecting the PF has blown up and resetting it to bring it back.

This has to work while VFs exist and bound to kernel drivers or vfio.

In the VFIO KVM case I would expect the VM to experiance a RAS error on its vPCI device and trigger a VF flr

This would need to be a device level RAS flow as we're sorely lacking on forwarding reset notification to VF drivers or providing any mechanism for recovery from the vfio error eventfd.

Quoted 2 lines

But we have to sort all this out through the hypervisor to not crash the machine or otherwise :)

In general guarding the high level pci_reset_function() family on (pci_num_vfs() == 0) seems to have more pros than cons and the restriction matches the scoped intent of the interface.

The low level __pci_reset_function_locked() interface remains untouched, and as the prefix implies, relies on the caller to do necessary verification and preparation. A "reset the PF regardless of VFs" seems like an underscore prefix sort of operation. We'll need to export the pci_dev_save_and_disable() and pci_dev_restore() functions to provide handlers the full suite of tools they need to replace the existing function and port those we find (maybe also questioning the author's intent on VF reset and recovery).

Of course making the guard parameterized with wrappers to expand this family of calls is also an option, pci_reset_function_locked_with_vfs()...

The mlx5 driver doesn't actually seem to be affected by these changes, doing its own link toggle or a PCI bus reset, not a pci_reset_function() call.

On the other improvements, triggering a pci_reset_function_locked() on unbind after SR-IOV is disabled, when needs_reset is indicated, looks pretty trivial.

The blocking domain operation looks like it might be simplest to implement in the IOMMU core. We can set a flag for a default blocking domain on the IOMMU group when we take_dma_ownership of the group. Then release_dma_ownership picks the blocking rather than default domain.

This is then unwound in use_default_domain, called via dma_configure, attaching the device to the default domain in probe of the next driver. Therefore until probe by another driver, a device used by vfio would remain in a blocking domain even while unused and unbound.

Does that seem reasonable (Cc +iommu)? Thanks,

Alex

#10 lore raw

Re: [RFC PATCH 1/5] PCI: Refuse function reset of an SR-IOV PF with enabled VFs

Quoted 57 lines · Alex Williamson
Quoted 9 lines · On Tue, 18 Aug 2026 11:03:04 -0300 Jason Gunthorpe <[email protected]> wrote:
Quoted 7 lines · Kevin

3) resetting a PF due to ad-hoc FW error

e.g. pdsc_check_pci_health() calls pci_reset_function() when FW reports broken PCI. Sounds a similar condition to AER.

but as it calls pci_reset_function() this series causes a regression in case of active VFs. Is it desired?

Quoted 7 lines

mlx5 does something similar. RAS flows require detecting the PF has blown up and resetting it to bring it back.

This has to work while VFs exist and bound to kernel drivers or vfio.

In the VFIO KVM case I would expect the VM to experiance a RAS error on its vPCI device and trigger a VF flr

This would need to be a device level RAS flow as we're sorely lacking on forwarding reset notification to VF drivers or providing any mechanism for recovery from the vfio error eventfd.

Quoted 2 lines

But we have to sort all this out through the hypervisor to not crash the machine or otherwise :)

In general guarding the high level pci_reset_function() family on (pci_num_vfs() == 0) seems to have more pros than cons and the restriction matches the scoped intent of the interface.

The low level __pci_reset_function_locked() interface remains untouched, and as the prefix implies, relies on the caller to do necessary verification and preparation. A "reset the PF regardless of VFs" seems like an underscore prefix sort of operation. We'll need to export the pci_dev_save_and_disable() and pci_dev_restore() functions to provide handlers the full suite of tools they need to replace the existing function and port those we find (maybe also questioning the author's intent on VF reset and recovery).

Of course making the guard parameterized with wrappers to expand this family of calls is also an option, pci_reset_function_locked_with_vfs()...

The mlx5 driver doesn't actually seem to be affected by these changes, doing its own link toggle or a PCI bus reset, not a pci_reset_function() call.

On the other improvements, triggering a pci_reset_function_locked() on unbind after SR-IOV is disabled, when needs_reset is indicated, looks pretty trivial.

The blocking domain operation looks like it might be simplest to implement in the IOMMU core. We can set a flag for a default blocking domain on the IOMMU group when we take_dma_ownership of the group. Then release_dma_ownership picks the blocking rather than default domain.

Quoted 4 lines

This is then unwound in use_default_domain, called via dma_configure, attaching the device to the default domain in probe of the next driver. Therefore until probe by another driver, a device used by vfio would remain in a blocking domain even while unused and unbound.

The devices are expected to be attached to the default_domain even when these are unbound and the use_default_domain assumes that, and it only checks the ownership and doesn't switch the domain to default_domain. I guess we should add a WARN in use_default_domain() if that is not true. I will probably send out a patch for that separately.

I think we can move the device back to default_domain after reset after unbind, maybe it can be done in pci_dma_cleanup() based on driver_managed_dma?

Quoted 5 lines

Does that seem reasonable (Cc +iommu)? Thanks,

Alex

Thanks,
Sami

#11 lore raw

Re: [RFC PATCH 1/5] PCI: Refuse function reset of an SR-IOV PF with enabled VFs

Quoted 16 lines · Samiullah Khawaja
Quoted 9 lines

The blocking domain operation looks like it might be simplest to implement in the IOMMU core. We can set a flag for a default blocking domain on the IOMMU group when we take_dma_ownership of the group. Then release_dma_ownership picks the blocking rather than default domain.

This is then unwound in use_default_domain, called via dma_configure, attaching the device to the default domain in probe of the next driver. Therefore until probe by another driver, a device used by vfio would remain in a blocking domain even while unused and unbound.

The devices are expected to be attached to the default_domain even when these are unbound and the use_default_domain assumes that, and it only checks the ownership and doesn't switch the domain to default_domain. I guess we should add a WARN in use_default_domain() if that is not true. I will probably send out a patch for that separately.

Quoted 3 lines

I think we can move the device back to default_domain after reset after unbind, maybe it can be done in pci_dma_cleanup() based on driver_managed_dma?

This blocking domain stuff sounds very similar to what Nicolin implemented for the per-function ATS issue?

Broadly we must setup a blocking domain in the iommu if ATS is available across reset or you get these ATS related issues.

I think at the time he looked at doing SRIOV as well but it was tricky..

Jason

#12 lore raw

Re: [RFC PATCH 1/5] PCI: Refuse function reset of an SR-IOV PF with enabled VFs

Quoted 18 lines · Jason Gunthorpe
Quoted 16 lines · Samiullah Khawaja
Quoted 9 lines

The blocking domain operation looks like it might be simplest to implement in the IOMMU core. We can set a flag for a default blocking domain on the IOMMU group when we take_dma_ownership of the group. Then release_dma_ownership picks the blocking rather than default domain.

This is then unwound in use_default_domain, called via dma_configure, attaching the device to the default domain in probe of the next driver. Therefore until probe by another driver, a device used by vfio would remain in a blocking domain even while unused and unbound.

The devices are expected to be attached to the default_domain even when these are unbound and the use_default_domain assumes that, and it only checks the ownership and doesn't switch the domain to default_domain. I guess we should add a WARN in use_default_domain() if that is not true. I will probably send out a patch for that separately.

Quoted 6 lines
Quoted 3 lines

I think we can move the device back to default_domain after reset after unbind, maybe it can be done in pci_dma_cleanup() based on driver_managed_dma?

This blocking domain stuff sounds very similar to what Nicolin implemented for the per-function ATS issue?

I see you are talking about this invalidation stuff:

https://lore.kernel.org/all/348c50ab6e95b5ec6d48ee3fa05d529a784a34c3.1765834788.git.nicolinc@nvidia.com/

But this was the case where the device is going to be reset and to prevent ATS issues, we attach it to blocking domain before doing the reset. But of course, with the PF reset here, it induces the same kind of ATS issues on the VFs.

Quoted 6 lines

Broadly we must setup a blocking domain in the iommu if ATS is available across reset or you get these ATS related issues.

I think at the time he looked at doing SRIOV as well but it was tricky..

Hmm... doing that for SRIOV also, by allowing PF reset but attaching the VFs to blocking domains before the PF is reset, will only resolve the ATS issues. But the software state is still out of sync with hardware state.

Quoted 2 lines

Jason

Sami

#13 lore raw

Re: [RFC PATCH 1/5] PCI: Refuse function reset of an SR-IOV PF with enabled VFs

Quoted 26 lines · Samiullah Khawaja
Quoted 18 lines · Jason Gunthorpe
Quoted 16 lines · Samiullah Khawaja
Quoted 9 lines

The blocking domain operation looks like it might be simplest to implement in the IOMMU core. We can set a flag for a default blocking domain on the IOMMU group when we take_dma_ownership of the group. Then release_dma_ownership picks the blocking rather than default domain.

This is then unwound in use_default_domain, called via dma_configure, attaching the device to the default domain in probe of the next driver. Therefore until probe by another driver, a device used by vfio would remain in a blocking domain even while unused and unbound.

The devices are expected to be attached to the default_domain even when these are unbound and the use_default_domain assumes that, and it only checks the ownership and doesn't switch the domain to default_domain. I guess we should add a WARN in use_default_domain() if that is not true. I will probably send out a patch for that separately.

Quoted 6 lines
Quoted 3 lines

I think we can move the device back to default_domain after reset after unbind, maybe it can be done in pci_dma_cleanup() based on driver_managed_dma?

This blocking domain stuff sounds very similar to what Nicolin implemented for the per-function ATS issue?

Quoted 8 lines

I see you are talking about this invalidation stuff:

https://lore.kernel.org/all/348c50ab6e95b5ec6d48ee3fa05d529a784a34c3.1765834788.git.nicolinc@nvidia.com/

But this was the case where the device is going to be reset and to prevent ATS issues, we attach it to blocking domain before doing the reset. But of course, with the PF reset here, it induces the same kind of ATS issues on the VFs.

Yes, we need to attach a blocking domain before we make the function unable to respond to ATC invalidation. PF or VF reset both trigger this condition.

Quoted 4 lines

Hmm... doing that for SRIOV also, by allowing PF reset but attaching the VFs to blocking domains before the PF is reset, will only resolve the ATS issues. But the software state is still out of sync with hardware state.

Sure, it doesn't fix everything, but it is something you'd need to do to avoid problems in the iommu driver side..

Jason

#14 lore raw

RE: [RFC PATCH 1/5] PCI: Refuse function reset of an SR-IOV PF with enabled VFs

In reply to Alex Williamson
Quoted 43 lines

From: Alex Williamson <[email protected]>
Sent: Wednesday, August 19, 2026 4:39 AM

Quoted 9 lines · On Tue, 18 Aug 2026 11:03:04 -0300 Jason Gunthorpe <[email protected]> wrote:
Quoted 7 lines · Kevin

3) resetting a PF due to ad-hoc FW error

e.g. pdsc_check_pci_health() calls pci_reset_function() when FW reports broken PCI. Sounds a similar condition to AER.

but as it calls pci_reset_function() this series causes a regression in case of active VFs. Is it desired?

Quoted 7 lines

mlx5 does something similar. RAS flows require detecting the PF has blown up and resetting it to bring it back.

This has to work while VFs exist and bound to kernel drivers or vfio.

In the VFIO KVM case I would expect the VM to experiance a RAS error on its vPCI device and trigger a VF flr

This would need to be a device level RAS flow as we're sorely lacking on forwarding reset notification to VF drivers or providing any mechanism for recovery from the vfio error eventfd.

Quoted 2 lines

But we have to sort all this out through the hypervisor to not crash the machine or otherwise :)

In general guarding the high level pci_reset_function() family on (pci_num_vfs() == 0) seems to have more pros than cons and the restriction matches the scoped intent of the interface.

The low level __pci_reset_function_locked() interface remains untouched, and as the prefix implies, relies on the caller to do necessary verification and preparation. A "reset the PF regardless of VFs" seems like an underscore prefix sort of operation. We'll need to export the pci_dev_save_and_disable() and pci_dev_restore() functions to provide handlers the full suite of tools they need to replace the existing function and port those we find (maybe also questioning the author's intent on VF reset and recovery).

Quoted 3 lines

Of course making the guard parameterized with wrappers to expand this family of calls is also an option, pci_reset_function_locked_with_vfs()...

+1 for wrappers. Maybe call it pci_force_reset_function_locked() which is slightly forward-looking if in future other conditions may reject the reset request using the base function.

Quoted 9 lines

The mlx5 driver doesn't actually seem to be affected by these changes, doing its own link toggle or a PCI bus reset, not a pci_reset_function() call.

On the other improvements, triggering a pci_reset_function_locked() on unbind after SR-IOV is disabled, when needs_reset is indicated, looks pretty trivial.

Quoted 5 lines

The blocking domain operation looks like it might be simplest to implement in the IOMMU core. We can set a flag for a default blocking domain on the IOMMU group when we take_dma_ownership of the group. Then
release_dma_ownership picks the blocking rather than default domain.

IMHO we should change release_dma_ownership() to always picks the blocking. No new flag.

this take/release interfaces are invented for drivers which manage dma on their own, so it sounds reasonable to not assume the operated device is in a good shape after the ownership is released.

Then only a clean reset can unwind it.

Quoted 6 lines

This is then unwound in use_default_domain, called via dma_configure, attaching the device to the default domain in probe of the next driver. Therefore until probe by another driver, a device used by vfio would remain in a blocking domain even while unused and unbound.

so unwinding it blindly at dma_configure time is also problematic, as the device may still have a bad state to hurt the kernel.

Instead use_default_domain should fail in such case (in blocked with owner_cnt being '0') then a reset is expected to unwind it (Nicolin's work will carry the resetting status to pci_dev_reset_iommu_done())

Once we follow Jason's suggestion to do reset on vfio unbind, user vfio experience is intact across binding/unbinding drivers.

Then when a 2nd driver claiming dma comes but it forgets to do reset on unbind, only manual reset can unblock the device to bind to a new driver.

#15 lore raw

Re: [RFC PATCH 1/5] PCI: Refuse function reset of an SR-IOV PF with enabled VFs

Quoted 82 lines · Kevin
Quoted 43 lines

From: Alex Williamson <[email protected]>
Sent: Wednesday, August 19, 2026 4:39 AM

Quoted 9 lines · On Tue, 18 Aug 2026 11:03:04 -0300 Jason Gunthorpe <[email protected]> wrote:
Quoted 7 lines · Kevin

3) resetting a PF due to ad-hoc FW error

e.g. pdsc_check_pci_health() calls pci_reset_function() when FW reports broken PCI. Sounds a similar condition to AER.

but as it calls pci_reset_function() this series causes a regression in case of active VFs. Is it desired?

Quoted 7 lines

mlx5 does something similar. RAS flows require detecting the PF has blown up and resetting it to bring it back.

This has to work while VFs exist and bound to kernel drivers or vfio.

In the VFIO KVM case I would expect the VM to experiance a RAS error on its vPCI device and trigger a VF flr

This would need to be a device level RAS flow as we're sorely lacking on forwarding reset notification to VF drivers or providing any mechanism for recovery from the vfio error eventfd.

Quoted 2 lines

But we have to sort all this out through the hypervisor to not crash the machine or otherwise :)

In general guarding the high level pci_reset_function() family on (pci_num_vfs() == 0) seems to have more pros than cons and the restriction matches the scoped intent of the interface.

The low level __pci_reset_function_locked() interface remains untouched, and as the prefix implies, relies on the caller to do necessary verification and preparation. A "reset the PF regardless of VFs" seems like an underscore prefix sort of operation. We'll need to export the pci_dev_save_and_disable() and pci_dev_restore() functions to provide handlers the full suite of tools they need to replace the existing function and port those we find (maybe also questioning the author's intent on VF reset and recovery).

Quoted 3 lines

Of course making the guard parameterized with wrappers to expand this family of calls is also an option, pci_reset_function_locked_with_vfs()...

+1 for wrappers. Maybe call it pci_force_reset_function_locked() which is slightly forward-looking if in future other conditions may reject the reset request using the base function.

Quoted 9 lines

The mlx5 driver doesn't actually seem to be affected by these changes, doing its own link toggle or a PCI bus reset, not a pci_reset_function() call.

On the other improvements, triggering a pci_reset_function_locked() on unbind after SR-IOV is disabled, when needs_reset is indicated, looks pretty trivial.

Quoted 5 lines

The blocking domain operation looks like it might be simplest to implement in the IOMMU core. We can set a flag for a default blocking domain on the IOMMU group when we take_dma_ownership of the group. Then
release_dma_ownership picks the blocking rather than default domain.

IMHO we should change release_dma_ownership() to always picks the blocking. No new flag.

this take/release interfaces are invented for drivers which manage dma on their own, so it sounds reasonable to not assume the operated device is in a good shape after the ownership is released.

Then only a clean reset can unwind it.

Quoted 6 lines

This is then unwound in use_default_domain, called via dma_configure, attaching the device to the default domain in probe of the next driver. Therefore until probe by another driver, a device used by vfio would remain in a blocking domain even while unused and unbound.

Quoted 6 lines

so unwinding it blindly at dma_configure time is also problematic, as the device may still have a bad state to hurt the kernel.

Instead use_default_domain should fail in such case (in blocked with owner_cnt being '0') then a reset is expected to unwind it (Nicolin's work will carry the resetting status to pci_dev_reset_iommu_done())

Thinking about this more, it might be tricky in multiple ways,

- This will only work if drivers do reset after dma ownership is released. Looking at the code, vfio currently resets the device first and then dma ownership is released.
- For some devices with no reset mechanism, vfio-pci uses bus or slot resets. This will need extra care to propagate the reset_iommu_prepare/reset_iommu_done to subordinate devices to bring the device out of blocking domain.
- AFAIU looking at vfio-pci code, some devices do not have proper reset mechanism, not even slot/bus, so those devices would be stuck in the blocking domain state. Probably need a mechanism to let IOMMU know that there is no reset mechanism?

Thanks,
Sami

#16 lore raw

Re: [RFC PATCH 1/5] PCI: Refuse function reset of an SR-IOV PF with enabled VFs

In reply to Alex Williamson
Quoted 32 lines · Alex Williamson

pci_reset_function() and its locked and try variants are intended to provide a function-scoped reset. The bus and slot methods supporting this interface refuse when sibling or subordinate devices are present. SR-IOV VFs however, are not currently considered in this scope.

Correct this oversight by testing for non-zero VF count in calls through the pci_reset_function() interfaces. This test needs to occur under device_lock to avoid races with .sriov_configure. It should also occur before pci_dev_save_and_disable() to avoid calling potentially destructive reset hooks. Tests are therefore added to each of pci_reset_function(), pci_reset_function_locked(), and pci_try_reset_function().

The __pci_reset_function_locked() interface remains a low-level primitive depending on the caller to perform such tests as necessary. The vfio_pci_core use case of __pci_reset_function_locked() is pulled through with this test. Other use cases, such as xen-pciback, that don't obviously support or prevent binding to SR-IOV enabled PFs will need to decide whether VFs are possible and can be preserved. Additionally, direct callers of sriov_enable() that do not hold device_lock (lpfc) are considered a preexisting, non-compliance issue.

Fixes dd7cc44d0bce ("PCI: add SR-IOV API for Physical Function driver")
Assisted-by Claude:claude-opus-4-8

---
drivers/pci/pci.c | 19 +++++++++++++++++++
drivers/vfio/pci/vfio_pci_core.c | 4 +++-

2 files changed, 22 insertions(+), 1 deletion(-)
drivers/vfio/pci/vfio_pci_core.c +0 -0

[snip]

drivers/vfio/pci/vfio_pci_core.c

Quoted 3 lines

index 3f11a9624b9c..9757b171791c 100644

drivers/vfio/pci/vfio_pci_core.c +0 -0

nit: This probably needs to be a different patch.

drivers/vfio/pci/vfio_pci_core.c void vfio_pci_core_disable(struct vfio_pci_core_device *vdev) · line 798

Quoted 11 lines
drivers/vfio/pci/vfio_pci_core.c +3 -1
@@ -790,7 +790,9 @@ void vfio_pci_core_disable(struct vfio_pci_core_device *vdev)
 		if (bridge && !pci_dev_trylock(bridge))
 			goto out_restore_state;
 		if (pci_dev_trylock(pdev)) {
-			if (!__pci_reset_function_locked(pdev))
+			/* Enforce function scope under lock for SR-IOV PFs */
+			if (!pci_num_vf(pdev) &&
+			    !__pci_reset_function_locked(pdev))
 				vdev->needs_reset = false;
 			pci_dev_unlock(pdev);
 		}

I was worried that this would fall into pci_restore_state() and disable sriov, but it doesn't since there is a check in pci_restore_iov_state() that skips disabling sriov if VFs are enabled.

Do you think we should skip the pci_restore_state() in general?

Quoted 3 lines
Signature · 1 line
2.53.0
#17 lore raw

RFC PATCH 2/5 PCI: Add pci_reset_bus_cond() for a caller-gated slot or bus reset

In reply to Alex Williamson

pci_reset_bus() locks every device affected by a slot or bus reset, performs the reset, and unlocks the devices, all internally. A caller has no way to evaluate what the reset would actually touch.

Add pci_reset_bus_cond(), which takes a callback invoked on each affected device once they are all locked. A nonzero return value from the callback aborts the reset and the value is returned to the caller. This allows, for instance, the caller to validate that SR-IOV is not enabled on any affected device under device_lock, where the value is known stable across the reset.

Assisted-by Claude:claude-opus-4-8
---
 drivers/pci/pci.c   | 97 ++++++++++++++++++++++++++++++++++++++-------
 include/linux/pci.h |  3 ++
 2 files changed, 85 insertions(+), 15 deletions(-)
drivers/pci/pci.c +82 -15
index b40b00c0c0c9..06728137c407 100644
@@ -5567,9 +5567,36 @@ int pci_probe_reset_slot(struct pci_slot *slot)
 }
 EXPORT_SYMBOL_GPL(pci_probe_reset_slot);
 
+/* Call @cb on every device a slot or bus reset affects, stopping on error. */
+static int pci_walk_reset_check(struct pci_bus *bus, struct pci_slot *slot,
+				int (*cb)(struct pci_dev *dev, void *data),
+				void *data)
+{
+	struct pci_dev *dev;
+	int rc;
+
+	list_for_each_entry(dev, &bus->devices, bus_list) {
+		if (slot && (!dev->slot || dev->slot != slot))
+			continue;
+		rc = cb(dev, data);
+		if (rc)
+			return rc;
+		if (dev->subordinate) {
+			rc = pci_walk_reset_check(dev->subordinate,
+						  NULL, cb, data);
+			if (rc)
+				return rc;
+		}
+	}
+
+	return 0;
+}
+
 /**
  * pci_try_reset_slot - Try to reset a PCI slot
  * @slot: PCI slot to reset
+ * @check: optional per-device callback that can abort the reset
+ * @data: opaque argument for @check
  *
  * A PCI bus may host multiple slots, each slot may support a reset mechanism
  * independent of other slots.  For instance, some slots may support slot power
@@ -5582,7 +5609,9 @@ EXPORT_SYMBOL_GPL(pci_probe_reset_slot);
  *
  * Same as above except return -EAGAIN if the slot cannot be locked
  */
-static int pci_try_reset_slot(struct pci_slot *slot)
+static int pci_try_reset_slot(struct pci_slot *slot,
+			      int (*check)(struct pci_dev *dev, void *data),
+			      void *data)
 {
 	int rc;
 
@@ -5591,10 +5620,14 @@ static int pci_try_reset_slot(struct pci_slot *slot)
 		return rc;
 
 	if (pci_slot_trylock(slot)) {
-		pci_slot_save_and_disable_locked(slot);
-		might_sleep();
-		rc = pci_reset_hotplug_slot(slot->hotplug, PCI_RESET_DO_RESET);
-		pci_slot_restore_locked(slot);
+		rc = check ? pci_walk_reset_check(slot->bus, slot, check, data) : 0;
+		if (!rc) {
+			pci_slot_save_and_disable_locked(slot);
+			might_sleep();
+			rc = pci_reset_hotplug_slot(slot->hotplug,
+						    PCI_RESET_DO_RESET);
+			pci_slot_restore_locked(slot);
+		}
 		pci_slot_unlock(slot);
 	} else
 		rc = -EAGAIN;
@@ -5626,10 +5659,14 @@ static int pci_bus_reset(struct pci_bus *bus, bool probe)
 /**
  * pci_try_reset_bus - Try to reset a PCI bus
  * @bus: top level PCI bus to reset
+ * @check: optional per-device callback that can abort the reset
+ * @data: opaque argument for @check
  *
  * Same as above except return -EAGAIN if the bus cannot be locked
  */
-static int pci_try_reset_bus(struct pci_bus *bus)
+static int pci_try_reset_bus(struct pci_bus *bus,
+			     int (*check)(struct pci_dev *dev, void *data),
+			     void *data)
 {
 	int rc;
 
@@ -5638,10 +5675,13 @@ static int pci_try_reset_bus(struct pci_bus *bus)
 		return rc;
 
 	if (pci_bus_trylock(bus)) {
-		pci_bus_save_and_disable_locked(bus);
-		might_sleep();
-		rc = pci_bridge_secondary_bus_reset(bus->self);
-		pci_bus_restore_locked(bus);
+		rc = check ? pci_walk_reset_check(bus, NULL, check, data) : 0;
+		if (!rc) {
+			pci_bus_save_and_disable_locked(bus);
+			might_sleep();
+			rc = pci_bridge_secondary_bus_reset(bus->self);
+			pci_bus_restore_locked(bus);
+		}
 		pci_bus_unlock(bus);
 	} else
 		rc = -EAGAIN;
@@ -5680,7 +5720,7 @@ static int pci_reset_bridge(struct pci_dev *bridge, bool restore)
 
 	list_for_each_entry(slot, &bus->slots, list) {
 		if (restore)
-			ret = pci_try_reset_slot(slot);
+			ret = pci_try_reset_slot(slot, NULL, NULL);
 		else
 			ret = pci_slot_reset(slot, PCI_RESET_DO_RESET);
 
@@ -5694,7 +5734,7 @@ static int pci_reset_bridge(struct pci_dev *bridge, bool restore)
 	mutex_unlock(&pci_slot_mutex);
 
 	if (restore)
-		return pci_try_reset_bus(bus);
+		return pci_try_reset_bus(bus, NULL, NULL);
 	return pci_bus_reset(bridge->subordinate, PCI_RESET_DO_RESET);
 }
 
@@ -5724,16 +5764,43 @@ int pci_probe_reset_bus(struct pci_bus *bus)
 }
 EXPORT_SYMBOL_GPL(pci_probe_reset_bus);
 
+/**
+ * pci_reset_bus_cond - conditionally reset the slot or bus containing a device
+ * @pdev: top level PCI device to reset via slot/bus
+ * @check: optional callback invoked on each affected device before the reset
+ * @data: opaque argument passed to @check
+ *
+ * Reset the slot or bus containing @pdev.  Once the entire physical bus/slot
+ * hierarchy is locked, @check (if not NULL) is called on each of those locked
+ * devices.  A nonzero return aborts the reset and is returned to the caller,
+ * otherwise the reset proceeds.
+ *
+ * NB. @check runs with the full set of device_locks noted above held; callbacks
+ * must take these locking semantics into account.  Use NULL to perform an
+ * unconditional reset.
+ *
+ * Return: 0 on success, -ENOTTY if @pdev is not resettable, -EAGAIN if the
+ * devices cannot be locked, or the value returned by @check.
+ */
+int pci_reset_bus_cond(struct pci_dev *pdev,
+		       int (*check)(struct pci_dev *dev, void *data),
+		       void *data)
+{
+	return !pci_probe_reset_slot(pdev->slot) ?
+		pci_try_reset_slot(pdev->slot, check, data) :
+		pci_try_reset_bus(pdev->bus, check, data);
+}
+EXPORT_SYMBOL_GPL(pci_reset_bus_cond);
+
 /**
  * pci_reset_bus - Try to reset a PCI bus
  * @pdev: top level PCI device to reset via slot/bus
  *
- * Same as above except return -EAGAIN if the bus cannot be locked
+ * Same as above without the conditional check.
  */
 int pci_reset_bus(struct pci_dev *pdev)
 {
-	return (!pci_probe_reset_slot(pdev->slot)) ?
-	    pci_try_reset_slot(pdev->slot) : pci_try_reset_bus(pdev->bus);
+	return pci_reset_bus_cond(pdev, NULL, NULL);
 }
 EXPORT_SYMBOL_GPL(pci_reset_bus);
 
include/linux/pci.h +3 -0
index 64b308b6e61c..ab41a49f4eb7 100644
@@ -1480,6 +1480,9 @@ int pci_try_reset_function(struct pci_dev *dev);
 int pci_probe_reset_slot(struct pci_slot *slot);
 int pci_probe_reset_bus(struct pci_bus *bus);
 int pci_reset_bus(struct pci_dev *dev);
+int pci_reset_bus_cond(struct pci_dev *pdev,
+		       int (*check)(struct pci_dev *dev, void *data),
+		       void *data);
 void pci_reset_secondary_bus(struct pci_dev *dev);
 void pcibios_reset_secondary_bus(struct pci_dev *dev);
 void pci_update_resource(struct pci_dev *dev, int resno);
Signature · 1 line
2.53.0
#18 lore raw

Re: [RFC PATCH 2/5] PCI: Add pci_reset_bus_cond() for a caller-gated slot or bus reset

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines

pci_reset_bus() locks every device affected by a slot or bus reset, performs the reset, and unlocks the devices, all internally. A caller has no way to evaluate what the reset would actually touch.

Add pci_reset_bus_cond(), which takes a callback invoked on each affected device once they are all locked. A nonzero return value from the callback aborts the reset and the value is returned to the caller. This allows, for instance, the caller to validate that SR-IOV is not enabled on any affected device under device_lock, where the value is known stable across the reset.

Quoted 2 lines
Assisted-by Claude:claude-opus-4-8

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#19 lore raw

RFC PATCH 3/5 vfio/pci: Refuse to reset an SR-IOV PF with enabled VFs

In reply to Alex Williamson

The vfio-pci hot-reset interface VFIO_DEVICE_PCI_HOT_RESET does not take into account whether an SR-IOV PF has active VFs. The VFs appear on a virtual bus, which is not enumerated in collecting affected devices.

Move the burden to the user when active VFs are present, require that there are no VFs present on SR-IOV capable PFs in order to conduct a hot reset.

Fixes 137e5531351d ("vfio/pci: Add sriov_configure support")
Assisted-by Claude:claude-opus-4-8
---
 drivers/vfio/pci/vfio_pci_core.c | 15 +++++++++++++--
 include/uapi/linux/vfio.h        |  3 +++
 2 files changed, 16 insertions(+), 2 deletions(-)
drivers/vfio/pci/vfio_pci_core.c +13 -2
index 9757b171791c..956a05ca12e5 100644
@@ -894,6 +894,17 @@ static int vfio_pci_count_devs(struct pci_dev *pdev, void *data)
 	return 0;
 }
 
+/*
+ * PCI walk callback to check for SR-IOV PFs with active VFs.  VFs are not
+ * enumerated when determining affected devices and may be owned by separate
+ * userspace processes from the PF.  It's therefore the user's responsibility
+ * to teardown VFs for any affected PF before performing a hot-reset.
+ */
+static int vfio_pci_dev_has_vfs(struct pci_dev *pdev, void *data)
+{
+	return pci_num_vf(pdev) ? -EBUSY : 0;
+}
+
 struct vfio_pci_fill_info {
 	struct vfio_device *vdev;
 	struct vfio_pci_dependent_device *devices;
@@ -2598,7 +2609,7 @@ static int vfio_pci_dev_set_hot_reset(struct vfio_device_set *dev_set,
 	list_for_each_entry(vdev, &dev_set->device_list, vdev.dev_set_list)
 		vfio_pci_set_power_state(vdev, PCI_D0);
 
-	ret = pci_reset_bus(pdev);
+	ret = pci_reset_bus_cond(pdev, vfio_pci_dev_has_vfs, NULL);
 
 	vdev = list_last_entry(&dev_set->device_list,
 			       struct vfio_pci_core_device, vdev.dev_set_list);
@@ -2661,7 +2672,7 @@ static void vfio_pci_dev_set_try_reset(struct vfio_device_set *dev_set)
 	if (vfio_pci_dev_set_pm_runtime_get(dev_set))
 		return;
 
-	if (!pci_reset_bus(pdev))
+	if (!pci_reset_bus_cond(pdev, vfio_pci_dev_has_vfs, NULL))
 		reset_done = true;
 
 	list_for_each_entry(cur, &dev_set->device_list, vdev.dev_set_list) {
include/uapi/linux/vfio.h +3 -0
index 5de618a3a5ee..8603959f1735 100644
@@ -772,6 +772,9 @@ struct vfio_pci_hot_reset_info {
  * Mixed usage of legacy groups and cdevs across the set of affected
  * devices is not supported.
  *
+ * Hot reset of SR-IOV PFs with active VFs is not supported, SR-IOV
+ * should first be disabled on any affected PF.
+ *
  * Return: 0 on success, -errno on failure.
  */
 struct vfio_pci_hot_reset {
Signature · 1 line
2.53.0
#20 lore raw

Re: [RFC PATCH 3/5] vfio/pci: Refuse to reset an SR-IOV PF with enabled VFs

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines

The vfio-pci hot-reset interface VFIO_DEVICE_PCI_HOT_RESET does not take into account whether an SR-IOV PF has active VFs. The VFs appear on a virtual bus, which is not enumerated in collecting affected devices.

Quoted 8 lines

Move the burden to the user when active VFs are present, require that there are no VFs present on SR-IOV capable PFs in order to conduct a hot reset.

Fixes 137e5531351d ("vfio/pci: Add sriov_configure support")
Assisted-by Claude:claude-opus-4-8

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#21 lore raw

RFC PATCH 4/5 PCI: Export pci_reset_supported()

In reply to Alex Williamson

The success or failure of pci_reset_function() is conditional on the state of the device, ex. VFs enabled on an SR-IOV PF. Therefore a driver can no longer infer through executing pci_reset_function() whether a device has supported reset methods. The reset_methods array indicates whether the device has any available reset mechanisms and is not gated on dynamic blockers, like SR-IOV enablement.

Export pci_reset_supported() for drivers to use for an instant snapshot of reset support.

Assisted-by Claude:claude-opus-4-8
---
 drivers/pci/pci.c   | 1 +
 drivers/pci/pci.h   | 1 -
 include/linux/pci.h | 1 +
 3 files changed, 2 insertions(+), 1 deletion(-)
drivers/pci/pci.c +1 -0
index 06728137c407..0b4f13397da2 100644
@@ -98,6 +98,7 @@ bool pci_reset_supported(struct pci_dev *dev)
 {
 	return dev->reset_methods[0] != 0;
 }
+EXPORT_SYMBOL_GPL(pci_reset_supported);
 
 #ifdef CONFIG_PCI_DOMAINS
 int pci_domains_supported = 1;
drivers/pci/pci.h +0 -1
index 4469e1a77f3c..416fd6b74abe 100644
@@ -230,7 +230,6 @@ enum pci_mmap_api {
 int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vmai,
 		  enum pci_mmap_api mmap_api);
 
-bool pci_reset_supported(struct pci_dev *dev);
 void pci_init_reset_methods(struct pci_dev *dev);
 int pci_bridge_secondary_bus_reset(struct pci_dev *dev);
 int pci_bus_error_reset(struct pci_dev *dev);
include/linux/pci.h +1 -0
index ab41a49f4eb7..4de21e6ac538 100644
@@ -1474,6 +1474,7 @@ void pcie_print_link_status(struct pci_dev *dev);
 int pcie_reset_flr(struct pci_dev *dev, bool probe);
 int pcie_flr(struct pci_dev *dev);
 int __pci_reset_function_locked(struct pci_dev *dev);
+bool pci_reset_supported(struct pci_dev *dev);
 int pci_reset_function(struct pci_dev *dev);
 int pci_reset_function_locked(struct pci_dev *dev);
 int pci_try_reset_function(struct pci_dev *dev);
Signature · 1 line
2.53.0
#22 lore raw

Re: [RFC PATCH 4/5] PCI: Export pci_reset_supported()

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

The success or failure of pci_reset_function() is conditional on the state of the device, ex. VFs enabled on an SR-IOV PF. Therefore a driver can no longer infer through executing pci_reset_function() whether a device has supported reset methods. The reset_methods array indicates whether the device has any available reset mechanisms and is not gated on dynamic blockers, like SR-IOV enablement.

Quoted 5 lines

Export pci_reset_supported() for drivers to use for an instant snapshot of reset support.

Assisted-by Claude:claude-opus-4-8

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#23 lore raw

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

In reply to Alex Williamson

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
---
 drivers/vfio/pci/vfio_pci_core.c | 9 ++++-----
 include/linux/vfio_pci_core.h    | 1 -
 2 files changed, 4 insertions(+), 6 deletions(-)
drivers/vfio/pci/vfio_pci_core.c +4 -5
index 956a05ca12e5..8e42342d56d3 100644
@@ -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);
include/linux/vfio_pci_core.h +0 -1
index 9a1674c152aa..6fb599ec2919 100644
@@ -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;
Signature · 1 line
2.53.0
#24 lore raw

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

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 14 lines

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.

Quoted 2 lines
Assisted-by Claude:claude-opus-4-8

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#25 lore raw
In reply to Alex Williamson

[+cc Andrii, Mitch, Nick, Tony, Przemek]

Quoted 4 lines · Alex Williamson

It's recently been found[1] that vfio-pci doesn't restrict resets on PFs while SR-IOV is enabled. This can not only result in an uncoordinated disruption of the use of the associated VFs, but the ongoing use of and access to the VF has the potential to result in machine checks.

I suspect this might also be related to the somewhat weird usage of pci_restore_msi_state() to restore VF MSI state in several network drivers:

https://git.kernel.org/linus/371e576ff3e8 ("i40e: Restore VF MSI-X state during PCI reset")
https://git.kernel.org/linus/7e4dcc13965c ("iavf: restore MSI state on reset")
https://git.kernel.org/linus/a54a0b24f4f5 ("ice: restore VF MSI-X state during PCI reset")

I think these are a little weird because they only run on a PF but call pci_restore_msi_state() on all the VFs.

I guess these paths are recovery after FLR of the PF destroys the VFs, and after the FLR, pci_restore_state() on the PF re-enables the VFs but leaves them uninitialized. It seems kind of ad hoc to restore VF MSI state but not the rest of VF config space. This all seems kind of messy and makes me dubious about exporting pci_restore_msi_state() directly to drivers.

Quoted 57 lines

This series proposes that this gap is largely an oversight of pci_reset_function() to recognize that a PF reset affecting SR-IOV VFs violates the scope boundary of the pci_reset_function() API.

Patch 1 introduces guards in the common wrappers where we can hold device_lock to prevent .sriov_configure races. This covers locking conformant use cases. __pci_reset_function_locked() can't be gated in PCI-core; it runs after the potentially destructive .reset_prepare. Therefore its callers must provide the gating, along with the locking and state manipulation the interface already demands. The vfio-pci change is included as an example and known use case here.

Patch 2 introduces a callback to pci_reset_bus() which allows a lock dependent callback to be evaluated after locking the physical hierarchy and before initiating the actual reset. This allows use cases such as in the following patch to evaluate the SR-IOV PF configuration without racing.

Patch 3 implements exactly that test in vfio-pci-core, such that the hot-reset ioctl can be blocked when SR-IOV VFs are present on a bus/slot affected PF. This completes the lockdown of resets induced on behalf of the vfio-pci in-kernel or userspace drivers.

Patch 4 exports pci_reset_supported, which allows patch 5 to remove the latched reset_works flag, which already had the potential to become stale due to reset_method manipulation through sysfs, but now may also become stale due to the SR-IOV state of the PF.

This is RFC to capture the discussion of [1] while it's active but requires testing before formal proposal. This effectively side-steps the feasibility and security question of the operating model in use by the referenced thread by generically gating resets affecting PFs with active SR-IOV. Please review and comment. Thanks,

Alex

[1]https://lore.kernel.org/all/[email protected]/

Alex Williamson (5):
PCI: Refuse function reset of an SR-IOV PF with enabled VFs
PCI: Add pci_reset_bus_cond() for a caller-gated slot or bus reset vfio/pci: Refuse to reset an SR-IOV PF with enabled VFs
PCI: Export pci_reset_supported()
vfio/pci: Use pci_reset_supported() in place of reset_works

 drivers/pci/pci.c                | 117 +++++++++++++++++++++++++++----
 drivers/pci/pci.h                |   1 -
 drivers/vfio/pci/vfio_pci_core.c |  28 +++++---
 include/linux/pci.h              |   4 ++
 include/linux/vfio_pci_core.h    |   1 -
 include/uapi/linux/vfio.h        |   3 +
 6 files changed, 129 insertions(+), 25 deletions(-)
Signature · 1 line
2.53.0
#26 lore raw
Quoted 19 lines · On Wed, 12 Aug 2026 16:45:54 -0500 Bjorn Helgaas <[email protected]> wrote:

[+cc Andrii, Mitch, Nick, Tony, Przemek]

Quoted 4 lines · Alex Williamson

It's recently been found[1] that vfio-pci doesn't restrict resets on PFs while SR-IOV is enabled. This can not only result in an uncoordinated disruption of the use of the associated VFs, but the ongoing use of and access to the VF has the potential to result in machine checks.

I suspect this might also be related to the somewhat weird usage of pci_restore_msi_state() to restore VF MSI state in several network drivers:

https://git.kernel.org/linus/371e576ff3e8 ("i40e: Restore VF MSI-X state during PCI reset")
https://git.kernel.org/linus/7e4dcc13965c ("iavf: restore MSI state on reset")
https://git.kernel.org/linus/a54a0b24f4f5 ("ice: restore VF MSI-X state during PCI reset")

I think these are a little weird because they only run on a PF but call pci_restore_msi_state() on all the VFs.

Quoted 6 lines

I guess these paths are recovery after FLR of the PF destroys the VFs, and after the FLR, pci_restore_state() on the PF re-enables the VFs but leaves them uninitialized. It seems kind of ad hoc to restore VF MSI state but not the rest of VF config space. This all seems kind of messy and makes me dubious about exporting pci_restore_msi_state() directly to drivers.

I don't understand how the i40e and ice NIC VFs can continue operation with only MSI-X state restored. It seems to directly contradict the requirements of the PCIe spec (7.0):

9.2.2.3 FLR That Targets a PF §

PFs must support FLR.

FLR to a PF resets the PF state as well as the SR-IOV extended capability including VF Enable which means that VFs no longer exist.

9.2.3 IOV Re-initialization and Reallocation §

If VF Enable is Cleared after having been Set, all of the VFs associated with the PF no longer exist and must no longer issue PCIe transactions or respond to Configuration Space or Memory Space accesses. VFs must not retain any architected state after VF Enable has been Cleared (including sticky bits). For security, unarchitected VF state configured through the VF must be cleared or randomized, with the exception of persistent storage data.

For the PF driver patches noted to be effective, the VFs must not be scrubbed on re-initialization, nor can a .reset_done hook in the PF driver do anything to avoid unsupported requests from ongoing DMA and MMIO accesses while VF Enable is cleared. So it looks like an incomplete fix for non-compliant devices? Thanks,

Alex

#27 lore raw
In reply to Bjorn Helgaas
Quoted 19 lines · Bjorn Helgaas

[+cc Andrii, Mitch, Nick, Tony, Przemek]

Quoted 4 lines · Alex Williamson

It's recently been found[1] that vfio-pci doesn't restrict resets on PFs while SR-IOV is enabled. This can not only result in an uncoordinated disruption of the use of the associated VFs, but the ongoing use of and access to the VF has the potential to result in machine checks.

I suspect this might also be related to the somewhat weird usage of pci_restore_msi_state() to restore VF MSI state in several network drivers:

https://git.kernel.org/linus/371e576ff3e8 ("i40e: Restore VF MSI-X state during PCI reset")
https://git.kernel.org/linus/7e4dcc13965c ("iavf: restore MSI state on reset")
https://git.kernel.org/linus/a54a0b24f4f5 ("ice: restore VF MSI-X state during PCI reset")

I think these are a little weird because they only run on a PF but call pci_restore_msi_state() on all the VFs.

Quoted 6 lines

I guess these paths are recovery after FLR of the PF destroys the VFs, and after the FLR, pci_restore_state() on the PF re-enables the VFs but leaves them uninitialized. It seems kind of ad hoc to restore VF MSI state but not the rest of VF config space. This all seems kind of messy and makes me dubious about exporting pci_restore_msi_state() directly to drivers.

Yea, this is situation we were trying to address; it seemed better for the user to try and recover functionality rather than leave the VFs non-operational. I like the idea of not allowing the call, when SR-IOV is enabled, to stop it from occurring in the first place though.

Thanks,
Tony

Quoted 57 lines
Quoted 57 lines

This series proposes that this gap is largely an oversight of pci_reset_function() to recognize that a PF reset affecting SR-IOV VFs violates the scope boundary of the pci_reset_function() API.

Patch 1 introduces guards in the common wrappers where we can hold device_lock to prevent .sriov_configure races. This covers locking conformant use cases. __pci_reset_function_locked() can't be gated in PCI-core; it runs after the potentially destructive .reset_prepare. Therefore its callers must provide the gating, along with the locking and state manipulation the interface already demands. The vfio-pci change is included as an example and known use case here.

Patch 2 introduces a callback to pci_reset_bus() which allows a lock dependent callback to be evaluated after locking the physical hierarchy and before initiating the actual reset. This allows use cases such as in the following patch to evaluate the SR-IOV PF configuration without racing.

Patch 3 implements exactly that test in vfio-pci-core, such that the hot-reset ioctl can be blocked when SR-IOV VFs are present on a bus/slot affected PF. This completes the lockdown of resets induced on behalf of the vfio-pci in-kernel or userspace drivers.

Patch 4 exports pci_reset_supported, which allows patch 5 to remove the latched reset_works flag, which already had the potential to become stale due to reset_method manipulation through sysfs, but now may also become stale due to the SR-IOV state of the PF.

This is RFC to capture the discussion of [1] while it's active but requires testing before formal proposal. This effectively side-steps the feasibility and security question of the operating model in use by the referenced thread by generically gating resets affecting PFs with active SR-IOV. Please review and comment. Thanks,

Alex

[1]https://lore.kernel.org/all/[email protected]/

Alex Williamson (5):
PCI: Refuse function reset of an SR-IOV PF with enabled VFs
PCI: Add pci_reset_bus_cond() for a caller-gated slot or bus reset vfio/pci: Refuse to reset an SR-IOV PF with enabled VFs
PCI: Export pci_reset_supported()
vfio/pci: Use pci_reset_supported() in place of reset_works

  drivers/pci/pci.c                | 117 +++++++++++++++++++++++++++----
  drivers/pci/pci.h                |   1 -
  drivers/vfio/pci/vfio_pci_core.c |  28 +++++---
  include/linux/pci.h              |   4 ++
  include/linux/vfio_pci_core.h    |   1 -
  include/uapi/linux/vfio.h        |   3 +
  6 files changed, 129 insertions(+), 25 deletions(-)
Signature · 1 line
2.53.0
Tested-by on the v1 series
#28 lore raw
In reply to Alex Williamson
Quoted 8 lines · Alex Williamson

It's recently been found[1] that vfio-pci doesn't restrict resets on PFs while SR-IOV is enabled. This can not only result in an uncoordinated disruption of the use of the associated VFs, but the ongoing use of and access to the VF has the potential to result in machine checks.

This series proposes that this gap is largely an oversight of pci_reset_function() to recognize that a PF reset affecting SR-IOV VFs violates the scope boundary of the pci_reset_function() API.

Hi Alex,

Thanks for sending out the RFC to fix this issue. I cherry-picked it into my environment to verify that whether it fixes the issue I was experiencing and it does fix it. I will continue to do more testing, but when you send this as a formal v1, you can add:

Sami

#29 lore raw
Quoted 12 lines · Samiullah Khawaja
Quoted 8 lines · Alex Williamson

It's recently been found[1] that vfio-pci doesn't restrict resets on PFs while SR-IOV is enabled. This can not only result in an uncoordinated disruption of the use of the associated VFs, but the ongoing use of and access to the VF has the potential to result in machine checks.

This series proposes that this gap is largely an oversight of pci_reset_function() to recognize that a PF reset affecting SR-IOV VFs violates the scope boundary of the pci_reset_function() API.

Hi Alex,

Quoted 8 lines

Thanks for sending out the RFC to fix this issue. I cherry-picked it into my environment to verify that whether it fixes the issue I was experiencing and it does fix it. I will continue to do more testing, but when you send this as a formal v1, you can add:

Hi Alex,

Is this series still on your radar for formal v1?

If this is the direction we are going in I can use it for liveupdate work
https://lore.kernel.org/all/auzftbPFO_6XBYVw%40google.com/

Thanks
Vipin

#30 lore raw
Quoted 24 lines · Vipin Sharma
Quoted 12 lines · Samiullah Khawaja
Quoted 8 lines · Alex Williamson

It's recently been found[1] that vfio-pci doesn't restrict resets on PFs while SR-IOV is enabled. This can not only result in an uncoordinated disruption of the use of the associated VFs, but the ongoing use of and access to the VF has the potential to result in machine checks.

This series proposes that this gap is largely an oversight of pci_reset_function() to recognize that a PF reset affecting SR-IOV VFs violates the scope boundary of the pci_reset_function() API.

Hi Alex,

Quoted 8 lines

Thanks for sending out the RFC to fix this issue. I cherry-picked it into my environment to verify that whether it fixes the issue I was experiencing and it does fix it. I will continue to do more testing, but when you send this as a formal v1, you can add:

Hi Alex,

Quoted 7 lines

Is this series still on your radar for formal v1?

If this is the direction we are going in I can use it for liveupdate work
https://lore.kernel.org/all/auzftbPFO_6XBYVw%40google.com/

Thanks
Vipin

Hi Vipin,

Alex asked me whether I or someone on our team could pick up this series. Pranjal is working on it and will send out a new version. There is some extra work needed on the IOMMU side to make sure that the device is moved to a blocking domain when the reset is skipped.

But I think the patch you need is fairly independent and can be sent out separately from this series:
https://lore.kernel.org/kvm/[email protected]/

Thanks,
Sami

#31 lore raw
Quoted 35 lines · Samiullah Khawaja
Quoted 24 lines · Vipin Sharma
Quoted 12 lines · Samiullah Khawaja
Quoted 8 lines · Alex Williamson

It's recently been found[1] that vfio-pci doesn't restrict resets on PFs while SR-IOV is enabled. This can not only result in an uncoordinated disruption of the use of the associated VFs, but the ongoing use of and access to the VF has the potential to result in machine checks.

This series proposes that this gap is largely an oversight of pci_reset_function() to recognize that a PF reset affecting SR-IOV VFs violates the scope boundary of the pci_reset_function() API.

Hi Alex,

Quoted 8 lines

Thanks for sending out the RFC to fix this issue. I cherry-picked it into my environment to verify that whether it fixes the issue I was experiencing and it does fix it. I will continue to do more testing, but when you send this as a formal v1, you can add:

Hi Alex,

Quoted 7 lines

Is this series still on your radar for formal v1?

If this is the direction we are going in I can use it for liveupdate work
https://lore.kernel.org/all/auzftbPFO_6XBYVw%40google.com/

Thanks
Vipin

Hi Vipin,

Quoted 9 lines

Alex asked me whether I or someone on our team could pick up this series. Pranjal is working on it and will send out a new version. There is some extra work needed on the IOMMU side to make sure that the device is moved to a blocking domain when the reset is skipped.

But I think the patch you need is fairly independent and can be sent out separately from this series:
https://lore.kernel.org/kvm/[email protected]/

That works for me. I can send this patch separately.

Thanks,
Vipin