From: Marek Vasut marek.vasut+renesas@mailbox.org
[ Upstream commit d5f6bd3ee3f5048f272182dc91675c082773999e ]
Currently, the test allocates BAR sizes according to fixed table bar_size. This does not work with controllers which have fixed size BARs that are 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 one of the BAR size, 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 possible 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
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org [mani: reworded description] Signed-off-by: Manivannan Sadhasivam mani@kernel.org Signed-off-by: Bjorn Helgaas bhelgaas@google.com Reviewed-by: Niklas Cassel cassel@kernel.org Link: https://patch.msgid.link/20250905184240.144431-1-marek.vasut+renesas@mailbox... Signed-off-by: Sasha Levin sashal@kernel.org ---
LLM Generated explanations, may be completely bogus:
YES
Explanation - Fixes a real test failure. The test function previously requested hard-coded BAR sizes from `bar_size[]`, e.g., `BAR_4` = 131072 bytes (128 KiB) in `drivers/pci/endpoint/functions/pci-epf-test.c:105`. On controllers with smaller fixed-size BARs (e.g., Renesas R-Car V4H BAR4 = 256 bytes), `pci_epf_alloc_space()` rejected the request and the test failed with: - "requested BAR size is larger than fixed size" - "Failed to allocate space for BAR4" These messages originate from the fixed-size enforcement in `pci_epf_alloc_space()` (drivers/pci/endpoint/pci-epf-core.c:267 and error at drivers/pci/endpoint/pci-epf-core.c:282).
- Minimal, targeted change in the EPF test. The patch adjusts the allocation loop so that for each non-register BAR it first checks if the EPC declares the BAR as fixed-size and, if so, requests that exact size instead of the hard-coded test size: - Added fixed-size check and selection: drivers/pci/endpoint/functions/pci-epf-test.c:1070 - Uses `fixed_size` for fixed BARs; otherwise falls back to `bar_size[]`: drivers/pci/endpoint/functions/pci-epf-test.c:1071 and drivers/pci/endpoint/functions/pci-epf-test.c:1073 - Passes the selected size into `pci_epf_alloc_space()`: drivers/pci/endpoint/functions/pci-epf-test.c:1075
- Aligns with existing EPC semantics. `pci_epf_alloc_space()` already enforces fixed-size BARs by returning NULL when a request exceeds the fixed size and coerces accepted requests to the hardware’s fixed size (drivers/pci/endpoint/pci-epf-core.c:267 and drivers/pci/endpoint/pci- epf-core.c:282). The change avoids over-sized requests up front, preventing spurious failures, and is consistent with what `pci_epf_alloc_space()` would have done anyway.
- Does not alter critical behavior for the register BAR. The test still computes the register BAR size as register space + optional MSI-X table + PBA and allocates that for the chosen `test_reg_bar` (drivers/pci/endpoint/functions/pci-epf-test.c:1046–1055). If a controller’s register BAR itself is fixed and too small to hold the required registers/MSI-X structures, failing is correct because the test cannot run on such hardware.
- Low regression risk: - Scope-limited to a test EPF driver (`pci-epf-test`). No UAPI or ABI changes. - For controllers whose fixed size is larger than the test’s `bar_size[]`, this change merely allocates the larger, correct fixed size that hardware requires (previously `pci_epf_alloc_space()` would coerce the result to fixed size anyway). - If `fixed_size` is reported as zero (misconfigured or unsupported case), `pci_epf_alloc_space()` still falls back to a minimum sane allocation (128 bytes), preserving prior behavior.
- Clear user impact: It addresses real-world failures on controllers with smaller fixed BARs (e.g., Renesas R-Car Gen4 endpoints specify fixed-size BARs such as BAR4=256 bytes: drivers/pci/controller/dwc/pcie-rcar-gen4.c:426), allowing the EPF test to run without allocation errors.
- Meets stable backport criteria: - Bug fix, not a feature. - Small and contained. - Minimal risk and no architectural changes. - Confined to PCI endpoint test function code.
Given the above, this is a solid candidate for stable backporting.
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 044f5ea0716d1..31617772ad516 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -1067,7 +1067,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",