Re: [PATCH] PCI: endpoint: pci-epf-test: Roll back BAR mapping when subrange setup fails

Christian Bruel
2026-03-17T09:14:05Z

On 3/17/26 03:57, Koichiro Den wrote:
> On Mon, Mar 16, 2026 at 05:19:26PM +0100, Niklas Cassel wrote:
>> On Mon, Mar 16, 2026 at 11:02:25PM +0900, Koichiro Den wrote:
>>> When the BAR subrange mapping test on DWC-based platforms fails due to
>>> insufficient free inbound iATU regions,
>>> pci_epf_test_bar_subrange_setup() returns an error (-ENOSPC) but does
>>> not restore the original BAR mapping. This causes subsequent test runs
>>> to become confusing, since the failure may leave room for the next
>>> subrange mapping test to pass.
>>>
>>> Fix this by restoring the original BAR mapping when preparation of the
>>> subrange mapping fails, so that no side effect remains regardless of the
>>> test success or failure.
>>>
>>> Fixes: 6c5e6101423b ("PCI: endpoint: pci-epf-test: Add BAR subrange mapping test support")
>>> Reported-by: Christian Bruel <christian.bruel@foss.st.com>
>>> Closes: https://lore.kernel.org/linux-pci/b2b03ebe-9482-4a13-b22f-7b44da096eed@foss.st.com/
>>> Signed-off-by: Koichiro Den <den@valinux.co.jp>
>>> ---
>>> drivers/pci/endpoint/functions/pci-epf-test.c | 6 ++++++
>>> 1 file changed, 6 insertions(+)
>>>
>>> diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
>>> index 14e61ebe1f11..f44c36f5cac5 100644
>>> --- a/drivers/pci/endpoint/functions/pci-epf-test.c
>>> +++ b/drivers/pci/endpoint/functions/pci-epf-test.c
>>> @@ -898,16 +898,22 @@ static void pci_epf_test_bar_subrange_setup(struct pci_epf_test *epf_test,
>>> bar->submap = submap;
>>> bar->num_submap = nsub;
>>>
>>> ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, bar);
>>> if (ret) {
>>> dev_err(&epf->dev, "pci_epc_set_bar() failed: %d\n", ret);
>>> bar->submap = old_submap;
>>> bar->num_submap = old_nsub;
>>> + ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, bar);
>>> + if (ret)
>>> + dev_warn(&epf->dev,
>>> + "failed to restore the original BAR mapping: %d\n",
>>
>> Nit:
>> I would use a capitalized F:
>> "Failed to restore ..."
>>
>> in order to match most other prints in this file.
>
> Agree. Bjorn or Mani, please feel free to fix this up (i.e. s/failed/Failed/)
> when applying, to avoid a respin for such a minor change.
>
>>
>> Reviewed-by: Niklas Cassel <cassel@kernel.org>
>
> Thanks again for reviewing, Niklas.
>
> Christian, if possible, it would be very helpful if you could take a look or
> test this slightly polished version and add a Tested-by or Reviewed-by.

Tested-by: Christian Bruel <christian.bruel@foss.st.com>

with the DISABLE BAR dependency
https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git/commit/?h=endpoint&id=33642e9e36dc084e4fc9245a266c9843bc8303b9

I will need to update the pci_epc_features after the merge.

A more general question: I don't understand why only the STM32 is
impacted. It seems that all targets, even those with 6 IB iATU entries,
should ensure that one BAR is disabled to handle subranges.

In other words, will there always be at least one BAR_TEST BAR variant
that is skipped for all platforms, or am I missing something here?

thank you

Christian

>
> Best regards,
> Koichiro