[PATCH v2 08/10] PCI/LUO: Add pci_liveupdate_get_driver_data()

Chris Li
2025-09-16T07:45:21Z

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@kernel.org>
---
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 ae8f4dc5cf92577a4da83743c3b80bc72974a43e..1b12fc0649f479c6f45ffb26e6e3754f41054ea8 100644
--- a/drivers/pci/liveupdate.c
+++ b/drivers/pci/liveupdate.c
@@ -395,6 +395,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.51.0.384.g4c02a37b29-goog