* [PATCH v1] PCI: endpoint: Skip upper halves of 64-bit BARs during search
@ 2026-10-21 8:06 Manikanta Maddireddy
2026-10-21 10:45 ` Niklas Cassel
0 siblings, 1 reply; 2+ messages in thread
From: Manikanta Maddireddy @ 2026-10-21 8:06 UTC (permalink / raw)
To: mani, kwilczynski, linux-pci
Cc: kishon, Frank.Li, bhelgaas, cassel, den, thierry.reding,
jonathanh, vidyas, linux-tegra, linux-kernel, mmaddireddy
pci_epc_get_next_free_bar() skips the upper half of a 64-bit BAR only
when it is the starting BAR. If the search subsequently passes a
reserved or disabled 64-bit BAR, it can return its upper half as an
independent BAR because that slot has a default programmable descriptor.
For example, Tegra exposes a programmable 64-bit BAR0 and reserved
64-bit BAR2 and BAR4. A search starting at BAR1 skips BAR1 and BAR2,
then incorrectly returns BAR3. The next search can similarly return
BAR5, causing the EPF test driver to allocate and program BARs that
belong to the reserved hardware windows.
Check each candidate's preceding descriptor inside the search loop so
upper halves are skipped throughout the search. With the Tegra layout,
BAR0 is the only available BAR and subsequent searches return NO_BAR.
Signed-off-by: Manikanta Maddireddy <mmaddireddy@nvidia.com>
---
drivers/pci/endpoint/pci-epc-core.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
index 831b40458dcd..8d0df9fc1df9 100644
--- a/drivers/pci/endpoint/pci-epc-core.c
+++ b/drivers/pci/endpoint/pci-epc-core.c
@@ -98,11 +98,11 @@ enum pci_barno pci_epc_get_next_free_bar(const struct pci_epc_features
if (!epc_features)
return BAR_0;
- /* If 'bar - 1' is a 64-bit BAR, move to the next BAR */
- if (bar > 0 && epc_features->bar[bar - 1].only_64bit)
- bar++;
-
for (i = bar; i < PCI_STD_NUM_BARS; i++) {
+ /* Skip the upper half of a 64-bit BAR. */
+ if (i > 0 && epc_features->bar[i - 1].only_64bit)
+ continue;
+
/* If the BAR is not reserved or disabled, return it. */
if (epc_features->bar[i].type != BAR_RESERVED &&
epc_features->bar[i].type != BAR_DISABLED)
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v1] PCI: endpoint: Skip upper halves of 64-bit BARs during search
2026-10-21 8:06 [PATCH v1] PCI: endpoint: Skip upper halves of 64-bit BARs during search Manikanta Maddireddy
@ 2026-10-21 10:45 ` Niklas Cassel
0 siblings, 0 replies; 2+ messages in thread
From: Niklas Cassel @ 2026-10-21 10:45 UTC (permalink / raw)
To: Manikanta Maddireddy
Cc: mani, kwilczynski, linux-pci, kishon, Frank.Li, bhelgaas, den,
thierry.reding, jonathanh, vidyas, linux-tegra, linux-kernel
On Wed, Oct 21, 2026 at 01:36:44PM +0530, Manikanta Maddireddy wrote:
> pci_epc_get_next_free_bar() skips the upper half of a 64-bit BAR only
> when it is the starting BAR. If the search subsequently passes a
> reserved or disabled 64-bit BAR, it can return its upper half as an
> independent BAR because that slot has a default programmable descriptor.
>
> For example, Tegra exposes a programmable 64-bit BAR0 and reserved
> 64-bit BAR2 and BAR4. A search starting at BAR1 skips BAR1 and BAR2,
> then incorrectly returns BAR3. The next search can similarly return
> BAR5, causing the EPF test driver to allocate and program BARs that
> belong to the reserved hardware windows.
The 'only_64bit' property tells an EPF that it can only configure the
BAR as 64-bit.
BARs that are reserved are hidden from an EPF, and can not be programmed
at all, so the 'only_64bit' property does not make sense on reserved BARs.
See:
9266514689fe ("PCI: endpoint: Drop only_64bit on reserved BARs")
At least when I cleanup up all the properties (including tegra) in:
e01c9797c0eb ("PCI: endpoint: Clean up hardware description for BARs")
I made sure that there were no BARs that were marked both reserved and
only_64bit.
This also matches the @only_64bit kdoc in include/linux/pci-epc.h.
I see you changed this in:
12a22fb38cbb ("PCI: tegra194: Expose BAR2 (MSI-X) and BAR4 (DMA) as
64-bit BAR_RESERVED").
I'm fine with this patch, but I think you need to rephrase the kdoc
to reflect this new reality, because currently the kdoc is confusing/
not in line with the 'new' meaning of BAR_RESERVED, which can contain
MSI-X table etc.
(The old BAR_RESERVED was renamed to be BAR_DISABLED, to be more clear.)
Kind regards,
Niklas
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-21 10:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-21 8:06 [PATCH v1] PCI: endpoint: Skip upper halves of 64-bit BARs during search Manikanta Maddireddy
2026-10-21 10:45 ` Niklas Cassel
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®