From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: Chengfeng Ye <dg573847474@gmail.com>,
vkoul@kernel.org, rsahu@apm.com, lho@apm.com,
allen.lkml@gmail.com, romain.perier@gmail.com,
dan.j.williams@intel.com
Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] dmaengine: xgene: Fix potential deadlock on &chan->lock
Date: Wed, 26 Jul 2023 22:57:56 +0200 [thread overview]
Message-ID: <5125e39b-0faf-63fc-0c51-982b2a567e21@wanadoo.fr> (raw)
In-Reply-To: <20230726111630.25670-1-dg573847474@gmail.com>
Le 26/07/2023 à 13:16, Chengfeng Ye a écrit :
> As xgene_dma_cleanup_descriptors() is invoked by both tasklet
> xgene_dma_tasklet_cb() under softirq context and
> xgene_dma_free_chan_resources() callback that executed under process
> context, the lock aquicision of &chan->lock inside
> xgene_dma_cleanup_descriptors() should disable irq otherwise deadlock
> could happen if the tasklet softirq preempts the execution of process
> context code while the lock is held in process context on the same CPU.
>
> Possible deadlock scenario:
> xgene_dma_free_chan_resources()
> -> xgene_dma_cleanup_descriptors()
> -> spin_lock(&chan->lock)
> <tasklet softirq>
> -> xgene_dma_tasklet_cb()
> -> xgene_dma_cleanup_descriptors()
> -> spin_lock(&chan->lock) (deadlock here)
>
> This flaw was found by an experimental static analysis tool I am developing
> for irq-related deadlock.
Hi,
first of all, for what I've seen from your numerous recent patches, all
this look real great ! :)
And your experimental tool looks really promising.
Even if I'm not always confident with my understanding of locking and
related subtilities, I wonder if in the cases of <tasklet softirq>, like
above, using spin_lock_bh() would be enough?
It should be less agressive than spin_lock_irqsave() but still handle
the use case you have spotted.
Just my 2c.
CJ
>
> The tentative patch fixes the potential deadlock by spin_lock_irqsave() in
> plx_dma_process_desc() to disable irq while lock is held.
>
> Signed-off-by: Chengfeng Ye <dg573847474@gmail.com>
> ---
> drivers/dma/xgene-dma.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/dma/xgene-dma.c b/drivers/dma/xgene-dma.c
> index 3589b4ef50b8..e766511badcf 100644
> --- a/drivers/dma/xgene-dma.c
> +++ b/drivers/dma/xgene-dma.c
> @@ -689,11 +689,12 @@ static void xgene_dma_cleanup_descriptors(struct xgene_dma_chan *chan)
> struct xgene_dma_desc_sw *desc_sw, *_desc_sw;
> struct xgene_dma_desc_hw *desc_hw;
> struct list_head ld_completed;
> + unsigned long flags;
> u8 status;
>
> INIT_LIST_HEAD(&ld_completed);
>
> - spin_lock(&chan->lock);
> + spin_lock_irqsave(&chan->lock, flags);
>
> /* Clean already completed and acked descriptors */
> xgene_dma_clean_completed_descriptor(chan);
> @@ -762,7 +763,7 @@ static void xgene_dma_cleanup_descriptors(struct xgene_dma_chan *chan)
> */
> xgene_chan_xfer_ld_pending(chan);
>
> - spin_unlock(&chan->lock);
> + spin_unlock_irqrestore(&chan->lock, flags);
>
> /* Run the callback for each descriptor, in order */
> list_for_each_entry_safe(desc_sw, _desc_sw, &ld_completed, node) {
prev parent reply other threads:[~2023-07-26 20:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-26 11:16 Chengfeng Ye
2023-07-26 20:57 ` Christophe JAILLET [this message]
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=5125e39b-0faf-63fc-0c51-982b2a567e21@wanadoo.fr \
--to=christophe.jaillet@wanadoo.fr \
--cc=allen.lkml@gmail.com \
--cc=dan.j.williams@intel.com \
--cc=dg573847474@gmail.com \
--cc=dmaengine@vger.kernel.org \
--cc=lho@apm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=romain.perier@gmail.com \
--cc=rsahu@apm.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®