Linux-i3c Archive on lore.kernel.org
 help / Atom feed
* [PATCH] i3c: master: dw: fix deadlock
@ 2019-01-25  7:29 Jisheng Zhang
  2019-01-25 11:55 ` vitor
  0 siblings, 1 reply; 2+ messages in thread
From: Jisheng Zhang @ 2019-01-25  7:29 UTC (permalink / raw)
  To: Vitor Soares, Boris Brezillon; +Cc: linux-i3c, linux-kernel, linux-arm-kernel

In dw_i3c_master_irq_handler(), we already have gotten
&master->xferqueue.lock, if we try to get the same lock again in
dw_i3c_master_dequeue_xfer(), deadlock happens.

We fix this issue by introduing dw_i3c_master_dequeue_xfer_locked()
which does all what dw_i3c_master_dequeue_xfer() does without trying
to lock &master->xferqueue.lock.

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
---
 drivers/i3c/master/dw-i3c-master.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
index f8c00b94817f..bb03079fbade 100644
--- a/drivers/i3c/master/dw-i3c-master.c
+++ b/drivers/i3c/master/dw-i3c-master.c
@@ -419,12 +419,9 @@ static void dw_i3c_master_enqueue_xfer(struct dw_i3c_master *master,
 	spin_unlock_irqrestore(&master->xferqueue.lock, flags);
 }
 
-static void dw_i3c_master_dequeue_xfer(struct dw_i3c_master *master,
-				       struct dw_i3c_xfer *xfer)
+static void dw_i3c_master_dequeue_xfer_locked(struct dw_i3c_master *master,
+					      struct dw_i3c_xfer *xfer)
 {
-	unsigned long flags;
-
-	spin_lock_irqsave(&master->xferqueue.lock, flags);
 	if (master->xferqueue.cur == xfer) {
 		u32 status;
 
@@ -439,6 +436,15 @@ static void dw_i3c_master_dequeue_xfer(struct dw_i3c_master *master,
 	} else {
 		list_del_init(&xfer->node);
 	}
+}
+
+static void dw_i3c_master_dequeue_xfer(struct dw_i3c_master *master,
+				       struct dw_i3c_xfer *xfer)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&master->xferqueue.lock, flags);
+	dw_i3c_master_dequeue_xfer_locked(master, xfer);
 	spin_unlock_irqrestore(&master->xferqueue.lock, flags);
 }
 
@@ -494,7 +500,7 @@ static void dw_i3c_master_end_xfer_locked(struct dw_i3c_master *master, u32 isr)
 	complete(&xfer->comp);
 
 	if (ret < 0) {
-		dw_i3c_master_dequeue_xfer(master, xfer);
+		dw_i3c_master_dequeue_xfer_locked(master, xfer);
 		writel(readl(master->regs + DEVICE_CTRL) | DEV_CTRL_RESUME,
 		       master->regs + DEVICE_CTRL);
 	}
-- 
2.20.1


_______________________________________________
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* Re: [PATCH] i3c: master: dw: fix deadlock
  2019-01-25  7:29 [PATCH] i3c: master: dw: fix deadlock Jisheng Zhang
@ 2019-01-25 11:55 ` vitor
  0 siblings, 0 replies; 2+ messages in thread
From: vitor @ 2019-01-25 11:55 UTC (permalink / raw)
  To: Jisheng Zhang, Vitor Soares, Boris Brezillon
  Cc: linux-i3c, linux-kernel, linux-arm-kernel

Hi Jisheng,

Thanks for your report.

On 25/01/19 07:29, Jisheng Zhang wrote:
> In dw_i3c_master_irq_handler(), we already have gotten
> &master->xferqueue.lock, if we try to get the same lock again in
> dw_i3c_master_dequeue_xfer(), deadlock happens.
>
> We fix this issue by introduing dw_i3c_master_dequeue_xfer_locked()
> which does all what dw_i3c_master_dequeue_xfer() does without trying
> to lock &master->xferqueue.lock.
>
> Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
> ---
>  drivers/i3c/master/dw-i3c-master.c | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
> index f8c00b94817f..bb03079fbade 100644
> --- a/drivers/i3c/master/dw-i3c-master.c
> +++ b/drivers/i3c/master/dw-i3c-master.c
> @@ -419,12 +419,9 @@ static void dw_i3c_master_enqueue_xfer(struct dw_i3c_master *master,
>  	spin_unlock_irqrestore(&master->xferqueue.lock, flags);
>  }
>  
> -static void dw_i3c_master_dequeue_xfer(struct dw_i3c_master *master,
> -				       struct dw_i3c_xfer *xfer)
> +static void dw_i3c_master_dequeue_xfer_locked(struct dw_i3c_master *master,
> +					      struct dw_i3c_xfer *xfer)
>  {
> -	unsigned long flags;
> -
> -	spin_lock_irqsave(&master->xferqueue.lock, flags);
>  	if (master->xferqueue.cur == xfer) {
>  		u32 status;
>  
> @@ -439,6 +436,15 @@ static void dw_i3c_master_dequeue_xfer(struct dw_i3c_master *master,
>  	} else {
>  		list_del_init(&xfer->node);
>  	}
> +}
> +
> +static void dw_i3c_master_dequeue_xfer(struct dw_i3c_master *master,
> +				       struct dw_i3c_xfer *xfer)
> +{
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&master->xferqueue.lock, flags);
> +	dw_i3c_master_dequeue_xfer_locked(master, xfer);
>  	spin_unlock_irqrestore(&master->xferqueue.lock, flags);
>  }
>  
> @@ -494,7 +500,7 @@ static void dw_i3c_master_end_xfer_locked(struct dw_i3c_master *master, u32 isr)
>  	complete(&xfer->comp);
>  
>  	if (ret < 0) {
> -		dw_i3c_master_dequeue_xfer(master, xfer);
> +		dw_i3c_master_dequeue_xfer_locked(master, xfer);
>  		writel(readl(master->regs + DEVICE_CTRL) | DEV_CTRL_RESUME,
>  		       master->regs + DEVICE_CTRL);
>  	}
Acked-by: Vitor Soares <vitor.soares@synopsys.com>

_______________________________________________
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-25  7:29 [PATCH] i3c: master: dw: fix deadlock Jisheng Zhang
2019-01-25 11:55 ` vitor

Linux-i3c Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-i3c/0 linux-i3c/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-i3c linux-i3c/ https://lore.kernel.org/linux-i3c \
		linux-i3c@lists.infradead.org linux-i3c@archiver.kernel.org
	public-inbox-index linux-i3c


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-i3c


AGPL code for this site: git clone https://public-inbox.org/ public-inbox