]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
PCI: pciehp: Fix race condition handling surprise link down
authorMika Westerberg <mika.westerberg@linux.intel.com>
Fri, 13 Oct 2017 18:35:46 +0000 (21:35 +0300)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 7 Nov 2017 00:49:00 +0000 (18:49 -0600)
A surprise link down may retrain very quickly causing the same slot
generate a link up event before handling the link down event completes.

Since the link is active, the power off work queued from the first link
down will cause a second down event when power is disabled. However, the
link up event sets the slot state to POWERON_STATE before the event to
handle this is enqueued, making the second down event believe it needs to
do something.

This creates constant link up and down event cycle.

To prevent this it is better to handle each event at the time in order it
occurred, so change the driver to use ordered workqueue instead.

A normal device hotplug triggers two events (presense detect and link up)
that are already handled properly in the driver but we currently log an
error if we find an existing device in the slot. Since this is not an error
change the log level to be debug instead to avoid scaring users.

This is based on the original work by Ashok Raj.

Link: https://patchwork.kernel.org/patch/9469023
Suggested-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/hotplug/pciehp_ctrl.c
drivers/pci/hotplug/pciehp_hpc.c
drivers/pci/hotplug/pciehp_pci.c

index ec0b4c11ccd9dc95cdb738d03ae292744e34127e..83f3d4af3677537f282269ad1041f227f313f011 100644 (file)
@@ -113,10 +113,11 @@ static int board_added(struct slot *p_slot)
 
        retval = pciehp_configure_device(p_slot);
        if (retval) {
-               ctrl_err(ctrl, "Cannot add device at %04x:%02x:00\n",
-                        pci_domain_nr(parent), parent->number);
-               if (retval != -EEXIST)
+               if (retval != -EEXIST) {
+                       ctrl_err(ctrl, "Cannot add device at %04x:%02x:00\n",
+                                pci_domain_nr(parent), parent->number);
                        goto err_exit;
+               }
        }
 
        pciehp_green_led_on(p_slot);
index ba5055c5115c0bafc3b51a70da27bb6b3e5d911e..fd0877e92b055b200c978b063e04feb33b9f79ed 100644 (file)
@@ -791,7 +791,7 @@ static int pcie_init_slot(struct controller *ctrl)
        if (!slot)
                return -ENOMEM;
 
-       slot->wq = alloc_workqueue("pciehp-%u", 0, 0, PSN(ctrl));
+       slot->wq = alloc_ordered_workqueue("pciehp-%u", 0, PSN(ctrl));
        if (!slot->wq)
                goto abort;
 
index c3af027ee1a688aa903291ac8629b82fe71a70ef..2a1ca020cf5a792eac7103a19368b4883ab6a46e 100644 (file)
@@ -46,7 +46,11 @@ int pciehp_configure_device(struct slot *p_slot)
 
        dev = pci_get_slot(parent, PCI_DEVFN(0, 0));
        if (dev) {
-               ctrl_err(ctrl, "Device %s already exists at %04x:%02x:00, cannot hot-add\n",
+               /*
+                * The device is already there. Either configured by the
+                * boot firmware or a previous hotplug event.
+                */
+               ctrl_dbg(ctrl, "Device %s already exists at %04x:%02x:00, skipping hot-add\n",
                         pci_name(dev), pci_domain_nr(parent), parent->number);
                pci_dev_put(dev);
                ret = -EEXIST;