From: David Matlack <dmatlack@google.com>
To: kexec@lists.infradead.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org
Cc: Alexander Graf <graf@amazon.com>,
Alex Williamson <alex@shazbot.org>,
Bjorn Helgaas <bhelgaas@google.com>,
David Matlack <dmatlack@google.com>,
Jason Gunthorpe <jgg@nvidia.com>,
Jonathan Corbet <corbet@lwn.net>, Josh Hilke <jrhilke@google.com>,
Lukas Wunner <lukas@wunner.de>,
Mahesh J Salgaonkar <mahesh@linux.ibm.com>,
Mike Rapoport <rppt@kernel.org>,
"Oliver O'Halloran" <oohall@gmail.com>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
Pratyush Yadav <pratyush@kernel.org>,
Randy Dunlap <rdunlap@infradead.org>,
Samiullah Khawaja <skhawaja@google.com>,
Shuah Khan <skhan@linuxfoundation.org>,
Vipin Sharma <vipinsh@google.com>
Subject: [PATCH v2 16/17] PCI: Remove the per-capability save buffers
Date: Fri, 6 Nov 2026 00:42:17 +0000 [thread overview]
Message-ID: <20261106004218.604799-17-dmatlack@google.com> (raw)
In-Reply-To: <20261106004218.604799-1-dmatlack@google.com>
Delete struct pci_cap_saved_state, struct pci_cap_saved_data,
pci_dev.saved_cap_space and the helpers that managed them. Every capability
now saves its registers in the offset-indexed capability store, so nothing
is left to find, allocate or free.
Drop pci_free_cap_save_buffers() from pci_release_capabilities();
pci_saved_caps_release() already frees the one remaining allocation.
pci_store_saved_state() and pci_load_saved_state() no longer have to append
and consume the records of the capabilities that still had a buffer, so the
blob they exchange is now just the saved DWORDs.
Signed-off-by: David Matlack <dmatlack@google.com>
---
drivers/pci/pci.c | 136 +-------------------------------------------
drivers/pci/pci.h | 19 -------
drivers/pci/probe.c | 1 -
include/linux/pci.h | 1 -
4 files changed, 1 insertion(+), 156 deletions(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index ab1e1d6847fc..d2a9718b6a65 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1802,28 +1802,6 @@ static const u16 pcie_saved_regs[] = {
PCI_EXP_SLTCTL2,
};
-static struct pci_cap_saved_state *_pci_find_saved_cap(struct pci_dev *pci_dev,
- u16 cap, bool extended)
-{
- struct pci_cap_saved_state *tmp;
-
- hlist_for_each_entry(tmp, &pci_dev->saved_cap_space, next) {
- if (tmp->cap.cap_extended == extended && tmp->cap.cap_nr == cap)
- return tmp;
- }
- return NULL;
-}
-
-struct pci_cap_saved_state *pci_find_saved_cap(struct pci_dev *dev, char cap)
-{
- return _pci_find_saved_cap(dev, cap, false);
-}
-
-struct pci_cap_saved_state *pci_find_saved_ext_cap(struct pci_dev *dev, u16 cap)
-{
- return _pci_find_saved_cap(dev, cap, true);
-}
-
static void pci_reserve_pcie_state(struct pci_dev *dev)
{
unsigned int i;
@@ -2017,32 +1995,12 @@ EXPORT_SYMBOL(pci_restore_state);
*
* Laid out so that the position of every value is described by the device's
* configuration space rather than by the kernel.
- *
- * Capabilities that have not moved to the saved capability store yet keep
- * their own buffer, and their records trail @dword_val until the last of
- * those buffers goes away. Both areas vary in length and only one of them
- * can be a flexible array member, so the records are reached with
- * pci_saved_state_records() rather than declared here.
*/
struct pci_saved_state {
unsigned long dword_map[BITS_TO_LONGS(PCI_CFG_SPACE_EXP_DWORDS)];
u32 dword_val[];
- /* struct pci_cap_saved_data cap[] follows dword_val */
};
-/*
- * The records that follow the saved DWORDs, one per capability that still has
- * its own save buffer, terminated by an empty record.
- */
-static struct pci_cap_saved_data *
-pci_saved_state_records(struct pci_saved_state *state)
-{
- unsigned int nr_dwords = bitmap_weight(state->dword_map,
- PCI_CFG_SPACE_EXP_DWORDS);
-
- return (struct pci_cap_saved_data *)&state->dword_val[nr_dwords];
-}
-
/**
* pci_store_saved_state - Allocate and return an opaque struct containing
* the device saved state.
@@ -2054,11 +2012,8 @@ struct pci_saved_state *pci_store_saved_state(struct pci_dev *dev)
{
DECLARE_BITMAP(map, PCI_CFG_SPACE_EXP_DWORDS);
struct pci_saved_caps *caps = &dev->saved_caps;
- struct pci_cap_saved_state *tmp;
- struct pci_cap_saved_data *cap;
struct pci_saved_state *state;
unsigned int dword, nr_dwords, i = 0;
- size_t size;
if (!dev->state_saved)
return NULL;
@@ -2070,14 +2025,7 @@ struct pci_saved_state *pci_store_saved_state(struct pci_dev *dev)
nr_dwords = bitmap_weight(map, PCI_CFG_SPACE_EXP_DWORDS);
- size = struct_size(state, dword_val, nr_dwords);
-
- /* Room for the buffers that are left, and for the terminator */
- size += sizeof(struct pci_cap_saved_data);
- hlist_for_each_entry(tmp, &dev->saved_cap_space, next)
- size += sizeof(struct pci_cap_saved_data) + tmp->cap.size;
-
- state = kzalloc(size, GFP_KERNEL);
+ state = kzalloc(struct_size(state, dword_val, nr_dwords), GFP_KERNEL);
if (!state)
return NULL;
@@ -2092,15 +2040,6 @@ struct pci_saved_state *pci_store_saved_state(struct pci_dev *dev)
pci_read_saved_cap_dword(dev, dword * sizeof(u32), val);
}
- cap = pci_saved_state_records(state);
- hlist_for_each_entry(tmp, &dev->saved_cap_space, next) {
- size_t len = sizeof(struct pci_cap_saved_data) + tmp->cap.size;
-
- memcpy(cap, &tmp->cap, len);
- cap = (struct pci_cap_saved_data *)((u8 *)cap + len);
- }
- /* Empty record terminates the list */
-
return state;
}
EXPORT_SYMBOL_GPL(pci_store_saved_state);
@@ -2113,7 +2052,6 @@ EXPORT_SYMBOL_GPL(pci_store_saved_state);
int pci_load_saved_state(struct pci_dev *dev,
struct pci_saved_state *state)
{
- struct pci_cap_saved_data *cap;
unsigned int dword, i = 0;
dev->state_saved = false;
@@ -2140,19 +2078,6 @@ int pci_load_saved_state(struct pci_dev *dev,
pci_write_saved_cap_dword(dev, off, val);
}
- cap = pci_saved_state_records(state);
- while (cap->size) {
- struct pci_cap_saved_state *tmp;
-
- tmp = _pci_find_saved_cap(dev, cap->cap_nr, cap->cap_extended);
- if (!tmp || tmp->cap.size != cap->size)
- return -EINVAL;
-
- memcpy(tmp->cap.data, cap->data, tmp->cap.size);
- cap = (struct pci_cap_saved_data *)((u8 *)cap +
- sizeof(struct pci_cap_saved_data) + cap->size);
- }
-
dev->state_saved = true;
return 0;
}
@@ -3652,56 +3577,6 @@ void pci_ea_init(struct pci_dev *dev)
offset = pci_ea_read(dev, offset);
}
-static void pci_add_saved_cap(struct pci_dev *pci_dev,
- struct pci_cap_saved_state *new_cap)
-{
- hlist_add_head(&new_cap->next, &pci_dev->saved_cap_space);
-}
-
-/**
- * _pci_add_cap_save_buffer - allocate buffer for saving given
- * capability registers
- * @dev: the PCI device
- * @cap: the capability to allocate the buffer for
- * @extended: Standard or Extended capability ID
- * @size: requested size of the buffer
- */
-static int _pci_add_cap_save_buffer(struct pci_dev *dev, u16 cap,
- bool extended, unsigned int size)
-{
- int pos;
- struct pci_cap_saved_state *save_state;
-
- if (extended)
- pos = pci_find_ext_capability(dev, cap);
- else
- pos = pci_find_capability(dev, cap);
-
- if (!pos)
- return 0;
-
- save_state = kzalloc(sizeof(*save_state) + size, GFP_KERNEL);
- if (!save_state)
- return -ENOMEM;
-
- save_state->cap.cap_nr = cap;
- save_state->cap.cap_extended = extended;
- save_state->cap.size = size;
- pci_add_saved_cap(dev, save_state);
-
- return 0;
-}
-
-int pci_add_cap_save_buffer(struct pci_dev *dev, char cap, unsigned int size)
-{
- return _pci_add_cap_save_buffer(dev, cap, false, size);
-}
-
-int pci_add_ext_cap_save_buffer(struct pci_dev *dev, u16 cap, unsigned int size)
-{
- return _pci_add_cap_save_buffer(dev, cap, true, size);
-}
-
/**
* pci_reserve_saved_caps - reserve room to save capability registers
* @dev: the PCI device
@@ -3715,15 +3590,6 @@ void pci_reserve_saved_caps(struct pci_dev *dev)
pci_reserve_vc_state(dev);
}
-void pci_free_cap_save_buffers(struct pci_dev *dev)
-{
- struct pci_cap_saved_state *tmp;
- struct hlist_node *n;
-
- hlist_for_each_entry_safe(tmp, n, &dev->saved_cap_space, next)
- kfree(tmp);
-}
-
/**
* pci_configure_ari - enable or disable ARI forwarding
* @dev: the PCI device
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 5a03561515ee..bc92b037b9d1 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -237,26 +237,7 @@ int pci_bridge_secondary_bus_reset(struct pci_dev *dev);
int pci_bus_error_reset(struct pci_dev *dev);
int pci_try_reset_bridge(struct pci_dev *bridge);
-struct pci_cap_saved_data {
- u16 cap_nr;
- bool cap_extended;
- unsigned int size;
- u32 data[];
-};
-
-struct pci_cap_saved_state {
- struct hlist_node next;
- struct pci_cap_saved_data cap;
-};
-
void pci_reserve_saved_caps(struct pci_dev *dev);
-void pci_free_cap_save_buffers(struct pci_dev *dev);
-int pci_add_cap_save_buffer(struct pci_dev *dev, char cap, unsigned int size);
-int pci_add_ext_cap_save_buffer(struct pci_dev *dev,
- u16 cap, unsigned int size);
-struct pci_cap_saved_state *pci_find_saved_cap(struct pci_dev *dev, char cap);
-struct pci_cap_saved_state *pci_find_saved_ext_cap(struct pci_dev *dev,
- u16 cap);
/* DWORDs of the configuration space header, i.e. pci_dev.saved_config_space */
#define PCI_STD_HEADER_DWORDS (PCI_STD_HEADER_SIZEOF / sizeof(u32))
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index c04adf606ab9..0a86de920225 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2475,7 +2475,6 @@ static void pci_release_capabilities(struct pci_dev *dev)
pci_aer_exit(dev);
pci_rcec_exit(dev);
pci_iov_release(dev);
- pci_free_cap_save_buffers(dev);
pci_saved_caps_release(dev);
}
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 2c27124c81e5..6ba724e1f04e 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -549,7 +549,6 @@ struct pci_dev {
spinlock_t pcie_cap_lock; /* Protects RMW ops in capability accessors */
u32 saved_config_space[16]; /* Config space saved at suspend time */
- struct hlist_head saved_cap_space;
struct pci_saved_caps saved_caps; /* Saved capability registers */
#ifdef CONFIG_HOTPLUG_PCI_PCIE
--
2.56.0.455.g6c5a503b38-goog
next prev parent reply other threads:[~2026-11-06 0:43 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 0:42 [PATCH v2 00/17] PCI: Index saved capability state by configuration space offset David Matlack
2026-11-06 0:42 ` [PATCH v2 01/17] PCI/DPC: Allocate the DPC save buffer during device setup David Matlack
2026-12-04 11:43 ` Lukas Wunner
2026-12-04 11:51 ` Lukas Wunner
2026-12-04 22:55 ` David Matlack
2026-12-04 22:53 ` David Matlack
2026-12-05 8:46 ` Lukas Wunner
2026-11-06 0:42 ` [PATCH v2 02/17] PCI: Add an offset-indexed store for saved capability registers David Matlack
2026-12-04 12:17 ` Lukas Wunner
2026-12-04 23:19 ` David Matlack
2026-12-04 17:55 ` Lukas Wunner
2026-12-04 23:22 ` David Matlack
2026-12-05 8:59 ` Lukas Wunner
2026-11-06 0:42 ` [PATCH v2 03/17] PCI: Lay out struct pci_saved_state by configuration space offset David Matlack
2026-11-06 0:42 ` [PATCH v2 04/17] PCI: Save PCIe state in the saved capability store David Matlack
2026-12-05 21:22 ` Lukas Wunner
2026-11-06 0:42 ` [PATCH v2 05/17] PCI: Save PCI-X " David Matlack
2026-11-06 0:42 ` [PATCH v2 06/17] PCI/ASPM: Save LTR " David Matlack
2026-11-06 0:42 ` [PATCH v2 07/17] PCI/ASPM: Save L1SS " David Matlack
2026-11-06 0:42 ` [PATCH v2 08/17] PCI/AER: Save AER " David Matlack
2026-11-06 0:42 ` [PATCH v2 09/17] PCI/PTM: Save PTM " David Matlack
2026-11-06 0:42 ` [PATCH v2 10/17] PCI/TPH: Save TPH " David Matlack
2026-11-06 0:42 ` [PATCH v2 11/17] PCI/DPC: Save DPC " David Matlack
2026-11-06 0:42 ` [PATCH v2 12/17] PCI: Save ACS " David Matlack
2026-11-06 0:42 ` [PATCH v2 13/17] PCI/VC: Split the VC Resource Control restore into a helper David Matlack
2026-11-06 0:42 ` [PATCH v2 14/17] PCI/VC: Save VC state in the saved capability store David Matlack
2026-11-06 0:42 ` [PATCH v2 15/17] PCI: Save reserved capability registers in a single pass David Matlack
2026-11-06 0:42 ` David Matlack [this message]
2026-11-06 0:42 ` [PATCH v2 17/17] PCI: liveupdate: Add helpers to preserve struct pci_saved_state David Matlack
2026-11-06 0:46 ` [PATCH v2 00/17] PCI: Index saved capability state by configuration space offset David Matlack
2026-11-08 14:58 ` Pasha Tatashin
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=20261106004218.604799-17-dmatlack@google.com \
--to=dmatlack@google.com \
--cc=alex@shazbot.org \
--cc=bhelgaas@google.com \
--cc=corbet@lwn.net \
--cc=graf@amazon.com \
--cc=jgg@nvidia.com \
--cc=jrhilke@google.com \
--cc=kexec@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-pci@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=lukas@wunner.de \
--cc=mahesh@linux.ibm.com \
--cc=oohall@gmail.com \
--cc=pasha.tatashin@soleen.com \
--cc=pratyush@kernel.org \
--cc=rdunlap@infradead.org \
--cc=rppt@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=skhawaja@google.com \
--cc=vipinsh@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.