pci_hp_spurious_link_change() awaits the end of a code section causing spurious link changes, such as a Secondary Bus Reset, and then tells whether such a section has executed, using test_and_clear_bit() on PCI_LINK_CHANGED. The answer is one-shot: only the first caller sees true.
Split the wait out into pci_hp_wait_link_change(), which leaves PCI_LINK_CHANGED alone, and implement pci_hp_spurious_link_change() on top of it. Test PCI_LINK_CHANGING with test_bit_acquire(), so that the caller's subsequent accesses are ordered after the end of the code section even if wait_event() returns without sleeping. No functional change intended. Signed-off-by: Abhin Parekadan Jose <[email protected]> Assisted-by: LLM --- Changes since RFC v2: - Test PCI_LINK_CHANGING with test_bit_acquire(). (Sashiko) RFC v2: https://lore.kernel.org/all/[email protected]/ Sashiko review of v2: https://lore.kernel.org/all/[email protected]/ --- drivers/pci/hotplug/pci_hotplug_core.c | 21 +++++++++++++++++++-- drivers/pci/pci.h | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c index fadcf98a8a660..75524fe2bec6e 100644 --- a/drivers/pci/hotplug/pci_hotplug_core.c +++ b/drivers/pci/hotplug/pci_hotplug_core.c @@ -528,6 +528,24 @@ void pci_hp_unignore_link_change(struct pci_dev *pdev) wake_up_all(&pci_hp_link_change_wq); } +/** + * pci_hp_wait_link_change - await end of code section causing spurious link changes + * @pdev: PCI hotplug bridge + * + * Await the end of a concurrently executing code section which is causing + * spurious link changes on the Secondary Bus of @pdev, if there is one. + * + * Unlike pci_hp_spurious_link_change(), leave the record that such a code + * section has executed in place. May be called by hotplug drivers which need + * the link to have settled, but not the cause of a link change, so that they + * don't take the answer away from the caller of pci_hp_spurious_link_change(). + */ +void pci_hp_wait_link_change(struct pci_dev *pdev) +{ + wait_event(pci_hp_link_change_wq, + !test_bit_acquire(PCI_LINK_CHANGING, &pdev->priv_flags)); +} + /** * pci_hp_spurious_link_change - check for spurious link changes * @pdev: PCI hotplug bridge @@ -551,8 +569,7 @@ void pci_hp_unignore_link_change(struct pci_dev *pdev) */ bool pci_hp_spurious_link_change(struct pci_dev *pdev) { - wait_event(pci_hp_link_change_wq, - !test_bit(PCI_LINK_CHANGING, &pdev->priv_flags)); + pci_hp_wait_link_change(pdev); return test_and_clear_bit(PCI_LINK_CHANGED, &pdev->priv_flags); } diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 175273756c183..cfa0202bf610b 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -360,6 +360,7 @@ static inline int pci_proc_detach_bus(struct pci_bus *bus) { return 0; } /* Functions for PCI Hotplug drivers to use */ int pci_hp_add_bridge(struct pci_dev *dev); +void pci_hp_wait_link_change(struct pci_dev *pdev); bool pci_hp_spurious_link_change(struct pci_dev *pdev); /* Lock for read/write access to pci device and bus lists */ -- 2.51.1
