From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: "Alex Bennée" <alex.bennee@linaro.org>,
"Simon Richter" <Simon.Richter@hogyros.de>,
"Lucas De Marchi" <lucas.demarchi@intel.com>,
"Alex Deucher" <alexander.deucher@amd.com>,
amd-gfx@lists.freedesktop.org,
"Bjorn Helgaas" <bhelgaas@google.com>,
"David Airlie" <airlied@gmail.com>,
dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
intel-xe@lists.freedesktop.org,
"Jani Nikula" <jani.nikula@linux.intel.com>,
"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
linux-pci@vger.kernel.org,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Tvrtko Ursulin" <tursulin@ursulin.net>,
"Christian König" <christian.koenig@amd.com>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Michał Winiarski" <michal.winiarski@intel.com>,
linux-kernel@vger.kernel.org
Cc: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Subject: [PATCH 1/9] PCI: Prevent resource tree corruption when BAR resize fails
Date: Tue, 28 Oct 2025 19:35:43 +0200 [thread overview]
Message-ID: <20251028173551.22578-2-ilpo.jarvinen@linux.intel.com> (raw)
In-Reply-To: <20251028173551.22578-1-ilpo.jarvinen@linux.intel.com>
pbus_reassign_bridge_resources() saves bridge windows into the saved
list before attempting to adjust resource assignments to perform a BAR
resize operation. If resource adjustments cannot be completed fully,
rollback is attempted by restoring the resource from the saved list.
The rollback, however, does not check whether the resources it restores were
assigned by the partial resize attempt. If restore changes addresses of the
resource, it can result in corrupting the resource tree.
An example of a corrupted resource tree with overlapping addresses:
6200000000000-6203fbfffffff : pciex@620c3c0000000
6200000000000-6203fbff0ffff : PCI Bus 0030:01
6200020000000-62000207fffff : 0030:01:00.0
6200000000000-6203fbff0ffff : PCI Bus 0030:02
A resource that are assigned into the resource tree must remain
unchanged. Thus, release such a resource before attempting to restore
and claim it back.
For simplicity, always do the release and claim back for the resource
even in the cases where it is restored to the same address range.
Note: this fix may "break" some cases where devices "worked" because
the resource tree corruption allowed address space double counting to
fit more resource than what can now be assigned without double
counting. The upcoming changes to BAR resizing should address those
scenarios (to the extent possible).
Fixes: 8bb705e3e79d ("PCI: Add pci_resize_resource() for resizing BARs")
Reported-by: Simon Richter <Simon.Richter@hogyros.de>
Reported-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/pci/setup-bus.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 4a8735b275e4..e6984bb530ae 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -2504,6 +2504,11 @@ int pbus_reassign_bridge_resources(struct pci_bus *bus, struct resource *res)
bridge = dev_res->dev;
i = pci_resource_num(bridge, res);
+ if (res->parent) {
+ release_child_resources(res);
+ pci_release_resource(bridge, i);
+ }
+
restore_dev_resource(dev_res);
pci_claim_resource(bridge, i);
--
2.39.5
next prev parent reply other threads:[~2025-10-28 17:36 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-28 17:35 [PATCH 0/9] PCI: BAR resizing fix/rework Ilpo Järvinen
2025-10-28 17:35 ` Ilpo Järvinen [this message]
2025-10-29 23:36 ` [PATCH 1/9] PCI: Prevent resource tree corruption when BAR resize fails Bjorn Helgaas
2025-10-30 8:22 ` Ilpo Järvinen
2025-11-10 22:59 ` Bjorn Helgaas
2025-10-28 17:35 ` [PATCH 2/9] PCI/IOV: Adjust ->barsz[] when changing BAR size Ilpo Järvinen
2025-11-13 16:29 ` Bjorn Helgaas
2025-11-13 16:35 ` Ilpo Järvinen
2025-11-13 16:57 ` Bjorn Helgaas
2025-11-13 21:02 ` Bjorn Helgaas
2025-10-28 17:35 ` [PATCH 3/9] PCI: Change pci_dev variable from 'bridge' to 'dev' Ilpo Järvinen
2025-10-28 17:35 ` [PATCH 4/9] PCI: Try BAR resize even when no window was released Ilpo Järvinen
2025-10-28 17:35 ` [PATCH 5/9] PCI: Fix restoring BARs on BAR resize rollback path Ilpo Järvinen
2025-10-28 17:35 ` [PATCH 6/9] drm/xe: Remove driver side BAR release before resize Ilpo Järvinen
2025-10-28 21:24 ` Lucas De Marchi
2025-10-30 14:37 ` Lucas De Marchi
2025-10-28 17:35 ` [PATCH 7/9] drm/i915: " Ilpo Järvinen
2025-11-10 22:53 ` Bjorn Helgaas
2025-10-28 17:35 ` [PATCH 8/9] drm/amdgpu: " Ilpo Järvinen
2025-11-10 22:54 ` Bjorn Helgaas
2025-11-11 9:08 ` Christian König
2025-11-11 11:08 ` Ilpo Järvinen
2025-11-11 12:08 ` Christian König
2025-11-11 12:56 ` Ilpo Järvinen
2025-11-11 15:07 ` Christian König
2025-11-11 15:52 ` Ilpo Järvinen
2025-11-11 23:30 ` Liu, Monk
2025-10-28 17:35 ` [PATCH 9/9] PCI: Prevent restoring assigned resources Ilpo Järvinen
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=20251028173551.22578-2-ilpo.jarvinen@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=Simon.Richter@hogyros.de \
--cc=airlied@gmail.com \
--cc=alex.bennee@linaro.org \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=bhelgaas@google.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lucas.demarchi@intel.com \
--cc=michal.winiarski@intel.com \
--cc=rodrigo.vivi@intel.com \
--cc=simona@ffwll.ch \
--cc=thomas.hellstrom@linux.intel.com \
--cc=tursulin@ursulin.net \
/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