mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Greg Lamberson <greg@lamco.io>
Cc: "Bjorn Helgaas" <bhelgaas@google.com>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	linux-pci@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
	regressions@lists.linux.dev
Subject: Re: [PATCH] PCI: Don't move a window's start when it holds a non-power-of-2 resource
Date: Wed, 2 Dec 2026 14:48:53 +0200 (EET)	[thread overview]
Message-ID: <14697f43-d43b-886d-7cc9-36f96c3f100d@linux.intel.com> (raw)
In-Reply-To: <179619168710.49678.17788537403657229665@lamco.io>

On Wed, 2 Dec 2026, Greg Lamberson wrote:

> pci_align_resource() moves a bridge window's start down by the part of
> its size that isn't a multiple of its alignment, so the smaller
> resources can fill the space before the first aligned address. That
> relies on every resource below the window having a power-of-2 size. An
> IOV resource is the VF BAR size times TotalVFs, which isn't a power of 2
> unless TotalVFs is.
> 
> On an Intel Arc Pro B60, BAR 2 is 32 GiB and each of the seven VF BAR 2s
> is 8 GiB, so the window needs 88 GiB plus 128 MiB, aligned to 32 GiB.
> Its start is moved down by 24 GiB plus 128 MiB, BAR 2 is placed at the
> lowest 32 GiB boundary in the window, and the 56 GiB IOV resource then
> fits neither below nor above it. Since v7.1, enabling SR-IOV fails:
> 
>   xe 0000:03:00.0: not enough MMIO resources for SR-IOV
>   xe 0000:03:00.0: [drm] PF: Failed to enable 5 VFs (-ENOMEM)
> 
> Keep the aligned start for a window that holds a resource whose size
> isn't a power of 2, directly or behind child bridges.
> 
> Fixes: 9036bd0efcb6 ("PCI: Align head space better")
> Cc: stable@vger.kernel.org # v7.1+
> Signed-off-by: Greg Lamberson <greg@lamco.io>
> ---
> I tested this on Proxmox's 7.3.5 kernel with the patch applied, on an
> AMD Raphael board with the B60 behind the card's own switch. With the
> patch, VF BAR 2 is assigned at the same address v7.0 gives it and all
> five VFs come up. Without it, the same kernel logs the two lines above.
> I haven't booted pci/next or mainline on that machine. The patch
> applies cleanly to both, and setup-res.c builds with W=1 on pci/next
> without warnings.
> 
> I used Claude (claude-opus-5-5) to trace the cause and write this
> patch. I've reviewed the change and tested it on the affected machine.

Hi,

Have you tested if the PCI resource placement generalization series v5 
fixes your problem:

https://lore.kernel.org/linux-pci/20261106134341.39493-1-ilpo.jarvinen@linux.intel.com/

--
 i.

>  drivers/pci/setup-res.c | 50 +++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 50 insertions(+)
> 
> diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
> index 376f09630a4a..8b2b6d5ef5ed 100644
> --- a/drivers/pci/setup-res.c
> +++ b/drivers/pci/setup-res.c
> @@ -260,10 +260,49 @@ resource_size_t pci_resource_alignment(const struct pci_dev *dev,
>  	return resource_alignment(res);
>  }
>  
> +/*
> + * Whether @win of @bus->self holds, directly or behind child bridges, a
> + * resource whose size isn't a power of 2. An IOV resource is the VF BAR size
> + * times TotalVFs, so it's a power of 2 only when TotalVFs is.
> + */
> +static bool pbus_window_holds_npot(struct pci_bus *bus,
> +				   const struct resource *win)
> +{
> +	struct pci_dev *dev;
> +
> +	list_for_each_entry(dev, &bus->devices, bus_list) {
> +		struct resource *r;
> +		int i;
> +
> +		pci_dev_for_each_resource(dev, r, i) {
> +			if (!r->flags || (r->flags & IORESOURCE_DISABLED) ||
> +			    !resource_size(r))
> +				continue;
> +			if (pbus_select_window(bus, r) != win)
> +				continue;
> +			if (pci_resource_is_bridge_win(i)) {
> +				if (dev->subordinate &&
> +				    pbus_window_holds_npot(dev->subordinate, r))
> +					return true;
> +				continue;
> +			}
> +			if (!is_power_of_2(resource_size(r)))
> +				return true;
> +		}
> +	}
> +
> +	return false;
> +}
> +
>  /*
>   * For mem bridge windows, try to relocate tail remainder space to space
>   * before res->start if there's enough free space there. This enables
>   * tighter packing for resources.
> + *
> + * The head can only be filled when every resource below the window has a
> + * power-of-2 size. A resource that isn't one may be larger than the head and
> + * still need its own alignment, so a window holding one keeps its aligned
> + * start.
>   */
>  resource_size_t pci_align_resource(struct pci_dev *dev,
>  				   const struct resource *res,
> @@ -290,6 +329,17 @@ resource_size_t pci_align_resource(struct pci_dev *dev,
>  	if (empty_res->start > start_addr)
>  		return res->start;
>  
> +	/*
> +	 * @res is the allocator's copy of the window, so find the window itself
> +	 * among the bridge's resources by type.
> +	 */
> +	if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE && dev->subordinate &&
> +	    pbus_window_holds_npot(dev->subordinate,
> +				   pci_resource_n(dev, res->flags & IORESOURCE_PREFETCH ?
> +						  PCI_BRIDGE_PREF_MEM_WINDOW :
> +						  PCI_BRIDGE_MEM_WINDOW)))
> +		return res->start;
> +
>  	pci_dbg(dev, "%pR: moving candidate start address below align to %llx\n",
>  		res, (unsigned long long)start_addr);
>  	return start_addr;
> 

-- 
 i.


      reply	other threads:[~2026-12-02 12:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  6:08 Greg Lamberson
2026-12-02 12:48 ` 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=14697f43-d43b-886d-7cc9-36f96c3f100d@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=bhelgaas@google.com \
    --cc=greg@lamco.io \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=regressions@lists.linux.dev \
    /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®