提交 13533782 编写于 作者: X Xiongfeng Wang 提交者: Xie XiuQi

pciehp: use completion to wait irq_thread 'pciehp_ist'

hulk inclusion
category: bugfix
bugzilla: NA
CVE: NA
-------------------

When I use the following command to power on a slot which has been
powered off already.
echo 1 > /sys/bus/pci/slots/22/power
It prints the following error:
-bash: echo: write error: No such device
But the slot is actually powered on and the devices is probed.

In function 'pciehp_sysfs_enable_slot()', we use 'wait_event()' to wait
until 'ctrl->pending_events' is cleared in 'pciehp_ist()'. But in some
situation, when 'pciehp_ist()' is woken up on a nearby CPU after
'pciehp_request' is called, 'ctrl->pending_events' is cleared before we
go into sleep state. 'wait_event()' will check the condition before
going into sleep. So we return immediately and '-ENODEV' is return.

This patch use struct completion to wait until irq_thread 'pciehp_ist'
is completed.
Signed-off-by: NXiongfeng Wang <wangxiongfeng2@huawei.com>
Reviewed-by: NYao Hongbo <yaohongbo@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 f49ed7d1
...@@ -126,7 +126,7 @@ struct controller { ...@@ -126,7 +126,7 @@ struct controller {
unsigned int power_fault_detected; unsigned int power_fault_detected;
atomic_t pending_events; atomic_t pending_events;
int request_result; int request_result;
wait_queue_head_t requester; struct completion requester;
}; };
/** /**
......
...@@ -403,9 +403,9 @@ int pciehp_sysfs_enable_slot(struct slot *p_slot) ...@@ -403,9 +403,9 @@ int pciehp_sysfs_enable_slot(struct slot *p_slot)
* card before the thread wakes up, so initialize to -ENODEV. * card before the thread wakes up, so initialize to -ENODEV.
*/ */
ctrl->request_result = -ENODEV; ctrl->request_result = -ENODEV;
reinit_completion(&ctrl->requester);
pciehp_request(ctrl, PCI_EXP_SLTSTA_PDC); pciehp_request(ctrl, PCI_EXP_SLTSTA_PDC);
wait_event(ctrl->requester, wait_for_completion(&ctrl->requester);
!atomic_read(&ctrl->pending_events));
return ctrl->request_result; return ctrl->request_result;
case POWERON_STATE: case POWERON_STATE:
ctrl_info(ctrl, "Slot(%s): Already in powering on state\n", ctrl_info(ctrl, "Slot(%s): Already in powering on state\n",
...@@ -436,9 +436,9 @@ int pciehp_sysfs_disable_slot(struct slot *p_slot) ...@@ -436,9 +436,9 @@ int pciehp_sysfs_disable_slot(struct slot *p_slot)
case BLINKINGOFF_STATE: case BLINKINGOFF_STATE:
case ON_STATE: case ON_STATE:
mutex_unlock(&p_slot->lock); mutex_unlock(&p_slot->lock);
reinit_completion(&ctrl->requester);
pciehp_request(ctrl, DISABLE_SLOT); pciehp_request(ctrl, DISABLE_SLOT);
wait_event(ctrl->requester, wait_for_completion(&ctrl->requester);
!atomic_read(&ctrl->pending_events));
return ctrl->request_result; return ctrl->request_result;
case POWEROFF_STATE: case POWEROFF_STATE:
ctrl_info(ctrl, "Slot(%s): Already in powering off state\n", ctrl_info(ctrl, "Slot(%s): Already in powering off state\n",
......
...@@ -739,7 +739,7 @@ static irqreturn_t pciehp_ist(int irq, void *dev_id) ...@@ -739,7 +739,7 @@ static irqreturn_t pciehp_ist(int irq, void *dev_id)
up_read(&ctrl->reset_lock); up_read(&ctrl->reset_lock);
pci_config_pm_runtime_put(pdev); pci_config_pm_runtime_put(pdev);
wake_up(&ctrl->requester); complete(&ctrl->requester);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -953,7 +953,7 @@ struct controller *pcie_init(struct pcie_device *dev) ...@@ -953,7 +953,7 @@ struct controller *pcie_init(struct pcie_device *dev)
ctrl->slot_cap = slot_cap; ctrl->slot_cap = slot_cap;
mutex_init(&ctrl->ctrl_lock); mutex_init(&ctrl->ctrl_lock);
init_rwsem(&ctrl->reset_lock); init_rwsem(&ctrl->reset_lock);
init_waitqueue_head(&ctrl->requester); init_completion(&ctrl->requester);
init_waitqueue_head(&ctrl->queue); init_waitqueue_head(&ctrl->queue);
dbg_ctrl(ctrl); dbg_ctrl(ctrl);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册