thunderbolt: Serialize PCIe tunnel creation with PCI rescan
authorMika Westerberg <mika.westerberg@linux.intel.com>
Thu, 18 Jan 2018 17:27:47 +0000 (20:27 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 24 Apr 2018 07:36:29 +0000 (09:36 +0200)
commit a03e828915c00ed0ea5aa40647c81472cfa7a984 upstream.

We need to make sure a new PCIe tunnel is not created in a middle of
previous PCI rescan because otherwise the rescan code might find too
much and fail to reconfigure devices properly. This is important when
native PCIe hotplug is used. In BIOS assisted hotplug there should be no
such issue.

Fixes: f67cf491175a ("thunderbolt: Add support for Internal Connection Manager (ICM)")
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/thunderbolt/switch.c

index 3953d17202a87f239b2a9209d030db87366fd30c..8bd1371099808975546fc301be2ccbdb2400f4de 100644 (file)
@@ -716,6 +716,13 @@ static int tb_switch_set_authorized(struct tb_switch *sw, unsigned int val)
        if (sw->authorized)
                goto unlock;
 
+       /*
+        * Make sure there is no PCIe rescan ongoing when a new PCIe
+        * tunnel is created. Otherwise the PCIe rescan code might find
+        * the new tunnel too early.
+        */
+       pci_lock_rescan_remove();
+
        switch (val) {
        /* Approve switch */
        case 1:
@@ -735,6 +742,8 @@ static int tb_switch_set_authorized(struct tb_switch *sw, unsigned int val)
                break;
        }
 
+       pci_unlock_rescan_remove();
+
        if (!ret) {
                sw->authorized = val;
                /* Notify status change to the userspace */