From: Bjorn Helgaas <helgaas@kernel.org>
To: Lukas Wunner <lukas@wunner.de>
Cc: Bernd Schumacher <bernd@bschu.de>,
"Alexandre N." <an.tech@mailo.com>,
Salvatore Bonaccorso <carnil@debian.org>,
1131025@bugs.debian.org, Uwe Kleine-Koenig <ukleinek@debian.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Mario Limonciello <mario.limonciello@amd.com>,
Alex Williamson <alex@shazbot.org>,
Ilpo Jarvinen <ilpo.jarvinen@linux.intel.com>,
regressions@lists.linux.dev, linux-pci@vger.kernel.org,
Thorsten Leemhuis <regressions@leemhuis.info>
Subject: Re: [PATCH] PCI: Update saved_config_space upon resource assignment
Date: Fri, 1 May 2026 14:51:18 -0500 [thread overview]
Message-ID: <20260501195118.GA516950@bhelgaas> (raw)
In-Reply-To: <febc3f354e0c1f5a9f5b3ee9ffddaa44caccf651.1776268054.git.lukas@wunner.de>
[+cc Thorsten, thanks for the reminder!]
On Wed, Apr 15, 2026 at 05:56:06PM +0200, Lukas Wunner wrote:
> Bernd reports passthrough failure of a Digital Devices Cine S2 V6 DVB
> adapter plugged into an ASRock X570S PG Riptide board with BIOS version
> P5.41 (09/07/2023):
>
> ddbridge 0000:05:00.0: detected Digital Devices Cine S2 V6 DVB adapter
> ddbridge 0000:05:00.0: cannot read registers
> ddbridge 0000:05:00.0: fail
>
> BIOS assigns an incorrect BAR to the DVB adapter which doesn't fit into
> the upstream bridge window. The kernel corrects the BAR assignment:
>
> pci 0000:07:00.0: BAR 0 [mem 0xfffffffffc500000-0xfffffffffc50ffff 64bit]: can't claim; no compatible bridge window
> pci 0000:07:00.0: BAR 0 [mem 0xfc500000-0xfc50ffff 64bit]: assigned
>
> Correction of the BAR assignment happens in an x86-specific fs_initcall,
> pcibios_assign_resources(), after device enumeration in a subsys_initcall.
> This order was introduced at the behest of Linus in 2004:
>
> https://git.kernel.org/tglx/history/c/a06a30144bbc
>
> No other architecture performs such a late BAR correction.
>
> Bernd bisected the issue to commit a2f1e22390ac ("PCI/ERR: Ensure error
> recoverability at all times"), but it only occurs in the absence of commit
> 4d4c10f763d7 ("PCI: Explicitly put devices into D0 when initializing").
> This combination exists in stable kernel v6.12.70, but not in mainline,
> hence Bernd cannot reproduce the issue with mainline.
>
> Since a2f1e22390ac, config space is saved on enumeration, prior to BAR
> correction. Upon passthrough, the corrected BAR is overwritten with the
> incorrect saved value by:
>
> vfio_pci_core_register_device()
> vfio_pci_set_power_state()
> pci_restore_state()
>
> But only if the device's current_state is PCI_UNKNOWN, as it was prior to
> commit 4d4c10f763d7. Since the commit, it is PCI_D0, which changes the
> behavior of vfio_pci_set_power_state() to no longer restore the state
> without saving it first.
>
> Alexandre is reporting the same issue as Bernd, but in his case, mainline
> is affected as well. The difference is that on Alexandre's system, the
> host kernel binds a driver to the device which is unbound prior to
> passthrough, whereas on Bernd's system no driver gets bound by the host
> kernel.
>
> Unbinding sets current_state to PCI_UNKNOWN in pci_device_remove(), so
> when vfio-pci is subsequently bound to the device, pci_restore_state() is
> once again called without invoking pci_save_state() first.
>
> To robustly fix the issue, always update saved_config_space upon resource
> assignment.
>
> Reported-by: Bernd Schumacher <bernd@bschu.de>
> Tested-by: Bernd Schumacher <bernd@bschu.de>
> Closes: https://lore.kernel.org/r/acfZrlP0Ua_5D3U4@eldamar.lan/
> Reported-by: Alexandre N. <an.tech@mailo.com>
> Tested-by: Alexandre N. <an.tech@mailo.com>
> Closes: https://lore.kernel.org/r/dd3c3358-de0f-4a56-9c81-04aceaab4058@mailo.com/
> Fixes: a2f1e22390ac ("PCI/ERR: Ensure error recoverability at all times")
> Signed-off-by: Lukas Wunner <lukas@wunner.de>
> Cc: stable@vger.kernel.org # v6.12+
a2f1e22390ac appeared in v6.19. Applied this fix to pci/for-linus for
v7.1, thanks!
> ---
> drivers/pci/setup-res.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
> index e5fcadf..1769ba9 100644
> --- a/drivers/pci/setup-res.c
> +++ b/drivers/pci/setup-res.c
> @@ -102,6 +102,7 @@ static void pci_std_update_resource(struct pci_dev *dev, int resno)
> }
>
> pci_write_config_dword(dev, reg, new);
> + dev->saved_config_space[reg / 4] = new;
> pci_read_config_dword(dev, reg, &check);
>
> if ((new ^ check) & mask) {
> @@ -112,6 +113,7 @@ static void pci_std_update_resource(struct pci_dev *dev, int resno)
> if (res->flags & IORESOURCE_MEM_64) {
> new = region.start >> 16 >> 16;
> pci_write_config_dword(dev, reg + 4, new);
> + dev->saved_config_space[(reg + 4) / 4] = new;
> pci_read_config_dword(dev, reg + 4, &check);
> if (check != new) {
> pci_err(dev, "%s: error updating (high %#010x != %#010x)\n",
> --
> 2.51.0
>
prev parent reply other threads:[~2026-05-01 19:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-15 15:56 [PATCH] PCI: Update saved_config_space upon resource assignment Lukas Wunner
2026-04-16 11:08 ` Ilpo Järvinen
2026-04-16 11:28 ` Lukas Wunner
2026-04-16 12:16 ` Ilpo Järvinen
2026-04-16 12:35 ` Lukas Wunner
2026-04-29 7:25 ` Thorsten Leemhuis
2026-05-01 19:51 ` Bjorn Helgaas [this message]
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=20260501195118.GA516950@bhelgaas \
--to=helgaas@kernel.org \
--cc=1131025@bugs.debian.org \
--cc=alex@shazbot.org \
--cc=an.tech@mailo.com \
--cc=bernd@bschu.de \
--cc=carnil@debian.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-pci@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=mario.limonciello@amd.com \
--cc=rafael@kernel.org \
--cc=regressions@leemhuis.info \
--cc=regressions@lists.linux.dev \
--cc=ukleinek@debian.org \
/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