Re: [PATCH v3 02/24] PCI: Add API to track PCI devices preserved across Live Update

From: Zhu Yanjun

Date: Sun Apr 05 2026 - 12:57:10 EST



在 2026/4/3 14:58, David Matlack 写道:
On Thu, Apr 2, 2026 at 2:29 PM Yanjun.Zhu <yanjun.zhu@xxxxxxxxx> wrote:
On 3/23/26 4:57 PM, David Matlack wrote:
+config PCI_LIVEUPDATE
+ bool "PCI Live Update Support (EXPERIMENTAL)"
+ depends on PCI && LIVEUPDATE
+ help
+ Support for preserving PCI devices across a Live Update. This option
+ should only be enabled by developers working on implementing this
+ support. Once enough support as landed in the kernel, this option
+ will no longer be marked EXPERIMENTAL.
+
+ If unsure, say N.
Currently, it only supports 'n' or 'y'. Is it possible to add 'm'
(modular support)?

This would allow the feature to be built as a kernel module. For
development

purposes, modularization means we only need to recompile a single module

for testing, rather than rebuilding the entire kernel. Compiling a
module should

be significantly faster than a full kernel build.
I don't think it is possible for CONFIG_PCI_LIVEUPDATE to support 'm'.
pci_setup_device() (which is under CONFIG_PCI) needs to call
pci_liveupdate_setup_device(), and CONFIG_PCI cannot be built as a
module. This call is necessary so the PCI core knows whether a device
being enumerated was preserved across a previous Live Update.

After the following changes, the liveupdate.ko can be generated successfully.

"

# ls drivers/pci/liveupdate.ko
drivers/pci/liveupdate.ko
"


diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig

index 05307d89c3f4..e172c31b33fa 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -335,7 +335,7 @@ config VGA_ARB_MAX_GPUS
          multiple GPUS.  The overhead for each GPU is very small.

 config PCI_LIVEUPDATE
-       bool "PCI Live Update Support (EXPERIMENTAL)"
+       tristate "PCI Live Update Support (EXPERIMENTAL)"
        depends on PCI && LIVEUPDATE
        help
          Support for preserving PCI devices across a Live Update. This option
diff --git a/drivers/pci/liveupdate.c b/drivers/pci/liveupdate.c
index c1251f4f8438..71bab8ecba85 100644
--- a/drivers/pci/liveupdate.c
+++ b/drivers/pci/liveupdate.c
@@ -413,3 +413,26 @@ void pci_liveupdate_unregister_flb(struct liveupdate_file_handler *fh)
        liveupdate_unregister_flb(fh, &pci_liveupdate_flb);
 }
 EXPORT_SYMBOL_GPL(pci_liveupdate_unregister_flb);
+
+extern void (*pci_liveupdate_setup_device_hook)(struct pci_dev *dev);
+extern u32 (*pci_liveupdate_incoming_nr_devices_hook)(void);
+static int __init liveupdate_module_init(void)
+{
+       pci_liveupdate_setup_device_hook = pci_liveupdate_setup_device;
+       pci_liveupdate_incoming_nr_devices_hook = pci_liveupdate_incoming_nr_devices;
+       pr_info("loaded\n");
+       return 0;
+}
+
+static void __exit liveupdate_module_exit(void)
+{
+       pci_liveupdate_setup_device_hook = NULL;
+       pci_liveupdate_incoming_nr_devices_hook = NULL;
+       pr_info("unloaded\n");
+}
+
+module_init(liveupdate_module_init);
+module_exit(liveupdate_module_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("PCI Live Update Support");
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 979cb9921340..93f76500cb0d 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -1434,18 +1434,12 @@ static inline int pci_msix_write_tph_tag(struct pci_dev *pdev, unsigned int inde
        (PCI_CONF1_ADDRESS(bus, dev, func, reg) | \
         PCI_CONF1_EXT_REG(reg))

-#ifdef CONFIG_PCI_LIVEUPDATE
+#if IS_ENABLED(CONFIG_PCI_LIVEUPDATE)
 void pci_liveupdate_setup_device(struct pci_dev *dev);
-u32 pci_liveupdate_incoming_nr_devices(void);
 #else
 static inline void pci_liveupdate_setup_device(struct pci_dev *dev)
 {
 }
-
-static inline u32 pci_liveupdate_incoming_nr_devices(void)
-{
-       return 0;
-}
 #endif

 #endif /* DRIVERS_PCI_H */
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 165056d71e66..4880302bca43 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1369,6 +1369,9 @@ bool pci_ea_fixed_busnrs(struct pci_dev *dev, u8 *sec, u8 *sub)
        return true;
 }

+u32 (*pci_liveupdate_incoming_nr_devices_hook)(void) = NULL;
+EXPORT_SYMBOL_GPL(pci_liveupdate_incoming_nr_devices_hook);
+
 static bool pci_assign_all_busses(void)
 {
        if (!pcibios_assign_all_busses())
@@ -1389,7 +1392,7 @@ static bool pci_assign_all_busses(void)
         * numbers during the initial cold boot, and then that topology would
         * then remain fixed across any subsequent Live Updates.
         */
-       if (pci_liveupdate_incoming_nr_devices()) {
+       if (pci_liveupdate_incoming_nr_devices_hook && pci_liveupdate_incoming_nr_devices_hook()) {
                pr_info_once("Ignoring pci=assign-busses and inheriting bus numbers during Live Update\n");
                return false;
        }
@@ -2030,6 +2033,9 @@ static const char *pci_type_str(struct pci_dev *dev)
        }
 }

+void (*pci_liveupdate_setup_device_hook)(struct pci_dev *dev) = NULL;
+EXPORT_SYMBOL_GPL(pci_liveupdate_setup_device_hook);
+
 /**
  * pci_setup_device - Fill in class and map information of a device
  * @dev: the device structure to fill
@@ -2091,7 +2097,8 @@ int pci_setup_device(struct pci_dev *dev)
        if (pci_early_dump)
                early_dump_pci_device(dev);

-       pci_liveupdate_setup_device(dev);
+       if (pci_liveupdate_setup_device_hook)
+               pci_liveupdate_setup_device_hook(dev);

        /* Need to have dev->class ready */
        dev->cfg_size = pci_cfg_space_size(dev);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 27ee9846a2fd..aaab6adb487e 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -592,7 +592,7 @@ struct pci_dev {
        u8              tph_mode;       /* TPH mode */
        u8              tph_req_type;   /* TPH requester type */
 #endif
-#ifdef CONFIG_PCI_LIVEUPDATE
+#if IS_ENABLED(CONFIG_PCI_LIVEUPDATE)
        unsigned int    liveupdate_incoming:1;  /* Preserved by previous kernel */
        unsigned int    liveupdate_outgoing:1;  /* Preserved for next kernel */
 #endif
@@ -2876,7 +2876,7 @@ 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_PCI_LIVEUPDATE
+#if IS_ENABLED(CONFIG_PCI_LIVEUPDATE)
 int pci_liveupdate_preserve(struct pci_dev *dev);
 void pci_liveupdate_unpreserve(struct pci_dev *dev);
 int pci_liveupdate_retrieve(struct pci_dev *dev);
diff --git a/kernel/liveupdate/luo_flb.c b/kernel/liveupdate/luo_flb.c
index 874830f8e44d..33fbdc6c417c 100644
--- a/kernel/liveupdate/luo_flb.c
+++ b/kernel/liveupdate/luo_flb.c
@@ -461,7 +461,7 @@ int liveupdate_register_flb(struct liveupdate_file_handler *fh,

        return 0;
 }
-
+EXPORT_SYMBOL_GPL(liveupdate_register_flb);
 /**
  * liveupdate_unregister_flb - Remove an FLB dependency from a file handler.
  * @fh:   The file handler that is currently depending on the FLB.
@@ -487,7 +487,7 @@ void liveupdate_unregister_flb(struct liveupdate_file_handler *fh,

        luo_flb_unregister_one(fh, flb);
 }
-
+EXPORT_SYMBOL_GPL(liveupdate_unregister_flb);
 /**
  * liveupdate_flb_get_incoming - Retrieve the incoming FLB object.
  * @flb:  The FLB definition.
@@ -525,7 +525,7 @@ int liveupdate_flb_get_incoming(struct liveupdate_flb *flb, void **objp)

        return 0;
 }
-
+EXPORT_SYMBOL_GPL(liveupdate_flb_get_incoming);
 /**
  * liveupdate_flb_get_outgoing - Retrieve the outgoing FLB object.
  * @flb:  The FLB definition.
@@ -552,6 +552,7 @@ int liveupdate_flb_get_outgoing(struct liveupdate_flb *flb, void **objp)

        return 0;
 }
+EXPORT_SYMBOL_GPL(liveupdate_flb_get_outgoing);

 int __init luo_flb_setup_outgoing(void *fdt_out)
 {

--
Best Regards,
Yanjun.Zhu