From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: "Bjorn Helgaas" <bhelgaas@google.com>,
"Lorenzo Pieralisi" <lorenzo.pieralisi@arm.com>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Wilczyński" <kw@linux.com>,
"Alex Deucher" <alexander.deucher@amd.com>,
"Christian König" <christian.koenig@amd.com>,
"Jani Nikula" <jani.nikula@linux.intel.com>,
"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"Tvrtko Ursulin" <tursulin@ursulin.net>,
"Matthew Brost" <matthew.brost@intel.com>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Michał Winiarski" <michal.winiarski@intel.com>,
"Ville Syrjälä" <ville.syrjala@linux.intel.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
"Anthony Pighin" <anthony.pighin@nokia.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH v2 02/16] PCI: Set new BAR Size only after releasing the BARs for BAR resize
Date: Sat, 5 Dec 2026 02:39:37 +0200 [thread overview]
Message-ID: <20261205003957.3304-3-ilpo.jarvinen@linux.intel.com> (raw)
In-Reply-To: <20261205003957.3304-1-ilpo.jarvinen@linux.intel.com>
pci_do_resource_release_and_resize() sets the new BAR Size before it
saves and releases the BARs that share the bridge window with the BAR
being resized. The BAR Size decides which bits of the Base Address
Register are read-only, so the address in the resized BAR may lose its
low bits right away.
Saving the BARs needs memory allocations, which can fail. If that
happens before the resized BAR has been saved, the BAR resize rollback
restores the old BAR Size but cannot restore the address of the resized
BAR, which leaves the BAR and its resource out of sync.
Nothing requires setting the new BAR Size that early. Set it only after
all the BARs have been saved and released, right before the resource is
resized.
Fixes: 337b1b566db0 ("PCI: Fix restoring BARs on BAR resize rollback path")
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Cc: stable@vger.kernel.org
---
drivers/pci/setup-bus.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index b69041fbbd39..db16c8c2913d 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -2394,10 +2394,6 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size
if (old < 0)
return old;
- ret = pci_rebar_set_size(pdev, resno, size);
- if (ret)
- return ret;
-
down_read(&pci_bus_sem);
pci_dev_for_each_resource(pdev, r, i) {
@@ -2416,12 +2412,16 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size
pci_release_resource(pdev, i);
}
+ ret = pci_rebar_set_size(pdev, resno, size);
+ if (ret)
+ goto restore;
+
pci_resize_resource_set_size(pdev, resno, size);
if (bridge) {
ret = pbus_reassign_bridge_resources(bus, res, &saved);
if (ret)
- goto restore;
+ goto restore_size;
} else {
/* No bridge window to adjust; let the core reassign the bus. */
pci_bus_assign_resources(bus);
@@ -2429,7 +2429,7 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size
list_for_each_entry(dev_res, &saved, list) {
if (!resource_assigned(dev_res->res)) {
ret = -ENOSPC;
- goto restore;
+ goto restore_size;
}
}
}
@@ -2439,7 +2439,7 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size
pci_dev_res_free_list(&saved);
return ret;
-restore:
+restore_size:
/*
* Revert to the old configuration.
*
@@ -2449,6 +2449,7 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size
*/
pci_rebar_set_size(pdev, resno, old);
+restore:
/*
* Release all resources first, otherwise a resource not yet released
* could block restoring another resource into its original place.
--
2.47.3
next prev parent reply other threads:[~2026-12-05 0:40 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261205003957.3304-1-ilpo.jarvinen@linux.intel.com>
2026-12-05 0:39 ` [PATCH v2 01/16] PCI: Release all resources before restoring them in BAR resize rollback Ilpo Järvinen
2026-12-05 0:39 ` Ilpo Järvinen [this message]
2026-12-05 0:39 ` [PATCH v2 03/16] PCI: Abort BAR resize only if saving the resized BAR fails Ilpo Järvinen
2026-12-05 1:04 ` sashiko-bot
2026-12-05 1:25 ` Ilpo Järvinen
2026-12-05 0:39 ` [PATCH v2 04/16] PCI: Consistently use Header Type to detect bridge headers Ilpo Järvinen
2026-12-05 1:04 ` sashiko-bot
2026-12-05 0:39 ` [PATCH v2 09/16] PCI: Do not release resources with children in pci_release_resource() Ilpo Järvinen
2026-12-05 1:04 ` sashiko-bot
2026-12-05 1:29 ` Ilpo Järvinen
2026-12-05 0:39 ` [PATCH v2 13/16] PCI: Split pci_resource_post_release() out of pci_release_resource() Ilpo Järvinen
2026-12-05 0:39 ` [PATCH v2 14/16] PCI: Add iterators for devices and resources in bus windows Ilpo Järvinen
2026-12-05 1:02 ` sashiko-bot
2026-12-05 1:12 ` Ilpo Järvinen
2026-12-05 0:39 ` [PATCH v2 15/16] PCI: Keep the range of fixed resources when releasing them Ilpo Järvinen
2026-12-05 0:39 ` [PATCH v2 16/16] PCI: Release only PCI resources when releasing a resource tree Ilpo Järvinen
2026-12-05 1:11 ` sashiko-bot
2026-12-05 1:57 ` 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=20261205003957.3304-3-ilpo.jarvinen@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=anthony.pighin@nokia.com \
--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=kw@linux.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=matthew.brost@intel.com \
--cc=michal.winiarski@intel.com \
--cc=robh@kernel.org \
--cc=rodrigo.vivi@intel.com \
--cc=simona@ffwll.ch \
--cc=stable@vger.kernel.org \
--cc=thomas.hellstrom@linux.intel.com \
--cc=tursulin@ursulin.net \
--cc=ville.syrjala@linux.intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox