From: David Matlack <dmatlack@google.com>
To: kexec@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, linux-pci@vger.kernel.org
Cc: "Adithya Jayachandran" <ajayachandra@nvidia.com>,
"Alexander Graf" <graf@amazon.com>,
"Alex Williamson" <alex@shazbot.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"David Matlack" <dmatlack@google.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Jacob Pan" <jacob.pan@linux.microsoft.com>,
"Jason Gunthorpe" <jgg@nvidia.com>,
"Josh Hilke" <jrhilke@google.com>,
"Leon Romanovsky" <leonro@nvidia.com>,
"Logan Gunthorpe" <logang@deltatee.com>,
"Lukas Wunner" <lukas@wunner.de>,
"Mike Rapoport" <rppt@kernel.org>,
"Parav Pandit" <parav@nvidia.com>,
"Pasha Tatashin" <pasha.tatashin@soleen.com>,
"Pranjal Shrivastava" <praan@google.com>,
"Pratyush Yadav" <pratyush@kernel.org>,
"Saeed Mahameed" <saeedm@nvidia.com>,
"Samiullah Khawaja" <skhawaja@google.com>,
"Vipin Sharma" <vipinsh@google.com>,
"William Tu" <witu@nvidia.com>
Subject: [PATCH 04/10] PCI: liveupdate: Avoid probing windows of incoming bridges
Date: Mon, 19 Oct 2026 21:30:48 +0000 [thread overview]
Message-ID: <20261019213054.3157159-5-dmatlack@google.com> (raw)
In-Reply-To: <20261019213054.3157159-1-dmatlack@google.com>
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@google.com>
---
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
next prev parent reply other threads:[~2026-10-19 21:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 21:30 [PATCH 00/10] PCI: liveupdate: Keep preserved devices accessible across Live Update David Matlack
2026-10-19 21:30 ` [PATCH 01/10] PCI: Factor out BAR sizing from pci_read_bases() David Matlack
2026-10-19 21:30 ` [PATCH 02/10] PCI: liveupdate: Avoid sizing BARs of incoming devices David Matlack
2026-10-19 21:30 ` [PATCH 03/10] PCI: Factor out bridge window probing from pci_read_bridge_windows() David Matlack
2026-10-19 21:30 ` David Matlack [this message]
2026-10-19 21:30 ` [PATCH 05/10] PCI: Skip programming bridge windows that are already programmed David Matlack
2026-10-19 21:30 ` [PATCH 06/10] PCI: liveupdate: Claim resources of incoming devices during scanning David Matlack
2026-10-19 21:30 ` [PATCH 07/10] PCI: liveupdate: Never assign resources of incoming devices David Matlack
2026-10-19 21:30 ` [PATCH 08/10] PCI: liveupdate: Prevent releasing resource windows of incoming bridges David Matlack
2026-10-19 21:30 ` [PATCH 09/10] PCI: liveupdate: Don't realign resources of incoming devices David Matlack
2026-10-19 21:30 ` [PATCH 10/10] PCI: liveupdate: Avoid enabling INTx on " David Matlack
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261019213054.3157159-5-dmatlack@google.com \
--to=dmatlack@google.com \
--cc=ajayachandra@nvidia.com \
--cc=alex@shazbot.org \
--cc=bhelgaas@google.com \
--cc=graf@amazon.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jacob.pan@linux.microsoft.com \
--cc=jgg@nvidia.com \
--cc=jrhilke@google.com \
--cc=kexec@lists.infradead.org \
--cc=leonro@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-pci@vger.kernel.org \
--cc=logang@deltatee.com \
--cc=lukas@wunner.de \
--cc=parav@nvidia.com \
--cc=pasha.tatashin@soleen.com \
--cc=praan@google.com \
--cc=pratyush@kernel.org \
--cc=rppt@kernel.org \
--cc=saeedm@nvidia.com \
--cc=skhawaja@google.com \
--cc=vipinsh@google.com \
--cc=witu@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox