public inbox for linux-pci@vger.kernel.org
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Geramy Loveless <gloveless@jqluv.com>
Cc: linux-pci@vger.kernel.org, cristi@ieee.org
Subject: Re: [PATCH] PCI: release empty sibling resources during bridge window resize
Date: Thu, 9 Apr 2026 16:26:43 +0300 (EEST)	[thread overview]
Message-ID: <f2cf6508-e2e8-d567-66f3-51b094585434@linux.intel.com> (raw)
In-Reply-To: <CAGpo2mcyLhY6muz9Zgg3zD=Ux-HT8RXeMvbUi27a+SX=VxCRPQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 5983 bytes --]

On Thu, 9 Apr 2026, Geramy Loveless wrote:

> Perfect I’ll get started on these changes, while I’m here, does the other bug create
> a cascade of problems if fixed? 

Hi,

I'm not sure what "other bug" refers to?

If you meant Cristian problem, he seemed to have empty bridge windows 
which this approach should be able to solve without extra problems 
expected.

If you refer to the resource entries having dangling resource tree 
pointers (sibling, etc.), it's not a big problem when the resource entry 
has been detached from the tree. It has some impact on whether 
resource_assigned() can always be trusted so it would be nice to clear all 
those links on removal (the current remove algorithm shortcuts the 
subtree).

-- 
 i.

> On Thu, Apr 9, 2026 at 1:03 AM Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> wrote:
>       On Wed, 8 Apr 2026, Geramy Loveless wrote:
> 
>       Thanks for the patch. The patch need some work but the general direction
>       looks acceptable.
> 
>       FYI, your patch is misformatted, tabs got eaten, probably something in
>       tha way you send the email does that.
> 
>       Please Cc also Cristian Cocos <cristi@ieee.org> on further submissions.
> 
>       > When pci_resize_resource() walks up the bridge hierarchy via
>       > pbus_reassign_bridge_resources(), bridge windows with any child
>       > resources are refused release. This prevents BAR resize on devices
>       > behind multi-port PCIe switches (such as Thunderbolt docks) where
>       > empty sibling downstream ports hold small reservations that block the
>       > parent bridge window from being freed and re-sized.
>       >
>       > Add pci_bus_release_bridge_resources_safe() which verifies that a
>       > resource subtree contains no active children before releasing it,
>       > and use it in pbus_reassign_bridge_resources() to clear empty sibling
>       > reservations so the bridge window can grow.
>       >
>       > Signed-off-by: Geramy Loveless <gloveless@jqluv.com>
> 
>       You may want to add Suggested-by tag.
> 
>       > ---
>       > drivers/pci/setup-bus.c | 30 +++++++++++++++++++++++++++---
>       > 1 file changed, 27 insertions(+), 3 deletions(-)
>       >
>       > diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
>       > index 4cf120ebe..9a3a23819 100644
>       > --- a/drivers/pci/setup-bus.c
>       > +++ b/drivers/pci/setup-bus.c
>       > @@ -2297,6 +2297,30 @@
>       > EXPORT_SYMBOL_GPL(pci_assign_unassigned_bridge_resources);
>       > * release it when possible. If the bridge window contains assigned
>       > * resources, it cannot be released.
>       > */
>       > +
>       > +/*
>       > + * Release child resources from a bridge window so it can be freed and
>       > + * re-sized, but only if the entire subtree is empty (no active device
>       > + * resources underneath). Walks the resource tree recursively to
>       handle
>       > + * arbitrarily deep bridge hierarchies. Returns true if the resources
>       > + * were released or the window was already empty.
>       > + */
>       > +static bool pci_bus_release_bridge_resources_safe(struct pci_bus *bus,
>       > + struct resource *res)
>       > +{
>       > + struct resource *child;
>       > +
>       > + for (child = res->child; child; child = child->sibling) {
>       > + if (child->child &&
>       > + !pci_bus_release_bridge_resources_safe(bus, child))
>       > + return false;
> 
>       This should walk bus devices and device resources using PCI side
>       iterators (not using the low-level resource list). This does not look
>       safe iteration anyway because the code is also removing entries from the
>       resource tree (it only works because resource code leaves stale sibling
>       pointers which should be corrected one day).
> 
>       PCI side should be enough to capture all resources, and that way you
>       still have access to all PCI side structs.
> 
>       Perhaps sanity checking ! ->child at the end wouldn't hurt but it the
>       release should be doable.
> 
>       You should also pass the saved list and store any released resources so
>       you can properly rollback in case of a failure (I think the rollback
>       code will already just-work as long as you add the entries there).
> 
>       > + }
>       > +
>       > + if (res->child)
>       > + pci_bus_release_bridge_resources(bus, res, whole_subtree);
> 
>       I think this could pass non-bridge window resources which looks wrong but
>       you need to rewrite the algorithm in this function anyway.
> 
>       > + return true;
>       > +}
>       > +
>       > static int pbus_reassign_bridge_resources(struct pci_bus *bus, struct
>       > resource *res,
>       > struct list_head *saved)
>       > {
>       > @@ -2316,8 +2340,8 @@ static int pbus_reassign_bridge_resources(struct
>       > pci_bus *bus, struct resource *
>       > i = pci_resource_num(bridge, res);
>       > - /* Ignore BARs which are still in use */
>       > - if (!res->child) {
>       > + if (!res->child ||
>       > + pci_bus_release_bridge_resources_safe(bridge->subordinate, res)) {
> 
>       Just call this release always before checking !res->child.
> 
>       You need to check bridge->subordinate before calling it.
> 
>       > ret = pci_dev_res_add_to_list(saved, bridge, res, 0, 0);
>       > if (ret)
>       > return ret;
>       > @@ -2327,7 +2351,7 @@ static int pbus_reassign_bridge_resources(struct
>       > pci_bus *bus, struct resource *
>       > const char *res_name = pci_resource_name(bridge, i);
>       > pci_warn(bridge,
>       > - "%s %pR: was not released (still contains assigned resources)\n",
>       > + "%s %pR: not released, active children present\n",
>       > res_name, res);
>       > }
>       >
> 
>       --
>        i.
> 
> 
> 

  parent reply	other threads:[~2026-04-09 13:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-08 22:31 [PATCH] PCI: release empty sibling resources during bridge window resize Geramy Loveless
2026-04-09  8:03 ` Ilpo Järvinen
     [not found]   ` <CAGpo2mcyLhY6muz9Zgg3zD=Ux-HT8RXeMvbUi27a+SX=VxCRPQ@mail.gmail.com>
2026-04-09 13:26     ` Ilpo Järvinen [this message]
2026-04-09 19:32       ` Cristian Cocos
2026-04-10  5:26         ` [PATCH v2] PCI: release empty sibling bridge windows during rebar expansion Geramy Loveless
2026-04-10 10:09           ` Ilpo Järvinen
2026-04-10 17:53             ` Geramy Loveless

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=f2cf6508-e2e8-d567-66f3-51b094585434@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=cristi@ieee.org \
    --cc=gloveless@jqluv.com \
    --cc=linux-pci@vger.kernel.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