From: Sergey Miroshnichenko <s.miroshnichenko@yadro.com> To: <linux-pci@vger.kernel.org>, <linuxppc-dev@lists.ozlabs.org> Cc: Bjorn Helgaas <helgaas@kernel.org>, <linux@yadro.com>, Sergey Miroshnichenko <s.miroshnichenko@yadro.com> Subject: [PATCH RFC 11/11] PCI: hotplug: movable bus numbers: compact the gaps in numbering Date: Thu, 24 Oct 2019 20:21:57 +0300 [thread overview] Message-ID: <20191024172157.878735-12-s.miroshnichenko@yadro.com> (raw) In-Reply-To: <20191024172157.878735-1-s.miroshnichenko@yadro.com> If bus numbers are distributed sparsely and there are lot of devices in the tree, hotplugging a bridge into the end of the tree may fail even if it has less slots then the total number of unused bus numbers. Thus, the feature of bus renaming relies on the continuity of bus numbers, so if a bridge was unplugged, the gap in bus numbers must be compacted. Let's densify the bus numbering at the beginning of a next PCI rescan. Signed-off-by: Sergey Miroshnichenko <s.miroshnichenko@yadro.com> --- drivers/pci/probe.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index fe9bf012ef33..0c91b9d453dd 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1319,6 +1319,30 @@ static bool pci_new_bus_needed(struct pci_bus *bus, const struct pci_dev *self) return true; } +static void pci_compact_bus_numbers(const int domain, const struct resource *valid_range) +{ + int busnr_p1 = valid_range->start; + + while (busnr_p1 < valid_range->end) { + int busnr_p2 = busnr_p1 + 1; + struct pci_bus *bus_p2; + int delta; + + while (busnr_p2 <= valid_range->end && + !(bus_p2 = pci_find_bus(domain, busnr_p2))) + ++busnr_p2; + + if (!bus_p2 || busnr_p2 > valid_range->end) + break; + + delta = busnr_p1 - busnr_p2 + 1; + if (delta) + pci_move_buses(domain, busnr_p2, delta, valid_range); + + ++busnr_p1; + } +} + static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus, unsigned int available_buses); /** @@ -3691,6 +3715,9 @@ unsigned int pci_rescan_bus(struct pci_bus *bus) pci_bus_update_immovable_range(root); pci_bus_release_root_bridge_resources(root); + pci_compact_bus_numbers(pci_domain_nr(bus), + &root->busn_res); + max = pci_scan_child_bus(root); pci_reassign_root_bus_resources(root); -- 2.23.0
WARNING: multiple messages have this Message-ID (diff)
From: Sergey Miroshnichenko <s.miroshnichenko@yadro.com> To: <linux-pci@vger.kernel.org>, <linuxppc-dev@lists.ozlabs.org> Cc: Sergey Miroshnichenko <s.miroshnichenko@yadro.com>, Bjorn Helgaas <helgaas@kernel.org>, linux@yadro.com Subject: [PATCH RFC 11/11] PCI: hotplug: movable bus numbers: compact the gaps in numbering Date: Thu, 24 Oct 2019 20:21:57 +0300 [thread overview] Message-ID: <20191024172157.878735-12-s.miroshnichenko@yadro.com> (raw) In-Reply-To: <20191024172157.878735-1-s.miroshnichenko@yadro.com> If bus numbers are distributed sparsely and there are lot of devices in the tree, hotplugging a bridge into the end of the tree may fail even if it has less slots then the total number of unused bus numbers. Thus, the feature of bus renaming relies on the continuity of bus numbers, so if a bridge was unplugged, the gap in bus numbers must be compacted. Let's densify the bus numbering at the beginning of a next PCI rescan. Signed-off-by: Sergey Miroshnichenko <s.miroshnichenko@yadro.com> --- drivers/pci/probe.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index fe9bf012ef33..0c91b9d453dd 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1319,6 +1319,30 @@ static bool pci_new_bus_needed(struct pci_bus *bus, const struct pci_dev *self) return true; } +static void pci_compact_bus_numbers(const int domain, const struct resource *valid_range) +{ + int busnr_p1 = valid_range->start; + + while (busnr_p1 < valid_range->end) { + int busnr_p2 = busnr_p1 + 1; + struct pci_bus *bus_p2; + int delta; + + while (busnr_p2 <= valid_range->end && + !(bus_p2 = pci_find_bus(domain, busnr_p2))) + ++busnr_p2; + + if (!bus_p2 || busnr_p2 > valid_range->end) + break; + + delta = busnr_p1 - busnr_p2 + 1; + if (delta) + pci_move_buses(domain, busnr_p2, delta, valid_range); + + ++busnr_p1; + } +} + static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus, unsigned int available_buses); /** @@ -3691,6 +3715,9 @@ unsigned int pci_rescan_bus(struct pci_bus *bus) pci_bus_update_immovable_range(root); pci_bus_release_root_bridge_resources(root); + pci_compact_bus_numbers(pci_domain_nr(bus), + &root->busn_res); + max = pci_scan_child_bus(root); pci_reassign_root_bus_resources(root); -- 2.23.0
next prev parent reply other threads:[~2019-10-24 17:22 UTC|newest] Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-10-24 17:21 [PATCH RFC 00/11] PCI: hotplug: Movable bus numbers Sergey Miroshnichenko 2019-10-24 17:21 ` Sergey Miroshnichenko 2019-10-24 17:21 ` [PATCH RFC 01/11] PCI: sysfs: Nullify freed pointers Sergey Miroshnichenko 2019-10-24 17:21 ` Sergey Miroshnichenko 2019-10-24 17:21 ` [PATCH RFC 02/11] PCI: proc: Nullify a freed pointer Sergey Miroshnichenko 2019-10-24 17:21 ` Sergey Miroshnichenko 2019-10-24 17:21 ` [PATCH RFC 03/11] drivers: base: Make bus_add_device() public Sergey Miroshnichenko 2019-10-24 17:21 ` Sergey Miroshnichenko 2019-10-24 17:21 ` [PATCH RFC 04/11] drivers: base: Make device_{add|remove}_class_symlinks() public Sergey Miroshnichenko 2019-10-24 17:21 ` Sergey Miroshnichenko 2019-10-24 17:21 ` [PATCH RFC 05/11] drivers: base: Add bus_disconnect_device() Sergey Miroshnichenko 2019-10-24 17:21 ` Sergey Miroshnichenko 2019-10-24 17:21 ` [PATCH RFC 06/11] powerpc/pci: Enable assigning bus numbers instead of reading them from DT Sergey Miroshnichenko 2019-10-24 17:21 ` Sergey Miroshnichenko 2019-10-24 17:21 ` [PATCH RFC 07/11] powerpc/pci: Don't reduce the host bridge bus range Sergey Miroshnichenko 2019-10-24 17:21 ` Sergey Miroshnichenko 2019-10-24 17:21 ` [PATCH RFC 08/11] PCI: Allow expanding the bridges Sergey Miroshnichenko 2019-10-24 17:21 ` Sergey Miroshnichenko 2019-10-24 17:21 ` [PATCH RFC 09/11] PCI: hotplug: Add initial support for movable bus numbers Sergey Miroshnichenko 2019-10-24 17:21 ` Sergey Miroshnichenko 2019-10-24 17:21 ` [PATCH RFC 10/11] PCI: hotplug: movable bus numbers: rename proc and sysfs entries Sergey Miroshnichenko 2019-10-24 17:21 ` Sergey Miroshnichenko 2019-10-24 17:21 ` Sergey Miroshnichenko [this message] 2019-10-24 17:21 ` [PATCH RFC 11/11] PCI: hotplug: movable bus numbers: compact the gaps in numbering Sergey Miroshnichenko
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20191024172157.878735-12-s.miroshnichenko@yadro.com \ --to=s.miroshnichenko@yadro.com \ --cc=helgaas@kernel.org \ --cc=linux-pci@vger.kernel.org \ --cc=linux@yadro.com \ --cc=linuxppc-dev@lists.ozlabs.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.