[PATCH RFC 10/25] PCI/LUO: Add pci_liveupdate_get_driver_data()

From: Chris Li
Date: Mon Jul 28 2025 - 04:27:01 EST


Similar to liveupdate_get_subsystem_data(), the PCI subsystem
provide pci_liveupdate_get_driver_data() for the driver to
receive the driver data during new kernel boot up, in the liveupdate
updated state.

This function  will return an error on any other liveupdate state.

For example, vfio-pci will use this API in probe() to access the
liveupdate state from the previous kernel.

Signed-off-by: Chris Li <chrisl@xxxxxxxxxx>
---
drivers/pci/liveupdate.c | 15 +++++++++++++++
include/linux/pci.h | 9 +++++++++
2 files changed, 24 insertions(+)

diff --git a/drivers/pci/liveupdate.c b/drivers/pci/liveupdate.c
index 09faba99e9218b443f66060db5142208e22c7dd5..f84c0a455f7055b9b64051b125368fb0f9e6144f 100644
--- a/drivers/pci/liveupdate.c
+++ b/drivers/pci/liveupdate.c
@@ -406,6 +406,21 @@ void pci_liveupdate_restore(struct pci_dev *dev)
return pci_dev_do_restore(dev, s);
}

+int pci_liveupdate_get_driver_data(struct pci_dev *pdev, u64 *data)
+{
+ struct dev_liveupdate *lu = &pdev->dev.lu;
+ struct pci_dev_ser *s = lu->dev_state;
+
+ if (!liveupdate_state_updated())
+ return -EINVAL;
+
+ if (!lu->dev_state)
+ return -ENOENT;
+
+ *data = s->driver_data;
+ return 0;
+}
+
void pci_liveupdate_override_driver(struct pci_dev *dev)
{
struct pci_dev_ser *s = dev->dev.lu.dev_state;
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 05e68f35f39238f8b9ce08df97b384d1c1e89bbe..50296bb04aaa7f2bbd2260f8ec4670533e019e38 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -2767,4 +2767,13 @@ void pci_uevent_ers(struct pci_dev *pdev, enum pci_ers_result err_type);
WARN_ONCE(condition, "%s %s: " fmt, \
dev_driver_string(&(pdev)->dev), pci_name(pdev), ##arg)

+#ifdef CONFIG_LIVEUPDATE
+int pci_liveupdate_get_driver_data(struct pci_dev *pdev, u64 *data);
+#else
+static inline int pci_liveupdate_get_driver_data(struct pci_dev *pdev,
+ u64 *data)
+{
+ return 0;
+}
+#endif
#endif /* LINUX_PCI_H */

--
2.50.1.487.gc89ff58d15-goog