PCI: liveupdate: PCI core support for Live Update
Subsystems (5)
v9 cover PCI: liveupdate: PCI core support for Live Update
This series can be found on GitHub:
https://github.com/dmatlack/linux/tree/liveupdate/pci/base/v9
This series introduces support in the PCI core for Live Update, enabling drivers to preserve PCI devices across a kexec-based kernel update without interrupting the device. This functionality is critical for minimizing downtime in environments where PCI devices (e.g., those assigned to VMs via VFIO) must continue operating or maintain state across a host kernel upgrade.
Specifically, this series allows preserved PCI devices to perform uninterrupted memory transactions (DMA) targeting system memory (specifically, preserved memfds) across a Live Update. These devices can be behind a bridge but must not be VFs. Support for P2P and VF preservation will be addressed in future series.
Series Overview
---------------
This series implements the following to support PCI device preservation across Live Update:
1. Set up a File-Lifecycle-Bound (FLB) handler to track and preserve PCI-specific state (struct pci_ser) across Live Update using Kexec Handover (KHO).
2. Add APIs for drivers to register devices for preservation (outgoing) and for the PCI core to identify preserved devices during enumeration (incoming)
3. Automatically preserve all upstream bridges for any preserved endpoint. Use reference counting to ensure bridges remain preserved as long as any downstream device is preserved.
4. Guarantee that preserved devices retain the same RequesterID (bus, device, function) for the duration of their preservation by inheriting secondary bus numbers, subordinate bus numbers, and ARI Forwarding Enable on preserved bridges.
5. Guarantee that memory transactions to/from preserved devices are routed consistently by inheriting Access Control Services (ACS) flags across a Live Update, from the endpoint up to the root port.
6. Modify the PCI shutdown path to avoid disabling bus mastering on preserved devices, thereby allowing preserved devices to perform uninterrupted during kexec for Live Update.
7. Provide comprehensive documentation for the FLB API, device tracking mechanisms, and the division of responsibilities between the PCI core, drivers, and userspace.
Merge Plan
----------
This series will be merged through liveupdate.git, matching the agreed-upon tree in the MAINTAINERS entry for PCI LIVE UPDATE.
Testing
-------
This series was tested in conjunction with v5 of the VFIO PCI driver series:
https://lore.kernel.org/kvm/[email protected]/
The full set of patches used for testing can be found on GitHub.
https://github.com/dmatlack/linux/tree/liveupdate/pci/base/v9-with-vfio
Testing was performed using the new VFIO selftests:
- vfio_pci_liveupdate_uapi_test
- vfio_pci_liveupdate_kexec_test
Both tests were run in a QEMU-based VM environment (using a single virtio-net PCIe device connected to a root port to exercise bridge support) and on bare metal using an Intel EMR server with 8x Intel DSA PCIe devices and 1x NVMe device.
Future Work
-----------
Following this series, we expect to make further improvements to the PCI core support for Live Update:
- Allow P2P across Live Update by avoiding resizing or moving preserved device BARs and preserving all upstream bridge windows.
- Support preserving Virtual Functions by preserving SR-IOV configuration on PFs and enumerating VFs after Live Update.
Changelog
---------
v9:
- Simplify pci_liveupdate_preserve_bus_numbers() to always return true if a device was preserved and drop pci_liveupdate_scan_bridge_end() (Bjorn)
- Add pci_liveupdate_refuse_bus_numbers() to determine when it is safe for the PCI core to assign bus numbers to unconfigured bridges. This required moving "Auto-preserve upstream bridges across Live Update" before "Preserve bus numbers during Live Update" (Bjorn)
- Add "PCI: Save and restore the ACS Control register" so that the ACS Control register is handled by the normal save/restore path (Bjorn)
- Rename struct pci_liveupdate::was_preserved to was_incoming, to disambiguate incoming from outgoing preservation (me)
- Log unfinished preserved devices from the incoming FLB rather than by walking struct pci_dev (Sashiko)
- Document that state handed over by the previous kernel is trusted, and panic in pci_flb_retrieve() where failures are detected rather than unwinding into a caller that panics anyway (Sashiko)
- Fall back to programming ACS from scratch when a preserved device has no ACS save buffer, since there is nowhere to record the adopted controls and they would be lost by the first reset (Sashiko)
- Drop Reviewed-by tags from "Preserve bus numbers during Live Update" and "Adopt ACS controls in incoming preserved devices", both of which changed materially since v8
- Extend commit messages and kernel-doc comments to make the FLB code flow more clear (Bjorn)
- Address various spelling, formatting, and stylistic issues (Bjorn)
v8: https://lore.kernel.org/linux-pci/[email protected]/
v7: https://lore.kernel.org/linux-pci/[email protected]/
v6: https://lore.kernel.org/linux-pci/[email protected]/
v5: https://lore.kernel.org/linux-pci/[email protected]/
v4: https://lore.kernel.org/linux-pci/[email protected]/
v3: https://lore.kernel.org/kvm/[email protected]/
v2: https://lore.kernel.org/kvm/[email protected]/
v1: https://lore.kernel.org/kvm/[email protected]/
rfc: https://lore.kernel.org/kvm/[email protected]/
David Matlack (13):
PCI: liveupdate: Set up FLB handler for the PCI core
PCI: liveupdate: Track outgoing preserved PCI devices
PCI: liveupdate: Track incoming preserved PCI devices
PCI: liveupdate: Document driver binding responsibilities
PCI: liveupdate: Auto-preserve upstream bridges across Live Update
PCI: liveupdate: Preserve bus numbers during Live Update
PCI: Refactor matching logic for pci_dev_acs_ops
PCI: Save and restore the ACS Control register
PCI: liveupdate: Adopt ACS controls in incoming preserved devices
PCI: liveupdate: Adopt ARI Forwarding Enable on preserved bridges
PCI: liveupdate: Freeze preservation status during shutdown
PCI: liveupdate: Do not disable bus mastering on preserved devices
during kexec
Documentation: PCI: Add documentation for Live Update
Documentation/PCI/index.rst | 1 + Documentation/PCI/liveupdate.rst | 35 + .../admin-guide/kernel-parameters.txt | 7 +- Documentation/core-api/liveupdate.rst | 5 + MAINTAINERS | 15 + drivers/pci/Kconfig | 15 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 1015 +++++++++++++++++ drivers/pci/liveupdate.h | 62 + drivers/pci/pci-driver.c | 9 +- drivers/pci/pci.c | 79 +- drivers/pci/pci.h | 5 + drivers/pci/probe.c | 16 +- drivers/pci/quirks.c | 58 +- include/linux/kho/abi/pci.h | 66 ++ include/linux/pci.h | 7 + include/linux/pci_liveupdate.h | 72 ++ 17 files changed, 1429 insertions(+), 39 deletions(-) create mode 100644 Documentation/PCI/liveupdate.rst create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/pci/liveupdate.h create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/pci_liveupdate.h
base-commit: 945d61765894dda2f0344de50cb1ade2e51b66fd
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
PATCH v9 1/13 PCI: liveupdate: Set up FLB handler for the PCI core
Set up a File-Lifecycle-Bound (FLB) handler so that the PCI core can preserve its own state across a Live Update kexec.
Preserving a PCI device across kexec requires preserving two independent sets of state:
- Driver state, e.g. everything vfio-pci needs so that userspace can keep using the device in the new kernel. The driver preserves this itself and the PCI core is not involved.
- PCI core state, e.g. which devices are preserved, so that the new kernel knows not to disturb them while they are still running and doing DMA. That is what this commit adds, serialized into struct pci_ser.
Userspace, not the kernel, decides which devices are preserved, and it does so through the Live Update Orchestrator's (LUO) support for file
preservation: a driver exposes a file that represents a single PCI device, and userspace preserves that device with ioctl(LIVEUPDATE_SESSION_PRESERVE_FD) on that file. Binding preservation to a file gives it proper lifecycle management, e.g. the preservation is undone if userspace cancels it or goes away. How a driver exposes that file is up to the driver and invisible to the PCI core (vfio-pci variant drivers, the first intended use-case, use their per-device cdev).
LUO only knows that a file was preserved; it does not know that it represents a PCI device, or which one. Bridging that gap, drivers register their liveupdate_file_handler with the PCI core:
pci_liveupdate_register_flb(driver_file_handler); pci_liveupdate_unregister_flb(driver_file_handler);
LUO then refcounts the PCI core's FLB against the files preserved by that handler, and that refcount drives the lifetime of struct pci_ser:
- On the first preserved file, luo_flb_file_preserve_one() calls pci_flb_preserve(), which allocates struct pci_ser and preserves it with KHO.
- On the last unpreserved file (i.e. preservation cancelled), liveupdate_flb_put_outgoing() calls pci_flb_unpreserve(), which unpreserves and frees struct pci_ser.
- In the next kernel, pci_flb_retrieve() hands the PCI core the struct pci_ser built by the previous kernel, whenever the PCI core asks for it (e.g. during enumeration), and pci_flb_finish() frees it once the PCI core is done with it.
So the flow for preserving a device, once a driver has registered, looks like this:
ioctl(LIVEUPDATE_SESSION_PRESERVE_FD)
luo_session_preserve_fd()
luo_preserve_file()
luo_flb_file_preserve()
luo_flb_file_preserve_one() # only on the first preserved file
pci_flb_preserve() # alloc + KHO-preserve pci_ser
fh->ops->preserve() # driver callback, e.g. vfio-pci
Note that struct pci_ser is deliberately not allocated when a driver calls pci_liveupdate_register_flb(). A driver can be loaded for the lifetime of the machine without ever preserving a device, and there is no reason to allocate memory and hand it to the next kernel in that case. Letting LUO own the lifetime also means the PCI core does not have to duplicate LUO's refcounting and unwind logic for preservation failures, session aborts and fd close, and the incoming side (retrieve/finish) comes from the same object rather than requiring a separate KHO FDT entry owned by the PCI core.
Note: This commit only allocates struct pci_ser and preserves it across Live Update. A subsequent commit adds pci_liveupdate_preserve(), the API drivers call from their fh->ops->preserve() callback to tell the PCI core exactly which devices are being preserved.
Note: There is no reason to check for kho_is_enabled() since it can be assumed to return true. If KHO was not enabled then Live Update would not be enabled and these routines would never run.
--- Documentation/core-api/liveupdate.rst | 4 + MAINTAINERS | 13 ++ drivers/pci/Kconfig | 15 ++ drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 206 ++++++++++++++++++++++++++ include/linux/kho/abi/pci.h | 65 ++++++++ include/linux/pci.h | 1 + include/linux/pci_liveupdate.h | 30 ++++ 8 files changed, 335 insertions(+) create mode 100644 drivers/pci/liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/pci_liveupdate.h
Documentation/core-api/liveupdate.rst +4 -0
@@ -1,5 +1,7 @@ .. SPDX-License-Identifier: GPL-2.0 +.. _luo: + ======================== Live Update Orchestrator ========================
@@ -18,6 +20,8 @@ LUO Preserving File Descriptors .. kernel-doc:: kernel/liveupdate/luo_file.c :doc: LUO File Descriptors +.. _flb: + LUO File Lifecycle Bound Global Data ==================================== .. kernel-doc:: kernel/liveupdate/luo_flb.c
MAINTAINERS +13 -0
@@ -21046,6 +21046,19 @@ L: [email protected] S: Supported F: Documentation/PCI/pci-error-recovery.rst +PCI LIVE UPDATE +M: David Matlack <[email protected]> +R: Pasha Tatashin <[email protected]> +R: Mike Rapoport <[email protected]> +R: Pratyush Yadav <[email protected]> +L: [email protected] +L: [email protected] +S: Maintained +T: git git://git.kernel.org/pub/scm/linux/kernel/git/liveupdate/linux.git +F: drivers/pci/liveupdate.c +F: include/linux/kho/abi/pci.h +F: include/linux/pci_liveupdate.h + PCI MSI DRIVER FOR ALTERA MSI IP L: [email protected] S: Orphan
drivers/pci/Kconfig +15 -0
@@ -271,6 +271,21 @@ config VGA_ARB_MAX_GPUS Reserves space in the kernel to maintain resource locking for multiple GPUS. The overhead for each GPU is very small. +config PCI_LIVEUPDATE + bool "PCI Live Update Support" + depends on PCI && LIVEUPDATE + help + Enable PCI core support for preserving PCI devices across Live + Update. This, in combination with support in a device's driver, + enables PCI devices to run and perform memory transactions + uninterrupted during a kexec for Live Update. + + This option should only be enabled by users who plan to use Live + Update for kernel upgrades and require preserving PCI devices during + those upgrades. + + If unsure, say N. + source "drivers/pci/hotplug/Kconfig" source "drivers/pci/controller/Kconfig" source "drivers/pci/endpoint/Kconfig"
drivers/pci/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_PROC_FS) += proc.o obj-$(CONFIG_SYSFS) += pci-sysfs.o slot.o obj-$(CONFIG_ACPI) += pci-acpi.o obj-$(CONFIG_GENERIC_PCI_IOMAP) += iomap.o +obj-$(CONFIG_PCI_LIVEUPDATE) += liveupdate.o endif obj-$(CONFIG_OF) += of.o
drivers/pci/liveupdate.c new file +206 -0
206 lines not on this page · raw message
include/linux/kho/abi/pci.h new file +65 -0
65 lines not on this page · raw message
include/linux/pci.h +1 -0
@@ -43,6 +43,7 @@#include <uapi/linux/pci.h> #include <linux/pci_ids.h> +#include <linux/pci_liveupdate.h> #define PCI_STATUS_ERROR_BITS (PCI_STATUS_DETECTED_PARITY | \ PCI_STATUS_SIG_SYSTEM_ERROR | \
include/linux/pci_liveupdate.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* PCI Live Update support (Public/Driver API) +* +* Copyright (c) 2026, Google LLC. +* David Matlack <[email protected]> +*/ +#ifndef LINUX_PCI_LIVEUPDATE_H +#define LINUX_PCI_LIVEUPDATE_H + +#include <linux/liveupdate.h> +#include <linux/types.h> + +struct pci_dev ; + +#ifdef CONFIG_PCI_LIVEUPDATE +int pci_liveupdate_register_flb (struct liveupdate_file_handler *fh); +void pci_liveupdate_unregister_flb (struct liveupdate_file_handler *fh); +#else +static inline int pci_liveupdate_register_flb (struct liveupdate_file_handler *fh) +{ +return -EOPNOTSUPP ; +} + +static inline void pci_liveupdate_unregister_flb (struct liveupdate_file_handler *fh) +{ +} +#endif + +#endif /* LINUX_PCI_LIVEUPDATE_H */
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
[email protected]
AI reviewRe: [PATCH v9 01/13] PCI: liveupdate: Set up FLB handler for the PCI core
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 15 lines
Set up a File-Lifecycle-Bound (FLB) handler so that the PCI core can preserve its own state across a Live Update kexec.
Preserving a PCI device across kexec requires preserving two independent sets of state:
- Driver state, e.g. everything vfio-pci needs so that userspace can keep using the device in the new kernel. The driver preserves this itself and the PCI core is not involved.
- PCI core state, e.g. which devices are preserved, so that the new kernel knows not to disturb them while they are still running and doing DMA. That is what this commit adds, serialized into struct
pci_ser.
Quoted 6 lines
[ ... ]
not be enabled and these routines would never run.Reviewed-by Pranjal Shrivastava <[email protected]>Reviewed-by Samiullah Khawaja <[email protected]>Signed-off-by David Matlack <[email protected]>
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
Re: [PATCH v9 01/13] PCI: liveupdate: Set up FLB handler for the PCI core
In reply to David MatlackQuoted 6 lines · David Matlack
Set up a File-Lifecycle-Bound (FLB) handler so that the PCI core can preserve its own state across a Live Update kexec.
Preserving a PCI device across kexec requires preserving two independent sets of state:
Quoted 8 lines
- Driver state, e.g. everything vfio-pci needs so that userspace can keep using the device in the new kernel. The driver preserves this itself and the PCI core is not involved.
- PCI core state, e.g. which devices are preserved, so that the new kernel knows not to disturb them while they are still running and doing DMA. That is what this commit adds, serialized into struct
pci_ser.
Thanks for this, it's an important key to my understanding.
Quoted 59 lines
Userspace, not the kernel, decides which devices are preserved, and it does so through the Live Update Orchestrator's (LUO) support for file
preservation: a driver exposes a file that represents a single PCI device, and userspace preserves that device withioctl(LIVEUPDATE_SESSION_PRESERVE_FD)on that file. Binding preservation to a file gives it proper lifecycle management, e.g. the preservation is undone if userspace cancels it or goes away. How a driver exposes that file is up to the driver and invisible to the PCI core (vfio-pci variant drivers, the first intended use-case, use their per-device cdev).LUO only knows that a file was preserved; it does not know that it represents a PCI device, or which one. Bridging that gap, drivers register their
liveupdate_file_handlerwith the PCI core:pci_liveupdate_register_flb(driver_file_handler); pci_liveupdate_unregister_flb(driver_file_handler);LUO then refcounts the PCI core's FLB against the files preserved by that handler, and that refcount drives the lifetime of struct
pci_ser:- On the first preserved file,
luo_flb_file_preserve_one()callspci_flb_preserve(), which allocates structpci_serand preserves it with KHO.- On the last unpreserved file (i.e. preservation cancelled),
liveupdate_flb_put_outgoing()callspci_flb_unpreserve(), which unpreserves and frees structpci_ser.- In the next kernel,
pci_flb_retrieve()hands the PCI core the structpci_serbuilt by the previous kernel, whenever the PCI core asks for it (e.g. during enumeration), andpci_flb_finish()frees it once the PCI core is done with it.So the flow for preserving a device, once a driver has registered, looks like this:
ioctl(LIVEUPDATE_SESSION_PRESERVE_FD)
luo_session_preserve_fd()
luo_preserve_file()
luo_flb_file_preserve()
luo_flb_file_preserve_one()# only on the first preserved file
pci_flb_preserve()# alloc + KHO-preservepci_ser
fh->ops->preserve()# driver callback, e.g. vfio-pciNote that struct
pci_seris deliberately not allocated when a driver callspci_liveupdate_register_flb(). A driver can be loaded for the lifetime of the machine without ever preserving a device, and there is no reason to allocate memory and hand it to the next kernel in that case. Letting LUO own the lifetime also means the PCI core does not have to duplicate LUO's refcounting and unwind logic for preservation failures, session aborts and fd close, and the incoming side (retrieve/finish) comes from the same object rather than requiring a separate KHO FDT entry owned by the PCI core.Note: This commit only allocates struct
pci_serand preserves it across Live Update. A subsequent commit addspci_liveupdate_preserve(), the API drivers call from theirfh->ops->preserve()callback to tell the PCI core exactly which devices are being preserved.
Quoted 7 lines
Note: There is no reason to check for
kho_is_enabled()since it can be assumed to return true. If KHO was not enabled then Live Update would not be enabled and these routines would never run.Reviewed-by Pranjal Shrivastava <[email protected]>Reviewed-by Samiullah Khawaja <[email protected]>Signed-off-by David Matlack <[email protected]>
Quoted 431 lines
--- Documentation/core-api/liveupdate.rst | 4 + MAINTAINERS | 13 ++ drivers/pci/Kconfig | 15 ++ drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 206 ++++++++++++++++++++++++++ include/linux/kho/abi/pci.h | 65 ++++++++ include/linux/pci.h | 1 + include/linux/pci_liveupdate.h | 30 ++++ 8 files changed, 335 insertions(+) create mode 100644 drivers/pci/liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/pci_liveupdate.hDocumentation/core-api/liveupdate.rst +4
-0@@ -1,5 +1,7 @@ .. SPDX-License-Identifier: GPL-2.0 +.. _luo: + ======================== Live Update Orchestrator ========================@@ -18,6 +20,8 @@ LUO Preserving File Descriptors .. kernel-doc:: kernel/liveupdate/luo_file.c :doc: LUO File Descriptors +.. _flb: + LUO File Lifecycle Bound Global Data ==================================== .. kernel-doc:: kernel/liveupdate/luo_flb.cMAINTAINERS +13
-0@@ -21046,6 +21046,19 @@ L: [email protected] S: Supported F: Documentation/PCI/pci-error-recovery.rst +PCI LIVE UPDATE +M: David Matlack <[email protected]> +R: Pasha Tatashin <[email protected]> +R: Mike Rapoport <[email protected]> +R: Pratyush Yadav <[email protected]> +L: [email protected] +L: [email protected] +S: Maintained +T: git git://git.kernel.org/pub/scm/linux/kernel/git/liveupdate/linux.git +F: drivers/pci/liveupdate.c +F: include/linux/kho/abi/pci.h +F: include/linux/pci_liveupdate.h + PCI MSI DRIVER FOR ALTERA MSI IP L: [email protected] S: Orphandrivers/pci/Kconfig +15
-0@@ -271,6 +271,21 @@ config VGA_ARB_MAX_GPUS Reserves space in the kernel to maintain resource locking for multiple GPUS. The overhead for each GPU is very small. +config PCI_LIVEUPDATE + bool "PCI Live Update Support" + depends on PCI && LIVEUPDATE + help + Enable PCI core support for preserving PCI devices across Live + Update. This, in combination with support in a device's driver, + enables PCI devices to run and perform memory transactions + uninterrupted during a kexec for Live Update. + + This option should only be enabled by users who plan to use Live + Update for kernel upgrades and require preserving PCI devices during + those upgrades. + + If unsure, say N. + source "drivers/pci/hotplug/Kconfig" source "drivers/pci/controller/Kconfig" source "drivers/pci/endpoint/Kconfig"drivers/pci/Makefile +1
-0@@ -16,6 +16,7 @@ obj-$(CONFIG_PROC_FS) += proc.o obj-$(CONFIG_SYSFS) += pci-sysfs.o slot.o obj-$(CONFIG_ACPI) += pci-acpi.o obj-$(CONFIG_GENERIC_PCI_IOMAP) += iomap.o +obj-$(CONFIG_PCI_LIVEUPDATE) += liveupdate.o endif obj-$(CONFIG_OF) += of.odrivers/pci/liveupdate.c new file +206
-0@@ -0,0 +1,206 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* Copyright (c) 2026, Google LLC. +* David Matlack <[email protected]> +*/ + +/** +* DOC: PCI Live Update +* +* The PCI subsystem participates in the Live Update process to enable drivers +* to preserve their PCI devices across kexec. +* +* Preserving a device requires preserving two independent sets of state: the +* driver's own state, which the driver preserves with no involvement from the +* PCI core, and the PCI core's state about the device, which the next kernel +* needs so that enumeration does not disturb a device that is still running. +* This file implements the latter. +* +* :ref:`FLB <flb>` Data +* ===================== +* +* Userspace decides which devices are preserved, using :ref:`LUO <luo>` file +* preservation: a driver exposes a file that represents a single PCI device, +* and userspace preserves the device with +* ``ioctl(LIVEUPDATE_SESSION_PRESERVE_FD)`` on that file. Binding preservation +* to a file gives it proper lifecycle management, e.g. the preservation is +* undone if userspace cancels it or goes away. How a driver exposes that file +* is up to the driver and invisible to the PCI core (vfio-pci variant drivers, +* the first intended use-case, use their per-device cdev). +* +* LUO only knows that a file was preserved; it does not know that the file +* represents a PCI device. Drivers therefore register their +* struct liveupdate_file_handler with the PCI core: +* +* * ``pci_liveupdate_register_flb(driver_file_handler)`` +* * ``pci_liveupdate_unregister_flb(driver_file_handler)`` +* +* LUO then refcounts the PCI core's FLB against the files preserved by that +* handler, and that refcount drives the lifetime of struct pci_ser: +* pci_flb_preserve() allocates and preserves it when the first file is +* preserved, and pci_flb_unpreserve() frees it when the last file is +* unpreserved. In the next kernel, pci_flb_retrieve() hands the PCI core the +* struct pci_ser built by the previous kernel, whenever the PCI core asks for +* it (e.g. during enumeration), and pci_flb_finish() frees it once the PCI +* core is done with it. +* +* Call Flow +* --------- +* +* :: +* +* # Driver initialization +* pci_liveupdate_register_flb(fh) +* +* # Userspace: ioctl(LIVEUPDATE_SESSION_PRESERVE_FD, devfd) +* luo_preserve_file() +* luo_flb_file_preserve() +* luo_flb_file_preserve_one() # first preserved file only +* pci_flb_preserve() # alloc and preserve struct pci_ser +* fh->ops->preserve() # driver callback +* +* # Userspace: preservation cancelled or session torn down +* luo_file_unpreserve_files() +* luo_flb_file_unpreserve() +* liveupdate_flb_put_outgoing() # last unpreserved file only +* pci_flb_unpreserve() # free struct pci_ser +* +* # ---------------- kexec ---------------- +* +* # New kernel: the PCI core asks for the previous kernel's state +* liveupdate_flb_get_incoming() +* luo_flb_retrieve_one() # first request only +* pci_flb_retrieve() # previous kernel's struct pci_ser +* +* # Userspace: ioctl(LIVEUPDATE_SESSION_FINISH) +* luo_file_finish_one() +* fh->ops->finish() # driver callback +* luo_flb_file_finish() +* liveupdate_flb_put_incoming() # last incoming file only +* pci_flb_finish() # free struct pci_ser +*/ + +#define pr_fmt (fmt) "PCI: liveupdate: " fmt + +#include <linux/io.h> +#include <linux/kexec_handover.h> +#include <linux/kho/abi/pci.h> +#include <linux/kho_block.h> +#include <linux/liveupdate.h> +#include <linux/mm.h> +#include <linux/mutex.h> +#include <linux/pci.h> +#include <linux/slab.h> + +/** +* struct pci_flb_outgoing - Outgoing PCI FLB object +* @ser: Pointer to the preserved struct pci_ser. +* @block_set: The KHO block set holding the outgoing devices. +* +* This structure holds the runtime state for the outgoing PCI Live Update +* state. It wraps the serialized pci_ser and the block_set used to manage +* the serialized entries. +*/ +struct pci_flb_outgoing { +struct pci_ser *ser; +struct kho_block_set block_set; +}; + +static int pci_flb_preserve (struct liveupdate_flb_op_args *args) +{ + struct pci_flb_outgoing *outgoing __free(kfree) = NULL; +struct pci_ser *ser; + + outgoing =kzalloc_obj (*outgoing); +if (!outgoing) +return -ENOMEM ; + + ser =kho_alloc_preserve (sizeof (*ser)); +if (IS_ERR (ser)) +return PTR_ERR (ser); + + ser->version =PCI_LUO_FLB_VERSION ; + ser->nr_devices =0 ; + ser->devices =0 ; + + outgoing->ser = ser; +kho_block_set_init (&outgoing->block_set,sizeof (struct pci_dev_ser )); + + args->obj =no_free_ptr (outgoing); + args->data =virt_to_phys (ser); +pr_debug ("Preserved struct pci_ser (0x%llx)\n" , args->data); +return 0 ; +} + +static void pci_flb_unpreserve (struct liveupdate_flb_op_args *args) +{ +struct pci_flb_outgoing *outgoing = args->obj; + +pr_debug ("Unpreserving struct pci_ser (0x%llx)\n" , args->data); + +WARN_ON (outgoing->ser->nr_devices); +kho_block_set_destroy (&outgoing->block_set); +kho_unpreserve_free (outgoing->ser); +kfree (outgoing); +} + +static int pci_flb_retrieve (struct liveupdate_flb_op_args *args) +{ +pr_debug ("Retrieving struct pci_ser (0x%llx)\n" , args->data); + args->obj =phys_to_virt (args->data); +return 0 ; +} + +static void pci_flb_finish (struct liveupdate_flb_op_args *args) +{ +pr_debug ("Finished struct pci_ser (0x%llx)\n" , args->data); +kho_restore_free (args->obj); +} + +static struct liveupdate_flb_ops pci_liveupdate_flb_ops = { + .preserve = pci_flb_preserve, + .unpreserve = pci_flb_unpreserve, + .retrieve = pci_flb_retrieve, + .finish = pci_flb_finish, + .owner =THIS_MODULE , +}; + +static struct liveupdate_flb pci_liveupdate_flb = { + .ops = &pci_liveupdate_flb_ops, + .compatible =PCI_LUO_FLB_COMPATIBLE , +}; + +/** +* pci_liveupdate_register_flb() - Register a file handler with the PCI core +* @fh: The file handler to register. +* +* Drivers that support preserving PCI devices across Live Update must call +* pci_liveupdate_register_flb() to register their +* struct liveupdate_file_handler with the PCI core, typically at module init, +* and always before any file managed by @fh can be preserved. +* +* Registering links the PCI core's FLB to @fh, so that LUO allocates the PCI +* core's outgoing struct pci_ser (via pci_flb_preserve()) when the first file +* managed by any registered handler is preserved, and frees it (via +* pci_flb_unpreserve()) when the last such file is unpreserved. +* +* Return: 0 on success, <0 on failure. +*/ +int pci_liveupdate_register_flb (struct liveupdate_file_handler *fh) +{ +pr_debug ("Registering file handler \"%s\"\n" , fh->compatible); +return liveupdate_register_flb (fh, &pci_liveupdate_flb); +} +EXPORT_SYMBOL_GPL (pci_liveupdate_register_flb); + +/** +* pci_liveupdate_unregister_flb() - Unregister a file handler with the PCI core +* @fh: The file handler to unregister. +*/ +void pci_liveupdate_unregister_flb (struct liveupdate_file_handler *fh) +{ +pr_debug ("Unregistering file handler \"%s\"\n" , fh->compatible); +liveupdate_unregister_flb (fh, &pci_liveupdate_flb); +} +EXPORT_SYMBOL_GPL (pci_liveupdate_unregister_flb);include/linux/kho/abi/pci.h new file +65
-0@@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* +* Copyright (c) 2026, Google LLC. +* David Matlack <[email protected]> +*/ + +#ifndef _LINUX_KHO_ABI_PCI_H +#define _LINUX_KHO_ABI_PCI_H + +#include <linux/bug.h> +#include <linux/compiler.h> +#include <linux/types.h> + +/** +* DOC: PCI File-Lifecycle Bound (FLB) Live Update ABI +* +* This header defines the ABI for preserving core PCI state across kexec using +* Live Update File-Lifecycle Bound (FLB) data. +* +* This interface is a contract. Any modification to any of the serialization +* structs defined here constitutes a breaking change. Such changes require +* incrementing the version number in the PCI_LUO_FLB_VERSION number. +*/ + +#define PCI_LUO_FLB_COMPATIBLE "pci" +#define PCI_LUO_FLB_VERSION 1 + +/** +* struct pci_dev_ser - Serialized state about a single PCI device. +* +* @domain: The device's PCI domain number (segment). +* @bdf: The device's PCI bus, device, and function number. +* @refcount: Reference count used by the PCI core to keep track of whether it +* is done using a device's struct pci_dev_ser. The value of the +* refcount is equal to 1 when the struct pci_dev_ser is in use, and +* 0 otherwise. +*/ +struct pci_dev_ser { +u32 domain; +u16 bdf; +u16 refcount; +} __packed; + +/** +* struct pci_ser - PCI Subsystem Live Update State +* +* This struct tracks state about all devices that are being preserved across +* a Live Update for the next kernel. It contains only state owned by the PCI +* core; the state a driver needs to resume its device is preserved separately +* by that driver. +* +* @version: The version of the "pci" FLB struct. This field must never be +* deleted, moved, or resized, as the kernel depends on always being +* able to check the struct pci_ser version number. +* @nr_devices: The number of devices that were preserved. +* @devices: Physical address of the first KHO block containing pci_dev_ser. +*/ +struct pci_ser { +u32 version; +u32 nr_devices; +u64 devices; +} __packed; + +#endif /* _LINUX_KHO_ABI_PCI_H */ include/linux/pci.h +1
-0@@ -43,6 +43,7 @@#include <uapi/linux/pci.h> #include <linux/pci_ids.h> +#include <linux/pci_liveupdate.h> #define PCI_STATUS_ERROR_BITS (PCI_STATUS_DETECTED_PARITY | \ PCI_STATUS_SIG_SYSTEM_ERROR | \include/linux/pci_liveupdate.h new file +30
-0@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* PCI Live Update support (Public/Driver API) +* +* Copyright (c) 2026, Google LLC. +* David Matlack <[email protected]> +*/ +#ifndef LINUX_PCI_LIVEUPDATE_H +#define LINUX_PCI_LIVEUPDATE_H + +#include <linux/liveupdate.h> +#include <linux/types.h> + +struct pci_dev ; + +#ifdef CONFIG_PCI_LIVEUPDATE +int pci_liveupdate_register_flb (struct liveupdate_file_handler *fh); +void pci_liveupdate_unregister_flb (struct liveupdate_file_handler *fh); +#else +static inline int pci_liveupdate_register_flb (struct liveupdate_file_handler *fh) +{ +return -EOPNOTSUPP ; +} + +static inline void pci_liveupdate_unregister_flb (struct liveupdate_file_handler *fh) +{ +} +#endif + +#endif /* LINUX_PCI_LIVEUPDATE_H */ Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
Mike Rapoport
maintainerRe: [PATCH v9 01/13] PCI: liveupdate: Set up FLB handler for the PCI core
In reply to David MatlackHi David,
Quoted 14 lines · David Matlack
Set up a File-Lifecycle-Bound (FLB) handler so that the PCI core can preserve its own state across a Live Update kexec.
Preserving a PCI device across kexec requires preserving two independent sets of state:
- Driver state, e.g. everything vfio-pci needs so that userspace can keep using the device in the new kernel. The driver preserves this itself and the PCI core is not involved.
- PCI core state, e.g. which devices are preserved, so that the new kernel knows not to disturb them while they are still running and doing DMA. That is what this commit adds, serialized into struct
pci_ser.
...
Quoted 14 lines
drivers/pci/liveupdate.c new file +8
-0@@ -0,0 +1,206 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* Copyright (c) 2026, Google LLC. +* David Matlack <[email protected]> +*/ + +/**
drivers/pci/liveupdate.c line 18
Quoted 10 lines
drivers/pci/liveupdate.c new file +10
-0+* DOC: PCI Live Update +* +* The PCI subsystem participates in the Live Update process to enable drivers +* to preserve their PCI devices across kexec. +* +* Preserving a device requires preserving two independent sets of state: the +* driver's own state, which the driver preserves with no involvement from the +* PCI core, and the PCI core's state about the device, which the next kernel +* needs so that enumeration does not disturb a device that is still running. +* This file implements the latter.
This does not look good in html docs :(
Quoted 11 lines
drivers/pci/liveupdate.c new file +11
-0+* +* :ref:`FLB <flb>` Data +* ===================== +* +* Userspace decides which devices are preserved, using :ref:`LUO <luo>` file +* preservation: a driver exposes a file that represents a single PCI device, +* and userspace preserves the device with +* ``ioctl(LIVEUPDATE_SESSION_PRESERVE_FD)`` on that file. Binding preservation +* to a file gives it proper lifecycle management, e.g. the preservation is +* undone if userspace cancels it or goes away. How a driver exposes that file +* is up to the driver and invisible to the PCI core (vfio-pci variant drivers,
drivers/pci/liveupdate.c line 39
Quoted 10 lines
drivers/pci/liveupdate.c new file +10
-0+* the first intended use-case, use their per-device cdev). +* +* LUO only knows that a file was preserved; it does not know that the file +* represents a PCI device. Drivers therefore register their +* struct liveupdate_file_handler with the PCI core: +* +* * ``pci_liveupdate_register_flb(driver_file_handler)`` +* * ``pci_liveupdate_unregister_flb(driver_file_handler)`` +* +* LUO then refcounts the PCI core's FLB against the files preserved by that
Please spell out reference count
drivers/pci/liveupdate.c line 40
Quoted 1 line
drivers/pci/liveupdate.c new file +1
-0+* handler, and that refcount drives the lifetime of struct pci_ser:
and here too ^
Quoted 6 lines
drivers/pci/liveupdate.c new file +6
-0+* pci_flb_preserve() allocates and preserves it when the first file is +* preserved, and pci_flb_unpreserve() frees it when the last file is +* unpreserved. In the next kernel, pci_flb_retrieve() hands the PCI core the +* struct pci_ser built by the previous kernel, whenever the PCI core asks for +* it (e.g. during enumeration), and pci_flb_finish() frees it once the PCI +* core is done with it.
...
Quoted 14 lines
include/linux/kho/abi/pci.h new file +8
-0@@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* +* Copyright (c) 2026, Google LLC. +* David Matlack <[email protected]> +*/ + +#ifndef _LINUX_KHO_ABI_PCI_H
include/linux/kho/abi/pci.h line 18
Quoted 10 lines
include/linux/kho/abi/pci.h new file +10
-0+#define _LINUX_KHO_ABI_PCI_H + +#include <linux/bug.h> +#include <linux/compiler.h> +#include <linux/types.h> + +/** +* DOC: PCI File-Lifecycle Bound (FLB) Live Update ABI +* +* This header defines the ABI for preserving core PCI state across kexec using
This does not look nice in html docs either :(
Quoted 6 lines
include/linux/kho/abi/pci.h new file +6
-0+* Live Update File-Lifecycle Bound (FLB) data. +* +* This interface is a contract. Any modification to any of the serialization +* structs defined here constitutes a breaking change. Such changes require +* incrementing the version number in the PCI_LUO_FLB_VERSION number. +*/
Signature · 2 lines
Sincerely yours, Mike.
PATCH v9 2/13 PCI: liveupdate: Track outgoing preserved PCI devices
In reply to David MatlackAdd APIs to allow drivers to notify the PCI core of which devices are being preserved across a Live Update for the next kernel, i.e. "outgoing" devices.
Drivers must notify the PCI core when devices are preserved so that the PCI core can update its FLB data (struct pci_ser) and track the list of outgoing devices. pci_liveupdate_preserve() notifies the PCI core that a device must be preserved across Live Update. pci_liveupdate_unpreserve() reverses this (cancels the preservation of the device).
This tracking ensures the PCI core is fully aware of which devices may need special handling during shutdown and kexec, and so the list of preserved devices can be handed off to the next kernel.
For now, the API only supports preserving non-VF devices on a root bus (not behind an PCI-to-PCI bridges).
--- drivers/pci/liveupdate.c | 211 +++++++++++++++++++++++++++++++++ drivers/pci/liveupdate.h | 21 ++++ drivers/pci/probe.c | 2 + include/linux/pci.h | 3 + include/linux/pci_liveupdate.h | 21 ++++ 5 files changed, 258 insertions(+) create mode 100644 drivers/pci/liveupdate.h
drivers/pci/liveupdate.c +211 -0
@@ -59,6 +59,7 @@* luo_flb_file_preserve_one() # first preserved file only * pci_flb_preserve() # alloc and preserve struct pci_ser * fh->ops->preserve() # driver callback +* pci_liveupdate_preserve(dev) # record this device in struct pci_ser * * # Userspace: preservation cancelled or session torn down * luo_file_unpreserve_files()
@@ -79,6 +80,27 @@* luo_flb_file_finish() * liveupdate_flb_put_incoming() # last incoming file only * pci_flb_finish() # free struct pci_ser +* +* Device Tracking +* =============== +* +* Drivers must notify the PCI core when specific devices are preserved or +* unpreserved with the following APIs: +* +* * ``pci_liveupdate_preserve(pci_dev)`` +* * ``pci_liveupdate_unpreserve(pci_dev)`` +* +* This allows the PCI core to keep its FLB data (struct pci_ser) up to date +* with the list of **outgoing** preserved devices for the next kernel. +* +* Restrictions +* ============ +* +* The PCI core enforces the following restrictions on which devices can be +* preserved. These may be relaxed in the future: +* +* * The device cannot be a Virtual Function (VF). +* * The device cannot be behind a PCI-to-PCI bridge. */ #define pr_fmt (fmt) "PCI: liveupdate: " fmt
@@ -93,6 +115,21 @@#include <linux/pci.h> #include <linux/slab.h> +#include "liveupdate.h" + +/** +* struct pci_liveupdate_global - Global state for PCI Live Update support +* @rwsem: Reader/writer semaphore used to protect the incoming and outgoing +* FLBs, and the references to them in struct pci_dev. +*/ +struct pci_liveupdate_global { +struct rw_semaphore rwsem; +}; + +static struct pci_liveupdate_global pci_liveupdate = { + .rwsem =__RWSEM_INITIALIZER (pci_liveupdate.rwsem), +}; +/** * struct pci_flb_outgoing - Outgoing PCI FLB object * @ser: Pointer to the preserved struct pci_ser.
@@ -171,6 +208,180 @@ static struct liveupdate_flb pci_liveupdate_flb = { .compatible = PCI_LUO_FLB_COMPATIBLE, }; +static void pci_liveupdate_flb_put_outgoing (void ) +{ +liveupdate_flb_put_outgoing (&pci_liveupdate_flb); +} + +static struct pci_flb_outgoing *pci_liveupdate_flb_get_outgoing (void ) +{ +struct pci_flb_outgoing *outgoing =NULL ; +int ret; + + ret =liveupdate_flb_get_outgoing (&pci_liveupdate_flb, (void **)&outgoing); +if (ret) +return ERR_PTR (ret); + +if (!outgoing) +return ERR_PTR (-ENOENT ); + +return outgoing; +} + +static struct pci_dev_ser *pci_flb_alloc_dev_ser (struct pci_flb_outgoing *outgoing) +{ +struct pci_dev_ser *dev_ser; +struct kho_block_set_it it; +u64 count =0 ; +int err; + +kho_block_set_it_init (&it, &outgoing->block_set); + +/* Try to find an existing, previously unpreserved, entry. */ +while ((dev_ser =kho_block_set_it_read_entry (&it))) { +if (!dev_ser->refcount) +return dev_ser; + + count++; + } + +/* Otherwise grow the block set and reserve a new entry. */ + err =kho_block_set_grow (&outgoing->block_set, count +1 ); +if (err) +return ERR_PTR (err); + +if (!count) +kho_block_set_it_init (&it, &outgoing->block_set); + +/* This should always succeed since kho_block_set_grow() succeeded. */ + dev_ser =kho_block_set_it_reserve_entry (&it); +if (WARN_ON_ONCE (!dev_ser)) +return ERR_PTR (-ENOSPC ); + +return dev_ser; +} + +static void pci_liveupdate_unpreserve_device (struct pci_flb_outgoing *outgoing, +struct pci_dev *dev) +{ +struct pci_dev_ser *dev_ser = dev->liveupdate.outgoing; + +if (!dev_ser) { +pci_warn (dev,"Cannot unpreserve device that is not preserved\n" ); +return ; + } + +pci_info (dev,"Device will no longer be preserved across next Live Update\n" ); + outgoing->ser->nr_devices--; +memset (dev_ser,0 ,sizeof (*dev_ser)); + dev->liveupdate.outgoing =NULL ; +} + +static int pci_liveupdate_preserve_device (struct pci_flb_outgoing *outgoing, +struct pci_dev *dev) +{ +struct pci_dev_ser *dev_ser; + +if (dev->is_virtfn) { +pci_warn (dev,"Cannot preserve Virtual Functions\n" ); +return -EINVAL ; + } + +if (dev->liveupdate.outgoing) { +pci_warn (dev,"Device is already preserved\n" ); +return -EBUSY ; + } + +if (!pci_is_root_bus (dev->bus)) { +pci_warn (dev,"Cannot preserve devices behind bridges\n" ); +return -EINVAL ; + } + + dev_ser =pci_flb_alloc_dev_ser (outgoing); +if (IS_ERR (dev_ser)) +return PTR_ERR (dev_ser); + +pci_info (dev,"Device will be preserved across next Live Update\n" ); + outgoing->ser->nr_devices++; + outgoing->ser->devices =kho_block_set_head_pa (&outgoing->block_set); + + dev_ser->domain =pci_domain_nr (dev->bus); + dev_ser->bdf =pci_dev_id (dev); + dev_ser->refcount++; + + dev->liveupdate.outgoing = dev_ser; +return 0 ; +} + +/** +* pci_liveupdate_preserve() - Preserve a PCI device across Live Update +* @dev: The PCI device to preserve. +* +* pci_liveupdate_preserve() notifies the PCI core that a PCI device should be +* preserved across the next Live Update. Drivers are expected to call +* pci_liveupdate_preserve() from their struct liveupdate_file_handler +* preserve() callback to ensure the outgoing struct pci_ser is already set up. +* +* Returns: 0 on success, <0 on failure. +*/ +int pci_liveupdate_preserve (struct pci_dev *dev) +{ +struct pci_flb_outgoing *outgoing =NULL ; +int ret; + +guard (rwsem_write)(&pci_liveupdate.rwsem); + + outgoing =pci_liveupdate_flb_get_outgoing (); +if (IS_ERR (outgoing)) +return PTR_ERR (outgoing); + + ret =pci_liveupdate_preserve_device (outgoing, dev); + +pci_liveupdate_flb_put_outgoing (); +return ret; +} +EXPORT_SYMBOL_GPL (pci_liveupdate_preserve); + +/** +* pci_liveupdate_unpreserve() - Cancel preservation of a PCI device +* @dev: The PCI device to unpreserve. +* +* pci_liveupdate_unpreserve() notifies the PCI core that a PCI device should no +* longer be preserved across the next Live Update. Drivers are expected to call +* pci_liveupdate_unpreserve() from their struct liveupdate_file_handler +* unpreserve() callback to ensure the outgoing struct pci_ser is already set +* up. +*/ +void pci_liveupdate_unpreserve (struct pci_dev *dev) +{ +struct pci_flb_outgoing *outgoing =NULL ; + +guard (rwsem_write)(&pci_liveupdate.rwsem); + + outgoing =pci_liveupdate_flb_get_outgoing (); +if (IS_ERR (outgoing)) { +pci_warn (dev,"Cannot unpreserve device without outgoing Live Update state\n" ); +return ; + } + +pci_liveupdate_unpreserve_device (outgoing, dev); +pci_liveupdate_flb_put_outgoing (); +} +EXPORT_SYMBOL_GPL (pci_liveupdate_unpreserve); + +void pci_liveupdate_cleanup_device (struct pci_dev *dev) +{ +/* +* It should be safe to READ_ONCE() outside of the rwsem during cleanup +* since there should no longer be any references to @dev on the system. +* +* This should never happen in practice. Drivers should block removal +* while a device is preserved. +*/ +if (READ_ONCE (dev->liveupdate.outgoing)) +pci_WARN (dev,1 ,"Destroying outgoing-preserved device!\n" ); +} +/** * pci_liveupdate_register_flb() - Register a file handler with the PCI core * @fh: The file handler to register.
drivers/pci/liveupdate.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* PCI Live Update support (core API) +* +* Copyright (c) 2026, Google LLC. +* David Matlack <[email protected]> +*/ +#ifndef DRIVERS_PCI_LIVEUPDATE_H +#define DRIVERS_PCI_LIVEUPDATE_H + +#include <linux/pci.h> + +#ifdef CONFIG_PCI_LIVEUPDATE +void pci_liveupdate_cleanup_device (struct pci_dev *dev); +#else +static inline void pci_liveupdate_cleanup_device (struct pci_dev *dev) +{ +} +#endif + +#endif /* DRIVERS_PCI_LIVEUPDATE_H */
drivers/pci/probe.c +2 -0
@@ -24,6 +24,7 @@#include <linux/pm_runtime.h> #include <linux/bitfield.h> #include <trace/events/pci.h> +#include "liveupdate.h" #include "pci.h" static struct resource busn_resource = {
@@ -2485,6 +2486,7 @@ static void pci_release_dev(struct device *dev) pci_dev =to_pci_dev (dev);pci_release_capabilities (pci_dev); +pci_liveupdate_cleanup_device (pci_dev);pci_release_of_node (pci_dev);pcibios_release_device (pci_dev);pci_bus_put (pci_dev->bus);
include/linux/pci.h +3 -0
@@ -599,6 +599,9 @@ struct pci_dev {u8 tph_mode;/* TPH mode */ u8 tph_req_type;/* TPH requester type */ #endif +#ifdef CONFIG_PCI_LIVEUPDATE +struct pci_liveupdate liveupdate; +#endif };static inline struct pci_dev *pci_physfn (struct pci_dev *dev)
include/linux/pci_liveupdate.h +21 -0
@@ -8,14 +8,26 @@ #ifndef LINUX_PCI_LIVEUPDATE_H #define LINUX_PCI_LIVEUPDATE_H +#include <linux/kho/abi/pci.h> #include <linux/liveupdate.h> +#include <linux/spinlock_types.h> #include <linux/types.h> +/** + * struct pci_liveupdate - PCI Live Update state for a struct pci_dev + * @outgoing: State preserved for the next kernel. + */ +struct pci_liveupdate { + struct pci_dev_ser *outgoing; +}; + struct pci_dev; #ifdef CONFIG_PCI_LIVEUPDATE int pci_liveupdate_register_flb(struct liveupdate_file_handler *fh); void pci_liveupdate_unregister_flb(struct liveupdate_file_handler *fh); +int pci_liveupdate_preserve(struct pci_dev *dev); +void pci_liveupdate_unpreserve(struct pci_dev *dev); #else static inline int pci_liveupdate_register_flb(struct liveupdate_file_handler *fh) {
@@ -25,6 +37,15 @@ static inline int pci_liveupdate_register_flb(struct liveupdate_file_handler *fhstatic inline void pci_liveupdate_unregister_flb (struct liveupdate_file_handler *fh) { } + +static inline int pci_liveupdate_preserve (struct pci_dev *dev) +{ +return -EOPNOTSUPP ; +} + +static inline void pci_liveupdate_unpreserve (struct pci_dev *dev) +{ +}#endif #endif /* LINUX_PCI_LIVEUPDATE_H */
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
[email protected]
AI reviewRe: [PATCH v9 02/13] PCI: liveupdate: Track outgoing preserved PCI devices
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 14 lines
Add APIs to allow drivers to notify the PCI core of which devices are being preserved across a Live Update for the next kernel, i.e. "outgoing" devices.
Drivers must notify the PCI core when devices are preserved so that the PCI core can update its FLB data (struct
pci_ser) and track the list of outgoing devices.pci_liveupdate_preserve()notifies the PCI core that a device must be preserved across Live Update.pci_liveupdate_unpreserve()reverses this (cancels the preservation of the device).This tracking ensures the PCI core is fully aware of which devices may need special handling during shutdown and kexec, and so the list of preserved devices can be handed off to the next kernel.
Quoted 8 lines
For now, the API only supports preserving non-VF devices on a root bus (not behind an PCI-to-PCI bridges).
Reviewed-by Pranjal Shrivastava <[email protected]>Reviewed-by Pasha Tatashin <[email protected]>Reviewed-by Bjorn Helgaas <[email protected]>Reviewed-by Samiullah Khawaja <[email protected]>Signed-off-by David Matlack <[email protected]>
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
PATCH v9 3/13 PCI: liveupdate: Track incoming preserved PCI devices
In reply to David MatlackDuring PCI enumeration, the previous kernel might have passed state about devices that were preserved across kexec. The PCI core needs to fetch this state to identify which devices are "incoming" and require special handling.
Add pci_liveupdate_setup_device() which is called during device setup to fetch the serialized state (struct pci_ser) from the Live Update Orchestrator. The first time this happens, pci_flb_retrieve() will run and convert the array of pci_dev_ser structs into an xarray so that it can be looked up efficiently.
If a device is found in the xarray, the PCI core stores a pointer to its state in dev->liveupdate_incoming until pci_liveupdate_finish() is called by the driver. This pointer allows the PCI core and drivers to apply Live Update-specific logic to incoming devices in subsequent commits.
Drivers can check if a device is an incoming preserved device (e.g. during probe) by calling pci_liveupdate_is_incoming().
Note that any error during pci_flb_retrieve() must be treated as fatal. The previous kernel handed off PCI devices that are performing DMA and the current kernel cannot safely take over those devices without this state.
CONFIG_64BIT is now required to enable CONFIG_PCI_LIVEUPDATE so that the domain and bdf can be guaranteed to fit in an unsigned long and be used as the xarray key.
--- MAINTAINERS | 1 + drivers/pci/Kconfig | 2 +- drivers/pci/liveupdate.c | 286 ++++++++++++++++++++++++++++++++- drivers/pci/liveupdate.h | 5 + drivers/pci/probe.c | 3 + include/linux/pci_liveupdate.h | 13 ++ 6 files changed, 303 insertions(+), 7 deletions(-)
MAINTAINERS +1 -0
@@ -21056,6 +21056,7 @@ L: [email protected] S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/liveupdate/linux.git F: drivers/pci/liveupdate.c +F: drivers/pci/liveupdate.h F: include/linux/kho/abi/pci.h F: include/linux/pci_liveupdate.h
drivers/pci/Kconfig +1 -1
@@ -273,7 +273,7 @@ config VGA_ARB_MAX_GPUS config PCI_LIVEUPDATE bool "PCI Live Update Support" - depends on PCI && LIVEUPDATE + depends on PCI && LIVEUPDATE && 64BIT help Enable PCI core support for preserving PCI devices across Live Update. This, in combination with support in a device's driver,
drivers/pci/liveupdate.c +280 -6
342 lines not on this page · raw message
drivers/pci/liveupdate.h +5 -0
@@ -11,8 +11,13 @@#include <linux/pci.h> #ifdef CONFIG_PCI_LIVEUPDATE +void pci_liveupdate_setup_device (struct pci_dev *dev);void pci_liveupdate_cleanup_device (struct pci_dev *dev);#else +static inline void pci_liveupdate_setup_device (struct pci_dev *dev) +{ +} +static inline void pci_liveupdate_cleanup_device (struct pci_dev *dev) { }
drivers/pci/probe.c +3 -0
@@ -2065,6 +2065,8 @@ int pci_setup_device(struct pci_dev *dev)if (pci_early_dump)early_dump_pci_device (dev); +pci_liveupdate_setup_device (dev); +/* Need to have dev->class ready */ dev->cfg_size =pci_cfg_space_size (dev);
@@ -2188,6 +2190,7 @@ int pci_setup_device(struct pci_dev *dev)default :/* unknown header */ pci_err (dev,"unknown header type %02x, ignoring device\n" , dev->hdr_type); +pci_liveupdate_cleanup_device (dev);pci_release_of_node (dev);return -EIO ;
include/linux/pci_liveupdate.h +13 -0
@@ -16,9 +16,11 @@/** * struct pci_liveupdate - PCI Live Update state for a struct pci_dev * @outgoing: State preserved for the next kernel. +* @incoming: State preserved by the previous kernel. */ struct pci_liveupdate {struct pci_dev_ser *outgoing; +struct pci_dev_ser *incoming; };struct pci_dev ;
@@ -28,6 +30,8 @@ int pci_liveupdate_register_flb(struct liveupdate_file_handler *fh);void pci_liveupdate_unregister_flb (struct liveupdate_file_handler *fh);int pci_liveupdate_preserve (struct pci_dev *dev);void pci_liveupdate_unpreserve (struct pci_dev *dev); +void pci_liveupdate_finish (struct pci_dev *dev); +bool pci_liveupdate_is_incoming (struct pci_dev *dev);#else static inline int pci_liveupdate_register_flb (struct liveupdate_file_handler *fh) {
@@ -46,6 +50,15 @@ static inline int pci_liveupdate_preserve(struct pci_dev *dev)static inline void pci_liveupdate_unpreserve (struct pci_dev *dev) { } + +static inline void pci_liveupdate_finish (struct pci_dev *dev) +{ +} + +static inline bool pci_liveupdate_is_incoming (struct pci_dev *dev) +{ +return false; +}#endif #endif /* LINUX_PCI_LIVEUPDATE_H */
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
[email protected]
AI reviewRe: [PATCH v9 03/13] PCI: liveupdate: Track incoming preserved PCI devices
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 18 lines
During PCI enumeration, the previous kernel might have passed state about devices that were preserved across kexec. The PCI core needs to fetch this state to identify which devices are "incoming" and require special handling.
Add
pci_liveupdate_setup_device()which is called during device setup to fetch the serialized state (structpci_ser) from the Live Update Orchestrator. The first time this happens,pci_flb_retrieve()will run and convert the array ofpci_dev_serstructs into an xarray so that it can be looked up efficiently.If a device is found in the xarray, the PCI core stores a pointer to its state in
dev->liveupdate_incominguntilpci_liveupdate_finish()is called by the driver. This pointer allows the PCI core and drivers to apply Live Update-specific logic to incoming devices in subsequent [ ... ]
as the xarray key.
Quoted 3 lines
Reviewed-by Pranjal Shrivastava <[email protected]>Reviewed-by Samiullah Khawaja <[email protected]>Signed-off-by David Matlack <[email protected]>
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
Re: [PATCH v9 03/13] PCI: liveupdate: Track incoming preserved PCI devices
In reply to David MatlackQuoted 25 lines · David Matlack
During PCI enumeration, the previous kernel might have passed state about devices that were preserved across kexec. The PCI core needs to fetch this state to identify which devices are "incoming" and require special handling.
Add
pci_liveupdate_setup_device()which is called during device setup to fetch the serialized state (structpci_ser) from the Live Update Orchestrator. The first time this happens,pci_flb_retrieve()will run and convert the array ofpci_dev_serstructs into an xarray so that it can be looked up efficiently.If a device is found in the xarray, the PCI core stores a pointer to its state in
dev->liveupdate_incominguntilpci_liveupdate_finish()is called by the driver. This pointer allows the PCI core and drivers to apply Live Update-specific logic to incoming devices in subsequent commits.Drivers can check if a device is an incoming preserved device (e.g. during probe) by calling
pci_liveupdate_is_incoming().Note that any error during
pci_flb_retrieve()must be treated as fatal. The previous kernel handed off PCI devices that are performing DMA and the current kernel cannot safely take over those devices without this state.
Quoted 7 lines
CONFIG_64BITis now required to enableCONFIG_PCI_LIVEUPDATEso that the domain and bdf can be guaranteed to fit in an unsigned long and be used as the xarray key.Reviewed-by Pranjal Shrivastava <[email protected]>Reviewed-by Samiullah Khawaja <[email protected]>Signed-off-by David Matlack <[email protected]>
One message question below.
Quoted 196 lines
--- MAINTAINERS | 1 + drivers/pci/Kconfig | 2 +- drivers/pci/liveupdate.c | 286 ++++++++++++++++++++++++++++++++- drivers/pci/liveupdate.h | 5 + drivers/pci/probe.c | 3 + include/linux/pci_liveupdate.h | 13 ++ 6 files changed, 303 insertions(+), 7 deletions(-)MAINTAINERS +1
-0@@ -21056,6 +21056,7 @@ L: [email protected] S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/liveupdate/linux.git F: drivers/pci/liveupdate.c +F: drivers/pci/liveupdate.h F: include/linux/kho/abi/pci.h F: include/linux/pci_liveupdate.hdrivers/pci/Kconfig +1
-1@@ -273,7 +273,7 @@ config VGA_ARB_MAX_GPUS config PCI_LIVEUPDATE bool "PCI Live Update Support" - depends on PCI && LIVEUPDATE + depends on PCI && LIVEUPDATE && 64BIT help Enable PCI core support for preserving PCI devices across Live Update. This, in combination with support in a device's driver,drivers/pci/liveupdate.c +111
-5@@ -45,6 +45,11 @@* it (e.g. during enumeration), and pci_flb_finish() frees it once the PCI * core is done with it. * +* State handed over by the previous kernel is trusted. The PCI core validates +* it only far enough to detect an incompatible or corrupt hand over, and makes +* no attempt to defend against deliberate modification, since a previous kernel +* able to corrupt preserved state is able to corrupt arbitrary memory anyway. +* * Call Flow * --------- * @@ -69,14 +74,17 @@* * # ---------------- kexec ---------------- * -* # New kernel: the PCI core asks for the previous kernel's state -* liveupdate_flb_get_incoming() -* luo_flb_retrieve_one() # first request only -* pci_flb_retrieve() # previous kernel's struct pci_ser +* # New kernel: PCI enumeration +* pci_setup_device() +* pci_liveupdate_setup_device() +* liveupdate_flb_get_incoming() +* luo_flb_retrieve_one() # first request only +* pci_flb_retrieve() # previous kernel's struct pci_ser * * # Userspace: ioctl(LIVEUPDATE_SESSION_FINISH) * luo_file_finish_one() * fh->ops->finish() # driver callback +* pci_liveupdate_finish(dev) # release this device's pci_dev_ser * luo_flb_file_finish() * liveupdate_flb_put_incoming() # last incoming file only * pci_flb_finish() # free struct pci_ser @@ -93,6 +101,20 @@* This allows the PCI core to keep its FLB data (struct pci_ser) up to date * with the list of **outgoing** preserved devices for the next kernel. * +* After kexec, whenever a device is enumerated, the PCI core will check if it +* is an **incoming** preserved device (i.e. preserved by the previous kernel) +* by checking the incoming FLB data (struct pci_ser). +* +* Drivers must notify the PCI core when an **incoming** device is done +* participating in the incoming Live Update with the following API: +* +* * ``pci_liveupdate_finish(pci_dev)`` +* +* The PCI core does not enforce any ordering of ``pci_liveupdate_finish()`` and +* ``pci_liveupdate_preserve()``, i.e., a PCI device can be **outgoing** +* (preserved for next kernel) and **incoming** (preserved by previous kernel) +* at the same time. +* * Restrictions * ============ * @@ -144,6 +166,27 @@ struct pci_flb_outgoing {struct kho_block_set block_set; }; +/** +* struct pci_flb_incoming - Incoming PCI FLB object +* @ser: The incoming struct pci_ser from the previous kernel. +* @xa: Xarray used to quickly lookup devices in @ser. +* @block_set: The KHO block set holding the incoming devices. +* +* This structure holds the runtime state for the incoming PCI Live Update +* state. It wraps the serialized pci_ser, the block_set used to restore +* the serialized entries, and an xarray for fast lookups. +*/ +struct pci_flb_incoming { +struct pci_ser *ser; +struct xarray xa; +struct kho_block_set block_set; +}; + +static unsigned long pci_ser_xa_key (u32 domain,u16 bdf) +{ +return (unsigned long )domain <<16 | bdf; +} +static int pci_flb_preserve (struct liveupdate_flb_op_args *args) { struct pci_flb_outgoing *outgoing __free(kfree) = NULL;@@ -182,17 +225,106 @@ static void pci_flb_unpreserve(struct liveupdate_flb_op_args *args)kfree (outgoing); } +/* +* Any failure here is fatal. The previous kernel handed over devices that are +* still performing DMA, and this kernel cannot identify them without this +* state. Continuing would let the PCI core reassign bus numbers and rebind +* drivers underneath live devices, so fail loudly instead of unwinding. +*/ static int pci_flb_retrieve (struct liveupdate_flb_op_args *args) { +struct pci_ser *ser =phys_to_virt (args->data); +struct pci_flb_incoming *incoming; +struct pci_dev_ser *dev_ser; +struct kho_block_set_it it; +int ret; +pr_debug ("Retrieving struct pci_ser (0x%llx)\n" , args->data); - args->obj =phys_to_virt (args->data); + +if (ser->version !=PCI_LUO_FLB_VERSION ) +panic ("Incoming PCI FLB version (v%d) is incompatible with this kernel (v%d)\n" , + ser->version,PCI_LUO_FLB_VERSION ); + + incoming =kzalloc_obj (*incoming); +if (!incoming) +panic ("Failed to allocate struct pci_flb_incoming\n" ); + + incoming->ser = ser; +xa_init (&incoming->xa); + +kho_block_set_init (&incoming->block_set,sizeof (struct pci_dev_ser )); + ret =kho_block_set_restore (&incoming->block_set, ser->devices); +if (ret) +panic ("Failed to restore devices KHO block set (%d)\n" , ret); + +kho_block_set_it_init (&it, &incoming->block_set); +while ((dev_ser =kho_block_set_it_read_entry (&it))) { +unsigned long key; + +if (!dev_ser->refcount) +continue ; + + key =pci_ser_xa_key (dev_ser->domain, dev_ser->bdf); + ret =xa_insert (&incoming->xa, key, dev_ser,GFP_KERNEL ); +if (ret) +panic ("Failed to insert PCI device %04x:%02x:%02x.%d into xarray (%d)\n" , + dev_ser->domain,PCI_BUS_NUM (dev_ser->bdf), +PCI_SLOT (dev_ser->bdf),PCI_FUNC (dev_ser->bdf), + ret); + } + + args->obj = incoming;return 0 ; } +static void pci_check_all_devices_finished (struct pci_flb_incoming *incoming) +{ +struct pci_dev_ser *dev_ser; +unsigned long index; +u32 nr_devices; + +/* +* nr_devices is only decremented by pci_liveupdate_finish_device(). +* This runs once the last reference to the incoming FLB is dropped, so +* there are no finishers left in flight. +*/ + nr_devices = incoming->ser->nr_devices; +if (nr_devices ==0 ) +return ; + +/* +* Report the unfinished devices from the incoming FLB rather than by +* walking struct pci_dev, so that devices that never showed up after
drivers/pci/liveupdate.c static void pci_flb_unpreserve(struct liveupdate_flb_op_args *args) · line 307
Quoted 10 lines
drivers/pci/liveupdate.c +10
-0+* kexec, or that were destroyed before they finished, are identified +* as well. +*/ +xa_for_each (&incoming->xa, index, dev_ser) { +if (!dev_ser->refcount) +continue ; + +pr_emerg ("%04x:%02x:%02x.%d was never finished!\n" , + dev_ser->domain,PCI_BUS_NUM (dev_ser->bdf), +PCI_SLOT (dev_ser->bdf),PCI_FUNC (dev_ser->bdf));
I guess "PCI: liveupdate: ... was never finished" has a specific technical meaning, but I don't know what it is and I'm not sure a user or admin who sees this message will know what to do with it.
Quoted 264 lines
drivers/pci/liveupdate.c +159
-1+ } + +/* +* This should only happen if a driver violated the contract to call +* pci_liveupdate_finish() (something is extremely broken). +*/ +panic ("%u preserved device(s) were never finished!\n" , nr_devices); +} +static void pci_flb_finish (struct liveupdate_flb_op_args *args) { +struct pci_flb_incoming *incoming = args->obj; +pr_debug ("Finished struct pci_ser (0x%llx)\n" , args->data); -kho_restore_free (args->obj); +pci_check_all_devices_finished (incoming); + +xa_destroy (&incoming->xa); +kho_block_set_destroy (&incoming->block_set); +kho_restore_free (incoming->ser); +kfree (incoming); }static struct liveupdate_flb_ops pci_liveupdate_flb_ops = {@@ -369,6 +501,75 @@ void pci_liveupdate_unpreserve(struct pci_dev *dev) }EXPORT_SYMBOL_GPL (pci_liveupdate_unpreserve); +static struct pci_flb_incoming *pci_liveupdate_flb_get_incoming (void ) +{ +struct pci_flb_incoming *incoming =NULL ; +int ret; + + ret =liveupdate_flb_get_incoming (&pci_liveupdate_flb, (void **)&incoming); + +/* Live Update is not enabled. */ +if (ret == -EOPNOTSUPP ) +return NULL ; + +/* Live Update is enabled, but there is no incoming FLB data. */ +if (ret == -ENODATA ) +return NULL ; + +/* +* Live Update is enabled and there is incoming FLB data, but none of it +* matches pci_liveupdate_flb.compatible. +*/ +if (ret == -ENOENT ) +return NULL ; + +/* +* There is incoming FLB data that matches pci_liveupdate_flb.compatible +* but retrieve failed (pci_flb_retrieve() returned an error or LUO +* failed to acquire a reference to pci_liveupdate_flb_ops.owner). +*/ +if (ret) +panic ("Failed to retrieve incoming FLB data (%d)\n" , ret); + +return incoming; +} + +static void pci_liveupdate_flb_put_incoming (void ) +{ +liveupdate_flb_put_incoming (&pci_liveupdate_flb); +} + +void pci_liveupdate_setup_device (struct pci_dev *dev) +{ +struct pci_flb_incoming *incoming; +struct pci_dev_ser *dev_ser; +unsigned long key; + +guard (rwsem_write)(&pci_liveupdate.rwsem); + + incoming =pci_liveupdate_flb_get_incoming (); +if (!incoming) +return ; + + key =pci_ser_xa_key (pci_domain_nr (dev->bus),pci_dev_id (dev)); + dev_ser =xa_load (&incoming->xa, key); + +/* +* This device was not preserved across Live Update, or it was preserved +* but has already been probed and gone through pci_liveupdate_finish(), +* e.g. due to removing and re-adding the device. Either way, it's not +* treated as incoming-preserved. +*/ +if (!dev_ser || !dev_ser->refcount) { +pci_liveupdate_flb_put_incoming (); +return ; + } + +pci_info (dev,"Device was preserved by previous kernel across Live Update\n" ); + dev->liveupdate.incoming = dev_ser; +pci_liveupdate_flb_put_incoming (); +} +void pci_liveupdate_cleanup_device (struct pci_dev *dev) {/* @@ -380,7 +581,80 @@ void pci_liveupdate_cleanup_device(struct pci_dev *dev)*/ if (READ_ONCE (dev->liveupdate.outgoing))pci_WARN (dev,1 ,"Destroying outgoing-preserved device!\n" ); + +if (READ_ONCE (dev->liveupdate.incoming)) +pci_WARN (dev,1 ,"Destroying incoming-preserved device!\n" ); +} + +static void pci_liveupdate_finish_device (struct pci_ser *ser,struct pci_dev *dev) +{ +if (!dev->liveupdate.incoming) { +pci_warn (dev,"Cannot finish preserving an unpreserved device\n" ); +return ; + } + +if (dev->liveupdate.incoming->refcount !=1 ) { +pci_WARN (dev,1 ,"Preserved device has a corrupted refcount!\n" ); +return ; + } + +/* +* Drop the refcount so this device does not get treated as an incoming +* device again, e.g. in case pci_liveupdate_setup_device() gets called +* again because the device is hot-plugged. +*/ + dev->liveupdate.incoming->refcount =0 ; + +pci_info (dev,"Device is finished participating in Live Update\n" ); + dev->liveupdate.incoming =NULL ; + ser->nr_devices--; +} + +/** +* pci_liveupdate_finish() - Finish the preservation of a PCI device +* @dev: The PCI device +* +* pci_liveupdate_finish() notifies the PCI core that a PCI device that was +* preserved across the previous Live Update has finished participating in Live +* Update. Drivers must call pci_liveupdate_finish() from their struct +* liveupdate_file_handler finish() callback to ensure the incoming struct +* pci_ser is allocated. +*/ +void pci_liveupdate_finish (struct pci_dev *dev) +{ +struct pci_flb_incoming *incoming; + +guard (rwsem_write)(&pci_liveupdate.rwsem); + + incoming =pci_liveupdate_flb_get_incoming (); +if (!incoming) { +pci_warn (dev,"Cannot finish preserving device without incoming FLB\n" ); +return ; + } + +pci_liveupdate_finish_device (incoming->ser, dev); +pci_liveupdate_flb_put_incoming (); +} +EXPORT_SYMBOL_GPL (pci_liveupdate_finish); + +/** +* pci_liveupdate_is_incoming() - Check if a device is incoming-preserved +* @dev: The PCI device to check +* +* Check if a device was preserved across Live Update by the previous kernel, +* i.e. the device is incoming-preserved. Note that a device is only considered +* incoming-preserved prior to pci_liveupdate_finish(). It is up to drivers to +* synchronize usage of pci_liveupdate_is_incoming() with their own call to +* pci_liveupdate_finish() to avoid acting on stale data. +* +* Returns: True if the device is incoming-preserved, false otherwise. +*/ +bool pci_liveupdate_is_incoming (struct pci_dev *dev) +{ +guard (rwsem_read)(&pci_liveupdate.rwsem); +return dev->liveupdate.incoming; } +EXPORT_SYMBOL_GPL (pci_liveupdate_is_incoming);/** * pci_liveupdate_register_flb() - Register a file handler with the PCI core drivers/pci/liveupdate.h +5
-0@@ -11,8 +11,13 @@#include <linux/pci.h> #ifdef CONFIG_PCI_LIVEUPDATE +void pci_liveupdate_setup_device (struct pci_dev *dev);void pci_liveupdate_cleanup_device (struct pci_dev *dev);#else +static inline void pci_liveupdate_setup_device (struct pci_dev *dev) +{ +} +static inline void pci_liveupdate_cleanup_device (struct pci_dev *dev) { }drivers/pci/probe.c +3
-0@@ -2065,6 +2065,8 @@ int pci_setup_device(struct pci_dev *dev)if (pci_early_dump)early_dump_pci_device (dev); +pci_liveupdate_setup_device (dev); +/* Need to have dev->class ready */ dev->cfg_size =pci_cfg_space_size (dev);@@ -2188,6 +2190,7 @@ int pci_setup_device(struct pci_dev *dev)default :/* unknown header */ pci_err (dev,"unknown header type %02x, ignoring device\n" , dev->hdr_type); +pci_liveupdate_cleanup_device (dev);pci_release_of_node (dev);return -EIO ;include/linux/pci_liveupdate.h +13
-0@@ -16,9 +16,11 @@/** * struct pci_liveupdate - PCI Live Update state for a struct pci_dev * @outgoing: State preserved for the next kernel. +* @incoming: State preserved by the previous kernel. */ struct pci_liveupdate {struct pci_dev_ser *outgoing; +struct pci_dev_ser *incoming; };struct pci_dev ;@@ -28,6 +30,8 @@ int pci_liveupdate_register_flb(struct liveupdate_file_handler *fh);void pci_liveupdate_unregister_flb (struct liveupdate_file_handler *fh);int pci_liveupdate_preserve (struct pci_dev *dev);void pci_liveupdate_unpreserve (struct pci_dev *dev); +void pci_liveupdate_finish (struct pci_dev *dev); +bool pci_liveupdate_is_incoming (struct pci_dev *dev);#else static inline int pci_liveupdate_register_flb (struct liveupdate_file_handler *fh) {@@ -46,6 +50,15 @@ static inline int pci_liveupdate_preserve(struct pci_dev *dev)static inline void pci_liveupdate_unpreserve (struct pci_dev *dev) { } + +static inline void pci_liveupdate_finish (struct pci_dev *dev) +{ +} + +static inline bool pci_liveupdate_is_incoming (struct pci_dev *dev) +{ +return false; +}#endif #endif /* LINUX_PCI_LIVEUPDATE_H */ Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
Mike Rapoport
maintainerRe: [PATCH v9 03/13] PCI: liveupdate: Track incoming preserved PCI devices
In reply to David MatlackHi David,
Quoted 10 lines · David Matlack
During PCI enumeration, the previous kernel might have passed state about devices that were preserved across kexec. The PCI core needs to fetch this state to identify which devices are "incoming" and require special handling.
Add
pci_liveupdate_setup_device()which is called during device setup to fetch the serialized state (structpci_ser) from the Live Update Orchestrator. The first time this happens,pci_flb_retrieve()will run and convert the array ofpci_dev_serstructs into an xarray so that it can be looked up efficiently.
...
drivers/pci/Kconfig config VGA_ARB_MAX_GPUS · line 276
Quoted 10 lines
drivers/pci/Kconfig +1
-1@@ -273,7 +273,7 @@ config VGA_ARB_MAX_GPUS config PCI_LIVEUPDATE bool "PCI Live Update Support" - depends on PCI && LIVEUPDATE + depends on PCI && LIVEUPDATE && 64BIT
This could have been there from the first patch, no? :)
Quoted 3 lines
drivers/pci/Kconfig +0
-0help Enable PCI core support for preserving PCI devices across Live Update. This, in combination with support in a device's driver,
Signature · 2 lines
Sincerely yours, Mike.
PATCH v9 4/13 PCI: liveupdate: Document driver binding responsibilities
In reply to David MatlackDocument how driver binding works during a Live Update and what the PCI core expects of drivers and users. Note that this is only a description of the current division of responsibilities. These can change in the future if we decide.
--- drivers/pci/liveupdate.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/pci/liveupdate.c +14 -0
@@ -123,6 +123,20 @@* * * The device cannot be a Virtual Function (VF). * * The device cannot be behind a PCI-to-PCI bridge. +* +* Driver Binding +* ============== +* +* In the outgoing kernel, the driver must ensure that it does not release a +* device between pci_liveupdate_preserve() and pci_liveupdate_unpreserve(). +* +* In the incoming kernel, the driver must ensure that it does not release a +* preserved device between probe() and pci_liveupdate_finish(). +* +* It is the user's responsibility to ensure that incoming preserved devices are +* bound to the correct driver. The PCI core does not protect against a device +* getting preserved by driver A in the outgoing kernel and then getting bound +* to driver B in the incoming kernel. */ #define pr_fmt (fmt) "PCI: liveupdate: " fmt
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
[email protected]
AI reviewRe: [PATCH v9 04/13] PCI: liveupdate: Document driver binding responsibilities
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines
Document how driver binding works during a Live Update and what the PCI core expects of drivers and users. Note that this is only a description of the current division of responsibilities. These can change in the future if we decide.
Reviewed-by Pasha Tatashin <[email protected]>Reviewed-by Pranjal Shrivastava <[email protected]>Reviewed-by Samiullah Khawaja <[email protected]>Signed-off-by David Matlack <[email protected]>
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
PATCH v9 5/13 PCI: liveupdate: Auto-preserve upstream bridges across Live Update
In reply to David MatlackWhen a PCI device is preserved across a Live Update, all of its upstream bridges up to the root port must also be preserved. This enables the PCI core and any drivers bound to the bridges to manage bridges correctly across a Live Update.
Notably, this will be used in subsequent commits to ensure that preserved devices can continue performing memory transactions without a disruption or change in routing.
To preserve bridges, the PCI core tracks the number of downstream devices preserved under each bridge using a reference count in struct pci_dev_ser. This allows a bridge to remain preserved until all its downstream preserved devices are unpreserved or finish their participation in the Live Update.
--- drivers/pci/liveupdate.c | 125 +++++++++++++++++++++++++++--------- include/linux/kho/abi/pci.h | 5 +- include/linux/pci.h | 3 + 3 files changed, 99 insertions(+), 34 deletions(-)
drivers/pci/liveupdate.c +93 -32
@@ -122,7 +122,6 @@* preserved. These may be relaxed in the future: * * * The device cannot be a Virtual Function (VF). -* * The device cannot be behind a PCI-to-PCI bridge. * * Driver Binding * ==============
@@ -137,6 +136,18 @@* bound to the correct driver. The PCI core does not protect against a device * getting preserved by driver A in the outgoing kernel and then getting bound * to driver B in the incoming kernel. +* +* PCI-to-PCI Bridges +* ================== +* +* Any PCI-to-PCI bridges upstream of a preserved device are automatically +* preserved when the device is preserved. The PCI core keeps track of the +* number of downstream devices that are preserved under a bridge so that the +* bridge is only unpreserved once all downstream devices are unpreserved. +* +* This enables the PCI core and any drivers bound to the bridge to participate +* in the Live Update so that preserved endpoints can continue issuing memory +* transactions during the Live Update. */ #define pr_fmt (fmt) "PCI: liveupdate: " fmt
@@ -407,55 +418,84 @@ static struct pci_dev_ser *pci_flb_alloc_dev_ser(struct pci_flb_outgoing *outgoireturn dev_ser; } -static void pci_liveupdate_unpreserve_device (struct pci_flb_outgoing *outgoing, -struct pci_dev *dev) +static int pci_liveupdate_unpreserve_device (struct pci_flb_outgoing *outgoing, +struct pci_dev *dev) {struct pci_dev_ser *dev_ser = dev->liveupdate.outgoing;if (!dev_ser) {pci_warn (dev,"Cannot unpreserve device that is not preserved\n" ); -return ; +return -EINVAL ; } +if (!dev_ser->refcount) { +pci_WARN (dev,1 ,"Preserved device has a 0 refcount!\n" ); +return -EINVAL ; + } + +if (--dev_ser->refcount) +return 0 ; +pci_info (dev,"Device will no longer be preserved across next Live Update\n" ); outgoing->ser->nr_devices--;memset (dev_ser,0 ,sizeof (*dev_ser)); dev->liveupdate.outgoing =NULL ; +return 0 ; +} + +static void pci_liveupdate_unpreserve_path (struct pci_flb_outgoing *outgoing, +struct pci_dev *dev, +struct pci_dev *end) +{ +for_each_pci_dev_in_path (dev) { +if (dev == end) +break ; + +if (pci_liveupdate_unpreserve_device (outgoing, dev)) +return ; + } }static int pci_liveupdate_preserve_device (struct pci_flb_outgoing *outgoing,struct pci_dev *dev) { -struct pci_dev_ser *dev_ser; -if (dev->is_virtfn) {pci_warn (dev,"Cannot preserve Virtual Functions\n" );return -EINVAL ; } -if (dev->liveupdate.outgoing) { +/* +* Endpoint devices should not be preserved more than once. +* Bridges are preserved once for every downstream device that +* is preserved. +*/ +if (dev->liveupdate.outgoing && !dev->subordinate) {pci_warn (dev,"Device is already preserved\n" );return -EBUSY ; } -if (!pci_is_root_bus (dev->bus)) { -pci_warn (dev,"Cannot preserve devices behind bridges\n" ); +if (dev->liveupdate.outgoing && !dev->liveupdate.outgoing->refcount) { +pci_WARN (dev,1 ,"Preserved device with 0 refcount!\n" );return -EINVAL ; } - dev_ser =pci_flb_alloc_dev_ser (outgoing); -if (IS_ERR (dev_ser)) -return PTR_ERR (dev_ser); +if (!dev->liveupdate.outgoing) { +struct pci_dev_ser *dev_ser; -pci_info (dev,"Device will be preserved across next Live Update\n" ); - outgoing->ser->nr_devices++; - outgoing->ser->devices =kho_block_set_head_pa (&outgoing->block_set); + dev_ser =pci_flb_alloc_dev_ser (outgoing); +if (IS_ERR (dev_ser)) +return PTR_ERR (dev_ser); - dev_ser->domain =pci_domain_nr (dev->bus); - dev_ser->bdf =pci_dev_id (dev); - dev_ser->refcount++; +pci_info (dev,"Device will be preserved across next Live Update\n" ); + outgoing->ser->nr_devices++; + outgoing->ser->devices =kho_block_set_head_pa (&outgoing->block_set); + + dev_ser->domain =pci_domain_nr (dev->bus); + dev_ser->bdf =pci_dev_id (dev); + dev->liveupdate.outgoing = dev_ser; + } - dev->liveupdate.outgoing = dev_ser; + dev->liveupdate.outgoing->refcount++;return 0 ; }
@@ -468,12 +508,16 @@ static int pci_liveupdate_preserve_device(struct pci_flb_outgoing *outgoing,* pci_liveupdate_preserve() from their struct liveupdate_file_handler * preserve() callback to ensure the outgoing struct pci_ser is already set up. * +* pci_liveupdate_preserve() automatically preserves all bridges upstream of +* @dev. +* * Returns: 0 on success, <0 on failure. */ int pci_liveupdate_preserve (struct pci_dev *dev) {struct pci_flb_outgoing *outgoing =NULL ; -int ret; +struct pci_dev *start = dev; +int ret = -ENODEV ;guard (rwsem_write)(&pci_liveupdate.rwsem);
@@ -481,7 +525,13 @@ int pci_liveupdate_preserve(struct pci_dev *dev)if (IS_ERR (outgoing))return PTR_ERR (outgoing); - ret =pci_liveupdate_preserve_device (outgoing, dev); +for_each_pci_dev_in_path (dev) { + ret =pci_liveupdate_preserve_device (outgoing, dev); +if (ret) { +pci_liveupdate_unpreserve_path (outgoing, start, dev); +break ; + } + }pci_liveupdate_flb_put_outgoing ();return ret;
@@ -497,6 +547,9 @@ EXPORT_SYMBOL_GPL(pci_liveupdate_preserve);* pci_liveupdate_unpreserve() from their struct liveupdate_file_handler * unpreserve() callback to ensure the outgoing struct pci_ser is already set * up. +* +* pci_liveupdate_unpreserve() automatically unpreserves all bridges upstream of +* @dev. */ void pci_liveupdate_unpreserve (struct pci_dev *dev) {
@@ -510,7 +563,7 @@ void pci_liveupdate_unpreserve(struct pci_dev *dev)return ; } -pci_liveupdate_unpreserve_device (outgoing, dev); +pci_liveupdate_unpreserve_path (outgoing, dev,/*end=*/ NULL );pci_liveupdate_flb_put_outgoing (); }EXPORT_SYMBOL_GPL (pci_liveupdate_unpreserve);
@@ -600,28 +653,30 @@ void pci_liveupdate_cleanup_device(struct pci_dev *dev)pci_WARN (dev,1 ,"Destroying incoming-preserved device!\n" ); } -static void pci_liveupdate_finish_device (struct pci_ser *ser,struct pci_dev *dev) +static int pci_liveupdate_finish_device (struct pci_ser *ser,struct pci_dev *dev) {if (!dev->liveupdate.incoming) {pci_warn (dev,"Cannot finish preserving an unpreserved device\n" ); -return ; +return -EINVAL ; } -if (dev->liveupdate.incoming->refcount !=1 ) { -pci_WARN (dev,1 ,"Preserved device has a corrupted refcount!\n" ); -return ; +if (!dev->liveupdate.incoming->refcount) { +pci_WARN (dev,1 ,"Preserved device has a 0 refcount!\n" ); +return -EINVAL ; }/* -* Drop the refcount so this device does not get treated as an incoming -* device again, e.g. in case pci_liveupdate_setup_device() gets called -* again because the device is hot-plugged. +* Decrement the refcount so this device does not get treated as an +* incoming device again, e.g. in case pci_liveupdate_setup_device() +* gets called again because the device is hot-plugged. */ - dev->liveupdate.incoming->refcount =0 ; +if (--dev->liveupdate.incoming->refcount) +return 0 ;pci_info (dev,"Device is finished participating in Live Update\n" ); dev->liveupdate.incoming =NULL ; ser->nr_devices--; +return 0 ; }/**
@@ -633,6 +688,8 @@ static void pci_liveupdate_finish_device(struct pci_ser *ser, struct pci_dev *de* Update. Drivers must call pci_liveupdate_finish() from their struct * liveupdate_file_handler finish() callback to ensure the incoming struct * pci_ser is allocated. +* +* pci_liveupdate_finish() automatically finishes all bridges upstream of @dev. */ void pci_liveupdate_finish (struct pci_dev *dev) {
@@ -646,7 +703,11 @@ void pci_liveupdate_finish(struct pci_dev *dev)return ; } -pci_liveupdate_finish_device (incoming->ser, dev); +for_each_pci_dev_in_path (dev) { +if (pci_liveupdate_finish_device (incoming->ser, dev)) +break ; + } +pci_liveupdate_flb_put_incoming (); }EXPORT_SYMBOL_GPL (pci_liveupdate_finish);
include/linux/kho/abi/pci.h +3 -2
@@ -24,7 +24,7 @@*/ #define PCI_LUO_FLB_COMPATIBLE "pci" -#define PCI_LUO_FLB_VERSION 1 +#define PCI_LUO_FLB_VERSION 2/** * struct pci_dev_ser - Serialized state about a single PCI device.
@@ -33,7 +33,8 @@* @bdf: The device's PCI bus, device, and function number. * @refcount: Reference count used by the PCI core to keep track of whether it * is done using a device's struct pci_dev_ser. The value of the -* refcount is equal to 1 when the struct pci_dev_ser is in use, and +* refcount is equal to the number of preserved devices at or below +* it in the PCI hierarchy when the struct pci_dev_ser is in use, and * 0 otherwise. */ struct pci_dev_ser {
include/linux/pci.h +3 -0
@@ -836,6 +836,9 @@ static inline struct pci_dev *pci_upstream_bridge(struct pci_dev *dev)return dev->bus->self; } +#define for_each_pci_dev_in_path (dev) \ + for (; dev; dev = pci_upstream_bridge(dev)) +#ifdef CONFIG_PCI_MSI static inline bool pci_dev_msi_enabled (struct pci_dev *pci_dev) {
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
[email protected]
AI reviewRe: [PATCH v9 05/13] PCI: liveupdate: Auto-preserve upstream bridges across Live Update
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 15 lines
When a PCI device is preserved across a Live Update, all of its upstream bridges up to the root port must also be preserved. This enables the PCI core and any drivers bound to the bridges to manage bridges correctly across a Live Update.
Notably, this will be used in subsequent commits to ensure that preserved devices can continue performing memory transactions without a disruption or change in routing.
To preserve bridges, the PCI core tracks the number of downstream devices preserved under each bridge using a reference count in struct
pci_dev_ser. This allows a bridge to remain preserved until all its downstream preserved devices are unpreserved or finish their participation in the Live Update.
Quoted 3 lines
Reviewed-by Pasha Tatashin <[email protected]>Reviewed-by Pranjal Shrivastava <[email protected]>Signed-off-by David Matlack <[email protected]>
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
Re: [PATCH v9 05/13] PCI: liveupdate: Auto-preserve upstream bridges across Live Update
In reply to David MatlackQuoted 15 lines · David Matlack
When a PCI device is preserved across a Live Update, all of its upstream bridges up to the root port must also be preserved. This enables the PCI core and any drivers bound to the bridges to manage bridges correctly across a Live Update.
Notably, this will be used in subsequent commits to ensure that preserved devices can continue performing memory transactions without a disruption or change in routing.
To preserve bridges, the PCI core tracks the number of downstream devices preserved under each bridge using a reference count in struct
pci_dev_ser. This allows a bridge to remain preserved until all its downstream preserved devices are unpreserved or finish their participation in the Live Update.
Quoted 3 lines
Reviewed-by Pasha Tatashin <[email protected]>Reviewed-by Pranjal Shrivastava <[email protected]>Signed-off-by David Matlack <[email protected]>
Quoted 127 lines
--- drivers/pci/liveupdate.c | 125 +++++++++++++++++++++++++++--------- include/linux/kho/abi/pci.h | 5 +- include/linux/pci.h | 3 + 3 files changed, 99 insertions(+), 34 deletions(-)drivers/pci/liveupdate.c +51
-18@@ -122,7 +122,6 @@* preserved. These may be relaxed in the future: * * * The device cannot be a Virtual Function (VF). -* * The device cannot be behind a PCI-to-PCI bridge. * * Driver Binding * ============== @@ -137,6 +136,18 @@* bound to the correct driver. The PCI core does not protect against a device * getting preserved by driver A in the outgoing kernel and then getting bound * to driver B in the incoming kernel. +* +* PCI-to-PCI Bridges +* ================== +* +* Any PCI-to-PCI bridges upstream of a preserved device are automatically +* preserved when the device is preserved. The PCI core keeps track of the +* number of downstream devices that are preserved under a bridge so that the +* bridge is only unpreserved once all downstream devices are unpreserved. +* +* This enables the PCI core and any drivers bound to the bridge to participate +* in the Live Update so that preserved endpoints can continue issuing memory +* transactions during the Live Update. */ #define pr_fmt (fmt) "PCI: liveupdate: " fmt@@ -407,55 +418,84 @@ static struct pci_dev_ser *pci_flb_alloc_dev_ser(struct pci_flb_outgoing *outgoireturn dev_ser; } -static void pci_liveupdate_unpreserve_device (struct pci_flb_outgoing *outgoing, -struct pci_dev *dev) +static int pci_liveupdate_unpreserve_device (struct pci_flb_outgoing *outgoing, +struct pci_dev *dev) {struct pci_dev_ser *dev_ser = dev->liveupdate.outgoing;if (!dev_ser) {pci_warn (dev,"Cannot unpreserve device that is not preserved\n" ); -return ; +return -EINVAL ; } +if (!dev_ser->refcount) { +pci_WARN (dev,1 ,"Preserved device has a 0 refcount!\n" ); +return -EINVAL ; + } + +if (--dev_ser->refcount) +return 0 ; +pci_info (dev,"Device will no longer be preserved across next Live Update\n" ); outgoing->ser->nr_devices--;memset (dev_ser,0 ,sizeof (*dev_ser)); dev->liveupdate.outgoing =NULL ; +return 0 ; +} + +static void pci_liveupdate_unpreserve_path (struct pci_flb_outgoing *outgoing, +struct pci_dev *dev, +struct pci_dev *end) +{ +for_each_pci_dev_in_path (dev) { +if (dev == end) +break ; + +if (pci_liveupdate_unpreserve_device (outgoing, dev)) +return ; + } }static int pci_liveupdate_preserve_device (struct pci_flb_outgoing *outgoing,struct pci_dev *dev) { -struct pci_dev_ser *dev_ser; -if (dev->is_virtfn) {pci_warn (dev,"Cannot preserve Virtual Functions\n" );return -EINVAL ; } -if (dev->liveupdate.outgoing) { +/* +* Endpoint devices should not be preserved more than once. +* Bridges are preserved once for every downstream device that +* is preserved. +*/ +if (dev->liveupdate.outgoing && !dev->subordinate) {pci_warn (dev,"Device is already preserved\n" );return -EBUSY ; } -if (!pci_is_root_bus (dev->bus)) { -pci_warn (dev,"Cannot preserve devices behind bridges\n" ); +if (dev->liveupdate.outgoing && !dev->liveupdate.outgoing->refcount) { +pci_WARN (dev,1 ,"Preserved device with 0 refcount!\n" );return -EINVAL ; } - dev_ser =pci_flb_alloc_dev_ser (outgoing); -if (IS_ERR (dev_ser)) -return PTR_ERR (dev_ser); +if (!dev->liveupdate.outgoing) { +struct pci_dev_ser *dev_ser; -pci_info (dev,"Device will be preserved across next Live Update\n" ); - outgoing->ser->nr_devices++; - outgoing->ser->devices =kho_block_set_head_pa (&outgoing->block_set); + dev_ser =pci_flb_alloc_dev_ser (outgoing); +if (IS_ERR (dev_ser)) +return PTR_ERR (dev_ser); - dev_ser->domain =pci_domain_nr (dev->bus); - dev_ser->bdf =pci_dev_id (dev); - dev_ser->refcount++; +pci_info (dev,"Device will be preserved across next Live Update\n" );
drivers/pci/liveupdate.c static struct pci_dev_ser *pci_flb_alloc_dev_ser(struct pci_flb_outgoing *outgoi · line 498
Quoted 10 lines
drivers/pci/liveupdate.c +8
-1+ outgoing->ser->nr_devices++; + outgoing->ser->devices =kho_block_set_head_pa (&outgoing->block_set); + + dev_ser->domain =pci_domain_nr (dev->bus); + dev_ser->bdf =pci_dev_id (dev); + dev->liveupdate.outgoing = dev_ser; + } - dev->liveupdate.outgoing = dev_ser; + dev->liveupdate.outgoing->refcount++;
Nice, thanks for this, I think it reads much better!
Quoted 157 lines
drivers/pci/liveupdate.c +34
-13return 0 ; }@@ -468,12 +508,16 @@ static int pci_liveupdate_preserve_device(struct pci_flb_outgoing *outgoing,* pci_liveupdate_preserve() from their struct liveupdate_file_handler * preserve() callback to ensure the outgoing struct pci_ser is already set up. * +* pci_liveupdate_preserve() automatically preserves all bridges upstream of +* @dev. +* * Returns: 0 on success, <0 on failure. */ int pci_liveupdate_preserve (struct pci_dev *dev) {struct pci_flb_outgoing *outgoing =NULL ; -int ret; +struct pci_dev *start = dev; +int ret = -ENODEV ;guard (rwsem_write)(&pci_liveupdate.rwsem);@@ -481,7 +525,13 @@ int pci_liveupdate_preserve(struct pci_dev *dev)if (IS_ERR (outgoing))return PTR_ERR (outgoing); - ret =pci_liveupdate_preserve_device (outgoing, dev); +for_each_pci_dev_in_path (dev) { + ret =pci_liveupdate_preserve_device (outgoing, dev); +if (ret) { +pci_liveupdate_unpreserve_path (outgoing, start, dev); +break ; + } + }pci_liveupdate_flb_put_outgoing ();return ret;@@ -497,6 +547,9 @@ EXPORT_SYMBOL_GPL(pci_liveupdate_preserve);* pci_liveupdate_unpreserve() from their struct liveupdate_file_handler * unpreserve() callback to ensure the outgoing struct pci_ser is already set * up. +* +* pci_liveupdate_unpreserve() automatically unpreserves all bridges upstream of +* @dev. */ void pci_liveupdate_unpreserve (struct pci_dev *dev) {@@ -510,7 +563,7 @@ void pci_liveupdate_unpreserve(struct pci_dev *dev)return ; } -pci_liveupdate_unpreserve_device (outgoing, dev); +pci_liveupdate_unpreserve_path (outgoing, dev,/*end=*/ NULL );pci_liveupdate_flb_put_outgoing (); }EXPORT_SYMBOL_GPL (pci_liveupdate_unpreserve);@@ -600,28 +653,30 @@ void pci_liveupdate_cleanup_device(struct pci_dev *dev)pci_WARN (dev,1 ,"Destroying incoming-preserved device!\n" ); } -static void pci_liveupdate_finish_device (struct pci_ser *ser,struct pci_dev *dev) +static int pci_liveupdate_finish_device (struct pci_ser *ser,struct pci_dev *dev) {if (!dev->liveupdate.incoming) {pci_warn (dev,"Cannot finish preserving an unpreserved device\n" ); -return ; +return -EINVAL ; } -if (dev->liveupdate.incoming->refcount !=1 ) { -pci_WARN (dev,1 ,"Preserved device has a corrupted refcount!\n" ); -return ; +if (!dev->liveupdate.incoming->refcount) { +pci_WARN (dev,1 ,"Preserved device has a 0 refcount!\n" ); +return -EINVAL ; }/* -* Drop the refcount so this device does not get treated as an incoming -* device again, e.g. in case pci_liveupdate_setup_device() gets called -* again because the device is hot-plugged. +* Decrement the refcount so this device does not get treated as an +* incoming device again, e.g. in case pci_liveupdate_setup_device() +* gets called again because the device is hot-plugged. */ - dev->liveupdate.incoming->refcount =0 ; +if (--dev->liveupdate.incoming->refcount) +return 0 ;pci_info (dev,"Device is finished participating in Live Update\n" ); dev->liveupdate.incoming =NULL ; ser->nr_devices--; +return 0 ; }/** @@ -633,6 +688,8 @@ static void pci_liveupdate_finish_device(struct pci_ser *ser, struct pci_dev *de* Update. Drivers must call pci_liveupdate_finish() from their struct * liveupdate_file_handler finish() callback to ensure the incoming struct * pci_ser is allocated. +* +* pci_liveupdate_finish() automatically finishes all bridges upstream of @dev. */ void pci_liveupdate_finish (struct pci_dev *dev) {@@ -646,7 +703,11 @@ void pci_liveupdate_finish(struct pci_dev *dev)return ; } -pci_liveupdate_finish_device (incoming->ser, dev); +for_each_pci_dev_in_path (dev) { +if (pci_liveupdate_finish_device (incoming->ser, dev)) +break ; + } +pci_liveupdate_flb_put_incoming (); }EXPORT_SYMBOL_GPL (pci_liveupdate_finish);include/linux/kho/abi/pci.h +3
-2@@ -24,7 +24,7 @@*/ #define PCI_LUO_FLB_COMPATIBLE "pci" -#define PCI_LUO_FLB_VERSION 1 +#define PCI_LUO_FLB_VERSION 2/** * struct pci_dev_ser - Serialized state about a single PCI device. @@ -33,7 +33,8 @@* @bdf: The device's PCI bus, device, and function number. * @refcount: Reference count used by the PCI core to keep track of whether it * is done using a device's struct pci_dev_ser. The value of the -* refcount is equal to 1 when the struct pci_dev_ser is in use, and +* refcount is equal to the number of preserved devices at or below +* it in the PCI hierarchy when the struct pci_dev_ser is in use, and * 0 otherwise. */ struct pci_dev_ser {include/linux/pci.h +3
-0@@ -836,6 +836,9 @@ static inline struct pci_dev *pci_upstream_bridge(struct pci_dev *dev)return dev->bus->self; } +#define for_each_pci_dev_in_path (dev) \ + for (; dev; dev = pci_upstream_bridge(dev)) +#ifdef CONFIG_PCI_MSI static inline bool pci_dev_msi_enabled (struct pci_dev *pci_dev) {Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
PATCH v9 6/13 PCI: liveupdate: Preserve bus numbers during Live Update
In reply to David MatlackKeep the secondary and subordinate bus numbers that the previous kernel programmed into bridges, rather than assigning new ones, if the previous kernel preserved any device across a Live Update. Do this even on architectures that would otherwise always assign bus numbers themselves, e.g. when pci=assign-busses is passed.
Preserved devices must be allowed to continue performing memory transactions across a Live Update, so the kernel cannot change the fabric topology. Changing the bus numbers of a bridge changes the RequesterIDs of the devices below it, which would require disabling and flushing any in-flight memory transactions first.
Apply the policy globally rather than only to the paths that contain preserved devices. Bus numbers have to be preserved above a preserved device anyway, since an upstream bridge cannot expand its window. A global policy matches the scope of pcibios_assign_all_busses(), and gives an answer that cannot change part way through the two passes of a bridge scan.
Bridges that do not have bus numbers are still assigned new ones, so hot-adding a bridge keeps working, both during and after a Live Update. The two-pass bridge scan guarantees such bridges are only assigned bus numbers above those already claimed by preserved bridges.
The exception is a bridge that was preserved but comes up without a valid bus number configuration, e.g. because it was reset during kexec. Refuse to assign it new bus numbers, since that would silently change the BDF of every preserved device in its hierarchy. Also refuse to assign bus numbers to the other bridges on the same bus, since the bus numbers of the failed bridge can no longer be read from hardware and handing them out would let an unrelated device inherit the BDF of a preserved device.
Require that CONFIG_CARDBUS is not enabled to enable CONFIG_PCI_LIVEUPDATE since preserving bus numbers on PCI-to-CardBus bridges requires additional work but is not a priority at the moment.
--- .../admin-guide/kernel-parameters.txt | 7 +- drivers/pci/Kconfig | 2 +- drivers/pci/liveupdate.c | 114 ++++++++++++++++++ drivers/pci/liveupdate.h | 13 ++ drivers/pci/probe.c | 11 +- include/linux/pci_liveupdate.h | 5 + 6 files changed, 146 insertions(+), 6 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +6 -1
@@ -5170,7 +5170,12 @@ Kernel parameters explicitly which ones they are. assign-busses [X86] Always assign all PCI bus numbers ourselves, overriding - whatever the firmware may have done. + whatever the firmware may have done. Ignored + if any device was preserved across a Live + Update, where the kernel must preserve the + PCI topology (including bus numbers) to + avoid interrupting ongoing memory transactions + of preserved devices. usepirqmask [X86] Honor the possible IRQ mask stored in the BIOS $PIR table. This is needed on some systems with broken BIOSes, notably
drivers/pci/Kconfig +1 -1
@@ -273,7 +273,7 @@ config VGA_ARB_MAX_GPUS config PCI_LIVEUPDATE bool "PCI Live Update Support" - depends on PCI && LIVEUPDATE && 64BIT + depends on PCI && LIVEUPDATE && 64BIT && !CARDBUS help Enable PCI core support for preserving PCI devices across Live Update. This, in combination with support in a device's driver,
drivers/pci/liveupdate.c +114 -0
147 lines not on this page · raw message
drivers/pci/liveupdate.h +13 -0
@@ -13,6 +13,8 @@#ifdef CONFIG_PCI_LIVEUPDATE void pci_liveupdate_setup_device (struct pci_dev *dev);void pci_liveupdate_cleanup_device (struct pci_dev *dev); +bool pci_liveupdate_preserve_bus_numbers (void ); +bool pci_liveupdate_refuse_bus_numbers (struct pci_bus *bus,struct pci_dev *dev);#else static inline void pci_liveupdate_setup_device (struct pci_dev *dev) {
@@ -21,6 +23,17 @@ static inline void pci_liveupdate_setup_device(struct pci_dev *dev)static inline void pci_liveupdate_cleanup_device (struct pci_dev *dev) { } + +static inline bool pci_liveupdate_preserve_bus_numbers (void ) +{ +return false; +} + +static inline bool pci_liveupdate_refuse_bus_numbers (struct pci_bus *bus, +struct pci_dev *dev) +{ +return false; +}#endif #endif /* DRIVERS_PCI_LIVEUPDATE_H */
drivers/pci/probe.c +7 -4
@@ -1397,6 +1397,8 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, int max, unsigned int available_buses, int pass) { + bool preserve_bus_numbers = !pcibios_assign_all_busses() || +pci_liveupdate_preserve_bus_numbers ();struct pci_bus *child;u32 buses;u16 bctl;
@@ -1449,8 +1451,7 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, goto out; } -if ((secondary || subordinate) && - !pcibios_assign_all_busses () && !broken) { +if ((secondary || subordinate) && preserve_bus_numbers && !broken) {unsigned int cmax, buses;/*
@@ -1492,8 +1493,7 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev,* do in the second pass. */ if (!pass) { -if (pcibios_assign_all_busses () || broken) - +if (!preserve_bus_numbers || broken)/* * Temporarily disable forwarding of the * configuration cycles on all bridges in
@@ -1507,6 +1507,9 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, goto out; } +if (pci_liveupdate_refuse_bus_numbers (bus, dev)) + goto out; +/* Clear errors */ pci_write_config_word (dev,PCI_STATUS ,0xffff );
include/linux/pci_liveupdate.h +5 -0
@@ -17,10 +17,15 @@* struct pci_liveupdate - PCI Live Update state for a struct pci_dev * @outgoing: State preserved for the next kernel. * @incoming: State preserved by the previous kernel. +* @was_incoming: True if this struct pci_dev was incoming-preserved when it was +* set up, i.e. it was matched to state preserved by the previous +* kernel. Unlike @incoming, this is never cleared, so it stays +* true after the device finishes participating in Live Update. */ struct pci_liveupdate {struct pci_dev_ser *outgoing;struct pci_dev_ser *incoming; +bool was_incoming; };struct pci_dev ;
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
[email protected]
AI reviewRe: [PATCH v9 06/13] PCI: liveupdate: Preserve bus numbers during Live Update
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 20 lines
Keep the secondary and subordinate bus numbers that the previous kernel programmed into bridges, rather than assigning new ones, if the previous kernel preserved any device across a Live Update. Do this even on architectures that would otherwise always assign bus numbers themselves, e.g. when pci=assign-busses is passed.
Preserved devices must be allowed to continue performing memory transactions across a Live Update, so the kernel cannot change the fabric topology. Changing the bus numbers of a bridge changes the RequesterIDs of the devices below it, which would require disabling and flushing any in-flight memory transactions first.
Apply the policy globally rather than only to the paths that contain preserved devices. Bus numbers have to be preserved above a preserved device anyway, since an upstream bridge cannot expand its window. A [ ... ]
Require thatCONFIG_CARDBUSis not enabled to enableCONFIG_PCI_LIVEUPDATEsince preserving bus numbers on PCI-to-CardBus bridges requires additional work but is not a priority at the moment.
Quoted 1 line
Signed-off-by David Matlack <[email protected]>
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=6
Re: [PATCH v9 06/13] PCI: liveupdate: Preserve bus numbers during Live Update
In reply to David MatlackQuoted 33 lines · David Matlack
Keep the secondary and subordinate bus numbers that the previous kernel programmed into bridges, rather than assigning new ones, if the previous kernel preserved any device across a Live Update. Do this even on architectures that would otherwise always assign bus numbers themselves, e.g. when pci=assign-busses is passed.
Preserved devices must be allowed to continue performing memory transactions across a Live Update, so the kernel cannot change the fabric topology. Changing the bus numbers of a bridge changes the RequesterIDs of the devices below it, which would require disabling and flushing any in-flight memory transactions first.
Apply the policy globally rather than only to the paths that contain preserved devices. Bus numbers have to be preserved above a preserved device anyway, since an upstream bridge cannot expand its window. A global policy matches the scope of
pcibios_assign_all_busses(), and gives an answer that cannot change part way through the two passes of a bridge scan.Bridges that do not have bus numbers are still assigned new ones, so hot-adding a bridge keeps working, both during and after a Live Update. The two-pass bridge scan guarantees such bridges are only assigned bus numbers above those already claimed by preserved bridges.
The exception is a bridge that was preserved but comes up without a valid bus number configuration, e.g. because it was reset during kexec. Refuse to assign it new bus numbers, since that would silently change the BDF of every preserved device in its hierarchy. Also refuse to assign bus numbers to the other bridges on the same bus, since the bus numbers of the failed bridge can no longer be read from hardware and handing them out would let an unrelated device inherit the BDF of a preserved device.
Quoted 5 lines
Require that
CONFIG_CARDBUSis not enabled to enableCONFIG_PCI_LIVEUPDATEsince preserving bus numbers on PCI-to-CardBus bridges requires additional work but is not a priority at the moment.Signed-off-by David Matlack <[email protected]>
Quoted 293 lines
--- .../admin-guide/kernel-parameters.txt | 7 +- drivers/pci/Kconfig | 2 +- drivers/pci/liveupdate.c | 114 ++++++++++++++++++ drivers/pci/liveupdate.h | 13 ++ drivers/pci/probe.c | 11 +- include/linux/pci_liveupdate.h | 5 + 6 files changed, 146 insertions(+), 6 deletions(-)Documentation/admin-guide/kernel-parameters.txt +6
-1@@ -5170,7 +5170,12 @@ Kernel parameters explicitly which ones they are. assign-busses [X86] Always assign all PCI bus numbers ourselves, overriding - whatever the firmware may have done. + whatever the firmware may have done. Ignored + if any device was preserved across a Live + Update, where the kernel must preserve the + PCI topology (including bus numbers) to + avoid interrupting ongoing memory transactions + of preserved devices. usepirqmask [X86] Honor the possible IRQ mask stored in the BIOS $PIR table. This is needed on some systems with broken BIOSes, notablydrivers/pci/Kconfig +1
-1@@ -273,7 +273,7 @@ config VGA_ARB_MAX_GPUS config PCI_LIVEUPDATE bool "PCI Live Update Support" - depends on PCI && LIVEUPDATE && 64BIT + depends on PCI && LIVEUPDATE && 64BIT && !CARDBUS help Enable PCI core support for preserving PCI devices across Live Update. This, in combination with support in a device's driver,drivers/pci/liveupdate.c +114
-0@@ -148,6 +148,32 @@* This enables the PCI core and any drivers bound to the bridge to participate * in the Live Update so that preserved endpoints can continue issuing memory * transactions during the Live Update. +* +* BDF Stability +* ============= +* +* The PCI core guarantees that preserved devices can be identified by the same +* bus, device, and function numbers for as long as they are preserved +* (including across kexec). To accomplish this, the PCI core keeps the +* secondary and subordinate bus numbers that the previous kernel programmed +* into bridges, if the previous kernel preserved any device. This is true even +* on architectures that always assign new bus numbers during scanning. The +* kernel assumes the previous kernel established a sane bus topology across +* kexec. +* +* Bridges that do not have bus numbers are assigned new ones as usual, so +* hot-adding a bridge keeps working, both during and after a Live Update. The +* two-pass bridge scan ensures such bridges are only assigned bus numbers above +* those already claimed by preserved bridges. +* +* If a preserved bridge comes up without a valid bus number configuration, e.g. +* because it was reset during kexec, the PCI core refuses to assign it new bus +* numbers and does not enumerate anything below it. Assigning new bus numbers +* would silently change the BDF of every preserved device in its hierarchy. The +* PCI core also stops assigning bus numbers to the other bridges on the same +* bus, since the bus numbers of the failed bridge can no longer be read from +* hardware and handing them to another bridge would let an unrelated device +* inherit the BDF of a preserved device. */ #define pr_fmt (fmt) "PCI: liveupdate: " fmt@@ -168,9 +194,13 @@* struct pci_liveupdate_global - Global state for PCI Live Update support * @rwsem: Reader/writer semaphore used to protect the incoming and outgoing * FLBs, and the references to them in struct pci_dev. +* @had_incoming: True if the previous kernel preserved at least one PCI device. +* Set when the incoming FLB is retrieved and never cleared, so +* it stays true after Live Update finishes. */ struct pci_liveupdate_global {struct rw_semaphore rwsem; +bool had_incoming; };static struct pci_liveupdate_global pci_liveupdate = {@@ -298,6 +328,14 @@ static int pci_flb_retrieve(struct liveupdate_flb_op_args *args) ret); } +/* +* Remember that the previous kernel preserved devices for the lifetime +* of this kernel, even after Live Update finishes and the incoming FLB +* is freed. See pci_liveupdate_preserve_bus_numbers(). +*/ +if (!xa_empty (&incoming->xa)) + pci_liveupdate.had_incoming = true; + args->obj = incoming;return 0 ; }@@ -606,6 +644,80 @@ static void pci_liveupdate_flb_put_incoming(void)liveupdate_flb_put_incoming (&pci_liveupdate_flb); } +/** +* pci_liveupdate_preserve_bus_numbers() - Determine if the PCI core should +* preserve bus numbers when scanning +* bridges. +* +* This function is called by the PCI core when it is scanning a bridge. It +* determines whether the PCI core should preserve the secondary and subordinate +* bus numbers that the previous kernel programmed into that bridge, rather than +* assigning new ones. This is necessary to keep RequesterIDs constant for +* preserved devices issuing memory transactions. +* +* Bus numbers are preserved everywhere, and for the lifetime of the kernel, if +* the previous kernel preserved any device. Bus numbers have to be preserved +* above a preserved device anyway, since an upstream bridge cannot expand its +* window. Applying the same policy everywhere matches the scope of +* pcibios_assign_all_busses(), and gives an answer that cannot change part way +* through the two passes of a bridge scan. +* +* The incoming FLB is retrieved while setting up the first device, which always +* happens before any bridge is scanned, so this returns the same answer for the +* entire enumeration. +* +* Note that this does not prevent the PCI core from assigning bus numbers to +* bridges that do not have any, e.g. bridges that are hot-added after the +* Live Update. See pci_liveupdate_refuse_bus_numbers() for the one case where +* the PCI core must refuse to do so. +* +* Return: True if bus numbers should be preserved, false otherwise. +*/ +bool pci_liveupdate_preserve_bus_numbers (void ) +{ +return pci_liveupdate.had_incoming; +} + +/** +* pci_liveupdate_refuse_bus_numbers() - Determine if the PCI core must refuse +* to assign bus numbers to the provided +* bridge. +* @bus: The PCI bus the bus numbers would be assigned from. +* @dev: The PCI bridge device the bus numbers would be assigned to. +* +* This function is called by the PCI core before it assigns bus numbers to a +* bridge that does not have any. +* +* A bridge that was preserved by the previous kernel but came up without a +* valid bus number configuration, e.g. because it was reset during kexec, is +* left alone by the PCI core and therefore has no child bus once the first pass +* of the bridge scan is done. +* +* The PCI core must not assign bus numbers from @bus while such a bridge is on +* it, including to the failed bridge itself. Assigning new bus numbers to the +* failed bridge would silently change the BDF of every preserved device in its +* hierarchy. Its bus numbers cannot be read from hardware anymore either, so +* they cannot be excluded from assignment, and handing them to another bridge +* would let an unrelated device inherit the BDF of a preserved device. +* +* Return: True if @dev must not be assigned bus numbers, false otherwise. +*/ +bool pci_liveupdate_refuse_bus_numbers (struct pci_bus *bus,struct pci_dev *dev) +{ +struct pci_dev *bridge; + +for_each_pci_bridge (bridge, bus) { +if (!bridge->liveupdate.was_incoming || bridge->subordinate) +continue ; + +pci_err (dev,"Not assigning bus numbers, preserved bridge %s lost its bus number configuration\n" , +pci_name (bridge)); +return true; + } + +return false; +} +void pci_liveupdate_setup_device (struct pci_dev *dev) {struct pci_flb_incoming *incoming;@@ -634,6 +746,8 @@ void pci_liveupdate_setup_device(struct pci_dev *dev)pci_info (dev,"Device was preserved by previous kernel across Live Update\n" ); dev->liveupdate.incoming = dev_ser; + dev->liveupdate.was_incoming = true; +pci_liveupdate_flb_put_incoming (); }drivers/pci/liveupdate.h +13
-0@@ -13,6 +13,8 @@#ifdef CONFIG_PCI_LIVEUPDATE void pci_liveupdate_setup_device (struct pci_dev *dev);void pci_liveupdate_cleanup_device (struct pci_dev *dev); +bool pci_liveupdate_preserve_bus_numbers (void ); +bool pci_liveupdate_refuse_bus_numbers (struct pci_bus *bus,struct pci_dev *dev);#else static inline void pci_liveupdate_setup_device (struct pci_dev *dev) {@@ -21,6 +23,17 @@ static inline void pci_liveupdate_setup_device(struct pci_dev *dev)static inline void pci_liveupdate_cleanup_device (struct pci_dev *dev) { } + +static inline bool pci_liveupdate_preserve_bus_numbers (void ) +{ +return false; +} + +static inline bool pci_liveupdate_refuse_bus_numbers (struct pci_bus *bus, +struct pci_dev *dev) +{ +return false; +}#endif #endif /* DRIVERS_PCI_LIVEUPDATE_H */ drivers/pci/probe.c +7
-4@@ -1397,6 +1397,8 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, int max, unsigned int available_buses, int pass) { + bool preserve_bus_numbers = !pcibios_assign_all_busses() || +pci_liveupdate_preserve_bus_numbers ();struct pci_bus *child;u32 buses;u16 bctl;@@ -1449,8 +1451,7 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, goto out; } -if ((secondary || subordinate) && - !pcibios_assign_all_busses () && !broken) { +if ((secondary || subordinate) && preserve_bus_numbers && !broken) {unsigned int cmax, buses;/* @@ -1492,8 +1493,7 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev,* do in the second pass. */ if (!pass) { -if (pcibios_assign_all_busses () || broken) - +if (!preserve_bus_numbers || broken)/* * Temporarily disable forwarding of the * configuration cycles on all bridges in @@ -1507,6 +1507,9 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, goto out; } +if (pci_liveupdate_refuse_bus_numbers (bus, dev)) + goto out; +/* Clear errors */ pci_write_config_word (dev,PCI_STATUS ,0xffff );include/linux/pci_liveupdate.h +5
-0@@ -17,10 +17,15 @@* struct pci_liveupdate - PCI Live Update state for a struct pci_dev * @outgoing: State preserved for the next kernel. * @incoming: State preserved by the previous kernel. +* @was_incoming: True if this struct pci_dev was incoming-preserved when it was +* set up, i.e. it was matched to state preserved by the previous +* kernel. Unlike @incoming, this is never cleared, so it stays +* true after the device finishes participating in Live Update. */ struct pci_liveupdate {struct pci_dev_ser *outgoing;struct pci_dev_ser *incoming; +bool was_incoming; };struct pci_dev ;Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
Re: [PATCH v9 06/13] PCI: liveupdate: Preserve bus numbers during Live Update
In reply to David MatlackQuoted 33 lines · David Matlack
Keep the secondary and subordinate bus numbers that the previous kernel programmed into bridges, rather than assigning new ones, if the previous kernel preserved any device across a Live Update. Do this even on architectures that would otherwise always assign bus numbers themselves, e.g. when pci=assign-busses is passed.
Preserved devices must be allowed to continue performing memory transactions across a Live Update, so the kernel cannot change the fabric topology. Changing the bus numbers of a bridge changes the RequesterIDs of the devices below it, which would require disabling and flushing any in-flight memory transactions first.
Apply the policy globally rather than only to the paths that contain preserved devices. Bus numbers have to be preserved above a preserved device anyway, since an upstream bridge cannot expand its window. A global policy matches the scope of
pcibios_assign_all_busses(), and gives an answer that cannot change part way through the two passes of a bridge scan.Bridges that do not have bus numbers are still assigned new ones, so hot-adding a bridge keeps working, both during and after a Live Update. The two-pass bridge scan guarantees such bridges are only assigned bus numbers above those already claimed by preserved bridges.
The exception is a bridge that was preserved but comes up without a valid bus number configuration, e.g. because it was reset during kexec. Refuse to assign it new bus numbers, since that would silently change the BDF of every preserved device in its hierarchy. Also refuse to assign bus numbers to the other bridges on the same bus, since the bus numbers of the failed bridge can no longer be read from hardware and handing them out would let an unrelated device inherit the BDF of a preserved device.
Quoted 5 lines
Require that
CONFIG_CARDBUSis not enabled to enableCONFIG_PCI_LIVEUPDATEsince preserving bus numbers on PCI-to-CardBus bridges requires additional work but is not a priority at the moment.Signed-off-by David Matlack <[email protected]>
Thanks,
Praan
PATCH v9 7/13 PCI: Refactor matching logic for pci_dev_acs_ops
In reply to David MatlackRefactor the logic to match devices to pci_dev_acs_ops by factoring out the device matching loop into its own routine, pci_dev_acs_ops_get(). This eliminates duplicate code between pci_dev_specific_enable_acs() and pci_dev_specific_disable_acs_redir(), and will also be used in a subsequent commit to check if a device requires device-specific enable_acs() during a Live Update.
No functional change intended.
--- drivers/pci/quirks.c | 51 ++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 30 deletions(-)
drivers/pci/quirks.c +21 -30
@@ -5377,9 +5377,6 @@ static void pci_quirk_enable_intel_rp_mpc_acs(struct pci_dev *dev)*/ static int pci_quirk_enable_intel_pch_acs (struct pci_dev *dev) { -if (!pci_quirk_intel_pch_acs_match (dev)) -return -ENOTTY ; -if (pci_quirk_enable_intel_lpc_acs (dev)) {pci_warn (dev,"Failed to enable Intel PCH ACS quirk\n" );return 0 ;
@@ -5399,9 +5396,6 @@ static int pci_quirk_enable_intel_spt_pch_acs(struct pci_dev *dev)int pos;u32 cap, ctrl; -if (!pci_quirk_intel_spt_pch_acs_match (dev)) -return -ENOTTY ; - pos = dev->acs_cap;if (!pos)return -ENOTTY ;
@@ -5429,9 +5423,6 @@ static int pci_quirk_disable_intel_spt_pch_acs_redir(struct pci_dev *dev)int pos;u32 cap, ctrl; -if (!pci_quirk_intel_spt_pch_acs_match (dev)) -return -ENOTTY ; - pos = dev->acs_cap;if (!pos)return -ENOTTY ;
@@ -5451,56 +5442,56 @@ static int pci_quirk_disable_intel_spt_pch_acs_redir(struct pci_dev *dev)static const struct pci_dev_acs_ops {u16 vendor;u16 device; +bool (*match)(struct pci_dev *dev);int (*enable_acs)(struct pci_dev *dev);int (*disable_acs_redir)(struct pci_dev *dev); } pci_dev_acs_ops[] = { {PCI_VENDOR_ID_INTEL ,PCI_ANY_ID , + .match = pci_quirk_intel_pch_acs_match, .enable_acs = pci_quirk_enable_intel_pch_acs, }, {PCI_VENDOR_ID_INTEL ,PCI_ANY_ID , + .match = pci_quirk_intel_spt_pch_acs_match, .enable_acs = pci_quirk_enable_intel_spt_pch_acs, .disable_acs_redir = pci_quirk_disable_intel_spt_pch_acs_redir, }, }; -int pci_dev_specific_enable_acs (struct pci_dev *dev) +static const struct pci_dev_acs_ops *pci_dev_acs_ops_get (struct pci_dev *dev) {const struct pci_dev_acs_ops *p; -int i, ret; +int i;for (i =0 ; i <ARRAY_SIZE (pci_dev_acs_ops); i++) { p = &pci_dev_acs_ops[i];if ((p->vendor == dev->vendor || p->vendor == (u16 )PCI_ANY_ID ) && (p->device == dev->device || - p->device == (u16 )PCI_ANY_ID ) && - p->enable_acs) { - ret = p->enable_acs (dev); -if (ret >=0 ) -return ret; + p->device == (u16 )PCI_ANY_ID )) { +if (!p->match || p->match (dev)) +return p; } } +return NULL ; +} + +int pci_dev_specific_enable_acs (struct pci_dev *dev) +{ +const struct pci_dev_acs_ops *p =pci_dev_acs_ops_get (dev); + +if (p && p->enable_acs) +return p->enable_acs (dev); +return -ENOTTY ; }int pci_dev_specific_disable_acs_redir (struct pci_dev *dev) { -const struct pci_dev_acs_ops *p; -int i, ret; +const struct pci_dev_acs_ops *p =pci_dev_acs_ops_get (dev); -for (i =0 ; i <ARRAY_SIZE (pci_dev_acs_ops); i++) { - p = &pci_dev_acs_ops[i]; -if ((p->vendor == dev->vendor || - p->vendor == (u16 )PCI_ANY_ID ) && - (p->device == dev->device || - p->device == (u16 )PCI_ANY_ID ) && - p->disable_acs_redir) { - ret = p->disable_acs_redir (dev); -if (ret >=0 ) -return ret; - } - } +if (p && p->disable_acs_redir) +return p->disable_acs_redir (dev);return -ENOTTY ; }
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
[email protected]
AI reviewRe: [PATCH v9 07/13] PCI: Refactor matching logic for pci_dev_acs_ops
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines
Refactor the logic to match devices to
pci_dev_acs_opsby factoring out the device matching loop into its own routine,pci_dev_acs_ops_get(). This eliminates duplicate code betweenpci_dev_specific_enable_acs()andpci_dev_specific_disable_acs_redir(), and will also be used in a subsequent commit to check if a device requires device-specificenable_acs()during a Live Update.
Quoted 6 lines
No functional change intended.
Reviewed-by Pranjal Shrivastava <[email protected]>Reviewed-by Pasha Tatashin <[email protected]>Reviewed-by Bjorn Helgaas <[email protected]>Signed-off-by David Matlack <[email protected]>
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=7
PATCH v9 8/13 PCI: Save and restore the ACS Control register
In reply to David MatlackSave the ACS Control register in pci_save_state() and write it back in pci_restore_state(), instead of recomputing the ACS controls from scratch with pci_enable_acs().
This makes ACS symmetric with the rest of a device's saved state. Today pci_save_state() ignores ACS entirely and pci_restore_state() re-enables the ACS controls from the kernel's current ACS policy. As a result, a device can come out of a reset with different ACS controls than it went in with, e.g. any controls programmed outside of pci_enable_acs() are silently dropped.
pci_enable_acs() runs when a driver binds to a device (pci_dma_configure()), i.e. after pci_bus_add_device() has already saved the device's state. Refresh the saved ACS Control register there as well, otherwise a subsequent reset would revert ACS back to the configuration left behind by firmware.
Devices that rely on device-specific quirks to enable an ACS equivalent keep that configuration outside of the ACS Control register, so keep configuring ACS from scratch for them. Do the same for devices that have no saved ACS state at all.
--- drivers/pci/pci.c | 66 +++++++++++++++++++++++++++++++++++++++++++- drivers/pci/pci.h | 5 ++++ drivers/pci/quirks.c | 7 +++++ 3 files changed, 77 insertions(+), 1 deletion(-)
drivers/pci/pci.c +65 -1
@@ -1021,6 +1021,55 @@ static void pci_std_enable_acs(struct pci_dev *dev, struct pci_acs *caps) caps->ctrl |= (dev->acs_capabilities &PCI_ACS_TB ); } +/** +* pci_save_acs_state - save the ACS Control register +* @dev: the PCI device +* +* Record the ACS controls currently programmed in hardware so that +* pci_restore_acs_state() can reapply them after a reset. +*/ +static void pci_save_acs_state (struct pci_dev *dev) +{ +struct pci_cap_saved_state *save_state; + +if (!dev->acs_cap) +return ; + + save_state =pci_find_saved_ext_cap (dev,PCI_EXT_CAP_ID_ACS ); +if (!save_state) +return ; + +pci_read_config_word (dev, dev->acs_cap +PCI_ACS_CTRL , + (u16 *)&save_state->cap.data[0 ]); +} + +/** +* pci_restore_acs_state - restore the ACS Control register +* @dev: the PCI device +*/ +static void pci_restore_acs_state (struct pci_dev *dev) +{ +struct pci_cap_saved_state *save_state =NULL ; + +if (dev->acs_cap && !pci_need_dev_specific_enable_acs (dev)) + save_state =pci_find_saved_ext_cap (dev,PCI_EXT_CAP_ID_ACS ); + +/* +* Devices that rely on device-specific quirks to enable an ACS +* equivalent keep that configuration outside of the ACS Control +* register, so there is nothing useful to restore for them. Configure +* ACS from scratch instead, which also covers devices that have no +* saved ACS state at all. +*/ +if (!save_state) { +pci_enable_acs (dev); +return ; + } + +pci_write_config_word (dev, dev->acs_cap +PCI_ACS_CTRL , + *(u16 *)&save_state->cap.data[0 ]); +} +/** * pci_enable_acs - enable ACS if hardware support it * @dev: the PCI device
@@ -1057,6 +1106,15 @@ void pci_enable_acs(struct pci_dev *dev)__pci_config_acs (dev, &caps, config_acs_param,0 ,0 );pci_write_config_word (dev, pos +PCI_ACS_CTRL , caps.ctrl); + +/* +* pci_enable_acs() runs when a driver binds to the device, i.e. after +* pci_bus_add_device() has already saved the device's state. Refresh +* the saved ACS Control register so that a subsequent reset restores +* the controls programmed here rather than the ones left behind by +* firmware. +*/ +pci_save_acs_state (dev); }/**
@@ -1800,6 +1858,7 @@ int pci_save_state(struct pci_dev *dev)pci_save_aer_state (dev);pci_save_ptm_state (dev);pci_save_tph_state (dev); +pci_save_acs_state (dev);return pci_save_vc_state (dev); }EXPORT_SYMBOL (pci_save_state);
@@ -1877,7 +1936,7 @@ void pci_restore_state(struct pci_dev *dev)pci_restore_msi_state (dev);/* Restore ACS and IOV configuration state */ -pci_enable_acs (dev); +pci_restore_acs_state (dev);pci_restore_iov_state (dev); dev->state_saved = false;
@@ -3532,6 +3591,11 @@ void pci_allocate_cap_save_buffers(struct pci_dev *dev)if (error)pci_err (dev,"unable to allocate suspend buffer for LTR\n" ); + error =pci_add_ext_cap_save_buffer (dev,PCI_EXT_CAP_ID_ACS , +sizeof (u16)); +if (error) +pci_err (dev,"unable to allocate suspend buffer for ACS\n" ); +pci_allocate_vc_save_buffers (dev); }
drivers/pci/pci.h +5 -0
@@ -1095,6 +1095,7 @@ void pci_acs_init(struct pci_dev *dev);void pci_enable_acs (struct pci_dev *dev);#ifdef CONFIG_PCI_QUIRKS int pci_dev_specific_acs_enabled (struct pci_dev *dev,u16 acs_flags); +bool pci_need_dev_specific_enable_acs (struct pci_dev *dev);int pci_dev_specific_enable_acs (struct pci_dev *dev);int pci_dev_specific_disable_acs_redir (struct pci_dev *dev);void pci_disable_broken_acs_cap (struct pci_dev *pdev);
@@ -1105,6 +1106,10 @@ static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev, {return -ENOTTY ; } +static inline bool pci_need_dev_specific_enable_acs (struct pci_dev *dev) +{ +return false; +}static inline int pci_dev_specific_enable_acs (struct pci_dev *dev) {return -ENOTTY ;
drivers/pci/quirks.c +7 -0
@@ -5476,6 +5476,13 @@ static const struct pci_dev_acs_ops *pci_dev_acs_ops_get(struct pci_dev *dev)return NULL ; } +bool pci_need_dev_specific_enable_acs (struct pci_dev *dev) +{ +const struct pci_dev_acs_ops *p =pci_dev_acs_ops_get (dev); + +return p && p->enable_acs; +} +int pci_dev_specific_enable_acs (struct pci_dev *dev) {const struct pci_dev_acs_ops *p =pci_dev_acs_ops_get (dev);
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
[email protected]
AI reviewRe: [PATCH v9 08/13] PCI: Save and restore the ACS Control register
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 17 lines
Save the ACS Control register in
pci_save_state()and write it back inpci_restore_state(), instead of recomputing the ACS controls from scratch withpci_enable_acs().This makes ACS symmetric with the rest of a device's saved state. Today
pci_save_state()ignores ACS entirely andpci_restore_state()re-enables the ACS controls from the kernel's current ACS policy. As a result, a device can come out of a reset with different ACS controls than it went in with, e.g. any controls programmed outside ofpci_enable_acs()are silently dropped.
pci_enable_acs()runs when a driver binds to a device (pci_dma_configure()), i.e. afterpci_bus_add_device()has already saved the device's state. Refresh the saved ACS Control register there as well, otherwise a subsequent reset would revert ACS back to the configuration left behind by firmware.
Quoted 8 lines
Devices that rely on device-specific quirks to enable an ACS equivalent keep that configuration outside of the ACS Control register, so keep configuring ACS from scratch for them. Do the same for devices that have no saved ACS state at all.
Reviewed-by Bjorn Helgaas <[email protected]>Assisted-by Claude:claude-opus-5Signed-off-by David Matlack <[email protected]>
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=8
Re: [PATCH v9 08/13] PCI: Save and restore the ACS Control register
In reply to David MatlackQuoted 10 lines · On Fri, 18 Sep 2026 20:06:34 +0000 David Matlack <[email protected]> wrote:
Save the ACS Control register in
pci_save_state()and write it back inpci_restore_state(), instead of recomputing the ACS controls from scratch withpci_enable_acs().This makes ACS symmetric with the rest of a device's saved state. Today
pci_save_state()ignores ACS entirely andpci_restore_state()re-enables the ACS controls from the kernel's current ACS policy. As a result, a device can come out of a reset with different ACS controls than it went in with, e.g. any controls programmed outside ofpci_enable_acs()are silently dropped.
Controls, yes, but if we're restoring controls that might have EC set now, should the Egress Control Vector also be part of the save state?
Currently EC always gets cleared on reset and won't be restored by pci_enable_acs(), so we can lose both EC and the EC vector. With this, I think we restore EC but still lose the EC vector. Thanks,
Alex
Quoted 166 lines
pci_enable_acs()runs when a driver binds to a device (pci_dma_configure()), i.e. afterpci_bus_add_device()has already saved the device's state. Refresh the saved ACS Control register there as well, otherwise a subsequent reset would revert ACS back to the configuration left behind by firmware.Devices that rely on device-specific quirks to enable an ACS equivalent keep that configuration outside of the ACS Control register, so keep configuring ACS from scratch for them. Do the same for devices that have no saved ACS state at all.
Reviewed-by Bjorn Helgaas <[email protected]>Assisted-by Claude:claude-opus-5Signed-off-by David Matlack <[email protected]>--- drivers/pci/pci.c | 66 +++++++++++++++++++++++++++++++++++++++++++- drivers/pci/pci.h | 5 ++++ drivers/pci/quirks.c | 7 +++++ 3 files changed, 77 insertions(+), 1 deletion(-)drivers/pci/pci.c +65
-1@@ -1021,6 +1021,55 @@ static void pci_std_enable_acs(struct pci_dev *dev, struct pci_acs *caps) caps->ctrl |= (dev->acs_capabilities &PCI_ACS_TB ); } +/** +* pci_save_acs_state - save the ACS Control register +* @dev: the PCI device +* +* Record the ACS controls currently programmed in hardware so that +* pci_restore_acs_state() can reapply them after a reset. +*/ +static void pci_save_acs_state (struct pci_dev *dev) +{ +struct pci_cap_saved_state *save_state; + +if (!dev->acs_cap) +return ; + + save_state =pci_find_saved_ext_cap (dev,PCI_EXT_CAP_ID_ACS ); +if (!save_state) +return ; + +pci_read_config_word (dev, dev->acs_cap +PCI_ACS_CTRL , + (u16 *)&save_state->cap.data[0 ]); +} + +/** +* pci_restore_acs_state - restore the ACS Control register +* @dev: the PCI device +*/ +static void pci_restore_acs_state (struct pci_dev *dev) +{ +struct pci_cap_saved_state *save_state =NULL ; + +if (dev->acs_cap && !pci_need_dev_specific_enable_acs (dev)) + save_state =pci_find_saved_ext_cap (dev,PCI_EXT_CAP_ID_ACS ); + +/* +* Devices that rely on device-specific quirks to enable an ACS +* equivalent keep that configuration outside of the ACS Control +* register, so there is nothing useful to restore for them. Configure +* ACS from scratch instead, which also covers devices that have no +* saved ACS state at all. +*/ +if (!save_state) { +pci_enable_acs (dev); +return ; + } + +pci_write_config_word (dev, dev->acs_cap +PCI_ACS_CTRL , + *(u16 *)&save_state->cap.data[0 ]); +} +/** * pci_enable_acs - enable ACS if hardware support it * @dev: the PCI device @@ -1057,6 +1106,15 @@ void pci_enable_acs(struct pci_dev *dev)__pci_config_acs (dev, &caps, config_acs_param,0 ,0 );pci_write_config_word (dev, pos +PCI_ACS_CTRL , caps.ctrl); + +/* +* pci_enable_acs() runs when a driver binds to the device, i.e. after +* pci_bus_add_device() has already saved the device's state. Refresh +* the saved ACS Control register so that a subsequent reset restores +* the controls programmed here rather than the ones left behind by +* firmware. +*/ +pci_save_acs_state (dev); }/** @@ -1800,6 +1858,7 @@ int pci_save_state(struct pci_dev *dev)pci_save_aer_state (dev);pci_save_ptm_state (dev);pci_save_tph_state (dev); +pci_save_acs_state (dev);return pci_save_vc_state (dev); }EXPORT_SYMBOL (pci_save_state);@@ -1877,7 +1936,7 @@ void pci_restore_state(struct pci_dev *dev)pci_restore_msi_state (dev);/* Restore ACS and IOV configuration state */ -pci_enable_acs (dev); +pci_restore_acs_state (dev);pci_restore_iov_state (dev); dev->state_saved = false;@@ -3532,6 +3591,11 @@ void pci_allocate_cap_save_buffers(struct pci_dev *dev)if (error)pci_err (dev,"unable to allocate suspend buffer for LTR\n" ); + error =pci_add_ext_cap_save_buffer (dev,PCI_EXT_CAP_ID_ACS , +sizeof (u16)); +if (error) +pci_err (dev,"unable to allocate suspend buffer for ACS\n" ); +pci_allocate_vc_save_buffers (dev); }drivers/pci/pci.h +5
-0@@ -1095,6 +1095,7 @@ void pci_acs_init(struct pci_dev *dev);void pci_enable_acs (struct pci_dev *dev);#ifdef CONFIG_PCI_QUIRKS int pci_dev_specific_acs_enabled (struct pci_dev *dev,u16 acs_flags); +bool pci_need_dev_specific_enable_acs (struct pci_dev *dev);int pci_dev_specific_enable_acs (struct pci_dev *dev);int pci_dev_specific_disable_acs_redir (struct pci_dev *dev);void pci_disable_broken_acs_cap (struct pci_dev *pdev);@@ -1105,6 +1106,10 @@ static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev, {return -ENOTTY ; } +static inline bool pci_need_dev_specific_enable_acs (struct pci_dev *dev) +{ +return false; +}static inline int pci_dev_specific_enable_acs (struct pci_dev *dev) {return -ENOTTY ;drivers/pci/quirks.c +7
-0@@ -5476,6 +5476,13 @@ static const struct pci_dev_acs_ops *pci_dev_acs_ops_get(struct pci_dev *dev)return NULL ; } +bool pci_need_dev_specific_enable_acs (struct pci_dev *dev) +{ +const struct pci_dev_acs_ops *p =pci_dev_acs_ops_get (dev); + +return p && p->enable_acs; +} +int pci_dev_specific_enable_acs (struct pci_dev *dev) {const struct pci_dev_acs_ops *p =pci_dev_acs_ops_get (dev);
Re: [PATCH v9 08/13] PCI: Save and restore the ACS Control register
Quoted 14 lines · Alex Williamson
Quoted 10 lines · On Fri, 18 Sep 2026 20:06:34 +0000 David Matlack <[email protected]> wrote:
Save the ACS Control register in
pci_save_state()and write it back inpci_restore_state(), instead of recomputing the ACS controls from scratch withpci_enable_acs().This makes ACS symmetric with the rest of a device's saved state. Today
pci_save_state()ignores ACS entirely andpci_restore_state()re-enables the ACS controls from the kernel's current ACS policy. As a result, a device can come out of a reset with different ACS controls than it went in with, e.g. any controls programmed outside ofpci_enable_acs()are silently dropped.
Quoted 6 lines
Controls, yes, but if we're restoring controls that might have EC set now, should the Egress Control Vector also be part of the save state?
Currently EC always gets cleared on reset and won't be restored by
pci_enable_acs(), so we can lose both EC and the EC vector. With this, I think we restore EC but still lose the EC vector. Thanks,
Hi Alex,
The kernel does not enable Egress Control today or program the vector. Would this be to cover the case where firmware or userspace enabled it?
Here is an updated patch to save/restore the vector, but I don't have any devices that support Egress Control on my normal testing system so I haven't been able to really test it yet.
From: David Matlack <[email protected]>
Date: Fri, 11 Sep 2026 20:05:04 +0000
Subject: [PATCH] PCI: Save and restore the ACS Control register and Egress
Control Vector
Save the ACS Control register and the ACS Egress Control Vector in pci_save_state() and write them back in pci_restore_state(), instead of recomputing the ACS controls from scratch with pci_enable_acs().
This makes ACS symmetric with the rest of a device's saved state. Today pci_save_state() ignores ACS entirely and pci_restore_state() re-enables the ACS controls from the kernel's current ACS policy. As a result, a device can come out of a reset with different ACS controls than it went in with, e.g. any controls programmed outside of pci_enable_acs() are silently dropped.
Notably, this prepares the kernel to be able to adopt the ACS controls established by a previous kernel across a Live Update rather than assigning new ones through pci_enable_acs().
Save and restore the Egress Control Vector as well to keep it in sync with the now-properly-restored Egress Control Enable bit in the ACS control register. The kernel never enables Egress Controls or programs the vector, but the firmware could have and they need to be kept in sync to avoid changing how P2P traffic is rounted.
The size of the Egress Control Vector is not known when pci_allocate_cap_save_buffers() runs, as the ACS Capability register is only read later, in pci_acs_init(). Rather than move the allocation, size the save buffer for the largest vector a device can implement, which costs at most 32 bytes per ACS-capable device.
pci_enable_acs() runs when a driver binds to a device (pci_dma_configure()), i.e. after pci_bus_add_device() has already saved the device's state. Refresh the saved ACS state there as well, otherwise a subsequent reset would revert ACS back to the configuration left behind by firmware.
Devices that rely on device-specific quirks to enable an ACS equivalent keep that configuration outside of the ACS Control register, so keep configuring ACS from scratch for them. Do the same for devices that have no saved ACS state at all.
--- drivers/pci/pci.c | 117 +++++++++++++++++++++++++++++++++- drivers/pci/pci.h | 5 ++ drivers/pci/quirks.c | 7 ++ include/uapi/linux/pci_regs.h | 1 + 4 files changed, 129 insertions(+), 1 deletion(-)
drivers/pci/pci.c +116 -1
@@ -1021,6 +1021,106 @@ static void pci_std_enable_acs(struct pci_dev *dev, struct pci_acs *caps) caps->ctrl |= (dev->acs_capabilities &PCI_ACS_TB ); } +/* +* Layout of the ACS save buffer. @ecv holds the ACS Egress Control Vector and +* is sized for the largest vector a device can implement. +*/ +struct pci_acs_saved_state { +u16 ctrl; +u32 ecv[8 ]; +}; + +/* +* Return the size in bytes of the ACS Egress Control Vector, or 0 if the +* device does not implement P2P Egress Control. +*/ +static unsigned int pci_acs_ecv_size (struct pci_dev *dev) +{ +unsigned int bits; + +if (!dev->acs_cap || !(dev->acs_capabilities &PCI_ACS_EC )) +return 0 ; + +/* An Egress Control Vector Size of 0 means 256 bits */ + bits =FIELD_GET (PCI_ACS_EGRESS_BITS_MASK , dev->acs_capabilities); +if (!bits) + bits =256 ; + +/* The vector is implemented as a series of DWORD registers */ +return round_up (bits,32 ) /8 ; +} + +/** +* pci_save_acs_state - save the ACS Control register and Egress Control Vector +* @dev: the PCI device +* +* Record the ACS configuration currently programmed in hardware so that +* pci_restore_acs_state() can reapply it after a reset. +*/ +static void pci_save_acs_state (struct pci_dev *dev) +{ +struct pci_cap_saved_state *save_state; +struct pci_acs_saved_state *acs; +unsigned int i, dwords; + +if (!dev->acs_cap) +return ; + + save_state =pci_find_saved_ext_cap (dev,PCI_EXT_CAP_ID_ACS ); +if (!save_state) +return ; + + acs = (struct pci_acs_saved_state *)save_state->cap.data; + +pci_read_config_word (dev, dev->acs_cap +PCI_ACS_CTRL , &acs->ctrl); + + dwords =pci_acs_ecv_size (dev) /sizeof (u32); +for (i =0 ; i < dwords; i++) +pci_read_config_dword (dev, dev->acs_cap +PCI_ACS_EGRESS_CTL_V + + i *sizeof (u32), &acs->ecv[i]); +} + +/** +* pci_restore_acs_state - restore the ACS Control register and Egress Control +* Vector +* @dev: the PCI device +*/ +static void pci_restore_acs_state (struct pci_dev *dev) +{ +struct pci_cap_saved_state *save_state =NULL ; +struct pci_acs_saved_state *acs; +unsigned int i, dwords; + +if (dev->acs_cap && !pci_need_dev_specific_enable_acs (dev)) + save_state =pci_find_saved_ext_cap (dev,PCI_EXT_CAP_ID_ACS ); + +/* +* Devices that rely on device-specific quirks to enable an ACS +* equivalent keep that configuration outside of the ACS Control +* register, so there is nothing useful to restore for them. Configure +* ACS from scratch instead, which also covers devices that have no +* saved ACS state at all. +*/ +if (!save_state) { +pci_enable_acs (dev); +return ; + } + + acs = (struct pci_acs_saved_state *)save_state->cap.data; + +/* +* Restore the Egress Control Vector before the ACS Control register. +* The vector resets to zero, so enabling P2P Egress Control first +* would briefly apply the reset vector instead of the saved one. +*/ + dwords =pci_acs_ecv_size (dev) /sizeof (u32); +for (i =0 ; i < dwords; i++) +pci_write_config_dword (dev, dev->acs_cap +PCI_ACS_EGRESS_CTL_V + + i *sizeof (u32), acs->ecv[i]); + +pci_write_config_word (dev, dev->acs_cap +PCI_ACS_CTRL , acs->ctrl); +} +/** * pci_enable_acs - enable ACS if hardware support it * @dev: the PCI device
@@ -1057,6 +1157,15 @@ void pci_enable_acs(struct pci_dev *dev)__pci_config_acs (dev, &caps, config_acs_param,0 ,0 );pci_write_config_word (dev, pos +PCI_ACS_CTRL , caps.ctrl); + +/* +* pci_enable_acs() runs when a driver binds to the device, i.e. after +* pci_bus_add_device() has already saved the device's state. Refresh +* the saved ACS state so that a subsequent reset restores the +* configuration programmed here rather than the one left behind by +* firmware. +*/ +pci_save_acs_state (dev); }/**
@@ -1800,6 +1909,7 @@ int pci_save_state(struct pci_dev *dev)pci_save_aer_state (dev);pci_save_ptm_state (dev);pci_save_tph_state (dev); +pci_save_acs_state (dev);return pci_save_vc_state (dev); }EXPORT_SYMBOL (pci_save_state);
@@ -1877,7 +1987,7 @@ void pci_restore_state(struct pci_dev *dev)pci_restore_msi_state (dev);/* Restore ACS and IOV configuration state */ -pci_enable_acs (dev); +pci_restore_acs_state (dev);pci_restore_iov_state (dev); dev->state_saved = false;
@@ -3532,6 +3642,11 @@ void pci_allocate_cap_save_buffers(struct pci_dev *dev)if (error)pci_err (dev,"unable to allocate suspend buffer for LTR\n" ); + error =pci_add_ext_cap_save_buffer (dev,PCI_EXT_CAP_ID_ACS , +sizeof (struct pci_acs_saved_state )); +if (error) +pci_err (dev,"unable to allocate suspend buffer for ACS\n" ); +pci_allocate_vc_save_buffers (dev); }
drivers/pci/pci.h +5 -0
@@ -1095,6 +1095,7 @@ void pci_acs_init(struct pci_dev *dev);void pci_enable_acs (struct pci_dev *dev);#ifdef CONFIG_PCI_QUIRKS int pci_dev_specific_acs_enabled (struct pci_dev *dev,u16 acs_flags); +bool pci_need_dev_specific_enable_acs (struct pci_dev *dev);int pci_dev_specific_enable_acs (struct pci_dev *dev);int pci_dev_specific_disable_acs_redir (struct pci_dev *dev);void pci_disable_broken_acs_cap (struct pci_dev *pdev);
@@ -1105,6 +1106,10 @@ static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev, {return -ENOTTY ; } +static inline bool pci_need_dev_specific_enable_acs (struct pci_dev *dev) +{ +return false; +}static inline int pci_dev_specific_enable_acs (struct pci_dev *dev) {return -ENOTTY ;
drivers/pci/quirks.c +7 -0
@@ -5476,6 +5476,13 @@ static const struct pci_dev_acs_ops *pci_dev_acs_ops_get(struct pci_dev *dev)return NULL ; } +bool pci_need_dev_specific_enable_acs (struct pci_dev *dev) +{ +const struct pci_dev_acs_ops *p =pci_dev_acs_ops_get (dev); + +return p && p->enable_acs; +} +int pci_dev_specific_enable_acs (struct pci_dev *dev) {const struct pci_dev_acs_ops *p =pci_dev_acs_ops_get (dev);
include/uapi/linux/pci_regs.h +1 -0
@@ -1023,6 +1023,7 @@#define PCI_ACS_UF 0x0010/* Upstream Forwarding */ #define PCI_ACS_EC 0x0020/* P2P Egress Control */ #define PCI_ACS_DT 0x0040/* Direct Translated P2P */ +#define PCI_ACS_EGRESS_BITS_MASK 0xff00/* Egress Control Vector Size */ #define PCI_ACS_EGRESS_BITS 0x05/* ACS Egress Control Vector Size */ #define PCI_ACS_CTRL 0x06/* ACS Control Register */ #define PCI_ACS_EGRESS_CTL_V 0x08/* ACS Egress Control Vector */
Re: [PATCH v9 08/13] PCI: Save and restore the ACS Control register
Quoted 23 lines · David Matlack
Quoted 14 lines · Alex Williamson
Quoted 10 lines · On Fri, 18 Sep 2026 20:06:34 +0000 David Matlack <[email protected]> wrote:
Save the ACS Control register in
pci_save_state()and write it back inpci_restore_state(), instead of recomputing the ACS controls from scratch withpci_enable_acs().This makes ACS symmetric with the rest of a device's saved state. Today
pci_save_state()ignores ACS entirely andpci_restore_state()re-enables the ACS controls from the kernel's current ACS policy. As a result, a device can come out of a reset with different ACS controls than it went in with, e.g. any controls programmed outside ofpci_enable_acs()are silently dropped.Quoted 6 lines
Controls, yes, but if we're restoring controls that might have EC set now, should the Egress Control Vector also be part of the save state?
Currently EC always gets cleared on reset and won't be restored by
pci_enable_acs(), so we can lose both EC and the EC vector. With this, I think we restore EC but still lose the EC vector. Thanks,
Quoted 6 lines
The kernel does not enable Egress Control today or program the vector. Would this be to cover the case where firmware or userspace enabled it?
Here is an updated patch to save/restore the vector, but I don't have any devices that support Egress Control on my normal testing system so I haven't been able to really test it yet.
Hey Alex, gentle ping on this.
This series is merged into the liveupdate tree to get linux-next exposure ahead of 7.4 merge window. If this patch needs a respin or a fixup I'd like to get the ball rolling on that.
I think the 3 options are:
1. Keep the patch as is based on the understanding that the kernel does not enable EC today or program the vector.
2. Save/restore the EC vector (the below patch).
3. Clear EC on restore to preserve the current behavior.
And if we decide to do (2) or (3) then that could be done with a respin of the patch ahead of the merge window, or a fixup patch on top to send in a later rc.
Thanks!
Quoted 262 lines
From: David Matlack <[email protected]>
Date: Fri, 11 Sep 2026 20:05:04 +0000
Subject: [PATCH] PCI: Save and restore the ACS Control register and Egress
Control VectorSave the ACS Control register and the ACS Egress Control Vector in
pci_save_state()and write them back inpci_restore_state(), instead of recomputing the ACS controls from scratch withpci_enable_acs().This makes ACS symmetric with the rest of a device's saved state. Today
pci_save_state()ignores ACS entirely andpci_restore_state()re-enables the ACS controls from the kernel's current ACS policy. As a result, a device can come out of a reset with different ACS controls than it went in with, e.g. any controls programmed outside ofpci_enable_acs()are silently dropped.Notably, this prepares the kernel to be able to adopt the ACS controls established by a previous kernel across a Live Update rather than assigning new ones through
pci_enable_acs().Save and restore the Egress Control Vector as well to keep it in sync with the now-properly-restored Egress Control Enable bit in the ACS control register. The kernel never enables Egress Controls or programs the vector, but the firmware could have and they need to be kept in sync to avoid changing how P2P traffic is rounted.
The size of the Egress Control Vector is not known when
pci_allocate_cap_save_buffers()runs, as the ACS Capability register is only read later, inpci_acs_init(). Rather than move the allocation, size the save buffer for the largest vector a device can implement, which costs at most 32 bytes per ACS-capable device.
pci_enable_acs()runs when a driver binds to a device (pci_dma_configure()), i.e. afterpci_bus_add_device()has already saved the device's state. Refresh the saved ACS state there as well, otherwise a subsequent reset would revert ACS back to the configuration left behind by firmware.Devices that rely on device-specific quirks to enable an ACS equivalent keep that configuration outside of the ACS Control register, so keep configuring ACS from scratch for them. Do the same for devices that have no saved ACS state at all.
Assisted-by Claude:claude-opus-5Signed-off-by David Matlack <[email protected]>--- drivers/pci/pci.c | 117 +++++++++++++++++++++++++++++++++- drivers/pci/pci.h | 5 ++ drivers/pci/quirks.c | 7 ++ include/uapi/linux/pci_regs.h | 1 + 4 files changed, 129 insertions(+), 1 deletion(-)drivers/pci/pci.c +116
-1@@ -1021,6 +1021,106 @@ static void pci_std_enable_acs(struct pci_dev *dev, struct pci_acs *caps) caps->ctrl |= (dev->acs_capabilities &PCI_ACS_TB ); } +/* +* Layout of the ACS save buffer. @ecv holds the ACS Egress Control Vector and +* is sized for the largest vector a device can implement. +*/ +struct pci_acs_saved_state { +u16 ctrl; +u32 ecv[8 ]; +}; + +/* +* Return the size in bytes of the ACS Egress Control Vector, or 0 if the +* device does not implement P2P Egress Control. +*/ +static unsigned int pci_acs_ecv_size (struct pci_dev *dev) +{ +unsigned int bits; + +if (!dev->acs_cap || !(dev->acs_capabilities &PCI_ACS_EC )) +return 0 ; + +/* An Egress Control Vector Size of 0 means 256 bits */ + bits =FIELD_GET (PCI_ACS_EGRESS_BITS_MASK , dev->acs_capabilities); +if (!bits) + bits =256 ; + +/* The vector is implemented as a series of DWORD registers */ +return round_up (bits,32 ) /8 ; +} + +/** +* pci_save_acs_state - save the ACS Control register and Egress Control Vector +* @dev: the PCI device +* +* Record the ACS configuration currently programmed in hardware so that +* pci_restore_acs_state() can reapply it after a reset. +*/ +static void pci_save_acs_state (struct pci_dev *dev) +{ +struct pci_cap_saved_state *save_state; +struct pci_acs_saved_state *acs; +unsigned int i, dwords; + +if (!dev->acs_cap) +return ; + + save_state =pci_find_saved_ext_cap (dev,PCI_EXT_CAP_ID_ACS ); +if (!save_state) +return ; + + acs = (struct pci_acs_saved_state *)save_state->cap.data; + +pci_read_config_word (dev, dev->acs_cap +PCI_ACS_CTRL , &acs->ctrl); + + dwords =pci_acs_ecv_size (dev) /sizeof (u32); +for (i =0 ; i < dwords; i++) +pci_read_config_dword (dev, dev->acs_cap +PCI_ACS_EGRESS_CTL_V + + i *sizeof (u32), &acs->ecv[i]); +} + +/** +* pci_restore_acs_state - restore the ACS Control register and Egress Control +* Vector +* @dev: the PCI device +*/ +static void pci_restore_acs_state (struct pci_dev *dev) +{ +struct pci_cap_saved_state *save_state =NULL ; +struct pci_acs_saved_state *acs; +unsigned int i, dwords; + +if (dev->acs_cap && !pci_need_dev_specific_enable_acs (dev)) + save_state =pci_find_saved_ext_cap (dev,PCI_EXT_CAP_ID_ACS ); + +/* +* Devices that rely on device-specific quirks to enable an ACS +* equivalent keep that configuration outside of the ACS Control +* register, so there is nothing useful to restore for them. Configure +* ACS from scratch instead, which also covers devices that have no +* saved ACS state at all. +*/ +if (!save_state) { +pci_enable_acs (dev); +return ; + } + + acs = (struct pci_acs_saved_state *)save_state->cap.data; + +/* +* Restore the Egress Control Vector before the ACS Control register. +* The vector resets to zero, so enabling P2P Egress Control first +* would briefly apply the reset vector instead of the saved one. +*/ + dwords =pci_acs_ecv_size (dev) /sizeof (u32); +for (i =0 ; i < dwords; i++) +pci_write_config_dword (dev, dev->acs_cap +PCI_ACS_EGRESS_CTL_V + + i *sizeof (u32), acs->ecv[i]); + +pci_write_config_word (dev, dev->acs_cap +PCI_ACS_CTRL , acs->ctrl); +} +/** * pci_enable_acs - enable ACS if hardware support it * @dev: the PCI device @@ -1057,6 +1157,15 @@ void pci_enable_acs(struct pci_dev *dev)__pci_config_acs (dev, &caps, config_acs_param,0 ,0 );pci_write_config_word (dev, pos +PCI_ACS_CTRL , caps.ctrl); + +/* +* pci_enable_acs() runs when a driver binds to the device, i.e. after +* pci_bus_add_device() has already saved the device's state. Refresh +* the saved ACS state so that a subsequent reset restores the +* configuration programmed here rather than the one left behind by +* firmware. +*/ +pci_save_acs_state (dev); }/** @@ -1800,6 +1909,7 @@ int pci_save_state(struct pci_dev *dev)pci_save_aer_state (dev);pci_save_ptm_state (dev);pci_save_tph_state (dev); +pci_save_acs_state (dev);return pci_save_vc_state (dev); }EXPORT_SYMBOL (pci_save_state);@@ -1877,7 +1987,7 @@ void pci_restore_state(struct pci_dev *dev)pci_restore_msi_state (dev);/* Restore ACS and IOV configuration state */ -pci_enable_acs (dev); +pci_restore_acs_state (dev);pci_restore_iov_state (dev); dev->state_saved = false;@@ -3532,6 +3642,11 @@ void pci_allocate_cap_save_buffers(struct pci_dev *dev)if (error)pci_err (dev,"unable to allocate suspend buffer for LTR\n" ); + error =pci_add_ext_cap_save_buffer (dev,PCI_EXT_CAP_ID_ACS , +sizeof (struct pci_acs_saved_state )); +if (error) +pci_err (dev,"unable to allocate suspend buffer for ACS\n" ); +pci_allocate_vc_save_buffers (dev); }drivers/pci/pci.h +5
-0@@ -1095,6 +1095,7 @@ void pci_acs_init(struct pci_dev *dev);void pci_enable_acs (struct pci_dev *dev);#ifdef CONFIG_PCI_QUIRKS int pci_dev_specific_acs_enabled (struct pci_dev *dev,u16 acs_flags); +bool pci_need_dev_specific_enable_acs (struct pci_dev *dev);int pci_dev_specific_enable_acs (struct pci_dev *dev);int pci_dev_specific_disable_acs_redir (struct pci_dev *dev);void pci_disable_broken_acs_cap (struct pci_dev *pdev);@@ -1105,6 +1106,10 @@ static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev, {return -ENOTTY ; } +static inline bool pci_need_dev_specific_enable_acs (struct pci_dev *dev) +{ +return false; +}static inline int pci_dev_specific_enable_acs (struct pci_dev *dev) {return -ENOTTY ;drivers/pci/quirks.c +7
-0@@ -5476,6 +5476,13 @@ static const struct pci_dev_acs_ops *pci_dev_acs_ops_get(struct pci_dev *dev)return NULL ; } +bool pci_need_dev_specific_enable_acs (struct pci_dev *dev) +{ +const struct pci_dev_acs_ops *p =pci_dev_acs_ops_get (dev); + +return p && p->enable_acs; +} +int pci_dev_specific_enable_acs (struct pci_dev *dev) {const struct pci_dev_acs_ops *p =pci_dev_acs_ops_get (dev);include/uapi/linux/pci_regs.h +1
-0@@ -1023,6 +1023,7 @@#define PCI_ACS_UF 0x0010/* Upstream Forwarding */ #define PCI_ACS_EC 0x0020/* P2P Egress Control */ #define PCI_ACS_DT 0x0040/* Direct Translated P2P */ +#define PCI_ACS_EGRESS_BITS_MASK 0xff00/* Egress Control Vector Size */ #define PCI_ACS_EGRESS_BITS 0x05/* ACS Egress Control Vector Size */ #define PCI_ACS_CTRL 0x06/* ACS Control Register */ #define PCI_ACS_EGRESS_CTL_V 0x08/* ACS Egress Control Vector */
Re: [PATCH v9 08/13] PCI: Save and restore the ACS Control register
Quoted 24 lines · On Wed, 7 Oct 2026 02:20:16 -0700 David Matlack <[email protected]> wrote:
Quoted 23 lines · David Matlack
Quoted 20 lines · Alex Williamson
Quoted 10 lines · On Fri, 18 Sep 2026 20:06:34 +0000 David Matlack <[email protected]> wrote:
Save the ACS Control register in
pci_save_state()and write it back inpci_restore_state(), instead of recomputing the ACS controls from scratch withpci_enable_acs().This makes ACS symmetric with the rest of a device's saved state. Today
pci_save_state()ignores ACS entirely andpci_restore_state()re-enables the ACS controls from the kernel's current ACS policy. As a result, a device can come out of a reset with different ACS controls than it went in with, e.g. any controls programmed outside ofpci_enable_acs()are silently dropped.Controls, yes, but if we're restoring controls that might have EC set now, should the Egress Control Vector also be part of the save state?
Currently EC always gets cleared on reset and won't be restored by
pci_enable_acs(), so we can lose both EC and the EC vector. With this, I think we restore EC but still lose the EC vector. Thanks,
Quoted 8 lines
Quoted 6 lines
The kernel does not enable Egress Control today or program the vector. Would this be to cover the case where firmware or userspace enabled it?
Here is an updated patch to save/restore the vector, but I don't have any devices that support Egress Control on my normal testing system so I haven't been able to really test it yet.
Hey Alex, gentle ping on this.
Sorry, I had missed the reply, thanks for the ping. Saving the full Egress Control Vector would mostly be for configurations where it's enabled by the firmware, similar to virtual channel. Honestly I don't know that anything pre-programs it, but handling it now avoids the issue entirely and also handles any future work to add such support in the kernel preemptively. It's the sort of thing that might otherwise be overlooked.
Quoted 6 lines
This series is merged into the liveupdate tree to get linux-next exposure ahead of 7.4 merge window. If this patch needs a respin or a fixup I'd like to get the ball rolling on that.
I think the 3 options are:
Quoted 8 lines
1. Keep the patch as is based on the understanding that the kernel does not enable EC today or program the vector.
2. Save/restore the EC vector (the below patch).
3. Clear EC on restore to preserve the current behavior.And if we decide to do (2) or (3) then that could be done with a respin of the patch ahead of the merge window, or a fixup patch on top to send in a later rc.
It's not complicated, I don't see why we wouldn't just do (2) in the first pass.
Quoted 20 lines
Quoted 20 lines
From: David Matlack <[email protected]>
Date: Fri, 11 Sep 2026 20:05:04 +0000
Subject: [PATCH] PCI: Save and restore the ACS Control register and Egress
Control VectorSave the ACS Control register and the ACS Egress Control Vector in
pci_save_state()and write them back inpci_restore_state(), instead of recomputing the ACS controls from scratch withpci_enable_acs().This makes ACS symmetric with the rest of a device's saved state. Today
pci_save_state()ignores ACS entirely andpci_restore_state()re-enables the ACS controls from the kernel's current ACS policy. As a result, a device can come out of a reset with different ACS controls than it went in with, e.g. any controls programmed outside ofpci_enable_acs()are silently dropped.Notably, this prepares the kernel to be able to adopt the ACS controls established by a previous kernel across a Live Update rather than assigning new ones through
pci_enable_acs().
Quoted 5 lines
Quoted 5 lines
Save and restore the Egress Control Vector as well to keep it in sync with the now-properly-restored Egress Control Enable bit in the ACS control register. The kernel never enables Egress Controls or programs the vector, but the firmware could have and they need to be kept in sync to avoid changing how P2P traffic is rounted.
s/rounted/routed/
Quoted 6 lines
Quoted 6 lines
The size of the Egress Control Vector is not known when
pci_allocate_cap_save_buffers()runs, as the ACS Capability register is only read later, inpci_acs_init(). Rather than move the allocation, size the save buffer for the largest vector a device can implement, which costs at most 32 bytes per ACS-capable device.
The argument that the size isn't known isn't really true. The egress control vector size is a hwinit field of the ACS capabilty register. We could just read it from the register during both the save and restore, much like we rely on similar hwinit fields in saving and restoring the VC capability.
Caching of the ACS capability was added in 8f05a5f6745c, and while it mentions that it removes some duplicate re-reads, its primary purpose is clearly to be able to quirk out misreported capabilities. Maybe a better option to avoid the egress vector size being cached on the pci_dev would be to only cache the lower byte of the register.
Quoted 6 lines
Quoted 6 lines
pci_enable_acs()runs when a driver binds to a device (pci_dma_configure()), i.e. afterpci_bus_add_device()has already saved the device's state. Refresh the saved ACS state there as well, otherwise a subsequent reset would revert ACS back to the configuration left behind by firmware.
Quoted 6 lines
Quoted 6 lines
Devices that rely on device-specific quirks to enable an ACS equivalent keep that configuration outside of the ACS Control register, so keep configuring ACS from scratch for them. Do the same for devices that have no saved ACS state at all.
Assisted-by Claude:claude-opus-5
Nit, I've been letting things already on the list slide through with the explicit model reference, but note that since 816d9992d9ed the recommended syntax is just "Assisted-by: LLM" (plus other tools as necessary). Thanks,
Alex
Quoted 217 lines
Quoted 217 lines
Signed-off-by David Matlack <[email protected]>--- drivers/pci/pci.c | 117 +++++++++++++++++++++++++++++++++- drivers/pci/pci.h | 5 ++ drivers/pci/quirks.c | 7 ++ include/uapi/linux/pci_regs.h | 1 + 4 files changed, 129 insertions(+), 1 deletion(-)drivers/pci/pci.c +116
-1@@ -1021,6 +1021,106 @@ static void pci_std_enable_acs(struct pci_dev *dev, struct pci_acs *caps) caps->ctrl |= (dev->acs_capabilities &PCI_ACS_TB ); } +/* +* Layout of the ACS save buffer. @ecv holds the ACS Egress Control Vector and +* is sized for the largest vector a device can implement. +*/ +struct pci_acs_saved_state { +u16 ctrl; +u32 ecv[8 ]; +}; + +/* +* Return the size in bytes of the ACS Egress Control Vector, or 0 if the +* device does not implement P2P Egress Control. +*/ +static unsigned int pci_acs_ecv_size (struct pci_dev *dev) +{ +unsigned int bits; + +if (!dev->acs_cap || !(dev->acs_capabilities &PCI_ACS_EC )) +return 0 ; + +/* An Egress Control Vector Size of 0 means 256 bits */ + bits =FIELD_GET (PCI_ACS_EGRESS_BITS_MASK , dev->acs_capabilities); +if (!bits) + bits =256 ; + +/* The vector is implemented as a series of DWORD registers */ +return round_up (bits,32 ) /8 ; +} + +/** +* pci_save_acs_state - save the ACS Control register and Egress Control Vector +* @dev: the PCI device +* +* Record the ACS configuration currently programmed in hardware so that +* pci_restore_acs_state() can reapply it after a reset. +*/ +static void pci_save_acs_state (struct pci_dev *dev) +{ +struct pci_cap_saved_state *save_state; +struct pci_acs_saved_state *acs; +unsigned int i, dwords; + +if (!dev->acs_cap) +return ; + + save_state =pci_find_saved_ext_cap (dev,PCI_EXT_CAP_ID_ACS ); +if (!save_state) +return ; + + acs = (struct pci_acs_saved_state *)save_state->cap.data; + +pci_read_config_word (dev, dev->acs_cap +PCI_ACS_CTRL , &acs->ctrl); + + dwords =pci_acs_ecv_size (dev) /sizeof (u32); +for (i =0 ; i < dwords; i++) +pci_read_config_dword (dev, dev->acs_cap +PCI_ACS_EGRESS_CTL_V + + i *sizeof (u32), &acs->ecv[i]); +} + +/** +* pci_restore_acs_state - restore the ACS Control register and Egress Control +* Vector +* @dev: the PCI device +*/ +static void pci_restore_acs_state (struct pci_dev *dev) +{ +struct pci_cap_saved_state *save_state =NULL ; +struct pci_acs_saved_state *acs; +unsigned int i, dwords; + +if (dev->acs_cap && !pci_need_dev_specific_enable_acs (dev)) + save_state =pci_find_saved_ext_cap (dev,PCI_EXT_CAP_ID_ACS ); + +/* +* Devices that rely on device-specific quirks to enable an ACS +* equivalent keep that configuration outside of the ACS Control +* register, so there is nothing useful to restore for them. Configure +* ACS from scratch instead, which also covers devices that have no +* saved ACS state at all. +*/ +if (!save_state) { +pci_enable_acs (dev); +return ; + } + + acs = (struct pci_acs_saved_state *)save_state->cap.data; + +/* +* Restore the Egress Control Vector before the ACS Control register. +* The vector resets to zero, so enabling P2P Egress Control first +* would briefly apply the reset vector instead of the saved one. +*/ + dwords =pci_acs_ecv_size (dev) /sizeof (u32); +for (i =0 ; i < dwords; i++) +pci_write_config_dword (dev, dev->acs_cap +PCI_ACS_EGRESS_CTL_V + + i *sizeof (u32), acs->ecv[i]); + +pci_write_config_word (dev, dev->acs_cap +PCI_ACS_CTRL , acs->ctrl); +} +/** * pci_enable_acs - enable ACS if hardware support it * @dev: the PCI device @@ -1057,6 +1157,15 @@ void pci_enable_acs(struct pci_dev *dev)__pci_config_acs (dev, &caps, config_acs_param,0 ,0 );pci_write_config_word (dev, pos +PCI_ACS_CTRL , caps.ctrl); + +/* +* pci_enable_acs() runs when a driver binds to the device, i.e. after +* pci_bus_add_device() has already saved the device's state. Refresh +* the saved ACS state so that a subsequent reset restores the +* configuration programmed here rather than the one left behind by +* firmware. +*/ +pci_save_acs_state (dev); }/** @@ -1800,6 +1909,7 @@ int pci_save_state(struct pci_dev *dev)pci_save_aer_state (dev);pci_save_ptm_state (dev);pci_save_tph_state (dev); +pci_save_acs_state (dev);return pci_save_vc_state (dev); }EXPORT_SYMBOL (pci_save_state);@@ -1877,7 +1987,7 @@ void pci_restore_state(struct pci_dev *dev)pci_restore_msi_state (dev);/* Restore ACS and IOV configuration state */ -pci_enable_acs (dev); +pci_restore_acs_state (dev);pci_restore_iov_state (dev); dev->state_saved = false;@@ -3532,6 +3642,11 @@ void pci_allocate_cap_save_buffers(struct pci_dev *dev)if (error)pci_err (dev,"unable to allocate suspend buffer for LTR\n" ); + error =pci_add_ext_cap_save_buffer (dev,PCI_EXT_CAP_ID_ACS , +sizeof (struct pci_acs_saved_state )); +if (error) +pci_err (dev,"unable to allocate suspend buffer for ACS\n" ); +pci_allocate_vc_save_buffers (dev); }drivers/pci/pci.h +5
-0@@ -1095,6 +1095,7 @@ void pci_acs_init(struct pci_dev *dev);void pci_enable_acs (struct pci_dev *dev);#ifdef CONFIG_PCI_QUIRKS int pci_dev_specific_acs_enabled (struct pci_dev *dev,u16 acs_flags); +bool pci_need_dev_specific_enable_acs (struct pci_dev *dev);int pci_dev_specific_enable_acs (struct pci_dev *dev);int pci_dev_specific_disable_acs_redir (struct pci_dev *dev);void pci_disable_broken_acs_cap (struct pci_dev *pdev);@@ -1105,6 +1106,10 @@ static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev, {return -ENOTTY ; } +static inline bool pci_need_dev_specific_enable_acs (struct pci_dev *dev) +{ +return false; +}static inline int pci_dev_specific_enable_acs (struct pci_dev *dev) {return -ENOTTY ;drivers/pci/quirks.c +7
-0@@ -5476,6 +5476,13 @@ static const struct pci_dev_acs_ops *pci_dev_acs_ops_get(struct pci_dev *dev)return NULL ; } +bool pci_need_dev_specific_enable_acs (struct pci_dev *dev) +{ +const struct pci_dev_acs_ops *p =pci_dev_acs_ops_get (dev); + +return p && p->enable_acs; +} +int pci_dev_specific_enable_acs (struct pci_dev *dev) {const struct pci_dev_acs_ops *p =pci_dev_acs_ops_get (dev);include/uapi/linux/pci_regs.h +1
-0@@ -1023,6 +1023,7 @@#define PCI_ACS_UF 0x0010/* Upstream Forwarding */ #define PCI_ACS_EC 0x0020/* P2P Egress Control */ #define PCI_ACS_DT 0x0040/* Direct Translated P2P */ +#define PCI_ACS_EGRESS_BITS_MASK 0xff00/* Egress Control Vector Size */ #define PCI_ACS_EGRESS_BITS 0x05/* ACS Egress Control Vector Size */ #define PCI_ACS_CTRL 0x06/* ACS Control Register */ #define PCI_ACS_EGRESS_CTL_V 0x08/* ACS Egress Control Vector */
Re: [PATCH v9 08/13] PCI: Save and restore the ACS Control register
In reply to David MatlackQuoted 17 lines · David Matlack
Save the ACS Control register in
pci_save_state()and write it back inpci_restore_state(), instead of recomputing the ACS controls from scratch withpci_enable_acs().This makes ACS symmetric with the rest of a device's saved state. Today
pci_save_state()ignores ACS entirely andpci_restore_state()re-enables the ACS controls from the kernel's current ACS policy. As a result, a device can come out of a reset with different ACS controls than it went in with, e.g. any controls programmed outside ofpci_enable_acs()are silently dropped.
pci_enable_acs()runs when a driver binds to a device (pci_dma_configure()), i.e. afterpci_bus_add_device()has already saved the device's state. Refresh the saved ACS Control register there as well, otherwise a subsequent reset would revert ACS back to the configuration left behind by firmware.
Quoted 8 lines
Devices that rely on device-specific quirks to enable an ACS equivalent keep that configuration outside of the ACS Control register, so keep configuring ACS from scratch for them. Do the same for devices that have no saved ACS state at all.
Reviewed-by Bjorn Helgaas <[email protected]>Assisted-by Claude:claude-opus-5Signed-off-by David Matlack <[email protected]>
Thanks,
Praan
PATCH v9 9/13 PCI: liveupdate: Adopt ACS controls in incoming preserved devices
In reply to David MatlackAdopt Access Control Services (ACS) controls on all incoming preserved devices (endpoints and upstream bridges) during a Live Update.
Inheriting ACS flags avoids changing routing rules while memory transactions are in flight from preserved devices. This is also strictly necessary to ensure that IOMMU group assignments do not change during or after Live Update.
The adopted controls are recorded by the pci_save_state() call in pci_bus_add_device(), which runs before drivers bind, so they are automatically reapplied by pci_restore_state() if the device is reset. If that save buffer could not be allocated there is nowhere to record the adopted controls, and they would be silently lost by the first reset. Program ACS from scratch in that case, which is a better outcome than leaving ACS disabled.
To simplify ACS inheritance, reject preserving any devices that require quirks to enable ACS as those quirks would also have to take Live Update into account.
--- drivers/pci/liveupdate.c | 78 ++++++++++++++++++++++++++++++++++++++++ drivers/pci/liveupdate.h | 6 ++++ drivers/pci/pci.c | 5 +++ 3 files changed, 89 insertions(+)
drivers/pci/liveupdate.c +78 -0
@@ -123,6 +123,9 @@* * * The device cannot be a Virtual Function (VF). * +* * The device cannot require device-specific quirks to enable Access +* Control Services (ACS). +* * Driver Binding * ============== *
@@ -174,6 +177,18 @@* bus, since the bus numbers of the failed bridge can no longer be read from * hardware and handing them to another bridge would let an unrelated device * inherit the BDF of a preserved device. +* +* Handling Preserved Devices +* ========================== +* +* The PCI core treats preserved devices differently than non-preserved devices. +* This section enumerates those differences. +* +* * The PCI core adopts all ACS controls enabled on incoming preserved devices +* rather than assigning new ones. This ensures that TLPs are routed the same +* way after Live Update and ensures that IOMMU groups do not change. Note +* that a device will use its adopted ACS controls for the lifetime of its +* struct pci_dev (i.e. even after pci_liveupdate_finish()). */ #define pr_fmt (fmt) "PCI: liveupdate: " fmt
@@ -189,6 +204,7 @@#include <linux/slab.h> #include "liveupdate.h" +#include "pci.h" /** * struct pci_liveupdate_global - Global state for PCI Live Update support
@@ -502,6 +518,16 @@ static int pci_liveupdate_preserve_device(struct pci_flb_outgoing *outgoing,return -EINVAL ; } +/* +* Do not preserve devices that rely on device-specific ACS equivalents +* (for now) since that would complicate keeping ACS constant across +* Live Update. +*/ +if (pci_need_dev_specific_enable_acs (dev)) { +pci_warn (dev,"Refusing to preserve device that relies on ACS quirks\n" ); +return -EINVAL ; + } +/* * Endpoint devices should not be preserved more than once. * Bridges are preserved once for every downstream device that
@@ -826,6 +852,58 @@ void pci_liveupdate_finish(struct pci_dev *dev) }EXPORT_SYMBOL_GPL (pci_liveupdate_finish); +/** +* pci_liveupdate_adopt_acs() - Adopt ACS controls +* @dev: The PCI device to adopt ACS controls for +* +* For devices preserved across a Live Update, leave the ACS controls +* established by the previous kernel alone instead of programming new ones. +* The adopted controls are recorded by the pci_save_state() call in +* pci_bus_add_device(), so they are reapplied by pci_restore_state() if the +* device is subsequently reset. +* +* Return: 0 on success, or -EINVAL if the device was not preserved, requires +* device-specific quirks, or has nowhere to record the adopted controls. +*/ +int pci_liveupdate_adopt_acs (struct pci_dev *dev) +{ +/* +* Check if the device was preserved over a previous Live Update (even +* if it has already gone through pci_liveupdate_finish()). This ensures +* that the device continues to use the ACS controls established by the +* previous kernel. +*/ +if (!dev->liveupdate.was_incoming) +return -EINVAL ; + +/* +* The previous kernel should not have preserved any devices that +* require device-specific quirks to enable ACS, but if such a device is +* detected (e.g. new device-specific ACS quirk in the current kernel), +* log a big warning and fall back to the normal enable ACS path. +*/ +if (pci_need_dev_specific_enable_acs (dev)) { +pci_warn (dev,"Device-specific quirk required to enable ACS!\n" ); +WARN_ON_ONCE (true); +return -EINVAL ; + } + +/* +* Adopting the previous kernel's controls depends on them being +* captured in the ACS save buffer, so that they are reapplied if the +* device is later reset. Without that buffer, e.g. because it could +* not be allocated under memory pressure, the adopted controls would +* be silently lost by the first reset. Program ACS from scratch +* instead, which is a better outcome than leaving ACS disabled. +*/ +if (dev->acs_cap && !pci_find_saved_ext_cap (dev,PCI_EXT_CAP_ID_ACS )) { +pci_err (dev,"No ACS save buffer, not adopting ACS controls\n" ); +return -EINVAL ; + } + +return 0 ; +} +/** * pci_liveupdate_is_incoming() - Check if a device is incoming-preserved * @dev: The PCI device to check
drivers/pci/liveupdate.h +6 -0
@@ -15,6 +15,7 @@ void pci_liveupdate_setup_device(struct pci_dev *dev);void pci_liveupdate_cleanup_device (struct pci_dev *dev);bool pci_liveupdate_preserve_bus_numbers (void );bool pci_liveupdate_refuse_bus_numbers (struct pci_bus *bus,struct pci_dev *dev); +int pci_liveupdate_adopt_acs (struct pci_dev *dev);#else static inline void pci_liveupdate_setup_device (struct pci_dev *dev) {
@@ -34,6 +35,11 @@ static inline bool pci_liveupdate_refuse_bus_numbers(struct pci_bus *bus, {return false; } + +static inline int pci_liveupdate_adopt_acs (struct pci_dev *dev) +{ +return -EINVAL ; +}#endif #endif /* DRIVERS_PCI_LIVEUPDATE_H */
drivers/pci/pci.c +5 -0
@@ -35,6 +35,8 @@#include <linux/aer.h> #include <linux/bitfield.h> #include <linux/suspend.h> + +#include "liveupdate.h" #include "pci.h" DEFINE_MUTEX (pci_slot_mutex);
@@ -1080,6 +1082,9 @@ void pci_enable_acs(struct pci_dev *dev)bool enable_acs = false;int pos; +if (!pci_liveupdate_adopt_acs (dev)) +return ; +/* If an iommu is present we start with kernel default caps */ if (pci_acs_enable) {if (pci_dev_specific_enable_acs (dev))
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
[email protected]
AI reviewRe: [PATCH v9 09/13] PCI: liveupdate: Adopt ACS controls in incoming preserved devices
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 16 lines
Adopt Access Control Services (ACS) controls on all incoming preserved devices (endpoints and upstream bridges) during a Live Update.
Inheriting ACS flags avoids changing routing rules while memory transactions are in flight from preserved devices. This is also strictly necessary to ensure that IOMMU group assignments do not change during or after Live Update.
The adopted controls are recorded by the
pci_save_state()call inpci_bus_add_device(), which runs before drivers bind, so they are automatically reapplied bypci_restore_state()if the device is reset. If that save buffer could not be allocated there is nowhere to record the adopted controls, and they would be silently lost by the first reset. Program ACS from scratch in that case, which is a better outcome than leaving ACS disabled.
Quoted 5 lines
To simplify ACS inheritance, reject preserving any devices that require quirks to enable ACS as those quirks would also have to take Live Update into account.
Signed-off-by David Matlack <[email protected]>
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=9
Re: [PATCH v9 09/13] PCI: liveupdate: Adopt ACS controls in incoming preserved devices
In reply to David MatlackQuoted 16 lines · David Matlack
Adopt Access Control Services (ACS) controls on all incoming preserved devices (endpoints and upstream bridges) during a Live Update.
Inheriting ACS flags avoids changing routing rules while memory transactions are in flight from preserved devices. This is also strictly necessary to ensure that IOMMU group assignments do not change during or after Live Update.
The adopted controls are recorded by the
pci_save_state()call inpci_bus_add_device(), which runs before drivers bind, so they are automatically reapplied bypci_restore_state()if the device is reset. If that save buffer could not be allocated there is nowhere to record the adopted controls, and they would be silently lost by the first reset. Program ACS from scratch in that case, which is a better outcome than leaving ACS disabled.
Quoted 5 lines
To simplify ACS inheritance, reject preserving any devices that require quirks to enable ACS as those quirks would also have to take Live Update into account.
Signed-off-by David Matlack <[email protected]>
Thanks,
Praan
PATCH v9 10/13 PCI: liveupdate: Adopt ARI Forwarding Enable on preserved bridges
In reply to David MatlackAdopt the ARI Forwarding Enable bit on preserved bridges and update pci_dev->ari_enabled accordingly during a Live Update. This ensures that the preserved devices on the bridge's secondary bus can be identified with the same expanded 8-bit function number after a Live Update.
--- drivers/pci/liveupdate.c | 30 ++++++++++++++++++++++++++++++ drivers/pci/liveupdate.h | 6 ++++++ drivers/pci/pci.c | 8 +++++++- 3 files changed, 43 insertions(+), 1 deletion(-)
drivers/pci/liveupdate.c +30 -0
@@ -189,6 +189,10 @@* way after Live Update and ensures that IOMMU groups do not change. Note * that a device will use its adopted ACS controls for the lifetime of its * struct pci_dev (i.e. even after pci_liveupdate_finish()). +* +* * The PCI core adopts ARI Forwarding Enable on all bridges with downstream +* preserved devices to ensure that all preserved devices on the bridge's +* secondary bus are addressable after the Live Update. */ #define pr_fmt (fmt) "PCI: liveupdate: " fmt
@@ -904,6 +908,32 @@ int pci_liveupdate_adopt_acs(struct pci_dev *dev)return 0 ; } +/** +* pci_liveupdate_adopt_ari() - Adopt ARI configuration +* @dev: The PCI device to adopt ARI configuration for +* +* For devices preserved across a Live Update, read the ARI state from +* hardware and adopt it. This ensures the device continues to use the ARI +* configuration established by the previous kernel. +* +* Return: 0 on success, or -EINVAL if the device was not preserved. +*/ +int pci_liveupdate_adopt_ari (struct pci_dev *dev) +{ +u16 val; + +guard (rwsem_read)(&pci_liveupdate.rwsem); + +if (!dev->liveupdate.incoming) +return -EINVAL ; + +pcie_capability_read_word (dev,PCI_EXP_DEVCTL2 , &val); + +/* Safe to modify dev->ari_enabled bitfield during enumeration. */ + dev->ari_enabled = !!(val &PCI_EXP_DEVCTL2_ARI ); +return 0 ; +} +/** * pci_liveupdate_is_incoming() - Check if a device is incoming-preserved * @dev: The PCI device to check
drivers/pci/liveupdate.h +6 -0
@@ -16,6 +16,7 @@ void pci_liveupdate_cleanup_device(struct pci_dev *dev);bool pci_liveupdate_preserve_bus_numbers (void );bool pci_liveupdate_refuse_bus_numbers (struct pci_bus *bus,struct pci_dev *dev);int pci_liveupdate_adopt_acs (struct pci_dev *dev); +int pci_liveupdate_adopt_ari (struct pci_dev *dev);#else static inline void pci_liveupdate_setup_device (struct pci_dev *dev) {
@@ -40,6 +41,11 @@ static inline int pci_liveupdate_adopt_acs(struct pci_dev *dev) {return -EINVAL ; } + +static inline int pci_liveupdate_adopt_ari (struct pci_dev *dev) +{ +return -EINVAL ; +}#endif #endif /* DRIVERS_PCI_LIVEUPDATE_H */
drivers/pci/pci.c +7 -1
@@ -3625,7 +3625,7 @@ void pci_configure_ari(struct pci_dev *dev)u32 cap;struct pci_dev *bridge; -if (pcie_ari_disabled || !pci_is_pcie (dev) || dev->devfn) +if (!pci_is_pcie (dev) || dev->devfn)return ; bridge = dev->bus->self;
@@ -3636,6 +3636,12 @@ void pci_configure_ari(struct pci_dev *dev)if (!(cap &PCI_EXP_DEVCAP2_ARI ))return ; +if (!pci_liveupdate_adopt_ari (bridge)) +return ; + +if (pcie_ari_disabled) +return ; +if (pci_find_ext_capability (dev,PCI_EXT_CAP_ID_ARI )) {pcie_capability_set_word (bridge,PCI_EXP_DEVCTL2 ,PCI_EXP_DEVCTL2_ARI );
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
[email protected]
AI reviewRe: [PATCH v9 10/13] PCI: liveupdate: Adopt ARI Forwarding Enable on preserved bridges
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines
Adopt the ARI Forwarding Enable bit on preserved bridges and update
pci_dev->ari_enabledaccordingly during a Live Update. This ensures that the preserved devices on the bridge's secondary bus can be identified with the same expanded 8-bit function number after a Live Update.Reviewed-by Bjorn Helgaas <[email protected]>Reviewed-by Pranjal Shrivastava <[email protected]>Signed-off-by David Matlack <[email protected]>
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=10
PATCH v9 11/13 PCI: liveupdate: Freeze preservation status during shutdown
In reply to David MatlackFreeze a device's outgoing preservation status (preserved or not preserved) during shutdown. This enables the PCI core and drivers to safely make decisions based on the device's preservation status during shutdown.
Note that pci_liveupdate_freeze() is triggered by the PCI core rather than from drivers participating in Live Update so that all devices can have their status frozen (i.e. prevent non-preserved devices from getting preserved late).
--- drivers/pci/liveupdate.c | 16 ++++++++++++++++ drivers/pci/liveupdate.h | 5 +++++ drivers/pci/pci-driver.c | 2 ++ include/linux/pci_liveupdate.h | 3 +++ 4 files changed, 26 insertions(+)
drivers/pci/liveupdate.c +16 -0
@@ -481,6 +481,11 @@ static int pci_liveupdate_unpreserve_device(struct pci_flb_outgoing *outgoing, {struct pci_dev_ser *dev_ser = dev->liveupdate.outgoing; +if (dev->liveupdate.frozen) { +pci_warn (dev,"Cannot unpreserve device after it is frozen!\n" ); +return -EINVAL ; + } +if (!dev_ser) {pci_warn (dev,"Cannot unpreserve device that is not preserved\n" );return -EINVAL ;
@@ -547,6 +552,11 @@ static int pci_liveupdate_preserve_device(struct pci_flb_outgoing *outgoing,return -EINVAL ; } +if (dev->liveupdate.frozen) { +pci_warn (dev,"Cannot preserve device after it is frozen!\n" ); +return -EINVAL ; + } +if (!dev->liveupdate.outgoing) {struct pci_dev_ser *dev_ser;
@@ -797,6 +807,12 @@ void pci_liveupdate_cleanup_device(struct pci_dev *dev)pci_WARN (dev,1 ,"Destroying incoming-preserved device!\n" ); } +void pci_liveupdate_freeze (struct pci_dev *dev) +{ +guard (rwsem_write)(&pci_liveupdate.rwsem); + dev->liveupdate.frozen = true; +} +static int pci_liveupdate_finish_device (struct pci_ser *ser,struct pci_dev *dev) {if (!dev->liveupdate.incoming) {
drivers/pci/liveupdate.h +5 -0
@@ -13,6 +13,7 @@#ifdef CONFIG_PCI_LIVEUPDATE void pci_liveupdate_setup_device (struct pci_dev *dev);void pci_liveupdate_cleanup_device (struct pci_dev *dev); +void pci_liveupdate_freeze (struct pci_dev *dev);bool pci_liveupdate_preserve_bus_numbers (void );bool pci_liveupdate_refuse_bus_numbers (struct pci_bus *bus,struct pci_dev *dev);int pci_liveupdate_adopt_acs (struct pci_dev *dev);
@@ -26,6 +27,10 @@ static inline void pci_liveupdate_cleanup_device(struct pci_dev *dev) { } +static inline void pci_liveupdate_freeze (struct pci_dev *dev) +{ +} +static inline bool pci_liveupdate_preserve_bus_numbers (void ) {return false;
drivers/pci/pci-driver.c +2 -0
@@ -21,6 +21,7 @@#include <linux/acpi.h> #include <linux/dma-map-ops.h> #include <linux/iommu.h> +#include "liveupdate.h" #include "pci.h" #include "pcie/portdrv.h"
@@ -559,6 +560,7 @@ static void pci_device_shutdown(struct device *dev)struct pci_dev *pci_dev =to_pci_dev (dev);struct pci_driver *drv = pci_dev->driver; +pci_liveupdate_freeze (pci_dev);pm_runtime_resume (dev);if (drv && drv->shutdown)
include/linux/pci_liveupdate.h +3 -0
@@ -21,11 +21,14 @@* set up, i.e. it was matched to state preserved by the previous * kernel. Unlike @incoming, this is never cleared, so it stays * true after the device finishes participating in Live Update. +* @frozen: True if the outgoing preservation status of this device is frozen +* and thus cannot be changed. */ struct pci_liveupdate {struct pci_dev_ser *outgoing;struct pci_dev_ser *incoming;bool was_incoming; +bool frozen; };struct pci_dev ;
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
[email protected]
AI reviewRe: [PATCH v9 11/13] PCI: liveupdate: Freeze preservation status during shutdown
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 10 lines
Freeze a device's outgoing preservation status (preserved or not preserved) during shutdown. This enables the PCI core and drivers to safely make decisions based on the device's preservation status during shutdown.
Note that
pci_liveupdate_freeze()is triggered by the PCI core rather than from drivers participating in Live Update so that all devices can have their status frozen (i.e. prevent non-preserved devices from getting preserved late).
Quoted 5 lines
Reviewed-by Pranjal Shrivastava <[email protected]>Reviewed-by Pasha Tatashin <[email protected]>Reviewed-by Samiullah Khawaja <[email protected]>Reviewed-by Bjorn Helgaas <[email protected]>Signed-off-by David Matlack <[email protected]>
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=11
PATCH v9 12/13 PCI: liveupdate: Do not disable bus mastering on preserved devices during kexec
In reply to David MatlackDo not disable bus mastering on outgoing preserved devices during pci_device_shutdown() for kexec.
Preserved devices must be allowed to perform memory transactions during a Live Update to ensure continuous operation. Clearing the bus mastering bit would prevent these devices from issuing any memory requests while the new kernel boots.
Because bridges upstream of preserved endpoint devices are also automatically preserved, this change also avoids clearing bus mastering on them. This is critical because clearing bus mastering on an upstream bridge prevents the bridge from forwarding memory requests upstream (i.e. it would prevent the endpoint device from accessing system RAM and doing peer-to-peer transactions with devices not downstream of the bridge).
--- drivers/pci/liveupdate.c | 11 +++++++++++ drivers/pci/liveupdate.h | 6 ++++++ drivers/pci/pci-driver.c | 7 +++++-- 3 files changed, 22 insertions(+), 2 deletions(-)
drivers/pci/liveupdate.c +11 -0
@@ -193,6 +193,10 @@* * The PCI core adopts ARI Forwarding Enable on all bridges with downstream * preserved devices to ensure that all preserved devices on the bridge's * secondary bus are addressable after the Live Update. +* +* * The PCI core does not disable bus mastering on outgoing preserved devices +* during kexec. This allows preserved devices to issue memory transactions +* throughout the Live Update. */ #define pr_fmt (fmt) "PCI: liveupdate: " fmt
@@ -950,6 +954,13 @@ int pci_liveupdate_adopt_ari(struct pci_dev *dev)return 0 ; } +bool pci_liveupdate_is_outgoing (struct pci_dev *dev) +{ +guard (rwsem_read)(&pci_liveupdate.rwsem); +pci_WARN_ONCE (dev, !dev->liveupdate.frozen,"Preservation status is unstable!\n" ); +return dev->liveupdate.outgoing; +} +/** * pci_liveupdate_is_incoming() - Check if a device is incoming-preserved * @dev: The PCI device to check
drivers/pci/liveupdate.h +6 -0
@@ -18,6 +18,7 @@ bool pci_liveupdate_preserve_bus_numbers(void);bool pci_liveupdate_refuse_bus_numbers (struct pci_bus *bus,struct pci_dev *dev);int pci_liveupdate_adopt_acs (struct pci_dev *dev);int pci_liveupdate_adopt_ari (struct pci_dev *dev); +bool pci_liveupdate_is_outgoing (struct pci_dev *dev);#else static inline void pci_liveupdate_setup_device (struct pci_dev *dev) {
@@ -51,6 +52,11 @@ static inline int pci_liveupdate_adopt_ari(struct pci_dev *dev) {return -EINVAL ; } + +static inline bool pci_liveupdate_is_outgoing (struct pci_dev *dev) +{ +return false; +}#endif #endif /* DRIVERS_PCI_LIVEUPDATE_H */
drivers/pci/pci-driver.c +5 -2
@@ -569,11 +569,14 @@ static void pci_device_shutdown(struct device *dev)/* * If this is a kexec reboot, turn off Bus Master bit on the * device to tell it to not continue to do DMA. Don't touch -* devices in D3cold or unknown states. +* devices being preserved for Live Update or in D3cold or +* unknown states. +* * If it is not a kexec reboot, firmware will hit the PCI * devices with big hammer and stop their DMA any way. */ -if (kexec_in_progress && (pci_dev->current_state <= PCI_D3hot)) +if (kexec_in_progress && !pci_liveupdate_is_outgoing (pci_dev) && + pci_dev->current_state <= PCI_D3hot)pci_clear_master (pci_dev); }
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
[email protected]
AI reviewRe: [PATCH v9 12/13] PCI: liveupdate: Do not disable bus mastering on preserved devices during kexec
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 15 lines
Do not disable bus mastering on outgoing preserved devices during
pci_device_shutdown()for kexec.Preserved devices must be allowed to perform memory transactions during a Live Update to ensure continuous operation. Clearing the bus mastering bit would prevent these devices from issuing any memory requests while the new kernel boots.
Because bridges upstream of preserved endpoint devices are also automatically preserved, this change also avoids clearing bus mastering on them. This is critical because clearing bus mastering on an upstream bridge prevents the bridge from forwarding memory requests upstream (i.e. it would prevent the endpoint device from accessing system RAM and doing peer-to-peer transactions with devices not downstream of the bridge).
Quoted 5 lines
Reviewed-by Pranjal Shrivastava <[email protected]>Reviewed-by Pasha Tatashin <[email protected]>Reviewed-by Samiullah Khawaja <[email protected]>Reviewed-by Bjorn Helgaas <[email protected]>Signed-off-by David Matlack <[email protected]>
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=12
PATCH v9 13/13 Documentation: PCI: Add documentation for Live Update
In reply to David MatlackAdd documentation files for the PCI subsystem's participation in Live Update.
These documentation files are generated from the kernel-doc comments in the PCI Live Update source code. They describe the File-Lifecycle-Bound (FLB) API, the device tracking API, and the specific policies applied to preserved devices (such as bus number inheritance and bus mastering preservation).
--- Documentation/PCI/index.rst | 1 + Documentation/PCI/liveupdate.rst | 35 +++++++++++++++++++++++++++ Documentation/core-api/liveupdate.rst | 1 + MAINTAINERS | 1 + 4 files changed, 38 insertions(+) create mode 100644 Documentation/PCI/liveupdate.rst
Documentation/PCI/index.rst +1 -0
@@ -20,3 +20,4 @@ PCI Bus Subsystem controller/index boot-interrupts tph + liveupdate
Documentation/PCI/liveupdate.rst new file +35 -0
@@ -0,0 +1,35 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +=========================== +PCI Support for Live Update +=========================== + +.. kernel-doc:: drivers/pci/liveupdate.c + :doc: PCI Live Update + +Driver API +========== + +.. kernel-doc:: drivers/pci/liveupdate.c + :export: + +Internal API +============ + +.. kernel-doc:: drivers/pci/liveupdate.c + :internal: + +Live Update ABI +=============== + +.. kernel-doc:: include/linux/kho/abi/pci.h + :doc: PCI File-Lifecycle Bound (FLB) Live Update ABI + +.. kernel-doc:: include/linux/kho/abi/pci.h + :internal: + +See Also +======== + + * :doc:`/core-api/liveupdate` + * :doc:`/core-api/kho/index`
Documentation/core-api/liveupdate.rst +1 -0
@@ -74,3 +74,4 @@ See Also - :doc:`Live Update uAPI </userspace-api/liveupdate>` - :doc:`/core-api/kho/index` +- :doc:`PCI </PCI/liveupdate>`
MAINTAINERS +1 -0
@@ -21055,6 +21055,7 @@ L: [email protected] L: [email protected] S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/liveupdate/linux.git +F: Documentation/PCI/liveupdate.rst F: drivers/pci/liveupdate.c F: drivers/pci/liveupdate.h F: include/linux/kho/abi/pci.h
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
[email protected]
AI reviewRe: [PATCH v9 13/13] Documentation: PCI: Add documentation for Live Update
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines
Add documentation files for the PCI subsystem's participation in Live Update.
These documentation files are generated from the kernel-doc comments in the PCI Live Update source code. They describe the File-Lifecycle-Bound (FLB) API, the device tracking API, and the specific policies applied to preserved devices (such as bus number inheritance and bus mastering preservation).
Quoted 4 lines
Reviewed-by Pranjal Shrivastava <[email protected]>Reviewed-by Samiullah Khawaja <[email protected]>Reviewed-by Bjorn Helgaas <[email protected]>Signed-off-by David Matlack <[email protected]>
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=13
Quoted 83 lines · David Matlack
This series can be found on GitHub:
https://github.com/dmatlack/linux/tree/liveupdate/pci/base/v9
This series introduces support in the PCI core for Live Update, enabling drivers to preserve PCI devices across a kexec-based kernel update without interrupting the device. This functionality is critical for minimizing downtime in environments where PCI devices (e.g., those assigned to VMs via VFIO) must continue operating or maintain state across a host kernel upgrade.
Specifically, this series allows preserved PCI devices to perform uninterrupted memory transactions (DMA) targeting system memory (specifically, preserved memfds) across a Live Update. These devices can be behind a bridge but must not be VFs. Support for P2P and VF preservation will be addressed in future series.
Series Overview
---------------This series implements the following to support PCI device preservation across Live Update:
1. Set up a File-Lifecycle-Bound (FLB) handler to track and preserve PCI-specific state (struct
pci_ser) across Live Update using Kexec Handover (KHO).2. Add APIs for drivers to register devices for preservation (outgoing) and for the PCI core to identify preserved devices during enumeration (incoming)
3. Automatically preserve all upstream bridges for any preserved endpoint. Use reference counting to ensure bridges remain preserved as long as any downstream device is preserved.
4. Guarantee that preserved devices retain the same RequesterID (bus, device, function) for the duration of their preservation by inheriting secondary bus numbers, subordinate bus numbers, and ARI Forwarding Enable on preserved bridges.
5. Guarantee that memory transactions to/from preserved devices are routed consistently by inheriting Access Control Services (ACS) flags across a Live Update, from the endpoint up to the root port.
6. Modify the PCI shutdown path to avoid disabling bus mastering on preserved devices, thereby allowing preserved devices to perform uninterrupted during kexec for Live Update.
7. Provide comprehensive documentation for the FLB API, device tracking mechanisms, and the division of responsibilities between the PCI core, drivers, and userspace.
Merge Plan
----------This series will be merged through liveupdate.git, matching the agreed-upon tree in the
MAINTAINERSentry for PCI LIVE UPDATE.Testing
-------This series was tested in conjunction with v5 of the VFIO PCI driver series:
https://lore.kernel.org/kvm/[email protected]/The full set of patches used for testing can be found on GitHub.
https://github.com/dmatlack/linux/tree/liveupdate/pci/base/v9-with-vfio
Testing was performed using the new VFIO selftests:
-
vfio_pci_liveupdate_uapi_test
-vfio_pci_liveupdate_kexec_testBoth tests were run in a QEMU-based VM environment (using a single virtio-net PCIe device connected to a root port to exercise bridge support) and on bare metal using an Intel EMR server with 8x Intel DSA PCIe devices and 1x NVMe device.
Future Work
-----------
Quoted 8 lines
Following this series, we expect to make further improvements to the PCI core support for Live Update:
- Allow P2P across Live Update by avoiding resizing or moving preserved device BARs and preserving all upstream bridge windows.
- Support preserving Virtual Functions by preserving SR-IOV configuration on PFs and enumerating VFs after Live Update.
Preserving the PCIe topology, bus numbers, ACS, and Bus Mastering across kexec is a foundational step for minimizing downtime.
As we look toward complete end-to-end support for DMA preservation across Live Update—especially for VFIO device passthrough and dma-buf sharing scenarios—IOMMU table/domain preservation becomes crucial to prevent IOMMU page faults when devices continue performing DMA during kexec.
I would like to ask about the current status and roadmap regarding IOMMU Live Update / KHO (Kexec Handover) support:
Is there an ongoing effort or RFC series for IOMMU handover / page-table preservation currently in development or under discussion?
How is the coordination between the PCI core Live Update mechanisms and the IOMMU subsystem being envisioned for preserving IOVA mappings (e.g., restoring domains or handing over root tables)?
Any pointers to active discussion threads, RFCs, or future plans regarding IOMMU participation in Live Update would be greatly appreciated.
Thanks,
Yanjun Zhu
Quoted 84 lines
Changelog
---------v9:
- Simplifypci_liveupdate_preserve_bus_numbers()to always return true if a device was preserved and droppci_liveupdate_scan_bridge_end()(Bjorn)
- Addpci_liveupdate_refuse_bus_numbers()to determine when it is safe for the PCI core to assign bus numbers to unconfigured bridges. This required moving "Auto-preserve upstream bridges across Live Update" before "Preserve bus numbers during Live Update" (Bjorn)
- Add "PCI: Save and restore the ACS Control register" so that the ACS Control register is handled by the normal save/restore path (Bjorn)
- Rename structpci_liveupdate::was_preservedtowas_incoming, to disambiguate incoming from outgoing preservation (me)
- Log unfinished preserved devices from the incoming FLB rather than by walking structpci_dev(Sashiko)
- Document that state handed over by the previous kernel is trusted, and panic inpci_flb_retrieve()where failures are detected rather than unwinding into a caller that panics anyway (Sashiko)
- Fall back to programming ACS from scratch when a preserved device has no ACS save buffer, since there is nowhere to record the adopted controls and they would be lost by the first reset (Sashiko)
- Drop Reviewed-by tags from "Preserve bus numbers during Live Update" and "Adopt ACS controls in incoming preserved devices", both of which changed materially since v8
- Extend commit messages and kernel-doc comments to make the FLB code flow more clear (Bjorn)
- Address various spelling, formatting, and stylistic issues (Bjorn)v8: https://lore.kernel.org/linux-pci/[email protected]/
v7: https://lore.kernel.org/linux-pci/[email protected]/
v6: https://lore.kernel.org/linux-pci/[email protected]/
v5: https://lore.kernel.org/linux-pci/[email protected]/
v4: https://lore.kernel.org/linux-pci/[email protected]/
v3: https://lore.kernel.org/kvm/[email protected]/
v2: https://lore.kernel.org/kvm/[email protected]/
v1: https://lore.kernel.org/kvm/[email protected]/
rfc: https://lore.kernel.org/kvm/[email protected]/David Matlack (13):
PCI: liveupdate: Set up FLB handler for the PCI core
PCI: liveupdate: Track outgoing preserved PCI devices
PCI: liveupdate: Track incoming preserved PCI devices
PCI: liveupdate: Document driver binding responsibilities
PCI: liveupdate: Auto-preserve upstream bridges across Live Update
PCI: liveupdate: Preserve bus numbers during Live Update
PCI: Refactor matching logic forpci_dev_acs_ops
PCI: Save and restore the ACS Control register
PCI: liveupdate: Adopt ACS controls in incoming preserved devices
PCI: liveupdate: Adopt ARI Forwarding Enable on preserved bridges
PCI: liveupdate: Freeze preservation status during shutdown
PCI: liveupdate: Do not disable bus mastering on preserved devices
during kexec
Documentation: PCI: Add documentation for Live UpdateDocumentation/PCI/index.rst | 1 + Documentation/PCI/liveupdate.rst | 35 + .../admin-guide/kernel-parameters.txt | 7 +- Documentation/core-api/liveupdate.rst | 5 + MAINTAINERS | 15 + drivers/pci/Kconfig | 15 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 1015 +++++++++++++++++ drivers/pci/liveupdate.h | 62 + drivers/pci/pci-driver.c | 9 +- drivers/pci/pci.c | 79 +- drivers/pci/pci.h | 5 + drivers/pci/probe.c | 16 +- drivers/pci/quirks.c | 58 +- include/linux/kho/abi/pci.h | 66 ++ include/linux/pci.h | 7 + include/linux/pci_liveupdate.h | 72 ++ 17 files changed, 1429 insertions(+), 39 deletions(-)create mode 100644
Documentation/PCI/liveupdate.rstcreate mode 100644drivers/pci/liveupdate.ccreate mode 100644drivers/pci/liveupdate.hcreate mode 100644include/linux/kho/abi/pci.hcreate mode 100644include/linux/pci_liveupdate.hbase-commit:
945d61765894dda2f0344de50cb1ade2e51b66fd
Quoted 27 lines · Zhu Yanjun
Quoted 11 lines · David Matlack
Future Work
-----------Following this series, we expect to make further improvements to the PCI core support for Live Update:
- Allow P2P across Live Update by avoiding resizing or moving preserved device BARs and preserving all upstream bridge windows.
- Support preserving Virtual Functions by preserving SR-IOV configuration on PFs and enumerating VFs after Live Update.
Preserving the PCIe topology, bus numbers, ACS, and Bus Mastering across kexec is a foundational step for minimizing downtime.
As we look toward complete end-to-end support for DMA preservation across Live Update—especially for VFIO device passthrough and dma-buf sharing scenarios—IOMMU table/domain preservation becomes crucial to prevent IOMMU page faults when devices continue performing DMA during kexec.
I would like to ask about the current status and roadmap regarding IOMMU Live Update / KHO (Kexec Handover) support:
Is there an ongoing effort or RFC series for IOMMU handover / page-table preservation currently in development or under discussion?
Quoted 6 lines
How is the coordination between the PCI core Live Update mechanisms and the IOMMU subsystem being envisioned for preserving IOVA mappings (e.g., restoring domains or handing over root tables)?
Any pointers to active discussion threads, RFCs, or future plans regarding IOMMU participation in Live Update would be greatly appreciated.
The first IOMMU series to support Live update, can be found here:
https://lore.kernel.org/linux-iommu/[email protected]/
The IOMMU series builds on top of the PCI core support (this series) and the VFIO series linked further up in the cover letter.
Quoted 31 lines · David Matlack
Quoted 30 lines · Zhu Yanjun
Quoted 11 lines · David Matlack
Future Work
-----------Following this series, we expect to make further improvements to the PCI core support for Live Update:
- Allow P2P across Live Update by avoiding resizing or moving preserved device BARs and preserving all upstream bridge windows.
- Support preserving Virtual Functions by preserving SR-IOV configuration on PFs and enumerating VFs after Live Update.
Preserving the PCIe topology, bus numbers, ACS, and Bus Mastering across kexec is a foundational step for minimizing downtime.
As we look toward complete end-to-end support for DMA preservation across Live Update—especially for VFIO device passthrough and dma-buf sharing scenarios—IOMMU table/domain preservation becomes crucial to prevent IOMMU page faults when devices continue performing DMA during kexec.
I would like to ask about the current status and roadmap regarding IOMMU Live Update / KHO (Kexec Handover) support:
Is there an ongoing effort or RFC series for IOMMU handover / page-table preservation currently in development or under discussion?
How is the coordination between the PCI core Live Update mechanisms and the IOMMU subsystem being envisioned for preserving IOVA mappings (e.g., restoring domains or handing over root tables)?
Quoted 5 lines
Quoted 2 lines
Any pointers to active discussion threads, RFCs, or future plans regarding IOMMU participation in Live Update would be greatly appreciated.
The first IOMMU series to support Live update, can be found here:
https://lore.kernel.org/linux-iommu/[email protected]/
Thanks.
I have a question regarding the restoration sequencing when module dependencies are involved during a Live Update reboot.
For the standard hardware/driver stack, the sequence seems to naturally follow the kernel's early initcalls and device probing (e.g., IOMMU early hardware handover -> PCI bus topology/BME preservation -> IOMMU domain attach & DMA ownership claim -> VFIO/iommufd cdev binding).
However, if there is a custom kernel module or subsystem (let's call it Module A) that is not part of the standard PCI/IOMMU device probe callback chain, but strictly depends on the fully restored state of PCI, IOMMU, and VFIO/iommufd:
1.
What is the recommended or standardized way in the Live Update architecture to guarantee that Module A's restoration happens *after* all its underlying dependencies (PCI / IOMMU / VFIO) have completely finished their restore processes?
2.
Is the expectation to rely on LUO (Live Update Orchestrator) phase notification callbacks (e.g., late restore notifiers), Driver Core mechanisms like |-EPROBE_DEFER| / |device_link|, or something else?
Any guidance on how cross-subsystem restoration order and async probe dependencies should be handled in the Live Update framework would be greatly appreciated.
Thanks,
Yanjun Zhu
Quoted 3 lines
The IOMMU series builds on top of the PCI core support (this series) and the VFIO series linked further up in the cover letter.
Signature · 2 lines
Best Regards, Yanjun.Zhu
Quoted 62 lines · Zhu Yanjun
Quoted 31 lines · David Matlack
Quoted 30 lines · Zhu Yanjun
Quoted 11 lines · David Matlack
Future Work
-----------Following this series, we expect to make further improvements to the PCI core support for Live Update:
- Allow P2P across Live Update by avoiding resizing or moving preserved device BARs and preserving all upstream bridge windows.
- Support preserving Virtual Functions by preserving SR-IOV configuration on PFs and enumerating VFs after Live Update.
Preserving the PCIe topology, bus numbers, ACS, and Bus Mastering across kexec is a foundational step for minimizing downtime.
As we look toward complete end-to-end support for DMA preservation across Live Update—especially for VFIO device passthrough and dma-buf sharing scenarios—IOMMU table/domain preservation becomes crucial to prevent IOMMU page faults when devices continue performing DMA during kexec.
I would like to ask about the current status and roadmap regarding IOMMU Live Update / KHO (Kexec Handover) support:
Is there an ongoing effort or RFC series for IOMMU handover / page-table preservation currently in development or under discussion?
How is the coordination between the PCI core Live Update mechanisms and the IOMMU subsystem being envisioned for preserving IOVA mappings (e.g., restoring domains or handing over root tables)?
Quoted 5 lines
Quoted 2 lines
Any pointers to active discussion threads, RFCs, or future plans regarding IOMMU participation in Live Update would be greatly appreciated.
The first IOMMU series to support Live update, can be found here:
https://lore.kernel.org/linux-iommu/[email protected]/Thanks.
I have a question regarding the restoration sequencing when module dependencies are involved during a Live Update reboot.
For the standard hardware/driver stack, the sequence seems to naturally follow the kernel's early initcalls and device probing (e.g., IOMMU early hardware handover -> PCI bus topology/BME preservation -> IOMMU domain attach & DMA ownership claim -> VFIO/iommufd cdev binding).
However, if there is a custom kernel module or subsystem (let's call it Module A) that is not part of the standard PCI/IOMMU device probe callback chain, but strictly depends on the fully restored state of PCI, IOMMU, and VFIO/iommufd:
1.
What is the recommended or standardized way in the Live Update architecture to guarantee that Module A's restoration happens *after* all its underlying dependencies (PCI / IOMMU / VFIO) have completely finished their restore processes?
2.
Quoted 7 lines
Is the expectation to rely on LUO (Live Update Orchestrator) phase notification callbacks (e.g., late restore notifiers), Driver Core mechanisms like |-EPROBE_DEFER| / |device_link|, or something else?
Any guidance on how cross-subsystem restoration order and async probe dependencies should be handled in the Live Update framework would be greatly appreciated.
Note: Some of what I write below is not yet merged into the Live Update tree so may change. Samiullah Khawaja will be giving a talk about file dependencies at LPC where some of these topics will be discussed.
LUO does not have a global "restore phase" or late-restore notifier. Restoration is on-demand and driven by dependencies, and userspace does the orchestration.
There are two types of objects that LUO manages:
1. FLB (File-Lifecycle-Bound) data, for shared/global state.
An FLB is retrieved lazily the first time someone calls liveupdate_flb_get_incoming(). The PCI core does that from pci_setup_device() during enumeration, and the IOMMU driver does it when it initializes. So the order in which this global state is restored is simply the normal boot/initcall/probe order of the subsystems that use it. LUO does not impose any extra order.
2. Files in sessions, for per-object state (vfio cdevs, iommufds, memfds, ...).
Files are retrieved either by userspace (LIVEUPDATE_SESSION_RETRIEVE_FD) or by kernel code (liveupdate_get_file_incoming()). Retrieval can happen in any order and is idempotent. When one file depends on another, the dependency is expressed between the two files, not through a global phase.
VFIO -> iommufd is an example to follow (see Samiullah's IOMMU series
[1] on top of Vipin's VFIO series [2]):
- Outgoing: when a vfio cdev is preserved, iommufd_device_preserve() calls liveupdate_get_token_outgoing() on the iommufd file the device is attached to. That fails unless userspace has already preserved the iommufd in the same session, so the dependency is enforced at preserve time. The iommufd token is then recorded in the preserved device state.
- Incoming: the recorded token is what connects the device back to its iommufd after kexec. Retrieving and re-attaching to the restored iommufd is the next phase of the IOMMU work, so that part is not in
[1] yet. The building blocks are there, though:
liveupdate_get_file_incoming() lets one file handler pull in a file it depends on by token (it is idempotent, so the order userspace retrieves in doesn't matter), and ->can_finish() lets a handler block LIVEUPDATE_SESSION_FINISH until everything it depends on is in a consistent state.
- Device binding: vfio-pci's ->retrieve() simply fails (-ENODEV) if the preserved device is not bound to vfio-pci yet. There is no probe deferral inside LUO. Userspace is expected to make sure the device is bound (e.g. wait for udev) before retrieving the file. In the meantime the device is protected: the PCI core keeps bus mastering and BDFs stable, and the IOMMU core reattaches the preserved domain and claims DMA ownership, so no other driver can bind to it.
If you can share more about what Module A is and what state it needs to carry across the update, I can try to go into more detail. But generically I would recommend:
- If Module A has state that must survive the Live Update, model it as a LUO file handler. If it depends on specific VFIO/iommufd files, record their tokens with liveupdate_get_token_outgoing() in your ->preserve(). Then in your ->retrieve(), get them back with liveupdate_get_file_incoming(). If something isn't ready yet (e.g. the device hasn't probed), fail ->retrieve() and let userspace retry, and use ->can_finish() to keep the session from finishing too early.
- If Module A is a driver that binds to a device, the normal driver core mechanisms (-EPROBE_DEFER, device links) still apply for probe-time dependencies. Live Update doesn't replace them. But restoring the preserved state itself should probably go through LUO as above.
- If Module A doesn't need to preserve anything itself but just consumes the restored VFIO/iommufd objects, the simplest option is to let userspace sequence it. Userspace already knows when the devices are bound and the FDs have been retrieved, so it can hand them to Module A at that point.
[1] https://lore.kernel.org/linux-iommu/[email protected]/
[2] https://lore.kernel.org/kvm/[email protected]/
Quoted 31 lines · David Matlack
Quoted 30 lines · Zhu Yanjun
Quoted 11 lines · David Matlack
Future Work
-----------Following this series, we expect to make further improvements to the PCI core support for Live Update:
- Allow P2P across Live Update by avoiding resizing or moving preserved device BARs and preserving all upstream bridge windows.
- Support preserving Virtual Functions by preserving SR-IOV configuration on PFs and enumerating VFs after Live Update.
Preserving the PCIe topology, bus numbers, ACS, and Bus Mastering across kexec is a foundational step for minimizing downtime.
As we look toward complete end-to-end support for DMA preservation across Live Update—especially for VFIO device passthrough and dma-buf sharing scenarios—IOMMU table/domain preservation becomes crucial to prevent IOMMU page faults when devices continue performing DMA during kexec.
I would like to ask about the current status and roadmap regarding IOMMU Live Update / KHO (Kexec Handover) support:
Is there an ongoing effort or RFC series for IOMMU handover / page-table preservation currently in development or under discussion?
How is the coordination between the PCI core Live Update mechanisms and the IOMMU subsystem being envisioned for preserving IOVA mappings (e.g., restoring domains or handing over root tables)?
Quoted 5 lines
Quoted 2 lines
Any pointers to active discussion threads, RFCs, or future plans regarding IOMMU participation in Live Update would be greatly appreciated.
The first IOMMU series to support Live update, can be found here:
https://lore.kernel.org/linux-iommu/[email protected]/
After cloning the source code from samikhawaja/linux, branch iommu/phase1-v5, I tested the VFIO live update functionality in my local KVM environment and encountered the following issue.
When I run the following commands to verify that VFIO live update works correctly, I get the output shown below.
I am currently testing with VFIO v5 and PCI core v9, and I am not sure whether this behavior is expected.
Interestingly, when I revert the following commit:
vfio/pci: Preserve the iommufd state of the vfio cdev
the issue disappears.
Could you please let me know whether this is expected behavior, or whether it indicates a problem with the current VFIO live update implementation?
"
echo "vfio-pci" > /sys/bus/pci/devices/0000:00:04.0/driver_override
echo "0000:00:04.0" > /sys/bus/pci/drivers/vfio-pci/bind Preserving device in session vfio_pci_liveupdate_kexec_test.c:122: Assertion Failure
Expression: ret == 0
Observed: 0xffffffffffffffea == 0
[errno: 22 - Invalid argument]
"
Thanks a lot.
Yanjun Zhu
Quoted 3 lines
The IOMMU series builds on top of the PCI core support (this series) and the VFIO series linked further up in the cover letter.
Signature · 2 lines
Best Regards, Yanjun.Zhu
Quoted 57 lines · Zhu Yanjun
Quoted 31 lines · David Matlack
Quoted 30 lines · Zhu Yanjun
Quoted 11 lines · David Matlack
Future Work
-----------Following this series, we expect to make further improvements to the PCI core support for Live Update:
- Allow P2P across Live Update by avoiding resizing or moving preserved device BARs and preserving all upstream bridge windows.
- Support preserving Virtual Functions by preserving SR-IOV configuration on PFs and enumerating VFs after Live Update.
Preserving the PCIe topology, bus numbers, ACS, and Bus Mastering across kexec is a foundational step for minimizing downtime.
As we look toward complete end-to-end support for DMA preservation across Live Update—especially for VFIO device passthrough and dma-buf sharing scenarios—IOMMU table/domain preservation becomes crucial to prevent IOMMU page faults when devices continue performing DMA during kexec.
I would like to ask about the current status and roadmap regarding IOMMU Live Update / KHO (Kexec Handover) support:
Is there an ongoing effort or RFC series for IOMMU handover / page-table preservation currently in development or under discussion?
How is the coordination between the PCI core Live Update mechanisms and the IOMMU subsystem being envisioned for preserving IOVA mappings (e.g., restoring domains or handing over root tables)?
Quoted 5 lines
Quoted 2 lines
Any pointers to active discussion threads, RFCs, or future plans regarding IOMMU participation in Live Update would be greatly appreciated.
The first IOMMU series to support Live update, can be found here:
After cloning the source code from samikhawaja/linux, branch iommu/phase1-v5, I tested the VFIO live update functionality in my local KVM environment and encountered the following issue.
When I run the following commands to verify that VFIO live update works correctly, I get the output shown below.
I am currently testing with VFIO v5 and PCI core v9, and I am not sure whether this behavior is expected.
Interestingly, when I revert the following commit:
vfio/pci: Preserve the iommufd state of the vfio cdev
the issue disappears.
Could you please let me know whether this is expected behavior, or whether it indicates a problem with the current VFIO live update implementation?
"
echo "vfio-pci" > /sys/bus/pci/devices/0000:00:04.0/driver_override
Quoted 8 lines
echo "0000:00:04.0" >
/sys/bus/pci/drivers/vfio-pci/bindPreserving device in session vfio_pci_liveupdate_kexec_test.c:122: Assertion FailureExpression: ret == 0
Observed:0xffffffffffffffea== 0
[errno: 22 - Invalid argument]
"
Hi Yanjun,
Thanks for testing this.
This is expected. With "vfio/pci: Preserve the iommufd state of the vfio cdev", preserving a vfio cdev depends on the preservation of its associated iommufd. Since the vfio_pci_liveupdate_kexec_test does not preserve the associated iommufd, it fails with -EINVAL.
Note that the IOMMU persistence series does not update the vfio_pci_liveupdate_kexec_test, with those extra bits, as it would regress after_kexec() part of the test because the retrieval of iommufd is not supported in phase1.
Please use tools/testing/selftests/iommu/iommufd_liveupdate_kexec_test added in the last patch of the series, it sets up the iommufd and HWPT preservation before preserving the vfio cdev.
The wip phase2 can be found here if you are interested.
https://github.com/samikhawaja/linux/tree/iommu/phase2-v1-wip
Thanks,
Sami
Quoted 13 lines
Thanks a lot.
Yanjun Zhu
Quoted 3 lines
The IOMMU series builds on top of the PCI core support (this series) and the VFIO series linked further up in the cover letter.
Signature · 2 lines
Best Regards, Yanjun.Zhu
Quoted 66 lines · David Matlack
This series can be found on GitHub:
https://github.com/dmatlack/linux/tree/liveupdate/pci/base/v9
This series introduces support in the PCI core for Live Update, enabling drivers to preserve PCI devices across a kexec-based kernel update without interrupting the device. This functionality is critical for minimizing downtime in environments where PCI devices (e.g., those assigned to VMs via VFIO) must continue operating or maintain state across a host kernel upgrade.
Specifically, this series allows preserved PCI devices to perform uninterrupted memory transactions (DMA) targeting system memory (specifically, preserved memfds) across a Live Update. These devices can be behind a bridge but must not be VFs. Support for P2P and VF preservation will be addressed in future series.
Series Overview
---------------This series implements the following to support PCI device preservation across Live Update:
1. Set up a File-Lifecycle-Bound (FLB) handler to track and preserve PCI-specific state (struct
pci_ser) across Live Update using Kexec Handover (KHO).2. Add APIs for drivers to register devices for preservation (outgoing) and for the PCI core to identify preserved devices during enumeration (incoming)
3. Automatically preserve all upstream bridges for any preserved endpoint. Use reference counting to ensure bridges remain preserved as long as any downstream device is preserved.
4. Guarantee that preserved devices retain the same RequesterID (bus, device, function) for the duration of their preservation by inheriting secondary bus numbers, subordinate bus numbers, and ARI Forwarding Enable on preserved bridges.
5. Guarantee that memory transactions to/from preserved devices are routed consistently by inheriting Access Control Services (ACS) flags across a Live Update, from the endpoint up to the root port.
6. Modify the PCI shutdown path to avoid disabling bus mastering on preserved devices, thereby allowing preserved devices to perform uninterrupted during kexec for Live Update.
7. Provide comprehensive documentation for the FLB API, device tracking mechanisms, and the division of responsibilities between the PCI core, drivers, and userspace.
Merge Plan
----------This series will be merged through liveupdate.git, matching the agreed-upon tree in the
MAINTAINERSentry for PCI LIVE UPDATE.Testing
-------This series was tested in conjunction with v5 of the VFIO PCI driver series:
https://lore.kernel.org/kvm/[email protected]/
Quoted 8 lines
The full set of patches used for testing can be found on GitHub.
https://github.com/dmatlack/linux/tree/liveupdate/pci/base/v9-with-vfio
Testing was performed using the new VFIO selftests:
-
vfio_pci_liveupdate_uapi_test
-vfio_pci_liveupdate_kexec_test
With this vfio_pci_liveupdate_kexec_test based on this patchset v9, I have made tests in my local kvm. It worked as expected.
Yanjun Zhu
Quoted 101 lines
Both tests were run in a QEMU-based VM environment (using a single virtio-net PCIe device connected to a root port to exercise bridge support) and on bare metal using an Intel EMR server with 8x Intel DSA PCIe devices and 1x NVMe device.
Future Work
-----------Following this series, we expect to make further improvements to the PCI core support for Live Update:
- Allow P2P across Live Update by avoiding resizing or moving preserved device BARs and preserving all upstream bridge windows.
- Support preserving Virtual Functions by preserving SR-IOV configuration on PFs and enumerating VFs after Live Update.
Changelog
---------v9:
- Simplifypci_liveupdate_preserve_bus_numbers()to always return true if a device was preserved and droppci_liveupdate_scan_bridge_end()(Bjorn)
- Addpci_liveupdate_refuse_bus_numbers()to determine when it is safe for the PCI core to assign bus numbers to unconfigured bridges. This required moving "Auto-preserve upstream bridges across Live Update" before "Preserve bus numbers during Live Update" (Bjorn)
- Add "PCI: Save and restore the ACS Control register" so that the ACS Control register is handled by the normal save/restore path (Bjorn)
- Rename structpci_liveupdate::was_preservedtowas_incoming, to disambiguate incoming from outgoing preservation (me)
- Log unfinished preserved devices from the incoming FLB rather than by walking structpci_dev(Sashiko)
- Document that state handed over by the previous kernel is trusted, and panic inpci_flb_retrieve()where failures are detected rather than unwinding into a caller that panics anyway (Sashiko)
- Fall back to programming ACS from scratch when a preserved device has no ACS save buffer, since there is nowhere to record the adopted controls and they would be lost by the first reset (Sashiko)
- Drop Reviewed-by tags from "Preserve bus numbers during Live Update" and "Adopt ACS controls in incoming preserved devices", both of which changed materially since v8
- Extend commit messages and kernel-doc comments to make the FLB code flow more clear (Bjorn)
- Address various spelling, formatting, and stylistic issues (Bjorn)v8: https://lore.kernel.org/linux-pci/[email protected]/
v7: https://lore.kernel.org/linux-pci/[email protected]/
v6: https://lore.kernel.org/linux-pci/[email protected]/
v5: https://lore.kernel.org/linux-pci/[email protected]/
v4: https://lore.kernel.org/linux-pci/[email protected]/
v3: https://lore.kernel.org/kvm/[email protected]/
v2: https://lore.kernel.org/kvm/[email protected]/
v1: https://lore.kernel.org/kvm/[email protected]/
rfc: https://lore.kernel.org/kvm/[email protected]/David Matlack (13):
PCI: liveupdate: Set up FLB handler for the PCI core
PCI: liveupdate: Track outgoing preserved PCI devices
PCI: liveupdate: Track incoming preserved PCI devices
PCI: liveupdate: Document driver binding responsibilities
PCI: liveupdate: Auto-preserve upstream bridges across Live Update
PCI: liveupdate: Preserve bus numbers during Live Update
PCI: Refactor matching logic forpci_dev_acs_ops
PCI: Save and restore the ACS Control register
PCI: liveupdate: Adopt ACS controls in incoming preserved devices
PCI: liveupdate: Adopt ARI Forwarding Enable on preserved bridges
PCI: liveupdate: Freeze preservation status during shutdown
PCI: liveupdate: Do not disable bus mastering on preserved devices
during kexec
Documentation: PCI: Add documentation for Live UpdateDocumentation/PCI/index.rst | 1 + Documentation/PCI/liveupdate.rst | 35 + .../admin-guide/kernel-parameters.txt | 7 +- Documentation/core-api/liveupdate.rst | 5 + MAINTAINERS | 15 + drivers/pci/Kconfig | 15 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 1015 +++++++++++++++++ drivers/pci/liveupdate.h | 62 + drivers/pci/pci-driver.c | 9 +- drivers/pci/pci.c | 79 +- drivers/pci/pci.h | 5 + drivers/pci/probe.c | 16 +- drivers/pci/quirks.c | 58 +- include/linux/kho/abi/pci.h | 66 ++ include/linux/pci.h | 7 + include/linux/pci_liveupdate.h | 72 ++ 17 files changed, 1429 insertions(+), 39 deletions(-)create mode 100644
Documentation/PCI/liveupdate.rstcreate mode 100644drivers/pci/liveupdate.ccreate mode 100644drivers/pci/liveupdate.hcreate mode 100644include/linux/kho/abi/pci.hcreate mode 100644include/linux/pci_liveupdate.hbase-commit:
945d61765894dda2f0344de50cb1ade2e51b66fd
Quoted 71 lines · Zhu Yanjun
Quoted 70 lines · David Matlack
This series can be found on GitHub:
https://github.com/dmatlack/linux/tree/liveupdate/pci/base/v9
This series introduces support in the PCI core for Live Update, enabling drivers to preserve PCI devices across a kexec-based kernel update without interrupting the device. This functionality is critical for minimizing downtime in environments where PCI devices (e.g., those assigned to VMs via VFIO) must continue operating or maintain state across a host kernel upgrade.
Specifically, this series allows preserved PCI devices to perform uninterrupted memory transactions (DMA) targeting system memory (specifically, preserved memfds) across a Live Update. These devices can be behind a bridge but must not be VFs. Support for P2P and VF preservation will be addressed in future series.
Series Overview
---------------This series implements the following to support PCI device preservation across Live Update:
1. Set up a File-Lifecycle-Bound (FLB) handler to track and preserve PCI-specific state (struct
pci_ser) across Live Update using Kexec Handover (KHO).2. Add APIs for drivers to register devices for preservation (outgoing) and for the PCI core to identify preserved devices during enumeration (incoming)
3. Automatically preserve all upstream bridges for any preserved endpoint. Use reference counting to ensure bridges remain preserved as long as any downstream device is preserved.
4. Guarantee that preserved devices retain the same RequesterID (bus, device, function) for the duration of their preservation by inheriting secondary bus numbers, subordinate bus numbers, and ARI Forwarding Enable on preserved bridges.
5. Guarantee that memory transactions to/from preserved devices are routed consistently by inheriting Access Control Services (ACS) flags across a Live Update, from the endpoint up to the root port.
6. Modify the PCI shutdown path to avoid disabling bus mastering on preserved devices, thereby allowing preserved devices to perform uninterrupted during kexec for Live Update.
7. Provide comprehensive documentation for the FLB API, device tracking mechanisms, and the division of responsibilities between the PCI core, drivers, and userspace.
Merge Plan
----------This series will be merged through liveupdate.git, matching the agreed-upon tree in the
MAINTAINERSentry for PCI LIVE UPDATE.Testing
-------This series was tested in conjunction with v5 of the VFIO PCI driver series:
https://lore.kernel.org/kvm/[email protected]/
The full set of patches used for testing can be found on GitHub.
https://github.com/dmatlack/linux/tree/liveupdate/pci/base/v9-with-vfio
Quoted 8 lines
Quoted 4 lines
Testing was performed using the new VFIO selftests:
-
vfio_pci_liveupdate_uapi_test
-vfio_pci_liveupdate_kexec_testWith this
vfio_pci_liveupdate_kexec_testbased on this patchset v9, I have made tests in my local kvm. It worked as expected.Yanjun Zhu
The test result with vfio_pci_liveupdate_kexec_test is as below.
1.
insmod /lib/modules/7.3.0-rc1-dmabuf+/kernel/drivers/iommu/iommufd/iommufd.ko insmod /lib/modules/7.3.0-rc1-dmabuf+/kernel/drivers/vfio/vfio.ko insmod /lib/modules/7.3.0-rc1-dmabuf+/kernel/drivers/vfio/vfio_iommu_type1.ko insmod /lib/modules/7.3.0-rc1-dmabuf+/kernel/drivers/vfio/pci/vfio-pci-core.ko insmod /lib/modules/7.3.0-rc1-dmabuf+/kernel/drivers/vfio/pci/vfio-pci.ko
+ echo "vfio-pci" > /sys/bus/pci/devices/0000:00:04.0/driver_override
+ echo "0000:00:04.0" > /sys/bus/pci/drivers/vfio-pci/bind Preserving device in session
Preserving memfd of size 0x40100000 in session
# [STAGE 1] Forking persistent child to hold sessions...
# [STAGE 1] Child PID: 1214. Resources are pinned.
# [STAGE 1] You may now perform kexec reboot.
2. kexec reboot
3.
insmod /lib/modules/7.3.0-rc1-dmabuf+/kernel/drivers/iommu/iommufd/iommufd.ko insmod /lib/modules/7.3.0-rc1-dmabuf+/kernel/drivers/vfio/vfio.ko insmod /lib/modules/7.3.0-rc1-dmabuf+/kernel/drivers/vfio/vfio_iommu_type1.ko insmod /lib/modules/7.3.0-rc1-dmabuf+/kernel/drivers/vfio/pci/vfio-pci-core.ko insmod /lib/modules/7.3.0-rc1-dmabuf+/kernel/drivers/vfio/pci/vfio-pci.ko
+ echo "vfio-pci" > /sys/bus/pci/devices/0000:00:04.0/driver_override
+ echo "0000:00:04.0" > /sys/bus/pci/drivers/vfio-pci/bind Retrieving memfd from LUO
Finishing the session before retrieving the device (should fail) Retrieving the device FD from LUO
Finishing the session before binding to iommufd (should fail) Binding the device to an iommufd and setting it up
Finishing the session
Yanjun Zhu
Quoted 103 lines
Quoted 102 lines
Both tests were run in a QEMU-based VM environment (using a single virtio-net PCIe device connected to a root port to exercise bridge support) and on bare metal using an Intel EMR server with 8x Intel DSA PCIe devices and 1x NVMe device.
Future Work
-----------Following this series, we expect to make further improvements to the PCI core support for Live Update:
- Allow P2P across Live Update by avoiding resizing or moving preserved device BARs and preserving all upstream bridge windows.
- Support preserving Virtual Functions by preserving SR-IOV configuration on PFs and enumerating VFs after Live Update.
Changelog
---------v9:
- Simplifypci_liveupdate_preserve_bus_numbers()to always return true if a device was preserved and droppci_liveupdate_scan_bridge_end()(Bjorn)
- Addpci_liveupdate_refuse_bus_numbers()to determine when it is safe for the PCI core to assign bus numbers to unconfigured bridges. This required moving "Auto-preserve upstream bridges across Live Update" before "Preserve bus numbers during Live Update" (Bjorn)
- Add "PCI: Save and restore the ACS Control register" so that the ACS Control register is handled by the normal save/restore path (Bjorn)
- Rename structpci_liveupdate::was_preservedtowas_incoming, to disambiguate incoming from outgoing preservation (me)
- Log unfinished preserved devices from the incoming FLB rather than by walking structpci_dev(Sashiko)
- Document that state handed over by the previous kernel is trusted, and panic inpci_flb_retrieve()where failures are detected rather than unwinding into a caller that panics anyway (Sashiko)
- Fall back to programming ACS from scratch when a preserved device has no ACS save buffer, since there is nowhere to record the adopted controls and they would be lost by the first reset (Sashiko)
- Drop Reviewed-by tags from "Preserve bus numbers during Live Update" and "Adopt ACS controls in incoming preserved devices", both of which changed materially since v8
- Extend commit messages and kernel-doc comments to make the FLB code flow more clear (Bjorn)
- Address various spelling, formatting, and stylistic issues (Bjorn)v8: https://lore.kernel.org/linux-pci/[email protected]/
v7: https://lore.kernel.org/linux-pci/[email protected]/
v6: https://lore.kernel.org/linux-pci/[email protected]/
v5: https://lore.kernel.org/linux-pci/[email protected]/
v4: https://lore.kernel.org/linux-pci/[email protected]/
v3: https://lore.kernel.org/kvm/[email protected]/
v2: https://lore.kernel.org/kvm/[email protected]/
v1: https://lore.kernel.org/kvm/[email protected]/
rfc: https://lore.kernel.org/kvm/[email protected]/David Matlack (13):
PCI: liveupdate: Set up FLB handler for the PCI core
PCI: liveupdate: Track outgoing preserved PCI devices
PCI: liveupdate: Track incoming preserved PCI devices
PCI: liveupdate: Document driver binding responsibilities
PCI: liveupdate: Auto-preserve upstream bridges across Live Update
PCI: liveupdate: Preserve bus numbers during Live Update
PCI: Refactor matching logic forpci_dev_acs_ops
PCI: Save and restore the ACS Control register
PCI: liveupdate: Adopt ACS controls in incoming preserved devices
PCI: liveupdate: Adopt ARI Forwarding Enable on preserved bridges
PCI: liveupdate: Freeze preservation status during shutdown
PCI: liveupdate: Do not disable bus mastering on preserved devices during kexec
Documentation: PCI: Add documentation for Live UpdateDocumentation/PCI/index.rst | 1 + Documentation/PCI/liveupdate.rst | 35 + .../admin-guide/kernel-parameters.txt | 7 +- Documentation/core-api/liveupdate.rst | 5 + MAINTAINERS | 15 + drivers/pci/Kconfig | 15 + drivers/pci/Makefile | 1 +
drivers/pci/liveupdate.c | 1015 +++++++++++++++++ drivers/pci/liveupdate.h | 62 + drivers/pci/pci-driver.c | 9 +-drivers/pci/pci.c | 79 +- drivers/pci/pci.h | 5 + drivers/pci/probe.c | 16 +- drivers/pci/quirks.c | 58 +- include/linux/kho/abi/pci.h | 66 ++ include/linux/pci.h | 7 + include/linux/pci_liveupdate.h | 72 ++
17 files changed, 1429 insertions(+), 39 deletions(-)create mode 100644
Documentation/PCI/liveupdate.rstcreate mode 100644drivers/pci/liveupdate.ccreate mode 100644drivers/pci/liveupdate.hcreate mode 100644include/linux/kho/abi/pci.hcreate mode 100644include/linux/pci_liveupdate.hbase-commit:
945d61765894dda2f0344de50cb1ade2e51b66fd
Signature · 2 lines
Best Regards, Yanjun.Zhu
Quoted 4 lines · David Matlack
This series can be found on GitHub:
https://github.com/dmatlack/linux/tree/liveupdate/pci/base/v9
Quoted 8 lines
This series introduces support in the PCI core for Live Update, enabling drivers to preserve PCI devices across a kexec-based kernel update without interrupting the device. This functionality is critical for minimizing downtime in environments where PCI devices (e.g., those assigned to VMs via VFIO) must continue operating or maintain state across a host kernel upgrade.
[...]
Applied, thanks!
https://git.kernel.org/pub/scm/linux/kernel/git/liveupdate/linux.git/log/?h=lu-pci-preservation
[01/13] PCI: liveupdate: Set up FLB handler for the PCI core
commit: b9affdf3de08c9e5fd8dca0c0bc9c54041362a10
[02/13] PCI: liveupdate: Track outgoing preserved PCI devices
commit: b7163342c1d4090bdd3eace61580197b2372bd34
[03/13] PCI: liveupdate: Track incoming preserved PCI devices
commit: 16c1ff9563333530f97888fca4e48548b22ce282
[04/13] PCI: liveupdate: Document driver binding responsibilities
commit: c7c6bc42b3eebba0562d128b5a578bfbe6a56d31
[05/13] PCI: liveupdate: Auto-preserve upstream bridges across Live Update
commit: 6f58dec26ea52b6451b3b427caa3326b407883a1
[06/13] PCI: liveupdate: Preserve bus numbers during Live Update
commit: ec2f2f51120b9461db0e04a7fb1fcdd9747fd96f
[07/13] PCI: Refactor matching logic for pci_dev_acs_ops
commit: 05d208bda0fd3ef41c3452d1c3f5b365c75b59ae
[08/13] PCI: Save and restore the ACS Control register
commit: 9f2072fd93310487bf3f51bd61f73ed722be3cc0
[09/13] PCI: liveupdate: Adopt ACS controls in incoming preserved devices
commit: 16709a37292e480a2d560242d88ba400e0793706
[10/13] PCI: liveupdate: Adopt ARI Forwarding Enable on preserved bridges
commit: f20575f35fd9ae63f80bc672fc6b31e4de12d4f7
[11/13] PCI: liveupdate: Freeze preservation status during shutdown
commit: f6590754926ecb0f9119f82a08ef073038ca3293
[12/13] PCI: liveupdate: Do not disable bus mastering on preserved devices during kexec
commit: 25ff6ea537fa2c1258cb73d57f11d6af51ec7f8c
[13/13] Documentation: PCI: Add documentation for Live Update
commit: 3b4d450a5bff74e36b4c9e864c0ba7d08288941dBest regards,
Signature · 1 line
Pasha Tatashin <[email protected]>