Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lukas Wunner" <lukas@wunner.de>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH] PCI: Drop unnecessary retries when restoring BARs
Date: Sun, 03 May 2026 13:51:08 +0000	[thread overview]
Message-ID: <20260503135109.46193C2BCB4@smtp.kernel.org> (raw)
In-Reply-To: <785c98b50a7a00d0698848c75d51b8f5669ad18f.1777814679.git.lukas@wunner.de>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Removing the read-back and retry loop for BAR restoration in `pci_restore_state()` introduces a risk of silent regressions for hardware resuming from non-FLR resets (such as D3hot to D0 transitions or custom driver resets). The commit incorrectly assumes the 60s delay from `pci_dev_wait()` covers all usages, but standard PM resume paths only delay for 10ms (`PCI_PM_D3_WAIT`) before calling `pci_restore_state()`. Historically, hardware that needed slightly longer to accept configuration writes relied on the 10x 1ms retry loop to successfully restore BARs. By removing both the retry and the read-back verification, BAR writes to slow devices will be silently dropped, leaving hardware unconfigured and causing MMIO accesses to result in IOMMU faults or kernel crashes.
--

commit 28d12557c0e570f2b2d21da1dcbb7889df2f4672
Author: Lukas Wunner <lukas@wunner.de>

PCI: Drop unnecessary retries when restoring BARs

This commit removes the retry loop when restoring PCI configuration space.
It relies on the lengthened FLR delays now present in the kernel, concluding
that retries for BAR restoration are no longer needed.

Closes: https://lore.kernel.org/r/20260416225745.GA41850@bhelgaas/

> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 8f7cfcc00090..1e386dfaa669 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -1764,7 +1764,7 @@ int pci_save_state(struct pci_dev *dev)

[ ... ]

>  static void pci_restore_config_dword(struct pci_dev *pdev, int offset,
> -				     u32 saved_val, int retry, bool force)
> +				     u32 saved_val, bool force)
>  {
>  	u32 val;
>  
> @@ -1772,52 +1772,42 @@ static void pci_restore_config_dword(struct pci_dev *pdev, int offset,
>  	if (!force && val == saved_val)
>  		return;
>  
> -	for (;;) {
> -		pci_dbg(pdev, "restore config %#04x: %#010x -> %#010x\n",
> -			offset, val, saved_val);
> -		pci_write_config_dword(pdev, offset, saved_val);
> -		if (retry-- <= 0)
> -			return;
> +	pci_dbg(pdev, "restore config %#04x: %#010x -> %#010x\n", offset, val,
> +		saved_val);
>  
> -		pci_read_config_dword(pdev, offset, &val);
> -		if (val == saved_val)
> -			return;
> -
> -		mdelay(1);
> -	}
> +	pci_write_config_dword(pdev, offset, saved_val);
>  }

Does removing the read-back and retry loop introduce a risk for hardware
resuming from non-FLR resets?

While FLR paths might now have a 60 second delay, pci_restore_state() is
used globally across the kernel. For example, during a PM resume from
D3hot to D0, the kernel typically only delays for 10ms (PCI_PM_D3_WAIT)
before restoring state.

If a device is slow to exit reset, will these configuration writes be
silently dropped without the fallback retry loop, potentially leaving BARs
unconfigured and causing MMIO accesses to fault?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/785c98b50a7a00d0698848c75d51b8f5669ad18f.1777814679.git.lukas@wunner.de?part=1

  reply	other threads:[~2026-05-03 13:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-03 13:34 [PATCH] PCI: Drop unnecessary retries when restoring BARs Lukas Wunner
2026-05-03 13:51 ` sashiko-bot [this message]
2026-05-04  7:49   ` Lukas Wunner
2026-05-04 17:09     ` Bjorn Helgaas
2026-05-04 19:31       ` Rafael J. Wysocki
2026-05-04 21:17         ` Bjorn Helgaas
2026-05-05 10:43           ` Rafael J. Wysocki
2026-05-08  0:17             ` Bjorn Helgaas
2026-05-08 12:51               ` Rafael J. Wysocki
2026-05-08 21:43                 ` Bjorn Helgaas

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=20260503135109.46193C2BCB4@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=sashiko@lists.linux.dev \
    /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