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,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Subject: [PATCH 09/15] PCI: Do not release resources with children in pci_release_resource()
Date: Tue, 1 Dec 2026 17:58:33 +0200 [thread overview]
Message-ID: <20261201155844.2278-10-ilpo.jarvinen@linux.intel.com> (raw)
In-Reply-To: <20261201155844.2278-1-ilpo.jarvinen@linux.intel.com>
pci_release_resource() releases the resource using release_resource()
which detaches the resource from the resource tree together with its
descendants. The descendants remain attached to the released resource
and keep their addresses. Once the resource is assigned elsewhere, the
descendants may end up outside of their parent, corrupting the resource
tree.
None of the callers wants that. pbus_reassign_bridge_resources() only
releases bridge windows that have no children. The BAR resize rollback
releases the children before releasing the resource itself. The BARs
released before BAR resize, however, are released even if they contain
regions requested by a driver, and the resize may then move such a BAR
from underneath those regions.
Use release_leaf_resource() in pci_release_resource() to return -EBUSY
if the resource has children. Remove a BAR that cannot be released from
the saved resources so that the BAR resize rollback leaves it alone, and
fail BAR resize if it is the resized BAR.
pbus_reassign_bridge_resources() checks for children without holding
resource_lock, so a child may still appear before the release. Remove
such a bridge window from the saved resources too so that the rollback
does not release the resources underneath it.
As the release can now fail, log both outcomes.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/pci/setup-bus.c | 10 ++++++++--
drivers/pci/setup-res.c | 12 ++++++++----
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index c1033191571c..e5bbde75337d 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -2330,7 +2330,8 @@ static int pbus_reassign_bridge_resources(struct pci_bus *bus, struct resource *
if (ret)
return ret;
- pci_release_resource(bridge, i);
+ if (pci_release_resource(bridge, i))
+ pci_dev_res_remove_from_list(saved, res);
} else {
const char *res_name = pci_resource_name(bridge, i);
@@ -2412,7 +2413,12 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size
goto restore;
continue;
}
- pci_release_resource(pdev, i);
+ ret = pci_release_resource(pdev, i);
+ if (ret) {
+ pci_dev_res_remove_from_list(&saved, r);
+ if (i == resno)
+ goto restore;
+ }
}
ret = pci_rebar_set_size(pdev, resno, size);
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index 376f09630a4a..1317d645a178 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -472,11 +472,15 @@ int pci_release_resource(struct pci_dev *dev, int resno)
if (!res->parent)
return 0;
- pci_info(dev, "%s %pR: releasing\n", res_name, res);
-
- ret = release_resource(res);
- if (ret)
+ ret = release_leaf_resource(res);
+ if (ret) {
+ pci_info(dev, "%s %pR: can't release; contains resources in use\n",
+ res_name, res);
return ret;
+ }
+
+ pci_info(dev, "%s %pR: released\n", res_name, res);
+
res->end = resource_size(res) - 1;
res->start = 0;
res->flags |= IORESOURCE_UNSET;
--
2.47.3
next prev parent reply other threads:[~2026-12-01 16:00 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 15:58 [PATCH 00/15] PCI: Resource release fixes and improvements Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 01/15] PCI: Release all resources before restoring them in BAR resize rollback Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 02/15] PCI: Set new BAR Size only after releasing the BARs for BAR resize Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 03/15] PCI: Abort BAR resize only if saving the resized BAR fails Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 04/15] PCI: Consistently use Header Type to detect bridge headers Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 05/15] resource: Check that the resource is in the tree when releasing it Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 06/15] resource: Add KUnit test for releasing a resource not in the tree Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 07/15] resource: Add release_leaf_resource() Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 08/15] resource: Add KUnit test for release_leaf_resource() Ilpo Järvinen
2026-12-01 15:58 ` Ilpo Järvinen [this message]
2026-12-01 15:58 ` [PATCH 10/15] resource: Rename next_resource() and for_each_resource() Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 11/15] resource: Make resource_lock and resource tree traversal available Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 12/15] resource: Add release_resource_locked() Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 13/15] PCI: Split pci_resource_post_release() out of pci_release_resource() Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 14/15] PCI: Add iterators for devices and resources in bus windows Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 15/15] PCI: Release only PCI resources when releasing a resource tree Ilpo Järvinen
2026-12-02 0:22 ` 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=20261201155844.2278-10-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=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=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
all inboxes | Powered by JetHome®