Re: [PATCH] PCI: Don't report fully optional resources as assignment failures

From: Ilpo Järvinen

Date: Mon Jul 20 2026 - 10:03:21 EST


On Fri, 17 Jul 2026, Anthony Pighin wrote:

> A hotplug bridge may request a window with required size 0 plus
> add_size headroom. For example, the PCI core speculatively requests
> a non-prefetchable MMIO reserve for a hotplug bridge even when no
> downstream BAR currently requires that space.
>
> reassign_resources_sorted() temporarily grows an unassigned resource
> from its required size to the required size plus add_size. If
> pci_assign_resource() fails, the failure is ignored because the
> additional space is optional, but the resource is left unassigned at
> the enlarged size.
>
> Since commit 96336ec70264 ("PCI: Perform reset_resource() and build
> fail list in sync") and commit 2499f5348431 ("PCI: Rework optional
> resource handling"), the __assign_resources_sorted() out path
> unconditionally adds every remaining unassigned resource to fail_head.
> The headroom-enlarged window is therefore reported as though a required
> resource failed.
>
> pci_assign_unassigned_bridge_resources() interprets the non-empty
> fail_head as grounds for another assignment round and releases bridge
> windows with whole_subtree. On a system whose < 4GB root-bus MMIO
> aperture was already fully allocated, hotplugging an endpoint that
> required only a 64-bit prefetchable BAR produced:
>
> pcieport 0000:00:03.3: bridge window [mem size 0x00000000] add_size 200000
> pcieport 0000:00:03.3: bridge window [mem size 0x00200000]: failed to assign
> PCI: No. 2 try to assign unassigned res
> pcieport 0000:00:01.3: bridge window [mem 0xe6800000-0xe68fffff]: releasing
> igb 0000:02:00.0 mgmt: PCIe link lost
>
> The endpoint's required prefetchable BAR had already been assigned; only
> the non-prefetchable hotplug reserve had failed. Releasing the sibling
> bridge window removed MMIO from the active igb device.
>
> Save the required size before attempting the optional allocation and
> restore it when that allocation fails. A fully optional bridge window
> is then left at size 0. In the __assign_resources_sorted() out path,
> only report unassigned resources that have non-zero size and are not
> otherwise optional. A zero-sized resource has no required part and
> does not represent a required failure.
>
> This leaves the speculative reserve unassigned without triggering
> another assignment round. Required resource failures continue to be
> reported and retried as before.
>
> Fixes: 96336ec70264 ("PCI: Perform reset_resource() and build fail list in sync")
> Fixes: 2499f5348431 ("PCI: Rework optional resource handling")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Anthony Pighin <anthony.pighin@xxxxxxxxx>
> ---
> drivers/pci/setup-bus.c | 19 ++++++++++++++++---
> 1 file changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
> index c0a949f2c995..c16f0a5f9456 100644
> --- a/drivers/pci/setup-bus.c
> +++ b/drivers/pci/setup-bus.c
> @@ -450,12 +450,19 @@ static void reassign_resources_sorted(struct list_head *realloc_head,
> add_size = add_res->add_size;
> align = add_res->min_align;
> if (!resource_assigned(res)) {
> - resource_set_range(res, align,
> - resource_size(res) + add_size);
> + resource_size_t req_size = resource_size(res);
> +
> + resource_set_range(res, align, req_size + add_size);
> if (pci_assign_resource(dev, idx)) {
> pci_dbg(dev,
> "%s %pR: ignoring failure in optional allocation\n",
> res_name, res);
> + /*
> + * Restore the required size so a fully optional
> + * resource is left zero-sized and not later
> + * mistaken for a required failure.
> + */
> + resource_set_range(res, align, req_size);

This part seems valid, the resource should not be left into enlarged
state if the assignment fails.

> }
> } else if (add_size > 0 || !IS_ALIGNED(res->start, align)) {
> res->flags |= add_res->flags &
> @@ -743,7 +750,13 @@ static void __assign_resources_sorted(struct list_head *head,
> if (resource_assigned(res))
> continue;
>
> - if (fail_head) {
> + /*
> + * Report only required failures. Skip optional and
> + * zero-sized resources; reporting them would trigger
> + * another release/retry round.
> + */
> + if (fail_head && resource_size(res) &&
> + !pci_resource_is_optional(dev, pci_resource_num(dev, res))) {

This, however, will break some cases I think.

We first want to try fitting also optional resources, if those optional
resources never go into fail_head, there won't be new pass and not enough
upstream bridge windows will be released so the algorithm won't really end
up even trying to fit the optional resources after this change if FW left
some bridge window too small.

Only after that has been tried, it should try to fallback into fitting
only required resources.

So, I think some other solution should be created to solve your issue.
I don't even know what that issue is since you don't show what happens
with the extra pass after release and why it fails.

--
i.