Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH 1/1] PCI: Non-empty add_list/realloc_head does not warrant BUG_ON()
@ 2025-05-11 21:52 Ilpo Järvinen
  2025-05-14 17:00 ` Krzysztof Wilczyński
  0 siblings, 1 reply; 2+ messages in thread
From: Ilpo Järvinen @ 2025-05-11 21:52 UTC (permalink / raw)
  To: Bjorn Helgaas, linux-pci, linux-kernel; +Cc: Ilpo Järvinen, Tudor Ambarus

Resource fitting/assignment code checks if there's a remainder in
add_list (aka. realloc_head in the inner functions) using BUG_ON().
This problem typically results in a mere PCI device resource assignment
failure which does not warrant using BUG_ON(). The machine could well
come up usable even if this condition occurs because the realloc_head
relates to resources which are optional anyway.

Change BUG_ON() to WARN_ON_ONCE() and free the list if it it's not
empty.

Reported-by: Tudor Ambarus <tudor.ambarus@linaro.org>
Link: https://lore.kernel.org/linux-pci/5f103643-5e1c-43c6-b8fe-9617d3b5447c@linaro.org/
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---

The cause for the regression reported by Tudor is not understood yet,
but this change seems useful regardless given somebody has now hit one
of these BUG_ON()s.

 drivers/pci/setup-bus.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 54d6f4fa3ce1..a0d815557f5c 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -2298,8 +2298,8 @@ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus)
 
 		/* Depth last, allocate resources and update the hardware. */
 		__pci_bus_assign_resources(bus, add_list, &fail_head);
-		if (add_list)
-			BUG_ON(!list_empty(add_list));
+		if (WARN_ON_ONCE(add_list && !list_empty(add_list)))
+			free_list(add_list);
 		tried_times++;
 
 		/* Any device complain? */
@@ -2361,7 +2361,8 @@ void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
 		pci_bridge_distribute_available_resources(bridge, &add_list);
 
 		__pci_bridge_assign_resources(bridge, &add_list, &fail_head);
-		BUG_ON(!list_empty(&add_list));
+		if (WARN_ON_ONCE(!list_empty(&add_list)))
+			free_list(&add_list);
 		tried_times++;
 
 		if (list_empty(&fail_head))
@@ -2437,7 +2438,8 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
 
 	__pci_bus_size_bridges(bridge->subordinate, &added);
 	__pci_bridge_assign_resources(bridge, &added, &failed);
-	BUG_ON(!list_empty(&added));
+	if (WARN_ON_ONCE(!list_empty(&added)))
+		free_list(&added);
 
 	if (!list_empty(&failed)) {
 		ret = -ENOSPC;
@@ -2493,6 +2495,7 @@ void pci_assign_unassigned_bus_resources(struct pci_bus *bus)
 			__pci_bus_size_bridges(dev->subordinate, &add_list);
 	up_read(&pci_bus_sem);
 	__pci_bus_assign_resources(bus, &add_list, NULL);
-	BUG_ON(!list_empty(&add_list));
+	if (WARN_ON_ONCE(!list_empty(&add_list)))
+		free_list(&add_list);
 }
 EXPORT_SYMBOL_GPL(pci_assign_unassigned_bus_resources);

base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8
-- 
2.39.5


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

* Re: [PATCH 1/1] PCI: Non-empty add_list/realloc_head does not warrant BUG_ON()
  2025-05-11 21:52 [PATCH 1/1] PCI: Non-empty add_list/realloc_head does not warrant BUG_ON() Ilpo Järvinen
@ 2025-05-14 17:00 ` Krzysztof Wilczyński
  0 siblings, 0 replies; 2+ messages in thread
From: Krzysztof Wilczyński @ 2025-05-14 17:00 UTC (permalink / raw)
  To: Bjorn Helgaas, Ilpo Järvinen, Tudor Ambarus, linux-pci,
	linux-kernel

Hello,

> Resource fitting/assignment code checks if there's a remainder in
> add_list (aka. realloc_head in the inner functions) using BUG_ON().
> This problem typically results in a mere PCI device resource assignment
> failure which does not warrant using BUG_ON(). The machine could well
> come up usable even if this condition occurs because the realloc_head
> relates to resources which are optional anyway.
> 
> [...]

Applied to misc, thank you!

[1/1] PCI: Non-empty add_list/realloc_head does not warrant BUG_ON()
      https://git.kernel.org/pci/pci/c/9b388104e87b

	Krzysztof

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

end of thread, other threads:[~2025-05-14 17:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-11 21:52 [PATCH 1/1] PCI: Non-empty add_list/realloc_head does not warrant BUG_ON() Ilpo Järvinen
2025-05-14 17:00 ` Krzysztof Wilczyński

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