From: sashiko-bot@kernel.org
To: "Sreeraj S Kurup" <sreekuttan2156239@gmail.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v2] PCI: mediatek: Fix integer truncation in fls() and clamp size
Date: Wed, 30 Sep 2026 11:04:49 +0000 [thread overview]
Message-ID: <20260930110450.0C42F1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260930105435.3660-1-sreekuttan2156239@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] pci: silent hardware window truncation causes unmapped BARs
--
commit 3807ae15ec6ca796b24e06b510d2cb2153d9a5c8
Author: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
PCI: mediatek: Fix integer truncation in fls() and clamp size
This commit fixes an integer truncation issue by using fls64() for 64-bit
resource sizes. It also clamps the resulting size_order to a maximum of 31
to avoid overflowing the 5-bit register field used in AHB2PCIE_SIZE().
> diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
> index 3a3e91cd0c211..ddc7ed28ef843 100644
> --- a/drivers/pci/controller/pcie-mediatek.c
> +++ b/drivers/pci/controller/pcie-mediatek.c
[ ... ]
> @@ -753,8 +756,13 @@ static int mtk_pcie_startup_port_v2(struct mtk_pcie_port *port)
> mtk_pcie_enable_msi(port);
>
> /* Set AHB to PCIe translation windows */
> + size = resource_size(mem);
> + size_order = fls64(size);
> + if (size_order > 31)
> + size_order = 31;
> +
[Severity: High]
Does clamping the size order here in mtk_pcie_startup_port_v2() cause
unmapped BARs?
The hardware translation window size is clamped to size order 31, but the
patch does not adjust the OS-level mem resource (e.g., mem->end). If the
device tree provides a PCIe memory resource of 4 GiB or larger, the Linux
PCI core will allocate BARs within the full original window. Because the
hardware only translates the truncated portion, will CPU accesses to BARs
placed above the clamped limit fail with a data abort or bus error?
Additionally, using fls64(size) on a power-of-two size computes
ilog2(size) + 1, which may evaluate to a larger window than requested.
Should the driver reject oversized windows entirely, or shrink the OS
resource size to match the hardware reality?
> val = lower_32_bits(mem->start) |
> - AHB2PCIE_SIZE(fls(resource_size(mem)));
> + AHB2PCIE_SIZE(size_order);
> writel(val, port->base + PCIE_AHB_TRANS_BASE0_L);
>
> val = upper_32_bits(mem->start);
[ ... ]
> @@ -829,8 +839,13 @@ static int mtk_pcie_startup_port_en7528(struct mtk_pcie_port *port)
> mtk_pcie_enable_msi(port);
>
> /* Set AHB to PCIe translation windows */
> + size = resource_size(mem);
> + size_order = fls64(size);
> + if (size_order > 31)
> + size_order = 31;
> +
[Severity: High]
Does this suffer from the same silent hardware window truncation issue as
mtk_pcie_startup_port_v2() above? The hardware translation window is
clamped without adjusting the corresponding OS-level resource.
> val = lower_32_bits(mem->start) |
> - AHB2PCIE_SIZE(fls(resource_size(mem)));
> + AHB2PCIE_SIZE(size_order);
> writel(val, port->base + PCIE_AHB_TRANS_BASE0_L);
>
> val = upper_32_bits(mem->start);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260930105435.3660-1-sreekuttan2156239@gmail.com?part=1
prev parent reply other threads:[~2026-09-30 11:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 10:54 [PATCH v2] PCI: mediatek: Fix integer truncation in fls() and clamp size Sreeraj S Kurup
2026-09-30 11:04 ` 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=20260930110450.0C42F1F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sreekuttan2156239@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