[PATCH 04/10] PCI: liveupdate: Avoid probing windows of incoming bridges
From: David Matlack
Date: Mon Oct 19 2026 - 17:39:00 EST
Avoid probing which windows incoming preserved bridges implement during
enumeration. Instead, add a new optional feature for passing the
results of probing in struct pci_dev_ser, and use it to pass which
windows each preserved bridge implements.
pci_probe_bridge_windows() always writes all 1s to the Prefetchable
Base Upper 32 Bits register of bridges with a 64-bit prefetchable
window to check that it is writable. This temporarily disables the
prefetchable window, so the bridge stops forwarding memory transactions
targeting devices below it, such as P2PDMA from other preserved devices,
or MMIO from VMs whose vCPUs keep running during kexec.
The new optional feature, PCI_SER_OPTIONAL_PROBED, appends two bitmasks
to struct pci_dev_ser: @probed holds the results of probing properties
of the device that require temporarily writing to it, one bit per
property (PCI_DEV_SER_PROBED_*), and @probed_supported indicates which
bits of @probed are valid. This allows passing the results of more
probes in the future (e.g. whether INTx masking is broken) without
adding a new feature flag for each one, and lets the next kernel use
the results it understands and probe the rest.
If the previous kernel did not pass which windows a bridge implements,
fall back to probing the windows.
Assisted-by: LLM
Signed-off-by: David Matlack <dmatlack@xxxxxxxxxx>
---
drivers/pci/liveupdate.c | 93 ++++++++++++++++++++++++++++++++++++-
drivers/pci/liveupdate.h | 6 +++
drivers/pci/probe.c | 9 ++++
include/linux/kho/abi/pci.h | 24 ++++++++++
4 files changed, 131 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/liveupdate.c b/drivers/pci/liveupdate.c
index f48cab3cc232..72ad4fd00f7b 100644
--- a/drivers/pci/liveupdate.c
+++ b/drivers/pci/liveupdate.c
@@ -204,6 +204,12 @@
* vCPUs keep running during kexec). Instead, the previous kernel passes the
* size of each BAR in struct pci_dev_ser. Everything else about the BARs
* (e.g. their addresses and types) is read from the device as usual.
+ *
+ * * The PCI core does not probe properties of incoming preserved devices
+ * that require temporarily writing to the device (e.g. which windows a
+ * bridge implements), since that would disrupt memory transactions
+ * targeting the device or devices below it. Instead, the previous kernel
+ * passes the results of probing in struct pci_dev_ser.
*/
#define pr_fmt(fmt) "PCI: liveupdate: " fmt
@@ -282,7 +288,13 @@ struct pci_flb_incoming {
* Bits in struct pci_ser::optional_flags that this kernel knows how to handle.
* This kernel also provides all of them to the next kernel.
*/
-#define PCI_SER_OPTIONAL_FLAGS_SUPPORTED PCI_SER_OPTIONAL_BAR_MASKS
+#define PCI_SER_OPTIONAL_FLAGS_SUPPORTED \
+ (PCI_SER_OPTIONAL_BAR_MASKS | PCI_SER_OPTIONAL_PROBED)
+
+#define PCI_DEV_SER_PROBED_WINDOWS \
+ (PCI_DEV_SER_PROBED_IO_WINDOW | \
+ PCI_DEV_SER_PROBED_PREF_WINDOW | \
+ PCI_DEV_SER_PROBED_PREF_64_WINDOW)
/*
* The minimum size of struct pci_dev_ser given the optional features that are
@@ -295,6 +307,9 @@ static u32 pci_dev_ser_min_size(u64 optional_flags)
if (optional_flags & PCI_SER_OPTIONAL_BAR_MASKS)
size = max(size, offsetofend(struct pci_dev_ser, rom_mask));
+ if (optional_flags & PCI_SER_OPTIONAL_PROBED)
+ size = max(size, offsetofend(struct pci_dev_ser, probed));
+
return size;
}
@@ -626,6 +641,28 @@ static void pci_liveupdate_save_bar_masks(struct pci_dev *dev,
dev_ser->rom_mask = lower_32_bits(mask);
}
+static void pci_liveupdate_preserve_probed(struct pci_dev *dev,
+ struct pci_dev_ser *dev_ser)
+{
+ u64 supported = 0, probed = 0;
+
+ if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
+ supported |= PCI_DEV_SER_PROBED_WINDOWS;
+
+ if (dev->io_window)
+ probed |= PCI_DEV_SER_PROBED_IO_WINDOW;
+
+ if (dev->pref_window)
+ probed |= PCI_DEV_SER_PROBED_PREF_WINDOW;
+
+ if (dev->pref_64_window)
+ probed |= PCI_DEV_SER_PROBED_PREF_64_WINDOW;
+ }
+
+ dev_ser->probed_supported = supported;
+ dev_ser->probed = probed;
+}
+
static int pci_liveupdate_preserve_device(struct pci_flb_outgoing *outgoing,
struct pci_dev *dev)
{
@@ -671,6 +708,8 @@ static int pci_liveupdate_preserve_device(struct pci_flb_outgoing *outgoing,
if (IS_ERR(dev_ser))
return PTR_ERR(dev_ser);
+ pci_liveupdate_preserve_probed(dev, 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);
@@ -1116,6 +1155,58 @@ int pci_liveupdate_read_bar_masks(struct pci_dev *dev, unsigned int nr_bars,
return 0;
}
+/*
+ * Get the results of probing @bits on the incoming device @dev, as passed by
+ * the previous kernel. Returns false if the previous kernel did not pass all of
+ * @bits, in which case they must be probed.
+ */
+static bool pci_liveupdate_read_probed(struct pci_dev *dev, u64 bits,
+ u64 *probed)
+{
+ struct pci_dev_ser *dev_ser = dev->liveupdate.incoming;
+
+ lockdep_assert_held(&pci_liveupdate.rwsem);
+
+ if (!dev_ser)
+ return false;
+
+ if (!(pci_liveupdate.incoming_optional_flags & PCI_SER_OPTIONAL_PROBED))
+ return false;
+
+ if ((dev_ser->probed_supported & bits) != bits)
+ return false;
+
+ *probed = dev_ser->probed & bits;
+ return true;
+}
+
+/**
+ * pci_liveupdate_read_bridge_windows() - Get the windows of an incoming bridge
+ * @bridge: The PCI bridge
+ *
+ * Set which windows @bridge implements (@bridge->io_window, pref_window, and
+ * pref_64_window) as determined by the previous kernel, so that the windows do
+ * not need to be probed.
+ *
+ * Return: 0 on success, or -ENODATA if @bridge is not incoming-preserved or
+ * the previous kernel did not pass which windows @bridge implements.
+ */
+int pci_liveupdate_read_bridge_windows(struct pci_dev *bridge)
+{
+ u64 probed;
+
+ guard(rwsem_read)(&pci_liveupdate.rwsem);
+
+ if (!pci_liveupdate_read_probed(bridge, PCI_DEV_SER_PROBED_WINDOWS,
+ &probed))
+ return -ENODATA;
+
+ bridge->io_window = !!(probed & PCI_DEV_SER_PROBED_IO_WINDOW);
+ bridge->pref_window = !!(probed & PCI_DEV_SER_PROBED_PREF_WINDOW);
+ bridge->pref_64_window = !!(probed & PCI_DEV_SER_PROBED_PREF_64_WINDOW);
+ return 0;
+}
+
/**
* pci_liveupdate_is_incoming() - Check if a device is incoming-preserved
* @dev: The PCI device to check
diff --git a/drivers/pci/liveupdate.h b/drivers/pci/liveupdate.h
index 80749f14beea..4c4104025a7e 100644
--- a/drivers/pci/liveupdate.h
+++ b/drivers/pci/liveupdate.h
@@ -21,6 +21,7 @@ int pci_liveupdate_adopt_ari(struct pci_dev *dev);
bool pci_liveupdate_is_outgoing(struct pci_dev *dev);
int pci_liveupdate_read_bar_masks(struct pci_dev *dev, unsigned int nr_bars,
u32 *bar_masks, u32 *rom_mask);
+int pci_liveupdate_read_bridge_windows(struct pci_dev *bridge);
#else
static inline void pci_liveupdate_setup_device(struct pci_dev *dev)
{
@@ -66,6 +67,11 @@ static inline int pci_liveupdate_read_bar_masks(struct pci_dev *dev,
{
return -EINVAL;
}
+
+static inline int pci_liveupdate_read_bridge_windows(struct pci_dev *bridge)
+{
+ return -EINVAL;
+}
#endif
#endif /* DRIVERS_PCI_LIVEUPDATE_H */
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 473e4389ffae..184d93aa8522 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -529,6 +529,15 @@ static void pci_probe_bridge_windows(struct pci_dev *bridge)
u16 io;
u32 pmem, tmp;
+ /*
+ * Writing to the window registers would disrupt memory transactions
+ * that bridges preserved across Live Update forward to devices below
+ * them, so use the windows determined by the previous kernel for those
+ * bridges.
+ */
+ if (!pci_liveupdate_read_bridge_windows(bridge))
+ return;
+
pci_read_config_word(bridge, PCI_IO_BASE, &io);
if (!io) {
pci_write_config_word(bridge, PCI_IO_BASE, 0xe0f0);
diff --git a/include/linux/kho/abi/pci.h b/include/linux/kho/abi/pci.h
index 5fa2ecfe5b6d..84a1bf71eeca 100644
--- a/include/linux/kho/abi/pci.h
+++ b/include/linux/kho/abi/pci.h
@@ -66,6 +66,13 @@
* which requires disabling decoding and would disrupt memory
* transactions targeting the device.
* @rom_mask: Same as @bar_masks, but for the Expansion ROM BAR.
+ * @probed_supported: The ``PCI_DEV_SER_PROBED_*`` bits that are valid in
+ * @probed.
+ * @probed: The results of probing properties of the device that require
+ * temporarily writing to it (``PCI_DEV_SER_PROBED_*``). Used by the
+ * next kernel instead of probing the device again, which would
+ * disrupt memory transactions targeting the device or devices below
+ * it.
*
* Each field after @refcount is only present if the ``PCI_SER_OPTIONAL_*``
* flag that covers it is set in ``pci_ser.optional_flags``.
@@ -76,8 +83,23 @@ struct pci_dev_ser {
u16 refcount;
u32 bar_masks[PCI_STD_NUM_BARS];
u32 rom_mask;
+ u64 probed_supported;
+ u64 probed;
} __packed;
+/*
+ * Bits in struct pci_dev_ser::probed_supported and probed:
+ *
+ * * PCI_DEV_SER_PROBED_IO_WINDOW: The bridge has an I/O window.
+ * * PCI_DEV_SER_PROBED_PREF_WINDOW: The bridge has a prefetchable memory
+ * window.
+ * * PCI_DEV_SER_PROBED_PREF_64_WINDOW: The bridge's prefetchable memory
+ * window is 64-bit.
+ */
+#define PCI_DEV_SER_PROBED_IO_WINDOW BIT_ULL(0)
+#define PCI_DEV_SER_PROBED_PREF_WINDOW BIT_ULL(1)
+#define PCI_DEV_SER_PROBED_PREF_64_WINDOW BIT_ULL(2)
+
/*
* The size of struct pci_dev_ser when this ABI was introduced. Since fields
* can only be appended, every struct pci_dev_ser is at least this large.
@@ -113,7 +135,9 @@ struct pci_ser {
* large enough to contain the fields of struct pci_dev_ser that it covers:
*
* * PCI_SER_OPTIONAL_BAR_MASKS: @bar_masks and @rom_mask
+ * * PCI_SER_OPTIONAL_PROBED: @probed_supported and @probed
*/
#define PCI_SER_OPTIONAL_BAR_MASKS BIT_ULL(0)
+#define PCI_SER_OPTIONAL_PROBED BIT_ULL(1)
#endif /* _LINUX_KHO_ABI_PCI_H */
--
2.56.0.212.g129ede20d9-goog