From: sashiko-bot@kernel.org
To: "Greg Lamberson" <greg@lamco.io>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v2] PCI: Don't move a window's start when it holds a non-power-of-2 resource
Date: Wed, 02 Dec 2026 12:27:04 +0000 [thread overview]
Message-ID: <sashiko-outbox-245718@kernel.org> (raw)
In-Reply-To: <179621321433.1105012.12699444202985653339@lamco.io>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] PCI: pbus_window_holds_npot() ignores non-power-of-2 child
bridge window size
--
commit eb9639b607c547d4e76987d498e27e3b03a3d942
Author: Greg Lamberson <greg@lamco.io>
PCI: Don't move a window's start when it holds a non-power-of-2 resource
This commit keeps the aligned start address in pci_align_resource() for a
bridge window that holds a resource with a non-power-of-2 size directly
or behind child bridges.
> diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
> index 376f09630a4ab..5c86a680db89f 100644
> --- a/drivers/pci/setup-res.c
> +++ b/drivers/pci/setup-res.c
> @@ -260,10 +260,60 @@ 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) {
> + resource_size_t size;
> +
> + if (!r->flags || (r->flags & IORESOURCE_DISABLED))
> + continue;
> + if (pbus_select_window(bus, r) != win)
> + continue;
> + /*
> + * A child window that holds only optional resources,
> + * such as SR-IOV BARs, has size 0 until its own bus is
> + * assigned, so look behind it whatever its size.
> + */
> + if (pci_resource_is_bridge_win(i)) {
> + if (dev->subordinate &&
> + pbus_window_holds_npot(dev->subordinate, r))
> + return true;
> + continue;
> + }
> + /*
> + * is_power_of_2() takes an unsigned long, which would
> + * truncate a 64-bit resource_size_t on 32-bit kernels.
> + */
> + size = resource_size(r);
> + if (size & (size - 1))
> + return true;
> + }
> + }
[Severity: Medium]
Does skipping the size & (size - 1) check on a child bridge window r when
pci_resource_is_bridge_win(i) is true leave the parent window susceptible
to the same splitting failure?
A child bridge window is allocated as a single contiguous resource inside
the parent window, and its total size need not be a power of 2 even when
every leaf BAR behind it is (for example, two 16 GiB BARs and an 8 GiB
BAR give a 40 GiB child window aligned to 8 GiB). Because r_size > align
for that child window, pbus_size_mem() excludes it from aligns[]:
drivers/pci/setup-bus.c:pbus_size_mem() {
...
if (r_size <= align)
aligns[order] += align;
...
}
If the parent bus also has a 32 GiB sibling BAR, the parent window is
sized to 72 GiB aligned to 32 GiB. When pbus_window_holds_npot() returns
false for the parent window, pci_align_resource() shifts the parent start
down by 8 GiB, and placing the 32 GiB sibling BAR at the first 32 GiB
boundary splits the parent window into 8 GiB head and 32 GiB tail
segments, neither of which can fit the 40 GiB child bridge window.
Note that checking size & (size - 1) on child bridge windows inside
pbus_window_holds_npot() only constrains parent windows containing a
child bridge window; a leaf bridge window is not a child of itself, so
relocating a leaf window that holds multiple power-of-2 BARs remains
unaffected.
--
Sashiko AI review · https://sashiko.dev/#/patchset/179621321433.1105012.12699444202985653339@lamco.io?part=1
prev parent reply other threads:[~2026-12-02 12:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 12:06 [PATCH v2] PCI: Don't move a window's start when it holds a non-power-of-2 resource Greg Lamberson
2026-12-02 12:27 ` sashiko-bot [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=sashiko-outbox-245718@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=greg@lamco.io \
--cc=linux-pci@vger.kernel.org \
--cc=sashiko-reviews@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.