[PATCH v4 06/11] PCI: liveupdate: Auto-preserve upstream bridges across Live Update
David Matlack
dmatlack at google.com
Thu Apr 23 14:23:10 PDT 2026
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.
Signed-off-by: David Matlack <dmatlack at google.com>
---
drivers/pci/liveupdate.c | 149 +++++++++++++++++++++++++++++----------
1 file changed, 111 insertions(+), 38 deletions(-)
diff --git a/drivers/pci/liveupdate.c b/drivers/pci/liveupdate.c
index cf8cff134a75..88125f9a2c6b 100644
--- a/drivers/pci/liveupdate.c
+++ b/drivers/pci/liveupdate.c
@@ -106,6 +106,18 @@
* If a misconfigured or unconfigured bridge is encountered during enumeration
* while there are incoming preserved devices, it's secondary and subordinate
* bus numbers will be cleared and devices below it will not be enumerated.
+ *
+ * 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
@@ -233,25 +245,14 @@ static struct liveupdate_flb pci_liveupdate_flb = {
.compatible = PCI_LUO_FLB_COMPATIBLE,
};
-int pci_liveupdate_preserve(struct pci_dev *dev)
+static int pci_liveupdate_preserve_device(struct pci_ser *ser, struct pci_dev *dev)
{
- struct pci_ser *ser;
- int i, ret;
-
- guard(mutex)(&pci_flb_outgoing_lock);
-
- ret = liveupdate_flb_get_outgoing(&pci_liveupdate_flb, (void **)&ser);
- if (ret)
- return ret;
+ int i;
- if (!ser)
- return -ENOENT;
-
- if (dev->is_virtfn)
- return -EINVAL;
-
- if (dev->liveupdate_outgoing)
- return -EBUSY;
+ if (dev->liveupdate_outgoing) {
+ dev->liveupdate_outgoing->refcount++;
+ return 0;
+ }
if (ser->nr_devices == ser->max_nr_devices)
return -ENOSPC;
@@ -281,11 +282,82 @@ int pci_liveupdate_preserve(struct pci_dev *dev)
return -ENOSPC;
}
+
+static void pci_liveupdate_unpreserve_path(struct pci_ser *ser, struct pci_dev *dev)
+{
+ struct pci_dev *upstream_bridge = dev->bus->self;
+ struct pci_dev_ser *dev_ser;
+
+ if (upstream_bridge)
+ pci_liveupdate_unpreserve_path(ser, upstream_bridge);
+
+ dev_ser = dev->liveupdate_outgoing;
+ if (!dev_ser) {
+ pci_warn(dev, "Cannot unpreserve device that is not preserved\n");
+ return;
+ }
+
+ if (--dev_ser->refcount == 0) {
+ pci_info(dev, "Device will no longer be preserved across next Live Update\n");
+ ser->nr_devices--;
+ memset(dev_ser, 0, sizeof(*dev_ser));
+ dev->liveupdate_outgoing = NULL;
+ }
+}
+
+static int pci_liveupdate_preserve_path(struct pci_ser *ser, struct pci_dev *dev)
+{
+ struct pci_dev *upstream_bridge = dev->bus->self;
+ int ret = 0;
+
+ if (upstream_bridge) {
+ ret = pci_liveupdate_preserve_path(ser, upstream_bridge);
+ if (ret)
+ return ret;
+ } else if (!pci_is_root_bus(dev->bus)) {
+ pci_err(dev, "Failed to preserve up to root port\n");
+ return -EINVAL;
+ }
+
+ ret = pci_liveupdate_preserve_device(ser, dev);
+ if (ret)
+ goto err;
+
+ return 0;
+
+err:
+ if (upstream_bridge)
+ pci_liveupdate_unpreserve_path(ser, upstream_bridge);
+
+ return ret;
+}
+
+int pci_liveupdate_preserve(struct pci_dev *dev)
+{
+ struct pci_ser *ser;
+ int ret;
+
+ guard(mutex)(&pci_flb_outgoing_lock);
+
+ ret = liveupdate_flb_get_outgoing(&pci_liveupdate_flb, (void **)&ser);
+ if (ret)
+ return ret;
+
+ if (!ser)
+ return -ENOENT;
+
+ if (dev->is_virtfn)
+ return -EINVAL;
+
+ if (dev->liveupdate_outgoing)
+ return -EBUSY;
+
+ return pci_liveupdate_preserve_path(ser, dev);
+}
EXPORT_SYMBOL_GPL(pci_liveupdate_preserve);
void pci_liveupdate_unpreserve(struct pci_dev *dev)
{
- struct pci_dev_ser *dev_ser;
struct pci_ser *ser = NULL;
int ret;
@@ -296,19 +368,9 @@ void pci_liveupdate_unpreserve(struct pci_dev *dev)
if (ret || !ser) {
pci_warn(dev, "Cannot unpreserve device without outgoing Live Update state\n");
return;
-
- }
-
- 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");
- ser->nr_devices--;
- memset(dev_ser, 0, sizeof(*dev_ser));
- dev->liveupdate_outgoing = NULL;
+ pci_liveupdate_unpreserve_path(ser, dev);
}
EXPORT_SYMBOL_GPL(pci_liveupdate_unpreserve);
@@ -428,6 +490,25 @@ void pci_liveupdate_cleanup_device(struct pci_dev *dev)
pci_liveupdate_flb_put_incoming();
}
+static void pci_liveupdate_finish_path(struct pci_dev *dev)
+{
+ struct pci_dev *upstream_bridge = dev->bus->self;
+
+ if (upstream_bridge)
+ pci_liveupdate_finish_path(upstream_bridge);
+
+ /*
+ * 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 becase the device is hot-plugged.
+ */
+ if (--dev->liveupdate_incoming->refcount)
+ return;
+
+ pci_info(dev, "Device is finished participating in Live Update\n");
+ dev->liveupdate_incoming = NULL;
+}
+
void pci_liveupdate_finish(struct pci_dev *dev)
{
if (!dev->liveupdate_incoming) {
@@ -435,15 +516,7 @@ void pci_liveupdate_finish(struct pci_dev *dev)
return;
}
- pci_info(dev, "Device is finished participating in Live Update\n");
-
- /*
- * 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 becase the device is hot-plugged.
- */
- dev->liveupdate_incoming->refcount = 0;
- dev->liveupdate_incoming = NULL;
+ pci_liveupdate_finish_path(dev);
/* Drop this device's reference on the incoming FLB. */
pci_liveupdate_flb_put_incoming();
--
2.54.0.rc2.544.gc7ae2d5bb8-goog
More information about the kexec
mailing list