Re: [PATCH] PCI: Don't report fully optional resources as assignment failures
From: Anthony Pighin
Date: Mon Jul 27 2026 - 15:42:00 EST
v2: https://lore.kernel.org/linux-pci/20260727193714.598562-1-anthony.pighin@xxxxxxxxx/
On Mon, 20 Jul 2026, Ilpo Järvinen wrote:
> This part seems valid, the resource should not be left into enlarged
> state if the assignment fails.
Kept in v2. reassign_resources_sorted() saves the required size and
restores it when the optional attempt fails.
> > + 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.
You're right about the pci_resource_is_optional() check. It also covers
IOV BARs and disabled ROMs, which have a real requested size, so it would
have kept them out of fail_head and killed the release/retry rounds they
depend on. The effect is worse in the root bus path, where a pass failing
only on optional resources would break the loop before the iteration that
passes add_list. v2 drops it and keeps only the zero-size check.
The case where FW left a window too small should still work, though.
pbus_size_mem() sizes the window from the required child resources, so
such a window has a non-zero required size and still reaches fail_head
and the retry round. So does a child BAR that fails to fit. Only a
window with required size 0, where nothing downstream needs that type at
all, is skipped.
reassign_resources_sorted() also still tries the enlarged window where it
always did, so the optional fit is attempted as before; v2 only restores
the size when that attempt fails. What v2 gives up in the size-0 case is
the extra pass, which releases live sibling windows to win headroom
nothing requested.
> 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.
Apologies, v1 omitted it. v2 carries the full sequence. The extra pass
does not fail to assign, it succeeds, and that is the problem. The
failing reserve is on 00:03.5, but pci_prepare_next_assign_round()
releases the window of its parent bus, so every non-prefetchable window
on bus 00 goes with whole_subtree, along with every BAR below them, and
each bridge is reprogrammed right away. The reassignment only covers the
hotplugged bridge, so none of that is restored. 00:03.5 ends up with a
2MB window nothing asked for, and the igb loses its BARs while its driver
is bound.
Thanks,
Anthony