From: Chengfeng Ye <dg573847474@gmail.com>
To: vkoul@kernel.org, sugaya.taichi@socionext.com,
orito.takao@socionext.com, len.baker@gmx.com,
jaswinder.singh@linaro.org
Cc: dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Chengfeng Ye <dg573847474@gmail.com>
Subject: [PATCH RESEND] dmaengine: milbeaut-hdmac: Fix potential deadlock on &mc->vc.lock
Date: Wed, 26 Jul 2023 09:06:28 +0000 [thread overview]
Message-ID: <20230726090628.1784-1-dg573847474@gmail.com> (raw)
As &mc->vc.lock is acquired by milbeaut_hdmac_interrupt() under irq
context, other acquisition of the same lock under process context should
disable irq, otherwise deadlock could happen if the irq preempts the
execution of process context code while the lock is held in process context
on the same CPU.
milbeaut_hdmac_chan_config(), milbeaut_hdmac_chan_resume() and
milbeaut_hdmac_chan_pause() are such callback functions not disable irq by
default.
Possible deadlock scenario:
milbeaut_hdmac_chan_config()
-> spin_lock(&mc->vc.lock)
<hard interruption>
-> milbeaut_hdmac_interrupt()
-> spin_lock(&mc->vc.lock); (deadlock here)
This flaw was found by an experimental static analysis tool I am developing
for irq-related deadlock.
The tentative patch fixes the potential deadlock by spin_lock_irqsave() in
the three callback functions to disable irq while lock is held.
Signed-off-by: Chengfeng Ye <dg573847474@gmail.com>
---
drivers/dma/milbeaut-hdmac.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/dma/milbeaut-hdmac.c b/drivers/dma/milbeaut-hdmac.c
index 1b0a95892627..6151c830ff6e 100644
--- a/drivers/dma/milbeaut-hdmac.c
+++ b/drivers/dma/milbeaut-hdmac.c
@@ -214,10 +214,11 @@ milbeaut_hdmac_chan_config(struct dma_chan *chan, struct dma_slave_config *cfg)
{
struct virt_dma_chan *vc = to_virt_chan(chan);
struct milbeaut_hdmac_chan *mc = to_milbeaut_hdmac_chan(vc);
+ unsigned long flags;
- spin_lock(&mc->vc.lock);
+ spin_lock_irqsave(&mc->vc.lock, flags);
mc->cfg = *cfg;
- spin_unlock(&mc->vc.lock);
+ spin_unlock_irqrestore(&mc->vc.lock, flags);
return 0;
}
@@ -226,13 +227,14 @@ static int milbeaut_hdmac_chan_pause(struct dma_chan *chan)
{
struct virt_dma_chan *vc = to_virt_chan(chan);
struct milbeaut_hdmac_chan *mc = to_milbeaut_hdmac_chan(vc);
+ unsigned long flags;
u32 val;
- spin_lock(&mc->vc.lock);
+ spin_lock_irqsave(&mc->vc.lock, flags);
val = readl_relaxed(mc->reg_ch_base + MLB_HDMAC_DMACA);
val |= MLB_HDMAC_PB;
writel_relaxed(val, mc->reg_ch_base + MLB_HDMAC_DMACA);
- spin_unlock(&mc->vc.lock);
+ spin_unlock_irqrestore(&mc->vc.lock, flags);
return 0;
}
@@ -241,13 +243,14 @@ static int milbeaut_hdmac_chan_resume(struct dma_chan *chan)
{
struct virt_dma_chan *vc = to_virt_chan(chan);
struct milbeaut_hdmac_chan *mc = to_milbeaut_hdmac_chan(vc);
+ unsigned long flags;
u32 val;
- spin_lock(&mc->vc.lock);
+ spin_lock_irqsave(&mc->vc.lock, flags);
val = readl_relaxed(mc->reg_ch_base + MLB_HDMAC_DMACA);
val &= ~MLB_HDMAC_PB;
writel_relaxed(val, mc->reg_ch_base + MLB_HDMAC_DMACA);
- spin_unlock(&mc->vc.lock);
+ spin_unlock_irqrestore(&mc->vc.lock, flags);
return 0;
}
--
2.17.1
next reply other threads:[~2023-07-26 9:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-26 9:06 Chengfeng Ye [this message]
2023-08-16 15:33 ` Chengfeng Ye
2023-08-16 16:26 ` Jassi Brar
2023-08-16 17:02 ` Chengfeng Ye
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230726090628.1784-1-dg573847474@gmail.com \
--to=dg573847474@gmail.com \
--cc=dmaengine@vger.kernel.org \
--cc=jaswinder.singh@linaro.org \
--cc=len.baker@gmx.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=orito.takao@socionext.com \
--cc=sugaya.taichi@socionext.com \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®