Linux PCI subsystem development
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Anthony Pighin <anthony.pighin@nokia.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	linux-pci@vger.kernel.org,  LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] PCI: Don't report fully optional resources as assignment failures
Date: Mon, 20 Jul 2026 16:21:40 +0300 (EEST)	[thread overview]
Message-ID: <0d249665-2d76-7609-f78b-71ec1a94b507@linux.intel.com> (raw)
In-Reply-To: <20260717180029.1829888-1-anthony.pighin@nokia.com>

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@vger.kernel.org
> Signed-off-by: Anthony Pighin <anthony.pighin@nokia.com>
> ---
>  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.


      parent reply	other threads:[~2026-07-20 13:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17 18:00 [PATCH] PCI: Don't report fully optional resources as assignment failures Anthony Pighin
2026-07-17 18:13 ` sashiko-bot
2026-07-20 13:21 ` Ilpo Järvinen [this message]

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=0d249665-2d76-7609-f78b-71ec1a94b507@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=anthony.pighin@nokia.com \
    --cc=bhelgaas@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --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