]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
PCI: pciehp: Add hotplug_lock to serialize hotplug events
authorRajat Jain <rajatxjain@gmail.com>
Tue, 30 Jun 2015 13:05:08 +0000 (15:05 +0200)
committerJiri Slaby <jslaby@suse.cz>
Thu, 30 Jul 2015 12:10:35 +0000 (14:10 +0200)
commit 50b52fdee050745935d92e7026373edea2647e60 upstream.

Today it is there is no protection around pciehp_enable_slot() and
pciehp_disable_slot() to ensure that they complete before another
hot-plug operation can be done on that particular slot.

This patch introduces the slot->hotplug_lock to ensure that any hotplug
operations (add / remove) complete before another hotplug event can begin
processing on that particular slot.

Signed-off-by: Rajat Jain <rajatxjain@gmail.com>
Signed-off-by: Rajat Jain <rajatjain@juniper.net>
Signed-off-by: Guenter Roeck <groeck@juniper.net>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
[backported for SLE12]
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
Signed-off-by: Jiri Slaby <jslaby@suse.com>
drivers/pci/hotplug/pciehp.h
drivers/pci/hotplug/pciehp_core.c
drivers/pci/hotplug/pciehp_ctrl.c
drivers/pci/hotplug/pciehp_hpc.c

index 541bbe6d5343e9c99da97f9e5fd8c74c554b24d3..b7f1ba33c4c10abd168a380181e9490dd5ef31a9 100644 (file)
@@ -77,6 +77,7 @@ struct slot {
        struct hotplug_slot *hotplug_slot;
        struct delayed_work work;       /* work for button event */
        struct mutex lock;
+       struct mutex hotplug_lock;
        struct workqueue_struct *wq;
 };
 
index f4a18f51a29cc3bc1c17121ab265ce9e199da0ec..3904483ef12b6fedb8e94015fc4a97e678d70fdf 100644 (file)
@@ -278,8 +278,11 @@ static int pciehp_probe(struct pcie_device *dev)
        slot = ctrl->slot;
        pciehp_get_adapter_status(slot, &occupied);
        pciehp_get_power_status(slot, &poweron);
-       if (occupied && pciehp_force)
+       if (occupied && pciehp_force) {
+               mutex_lock(&slot->hotplug_lock);
                pciehp_enable_slot(slot);
+               mutex_unlock(&slot->hotplug_lock);
+       }
        /* If empty slot's power status is on, turn power off */
        if (!occupied && poweron && POWER_CTRL(ctrl))
                pciehp_power_off_slot(slot);
@@ -323,10 +326,12 @@ static int pciehp_resume (struct pcie_device *dev)
 
        /* Check if slot is occupied */
        pciehp_get_adapter_status(slot, &status);
+       mutex_lock(&slot->hotplug_lock);
        if (status)
                pciehp_enable_slot(slot);
        else
                pciehp_disable_slot(slot);
+       mutex_unlock(&slot->hotplug_lock);
        return 0;
 }
 #endif /* PM */
index 38f01867917521a6402e92dbaaf5add19b27a640..62bfb528b4ffba8293b64e1788a38d4b7cc990e6 100644 (file)
@@ -290,6 +290,7 @@ static void pciehp_power_thread(struct work_struct *work)
        struct power_work_info *info =
                container_of(work, struct power_work_info, work);
        struct slot *p_slot = info->p_slot;
+       int ret;
 
        mutex_lock(&p_slot->lock);
        switch (p_slot->state) {
@@ -299,13 +300,18 @@ static void pciehp_power_thread(struct work_struct *work)
                         "Disabling domain:bus:device=%04x:%02x:00\n",
                         pci_domain_nr(p_slot->ctrl->pcie->port->subordinate),
                         p_slot->ctrl->pcie->port->subordinate->number);
+               mutex_lock(&p_slot->hotplug_lock);
                pciehp_disable_slot(p_slot);
+               mutex_unlock(&p_slot->hotplug_lock);
                mutex_lock(&p_slot->lock);
                p_slot->state = STATIC_STATE;
                break;
        case POWERON_STATE:
                mutex_unlock(&p_slot->lock);
-               if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl))
+               mutex_lock(&p_slot->hotplug_lock);
+               ret = pciehp_enable_slot(p_slot);
+               mutex_unlock(&p_slot->hotplug_lock);
+               if (ret && PWR_LED(p_slot->ctrl))
                        pciehp_green_led_off(p_slot);
                mutex_lock(&p_slot->lock);
                p_slot->state = STATIC_STATE;
@@ -476,6 +482,9 @@ static void interrupt_event_handler(struct work_struct *work)
        kfree(info);
 }
 
+/*
+ * Note: This function must be called with slot->hotplug_lock held
+ */
 int pciehp_enable_slot(struct slot *p_slot)
 {
        u8 getstatus = 0;
@@ -514,7 +523,9 @@ int pciehp_enable_slot(struct slot *p_slot)
        return rc;
 }
 
-
+/*
+ * Note: This function must be called with slot->hotplug_lock held
+ */
 int pciehp_disable_slot(struct slot *p_slot)
 {
        u8 getstatus = 0;
@@ -566,7 +577,9 @@ int pciehp_sysfs_enable_slot(struct slot *p_slot)
        case STATIC_STATE:
                p_slot->state = POWERON_STATE;
                mutex_unlock(&p_slot->lock);
+               mutex_lock(&p_slot->hotplug_lock);
                retval = pciehp_enable_slot(p_slot);
+               mutex_unlock(&p_slot->hotplug_lock);
                mutex_lock(&p_slot->lock);
                p_slot->state = STATIC_STATE;
                break;
index 51f56ef4ab6f83a9382527f9061172800fff589a..f49e74239aed003c036ad1e67fe14d5b9b1e1c04 100644 (file)
@@ -815,6 +815,7 @@ static int pcie_init_slot(struct controller *ctrl)
 
        slot->ctrl = ctrl;
        mutex_init(&slot->lock);
+       mutex_init(&slot->hotplug_lock);
        INIT_DELAYED_WORK(&slot->work, pciehp_queue_pushbutton_work);
        ctrl->slot = slot;
        return 0;