public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PCI: endpoint: pci-epf-test: Roll back BAR mapping when subrange setup fails
@ 2026-03-16 14:02 Koichiro Den
  2026-03-16 14:36 ` Koichiro Den
                   ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: Koichiro Den @ 2026-03-16 14:02 UTC (permalink / raw)
  To: Bjorn Helgaas, Niklas Cassel, Christian Bruel,
	Manivannan Sadhasivam, Krzysztof Wilczyński,
	Kishon Vijay Abraham I, Frank Li, Kees Cook,
	Shin'ichiro Kawasaki, Andy Shevchenko,
	Bhanu Seshu Kumar Valluri
  Cc: linux-pci, linux-kernel

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",
+				 ret);
+
 		kfree(submap);
 		goto err;
 	}
 	kfree(old_submap);
 
 	/*
 	 * Fill deterministic signatures into the physical regions that
 	 * each BAR subrange maps to. RC verifies these to ensure the
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2026-03-18 12:58 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-16 14:02 [PATCH] PCI: endpoint: pci-epf-test: Roll back BAR mapping when subrange setup fails Koichiro Den
2026-03-16 14:36 ` Koichiro Den
2026-03-16 14:41   ` Koichiro Den
2026-03-16 16:19 ` Niklas Cassel
2026-03-17  2:57   ` Koichiro Den
2026-03-17  3:27     ` Manivannan Sadhasivam
2026-03-17  9:13     ` Christian Bruel
2026-03-17  9:24       ` Niklas Cassel
2026-03-17  9:55         ` Christian Bruel
2026-03-17 10:01           ` Christian Bruel
2026-03-17 10:12             ` Niklas Cassel
2026-03-17 10:29               ` Christian Bruel
2026-03-17 10:46                 ` Niklas Cassel
2026-03-17 15:14                   ` Koichiro Den
2026-03-18  8:02                     ` Christian Bruel
2026-03-18  8:35                       ` Christian Bruel
2026-03-18  8:58                         ` Niklas Cassel
2026-03-18 12:58                           ` Christian Bruel
2026-03-17 15:17           ` Koichiro Den
2026-03-17  9:59       ` Manivannan Sadhasivam
2026-03-17 10:02         ` Christian Bruel
2026-03-17 10:05         ` Niklas Cassel
2026-03-17 15:27 ` Bjorn Helgaas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox