All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	linux-pci@vger.kernel.org
Subject: Re: [PATCH v3 4/8] PCI: Fix nesting windows with remainder at the left edge
Date: Tue, 13 Oct 2026 13:25:22 +0000	[thread overview]
Message-ID: <sashiko-outbox-169804@kernel.org> (raw)
In-Reply-To: <20261013130948.6231-5-ilpo.jarvinen@linux.intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] pci: uninitialized variable causes random bypass of remainder logic
--

commit d763cceb79214019a0738e421be1a8a6485d37bc
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

PCI: Fix nesting windows with remainder at the left edge

If a bridge window has its non-aligning remainder at the left edge of
the window, assigning a nested bridge window of same size will fail
because resource side code will only allow starting a candicate range
from an aligning address. In such case, aligned address is somewhere in
the middle, not at the left edge of the window. Since the entire
available space is required for full-sized nested bridge window,
resource side code rejects the free space.

> diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
> index 441a62807719d..2ca3784aa323f 100644
> --- a/drivers/pci/setup-res.c
> +++ b/drivers/pci/setup-res.c
[ ... ]
> @@ -324,9 +366,17 @@ static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev,
>  	int ret;
>  
>  	pci_init_pci_resreq_data(&rr, dev);
> +	rr.real_align = align;
>  
>  	min = (res->flags & IORESOURCE_IO) ? PCIBIOS_MIN_IO : PCIBIOS_MIN_MEM;
>  
> +	if (!rr.user_align &&
> +	    (res->flags & IORESOURCE_MEM) && pci_resreq_remainder(size, align)) {
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

[Severity: High]
Does the remainder logic rely on rr.user_align being reliably initialized to 0
for non-overridden resources?

In include/linux/pci.h, pci_init_pci_resreq_data() declares an uninitialized
variable bool user_aligned; and passes it by reference:

include/linux/pci.h:pci_init_pci_resreq_data() {
    bool user_aligned;
    ...
    rr->user_align = pci_specified_resource_alignment(dev, &user_aligned);
    if (!user_aligned)
        rr->user_align = 0;
}

If the user did not specify an alignment parameter,
pci_specified_resource_alignment() returns early without writing to
user_aligned:

drivers/pci/pci.c:pci_specified_resource_alignment() {
    ...
    if (!p || !*p)
        goto out;
    ...
out:
    return pcibios_default_alignment();
}

If the stack garbage in user_aligned evaluates to true, rr->user_align
incorrectly retains pcibios_default_alignment(). On architectures where
pcibios_default_alignment() is non-zero (like powernv), rr.user_align
becomes non-zero, causing !rr.user_align to evaluate to false. This skips
the align = 1U override randomly, breaking the remainder alignment logic
for nested bridge windows.

> +		align = 1U;
> +		if (pci_resource_is_bridge_win(resno))
> +			align = pci_min_window_alignment(bus, res->flags);
> +	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261013130948.6231-1-ilpo.jarvinen@linux.intel.com?part=4

  reply	other threads:[~2026-10-13 13:25 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13 13:09 [PATCH v3 0/8] PCI: Resource placement algorithm fixes Ilpo Järvinen
2026-10-13 13:09 ` [PATCH v3 1/8] resource: Mark free space assigned Ilpo Järvinen
2026-10-13 13:28   ` sashiko-bot
2026-10-13 13:09 ` [PATCH v3 2/8] PCI/parisc: Clean up resource debug print & use dynamic debug Ilpo Järvinen
2026-10-13 13:19   ` sashiko-bot
2026-10-13 13:09 ` [PATCH v3 3/8] PCI: Honor alignment overrides Ilpo Järvinen
2026-10-13 13:24   ` sashiko-bot
2026-10-13 14:08   ` Rodrigo Vivi
2026-10-13 13:09 ` [PATCH v3 4/8] PCI: Fix nesting windows with remainder at the left edge Ilpo Järvinen
2026-10-13 13:25   ` sashiko-bot [this message]
2026-10-13 13:09 ` [PATCH v3 5/8] linux/log2.h: Add 64-bit roundup/down_pow_of_two64() variants Ilpo Järvinen
2026-10-13 13:16   ` sashiko-bot
2026-10-13 13:09 ` [PATCH v3 6/8] PCI: Place resources to either edge of the window Ilpo Järvinen
2026-10-13 13:19   ` sashiko-bot
2026-10-13 13:09 ` [PATCH v3 7/8] PCI: Fix composite resource sizing Ilpo Järvinen
2026-10-13 13:26   ` sashiko-bot
2026-10-13 13:09 ` [PATCH v3 8/8] PCI/quirks: Avoid certain address on Genoa systems Ilpo Järvinen
2026-10-13 13:24   ` sashiko-bot
2026-10-13 17:00   ` Mario Limonciello
2026-10-13 17:03     ` Mario Limonciello
2026-10-13 17:26       ` Ilpo Järvinen
2026-10-13 18:59         ` Mario Limonciello

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-169804@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --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.