[PATCH v3] PCI: endpoint: pci-epf-test: Limit PCIe BAR size for fixed BARs

Marek Vasut posted 1 patch 4 days, 7 hours ago
drivers/pci/endpoint/functions/pci-epf-test.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
[PATCH v3] PCI: endpoint: pci-epf-test: Limit PCIe BAR size for fixed BARs
Posted by Marek Vasut 4 days, 7 hours ago
Currently, the test allocates BAR sizes according to fixed table
bar_size[] = { 512, 512, 1024, 16384, 131072, 1048576 } . This
does not work with controllers which have fixed size BARs that
is smaller than the requested BAR size. One such controller is
Renesas R-Car V4H PCIe controller, which has BAR4 size limited
to 256 Bytes, which is much less than 131072 currently requested
by this test. a lot of controllers drivers in-tree have fixed
size BARs, and they do work perfectly fine, but it is only
because their fixed size is larger than the size requested
by pci-epf-test.c

Adjust the test such that in case a fixed size BAR is detected,
the fixed BAR size is used, as that is the only possibly option.

This helps with test failures reported as follows:
"
pci_epf_test pci_epf_test.0: requested BAR size is larger than fixed size
pci_epf_test pci_epf_test.0: Failed to allocate space for BAR4
"

Reviewed-by: Niklas Cassel <cassel@kernel.org>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
Cc: "Krzysztof Wilczyński" <kwilczynski@kernel.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Damien Le Moal <dlemoal@kernel.org>
Cc: Frank Li <Frank.Li@nxp.com>
Cc: Jerome Brunet <jbrunet@baylibre.com>
Cc: Kishon Vijay Abraham I <kishon@kernel.org>
Cc: Manivannan Sadhasivam <mani@kernel.org>
Cc: Niklas Cassel <cassel@kernel.org>
Cc: Wang Jiang <jiangwang@kylinos.cn>
Cc: linux-kernel@vger.kernel.org
Cc: linux-pci@vger.kernel.org
Cc: linux-renesas-soc@vger.kernel.org
---
V2: Simplify the conditional to always use fixed size BAR size for test
V3: - Update commit message
    - Add RB from Niklas
---
 drivers/pci/endpoint/functions/pci-epf-test.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
index e091193bd8a8a..2418add64104a 100644
--- a/drivers/pci/endpoint/functions/pci-epf-test.c
+++ b/drivers/pci/endpoint/functions/pci-epf-test.c
@@ -1050,7 +1050,12 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)
 		if (bar == test_reg_bar)
 			continue;
 
-		base = pci_epf_alloc_space(epf, bar_size[bar], bar,
+		if (epc_features->bar[bar].type == BAR_FIXED)
+			test_reg_size = epc_features->bar[bar].fixed_size;
+		else
+			test_reg_size = bar_size[bar];
+
+		base = pci_epf_alloc_space(epf, test_reg_size, bar,
 					   epc_features, PRIMARY_INTERFACE);
 		if (!base)
 			dev_err(dev, "Failed to allocate space for BAR%d\n",
-- 
2.50.1

Re: [PATCH v3] PCI: endpoint: pci-epf-test: Limit PCIe BAR size for fixed BARs
Posted by Manivannan Sadhasivam 1 day, 13 hours ago
On Fri, 05 Sep 2025 20:42:10 +0200, Marek Vasut wrote:
> Currently, the test allocates BAR sizes according to fixed table
> bar_size[] = { 512, 512, 1024, 16384, 131072, 1048576 } . This
> does not work with controllers which have fixed size BARs that
> is smaller than the requested BAR size. One such controller is
> Renesas R-Car V4H PCIe controller, which has BAR4 size limited
> to 256 Bytes, which is much less than 131072 currently requested
> by this test. a lot of controllers drivers in-tree have fixed
> size BARs, and they do work perfectly fine, but it is only
> because their fixed size is larger than the size requested
> by pci-epf-test.c
> 
> [...]

Applied, thanks!

[1/1] PCI: endpoint: pci-epf-test: Limit PCIe BAR size for fixed BARs
      commit: db4291ba733d857f2326db88c5c41ad6072350e5

Best regards,
-- 
Manivannan Sadhasivam <mani@kernel.org>