From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Geramy Loveless <gloveless@jqluv.com>
Cc: "Bjorn Helgaas" <bhelgaas@google.com>,
alexander.deucher@amd.com, amd-gfx@lists.freedesktop.org,
mario.limonciello@amd.com, nra3088@gmail.com,
"Christian König" <christian.koenig@amd.com>,
meiling.leung@embeddedllm.com, linux-pci@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] PCI: Reserve prefetchable window headroom for Resizable BARs
Date: Mon, 31 Aug 2026 21:47:41 +0300 (EEST) [thread overview]
Message-ID: <034f9ce3-3c50-b0f2-8ac7-e6180242de00@linux.intel.com> (raw)
In-Reply-To: <7771e88e-9cdf-4415-97ac-69d15c015d1e@jqluv.com>
[-- Attachment #1: Type: text/plain, Size: 5828 bytes --]
On Mon, 31 Aug 2026, Geramy Loveless wrote:
>
> On 8/31/26 9:31 AM, Ilpo Järvinen wrote:
> > On Fri, 28 Aug 2026, Geramy Loveless wrote:
> >
> >> Firmware typically sizes prefetchable bridge windows for the boot-time
> >> BAR size. Behind a fixed (non-hotplug) PCIe switch fabric, there is then
> >> no room for a driver to grow a Resizable BAR afterwards: every window
> >> from the leaf up to the root is sized for the small BAR, so
> >> pci_resize_resource() fails with -ENOSPC.
> >>
> >> Furthermore, a small prefetchable BAR (e.g., a 2 MiB doorbell) sharing a
> >> bridge's single prefetchable window with a much larger one (e.g., a 32 GiB
> >> VRAM BAR) pushes the required window size past the large BAR's alignment.
> >> Because bridge windows round up to a power of two,
> > Do they??? In which kernel version I must ask??
> I'm sorry this was in reference to a prior patch I made, **ignore**
> >
> >> this forces a massive
> >> alignment waste (e.g., 32 GiB + 2 MiB rounds up to a 64 GiB window,
> >> wasting ~32 GiB per GPU).
> > The largest I've seen is 32GB + half of that. And that's not with the
> > latest kernel.
>
> This is in reference to when there are two R9700s on one switch basically.
> As far as my understanding currently how it works is that when there are two GPUs they both have a BAR0, BAR2, and BAR5 the BAR5 goes onto the 32-bit window.
> Bar 0 and 2 don't go onto the second window by default as they could overfill it of course, bar 0 would not fit period, and 2 might which is the case I took.
> This allows BAR 0 on (GPU 0) in leaf 0 on window 0 to align as a multiple of 32G like it I guess has to? This is how I understand it, so if R9700 has 32G on, bar0, leaf 0, window 0, and share the same window as GPU 1 then we have to pad the space between GPU0 BARs on window 0 by 32G, meaning BAR2 really is also using 32G, its not possible or at least right now its not possible to move BAR2 to the end of all the allocations it doesnt fit the standards? Keep in mind this is not my specialty here I am trying my best to understand and solve the issue at hand.
With the empty space in between, your 64GB calculation would indeed be
true, but that wasn't what you said because you made an inaccurate claim
about window sizes being power of two in case of 32G+2M.
(I suppose we're generally in agreement here but just ended up discussion
on finer details and the interpretation of those details.)
> >> This patch solves both issues to enable ReBAR on cascaded switch fabrics:
> >>
> >> 1. Reserve Headroom:
> >> Reserve prefetchable window headroom for the maximum size of each
> >> downstream Resizable BAR during the bridge sizing pass. The device BAR
> >> and hardware ReBAR are left at their boot size to prevent tearing down
> >> firmware-loaded state (e.g., AMD R9700 PSP) before the driver binds.
> > ... reorganizing ...
> >
> >> Fallback / Alignment logic:
> >> If the 32-bit space is exhausted, small BARs remain in the prefetchable
> >> window. The alignment logic gracefully handles this by rounding the bridge
> >> window up to the next power of two (e.g., growing to 64 GiB to fit a 32 GiB
> >> BAR + BAR2) to maintain PCIe compatibility, ensuring sibling GPUs land in
> >> properly aligned slots.
> >>
> >> Reserving is safe by default: __assign_resources_sorted() satisfies all
> >> required resources first. Use pci=no_rebar_reserve and pci=no_bar_demote
> >> to restore previous behaviours.
> >
> > And how does this fallback, if the largest size doesn't fit? What are the
> > failure modes?
>
> So if the smaller bars under 16M don't fit in the 32-bit addressable
> space the fallback mode is to do as I said above to your prior comment,
> basically put.
> Don't move the 2M BAR2 over to the 32-bit addressable space / window and
> instead fallback to aligning the prior window by the size of the GPUs
> memory space as I understand it, when you have gpu0 and gpu1 both
> requiring 32GB their address has to be a multiple of their allocation
> size? meaning we get 32G for BAR0 and 32G for BAR2 even though BAR2 only
> needs 2M because its not aligned to allow GPU1 to be on a aligned space?
I'm more referring to the case where the big ReBARs cannot be assigned as
space runs out or some other BAR fails to assign because ReBAR took "too
much", and the numerous ripple effects from that. When that happens in
some system for something important breaking something, you'd have to
solve that problem too or this change gets reverted...
> > It's correct that the sizing decision should be done in pbus_size_mem()
> > but it must not result in breaking things which a naive approach like
> > this will surely do.
> >
> > Without proper fallbacks done, there will be too much breakage it's a
> > showstopper for a naive patch like this.
> >
> > Basically, what we'd want to do is try with the largest size, then reduce
> > it one step at a time (because it's 2^n -> 2^(n-1) even one step saves
> > quite much so one might not need to reduce that many steps). But also, in
> > some IOV enabled cases the oversubscription of the space is very
> > substantial and you'd still want to maximize the BAR sizes to what is
> > allowed by the available space.
> >
> > Fallback is hard to implement, because sizing and assignment are quite far
> > from each other codewise and there are no structures to carry information
> > over to the next retry phase.
...And that's why there should be proper fallback so that failing one
assignment somewhere middle will not result in failure in the end.
Basically, my own plan is for the algorithm to try smaller sizes until all
things fit. And all that retry logic is far from simple.
--
i.
prev parent reply other threads:[~2026-09-01 7:59 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 21:37 [PATCH] PCI: Reserve prefetchable window headroom for Resizable BARs Geramy Loveless
2026-08-31 7:49 ` Christian König
2026-08-31 16:58 ` Ilpo Järvinen
2026-08-31 17:49 ` Geramy Loveless
2026-08-31 18:07 ` Christian König
2026-08-31 18:19 ` Mario Limonciello
2026-08-31 18:32 ` Ilpo Järvinen
2026-08-31 17:52 ` Christian König
2026-08-31 17:55 ` Mario Limonciello
2026-08-31 16:31 ` Ilpo Järvinen
2026-08-31 17:40 ` Geramy Loveless
2026-08-31 18:47 ` 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=034f9ce3-3c50-b0f2-8ac7-e6180242de00@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=bhelgaas@google.com \
--cc=christian.koenig@amd.com \
--cc=gloveless@jqluv.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=meiling.leung@embeddedllm.com \
--cc=nra3088@gmail.com \
/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