From: Sascha Hauer <s.hauer@pengutronix.de>
To: dmaengine@vger.kernel.org
Cc: "Vinod Koul" <vkoul@kernel.org>,
"Peter Ujfalusi" <peter.ujfalusi@ti.com>,
"Florian Fainelli" <f.fainelli@gmail.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Green Wan" <green.wan@sifive.com>,
"Kukjin Kim" <kgene@kernel.org>,
"Krzysztof Kozlowski" <krzk@kernel.org>,
"Andreas Färber" <afaerber@suse.de>,
"Sean Wang" <sean.wang@mediatek.com>,
"Eugeniy Paltsev" <Eugeniy.Paltsev@synopsys.com>,
"Pengutronix Kernel Team" <kernel@pengutronix.de>,
"NXP Linux Team" <linux-imx@nxp.com>,
"Robert Jarzmik" <robert.jarzmik@free.fr>,
"Sascha Hauer" <s.hauer@pengutronix.de>
Subject: [PATCH 4/9] dmaengine: virt-dma: Do not call desc_free() under a spin_lock
Date: Mon, 16 Dec 2019 11:53:23 +0100 [thread overview]
Message-ID: <20191216105328.15198-5-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20191216105328.15198-1-s.hauer@pengutronix.de>
vchan_vdesc_fini() shouldn't be called under a spin_lock. This is done
in two places, once in vchan_terminate_vdesc() and once in
vchan_synchronize(). Instead of freeing the vdesc right away, collect
the aborted vdescs on a separate list and free them along with the other
vdescs. The terminated descs are also freed in vchan_synchronize as done
before this patch.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/dma/virt-dma.c | 1 +
drivers/dma/virt-dma.h | 18 +++++++++---------
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/drivers/dma/virt-dma.c b/drivers/dma/virt-dma.c
index 7ba712888ac7..26e08c7a7465 100644
--- a/drivers/dma/virt-dma.c
+++ b/drivers/dma/virt-dma.c
@@ -138,6 +138,7 @@ void vchan_init(struct virt_dma_chan *vc, struct dma_device *dmadev)
INIT_LIST_HEAD(&vc->desc_submitted);
INIT_LIST_HEAD(&vc->desc_issued);
INIT_LIST_HEAD(&vc->desc_completed);
+ INIT_LIST_HEAD(&vc->desc_terminated);
tasklet_init(&vc->task, vchan_complete, (unsigned long)vc);
diff --git a/drivers/dma/virt-dma.h b/drivers/dma/virt-dma.h
index ab158bac03a7..e213137b6bc1 100644
--- a/drivers/dma/virt-dma.h
+++ b/drivers/dma/virt-dma.h
@@ -31,9 +31,9 @@ struct virt_dma_chan {
struct list_head desc_submitted;
struct list_head desc_issued;
struct list_head desc_completed;
+ struct list_head desc_terminated;
struct virt_dma_desc *cyclic;
- struct virt_dma_desc *vd_terminated;
};
static inline struct virt_dma_chan *to_virt_chan(struct dma_chan *chan)
@@ -141,11 +141,8 @@ static inline void vchan_terminate_vdesc(struct virt_dma_desc *vd)
{
struct virt_dma_chan *vc = to_virt_chan(vd->tx.chan);
- /* free up stuck descriptor */
- if (vc->vd_terminated)
- vchan_vdesc_fini(vc->vd_terminated);
+ list_add_tail(&vd->node, &vc->desc_terminated);
- vc->vd_terminated = vd;
if (vc->cyclic == vd)
vc->cyclic = NULL;
}
@@ -179,6 +176,7 @@ static inline void vchan_get_all_descriptors(struct virt_dma_chan *vc,
list_splice_tail_init(&vc->desc_submitted, head);
list_splice_tail_init(&vc->desc_issued, head);
list_splice_tail_init(&vc->desc_completed, head);
+ list_splice_tail_init(&vc->desc_terminated, head);
}
static inline void vchan_free_chan_resources(struct virt_dma_chan *vc)
@@ -207,16 +205,18 @@ static inline void vchan_free_chan_resources(struct virt_dma_chan *vc)
*/
static inline void vchan_synchronize(struct virt_dma_chan *vc)
{
+ LIST_HEAD(head);
unsigned long flags;
tasklet_kill(&vc->task);
spin_lock_irqsave(&vc->lock, flags);
- if (vc->vd_terminated) {
- vchan_vdesc_fini(vc->vd_terminated);
- vc->vd_terminated = NULL;
- }
+
+ list_splice_tail_init(&vc->desc_terminated, &head);
+
spin_unlock_irqrestore(&vc->lock, flags);
+
+ vchan_dma_desc_free_list(vc, &head);
}
#endif
--
2.24.0
next prev parent reply other threads:[~2019-12-16 10:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-16 10:53 [PATCH v3 0/9] dmaengine: virt-dma related fixes Sascha Hauer
2019-12-16 10:53 ` [PATCH 1/9] dmaengine: bcm2835: do not call vchan_vdesc_fini() with lock held Sascha Hauer
2019-12-16 10:53 ` [PATCH 2/9] dmaengine: virt-dma: Add missing locking Sascha Hauer
2019-12-16 10:53 ` [PATCH 3/9] dmaengine: virt-dma: remove debug message Sascha Hauer
2019-12-16 10:53 ` Sascha Hauer [this message]
2019-12-16 10:53 ` [PATCH 5/9] dmaengine: virt-dma: Add missing locking around list operations Sascha Hauer
2019-12-16 10:53 ` [PATCH 6/9] dmaengine: virt-dma: use vchan_vdesc_fini() to free descriptors Sascha Hauer
2019-12-16 10:53 ` [PATCH 7/9] dmaengine: imx-sdma: rename function Sascha Hauer
2019-12-16 10:53 ` [PATCH 8/9] dmaengine: imx-sdma: find desc first in sdma_tx_status Sascha Hauer
2019-12-16 10:53 ` [PATCH 9/9] dmaengine: imx-sdma: Fix memory leak Sascha Hauer
2019-12-18 10:09 ` Robin Gong
2019-12-16 11:49 ` [PATCH v3 0/9] dmaengine: virt-dma related fixes Peter Ujfalusi
2019-12-24 6:25 ` Vinod Koul
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=20191216105328.15198-5-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=Eugeniy.Paltsev@synopsys.com \
--cc=afaerber@suse.de \
--cc=dmaengine@vger.kernel.org \
--cc=f.fainelli@gmail.com \
--cc=green.wan@sifive.com \
--cc=kernel@pengutronix.de \
--cc=kgene@kernel.org \
--cc=krzk@kernel.org \
--cc=linux-imx@nxp.com \
--cc=mripard@kernel.org \
--cc=peter.ujfalusi@ti.com \
--cc=robert.jarzmik@free.fr \
--cc=sean.wang@mediatek.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