Re: [RFC PATCH 08/13] pci: Save only spec-defined configuration space
From: Jonathan Cameron
Date: Thu Oct 09 2025 - 10:59:26 EST
On Fri, 3 Oct 2025 09:00:44 +0000
Evangelos Petrongonas <epetron@xxxxxxxxx> wrote:
> Change PCI configuration space save/restore operations by
> saving only the regions defined by the PCI specification avoiding any
> potential side effects of undefined behaviour.
>
> The current implementation saves the entire configuration space for
> device restore operations, including reserved and undefined regions.
> This change modifies the save logic to save only architecturally defined
> configuration space regions and skipping the undefined areas.
>
> This benefits the PCSC hitrate, as a 4byte access to a region where only
> 2 bytes are cacheable and 2 are undefined, therefore uncached, will lead
> to a HW access instead.
>
> Signed-off-by: Evangelos Petrongonas <epetron@xxxxxxxxx>
> ---
> drivers/pci/pci.c | 61 +++++++++++++++++++++++++++++++++++++++++++----
> 1 file changed, 56 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index db940f8fd408..3e99baaaf8cd 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -1752,11 +1752,62 @@ static void pci_restore_pcix_state(struct pci_dev *dev)
> int pci_save_state(struct pci_dev *dev)
> {
> int i;
> - /* XXX: 100% dword access ok here? */
> - for (i = 0; i < 16; i++) {
> - pci_read_config_dword(dev, i * 4, &dev->saved_config_space[i]);
> - pci_dbg(dev, "save config %#04x: %#010x\n",
> - i * 4, dev->saved_config_space[i]);
> +
> + if (dev->hdr_type == PCI_HEADER_TYPE_NORMAL) {
> + for (i = 0; i < 13; i++) {
Needs basing on the register defines not magic numbers.
Same for other cases.
Jonathan