dmaengine.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Ujfalusi <peter.ujfalusi@ti.com>
To: Sascha Hauer <s.hauer@pengutronix.de>, <dmaengine@vger.kernel.org>
Cc: Vinod Koul <vkoul@kernel.org>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	NXP Linux Team <linux-imx@nxp.com>,
	Robert Jarzmik <robert.jarzmik@free.fr>
Subject: Re: [PATCH 2/5] dmaengine: virt-dma: Do not call desc_free() under a spin_lock
Date: Mon, 9 Dec 2019 10:33:36 +0200	[thread overview]
Message-ID: <c0839f58-9f85-4b23-59cc-75f7bdb98c18@ti.com> (raw)
In-Reply-To: <65b923ed-4370-089c-1d6c-ce7efac176e6@ti.com>



On 09/12/2019 9.48, Peter Ujfalusi wrote:
> Hi Sascha,
> 
> 
> On 06/12/2019 15.53, Sascha Hauer wrote:
>> 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.
>>
>> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
>> ---
>>  drivers/dma/virt-dma.c |  1 +
>>  drivers/dma/virt-dma.h | 17 +++--------------
>>  2 files changed, 4 insertions(+), 14 deletions(-)
>>
>> diff --git a/drivers/dma/virt-dma.c b/drivers/dma/virt-dma.c
>> index ec4adf4260a0..87d5bd53c98b 100644
>> --- a/drivers/dma/virt-dma.c
>> +++ b/drivers/dma/virt-dma.c
>> @@ -135,6 +135,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_aborted);
> 
> Can we keep the terminated term instead of aborted: 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 41883ee2c29f..6cae93624f0d 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_aborted;
>>  
>>  	struct virt_dma_desc *cyclic;
>> -	struct virt_dma_desc *vd_terminated;
>>  };
>>  
>>  static inline struct virt_dma_chan *to_virt_chan(struct dma_chan *chan)
>> @@ -146,11 +146,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_aborted);
>>  
>> -	vc->vd_terminated = vd;
>>  	if (vc->cyclic == vd)
>>  		vc->cyclic = NULL;
>>  }
>> @@ -184,6 +181,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_aborted, head);
>>  }
>>  
>>  static inline void vchan_free_chan_resources(struct virt_dma_chan *vc)
>> @@ -212,16 +210,7 @@ static inline void vchan_free_chan_resources(struct virt_dma_chan *vc)
>>   */
>>  static inline void vchan_synchronize(struct virt_dma_chan *vc)
>>  {
>> -	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;
>> -	}
>> -	spin_unlock_irqrestore(&vc->lock, flags);
> 
> We don't want the terminated descriptors to accumulate until the channel
> is freed up.

Well, most DMA driver will clean it up in their terminate_all, but it is
better to do it in synchronize as well.

> 
> spin_lock_irqsave(&vc->lock, flags);
> list_splice_tail_init(&vc->desc_terminated, &head);
> spin_unlock_irqrestore(&vc->lock, flags);
> 
> list_for_each_entry_safe(vd, _vd, &head, node) {
> 	list_del(&vd->node);
> 	vchan_vdesc_fini(vd);
> }
> 
> 
>>  }
>>  
>>  #endif
>>
> 
> - Péter
> 
> Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
> Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
> 

- Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

  reply	other threads:[~2019-12-09  8:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-06 13:53 [PATCH 0/5] virt-dma and i.MX SDMA fixes Sascha Hauer
2019-12-06 13:53 ` [PATCH 1/5] dmaengine: virt-dma: Add missing locking around list operations Sascha Hauer
2019-12-09  7:38   ` Peter Ujfalusi
2019-12-10 11:56     ` Sascha Hauer
2019-12-06 13:53 ` [PATCH 2/5] dmaengine: virt-dma: Do not call desc_free() under a spin_lock Sascha Hauer
2019-12-09  7:48   ` Peter Ujfalusi
2019-12-09  8:33     ` Peter Ujfalusi [this message]
2019-12-10 11:58     ` Sascha Hauer
2019-12-06 13:53 ` [PATCH 3/5] dmaengine: imx-sdma: rename function Sascha Hauer
2019-12-06 13:53 ` [PATCH 4/5] dmaengine: imx-sdma: find desc first in sdma_tx_status Sascha Hauer
2019-12-06 13:53 ` [PATCH 5/5] dmaengine: imx-sdma: Fix memory leak Sascha Hauer

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=c0839f58-9f85-4b23-59cc-75f7bdb98c18@ti.com \
    --to=peter.ujfalusi@ti.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=linux-imx@nxp.com \
    --cc=robert.jarzmik@free.fr \
    --cc=s.hauer@pengutronix.de \
    --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;
as well as URLs for NNTP newsgroup(s).