public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i2c_dw: deadlock happening when system is trying to suspend
@ 2012-06-26 14:29 Liu, Chuansheng
       [not found] ` <27240C0AC20F114CBF8149A2696CBE4A0EE76A-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Liu, Chuansheng @ 2012-06-26 14:29 UTC (permalink / raw)
  To: linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org
  Cc: khali@linux-fr.org, ben-linux@fluff.org,
	Yanmin Zhang <yanmin_zhang@linux.intel.com> (yanmin_zhang@linux.intel.com),
	Srivatsa S. Bhat, Tu, Xiaobing

From: liu chuansheng <chuansheng.liu@intel.com>
Subject: [PATCH] i2c_dw: deadlock happening when system is trying to suspend

In i2c_dw code, there is a race condition that causes pm suspend
thread blocking there always. The scenerio is as below:

PM thread:
suspend -->
pm_suspend -->
enter_state -->
dpm_suspend_start(will call i2c_dw_pci_suspend(),
and the dw_i2c_dev->lock is hold)
...
suspend_enter -->
dpm_suspend_noirq -->
suspend_device_irqs -->
synchronize_irq()

synchronize_irq will wait for any pending irq is handled, and
the correpsonding irq thread is finished.

In this case, there is a i2c device interrupt is pending, the irq
thread do the below things:
IRQ thread:
i2c_smbus_read_byte_data -->
i2c_smbus_xfer -->
i2c_transfer -->
i2c_dw_xfer -->
down()

The irq thread blocked at down dw_i2c_dev->lock, because in PM thread,
it has been hold after calling i2c_dw_pci_suspend(), but PM thread is
waiting for IRQ thread, then deadlock happened.

The solution is moving the down() action after pm_runtime_get_sync().

Signed-off-by: liu chuansheng <chuansheng.liu@intel.com>
---
 drivers/i2c/busses/i2c-designware-core.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
index 1e48bec..748ecb1 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -512,8 +512,8 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
 
        dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num);
 
-       mutex_lock(&dev->lock);
        pm_runtime_get_sync(dev->dev);
+       mutex_lock(&dev->lock);
 
        INIT_COMPLETION(dev->cmd_complete);
        dev->msgs = msgs;
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-07-09 13:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-26 14:29 [PATCH] i2c_dw: deadlock happening when system is trying to suspend Liu, Chuansheng
     [not found] ` <27240C0AC20F114CBF8149A2696CBE4A0EE76A-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2012-07-09 13:31   ` Wolfram Sang
     [not found]     ` <20120709133154.GK1296-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2012-07-09 13:40       ` Liu, Chuansheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox