Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH] vfio/pci: Restore standard PCI config space in .slot_reset()
@ 2026-08-17 19:51 Keith Busch
  2026-08-17 20:04 ` sashiko-bot
  2026-08-17 21:50 ` Alex Williamson
  0 siblings, 2 replies; 5+ messages in thread
From: Keith Busch @ 2026-08-17 19:51 UTC (permalink / raw)
  To: alex, bhelgaas, linux-pci; +Cc: mattev, matt, nekto0n, Keith Busch

From: Keith Busch <kbusch@kernel.org>

Hi Alex, Bjorn, Linux-PCI, and VFIO,

I'd like to initiate, or maybe restart, a discussion regarding the
current state of PCIe AER and DPC (Downstream Port Containment) recovery
for devices bound to vfio-pci, potentially expanding to devices not
bound to anything at all.

Currently, when a link reset or Secondary Bus Reset occurs due to an
AER/DPC event, the kernel PCI error recovery service executes reset
routines across affected downstream devices. Since vfio-pci does not
implement the .slot_reset() callback in its pci_error_handlers struct,
the standard PCI config space (BARs, Command register, MSI-X setup,
DevCtl, etc.) for downstream devices is left entirely uninitialized
after the link is brought back up.

Historically the PCI core introduced early pci_save_state()
checkpointing prior to driver probe (e.g. commit 30d52f6385d8, "PCI:
Save device state in pci_pm_init() before driver probe") precisely to
ensure that the kernel maintains a valid baseline config space
snapshot—even for driverless or stub-bound devices. However, that
infrastructure was never fully connected to the error recovery callbacks
for generic pass-through drivers.

For bare-metal userspace drivers, like custom user-level drivers, this
creates an operational deadlock:

1. The kernel PCI error handling triggers a bus/link reset, but leaves
   standard PCI config space wiped back to power-on defaults.
2. The eventfd (VFIO_PCI_ERR_IRQ_INDEX) alerts userspace that an error occurred,
   but gives no indication of when link recovery/reset completes.
3. Userspace attempting to re-initialize or access the device races against
   the kernel's reset sequence or operates on zeroed/uninitialized config registers.
4. While QEMU originally included stubs intended to coordinate AER recovery with
   guest OS drivers, that guest-host coordination infrastructure has remained
   unimplemented for over a decade.

In scenarios where userspace simply needs the underlying hardware
restored to its known-good baseline state post-reset, having vfio-pci
implement .slot_reset() and leverage the existing PCI core snapshot via
pci_restore_state() bridges this gap cleanly.

We recently saw related discussions around VFIO error recovery on s390x
(https://lore.kernel.org/linux-pci/20260603182415.2324-1-alifm@linux.ibm.com/#t),
where platform-specific mechanisms had to be wired up to communicate PCI
errors to userspace. However, for standard PCIe setups relying on
generic kernel error recovery (pcie_do_recovery), vfio-pci still lacks
the fundamental .slot_reset() handling needed to restore standard PCI
config space after recoverying from a fatal error.
---
A few questions I'd like to put to the list:
1. Since the PCI core already takes responsibility for holding the early 
   config space checkpoint, is calling pci_restore_state() during
   .slot_reset() the appropriate place for vfio-pci to apply it, or
   should this be explicitly driven/triggered via a VFIO ioctl?
2. Does returning PCI_ERS_RESULT_RECOVERED here create subtle state
   issues if userspace directly modified config space registers that
   were not captured in pdev->saved_config_space?
3. Should we pair this with an explicit "link restored / reset complete"
   eventfd notification so userspace knows exactly when it is safe to
   resume access?

Appreciate any feedback or historical context on how VFIO and PCI error
recovery should interact here.

 drivers/vfio/pci/vfio_pci_core.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index 3f11a9624b9c0..5b42430337e29 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -2347,6 +2347,13 @@ pci_ers_result_t vfio_pci_core_aer_err_detected(struct pci_dev *pdev,
 }
 EXPORT_SYMBOL_GPL(vfio_pci_core_aer_err_detected);
 
+pci_ers_result_t vfio_pci_core_aer_slot_reset(struct pci_dev *pdev,
+					      pci_channel_state_t state)
+{
+	pci_restore_state(pdev);
+	return PCI_ERS_RESULT_RECOVERED;
+}
+
 int vfio_pci_core_sriov_configure(struct vfio_pci_core_device *vdev,
 				  int nr_virtfn)
 {
@@ -2419,6 +2426,7 @@ EXPORT_SYMBOL_GPL(vfio_pci_core_sriov_configure);
 
 const struct pci_error_handlers vfio_pci_core_err_handlers = {
 	.error_detected = vfio_pci_core_aer_err_detected,
+	.slot_reset = vfio_pci_core_aer_slot_reset,
 };
 EXPORT_SYMBOL_GPL(vfio_pci_core_err_handlers);
 
-- 
2.53.0-Meta


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-08-17 23:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-17 19:51 [PATCH] vfio/pci: Restore standard PCI config space in .slot_reset() Keith Busch
2026-08-17 20:04 ` sashiko-bot
2026-08-17 20:18   ` Keith Busch
2026-08-17 21:50 ` Alex Williamson
2026-08-17 23:21   ` Keith Busch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox