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/6] dmaengine: virt-dma: Add missing locking around list operations
Date: Tue, 10 Dec 2019 15:16:51 +0200	[thread overview]
Message-ID: <6fd01a9e-9eda-b1a3-88e3-893d2c3ee70a@ti.com> (raw)
In-Reply-To: <20191210123352.7555-3-s.hauer@pengutronix.de>



On 10/12/2019 14.33, Sascha Hauer wrote:
> All list operations are protected by &vc->lock. As vchan_vdesc_fini()
> is called unlocked add the missing locking around the list operations.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  drivers/dma/virt-dma.h | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma/virt-dma.h b/drivers/dma/virt-dma.h
> index e213137b6bc1..e9f5250fbe4d 100644
> --- a/drivers/dma/virt-dma.h
> +++ b/drivers/dma/virt-dma.h
> @@ -113,10 +113,15 @@ static inline void vchan_vdesc_fini(struct virt_dma_desc *vd)
>  {
>  	struct virt_dma_chan *vc = to_virt_chan(vd->tx.chan);
>  
> -	if (dmaengine_desc_test_reuse(&vd->tx))
> +	if (dmaengine_desc_test_reuse(&vd->tx)) {
> +		unsigned long flags;
> +
> +		spin_lock_irqsave(&vc->lock, flags);
>  		list_add(&vd->node, &vc->desc_allocated);
> -	else
> +		spin_unlock_irqrestore(&vc->lock, flags);
> +	} else {

If we add:
		list_del(&vd->node);

here, then the list_del() can be removed from vchan_complete() before
vchan_vdesc_fini() is called and as a plus the
vchan_dma_desc_free_list() can be as simple as:

list_for_each_entry_safe(vd, _vd, head, node)
	vchan_vdesc_fini(vd);

But only if we don't care about the debug print in there, if we care
then the vchan_synchronize() could use the very same simple loop to free
up only the descriptors from the desc_terminated list.


>  		vc->desc_free(vd);
> +	}
>  }
>  
>  /**
> 

- Péter

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

  reply	other threads:[~2019-12-10 13:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-10 12:33 [PATCH v2 0/6] virt-dma and i.MX SDMA fixes Sascha Hauer
2019-12-10 12:33 ` [PATCH 1/6] dmaengine: virt-dma: Do not call desc_free() under a spin_lock Sascha Hauer
2019-12-10 13:12   ` Peter Ujfalusi
2019-12-10 14:19     ` Sascha Hauer
2019-12-10 15:23       ` Peter Ujfalusi
2019-12-10 12:33 ` [PATCH 2/6] dmaengine: virt-dma: Add missing locking around list operations Sascha Hauer
2019-12-10 13:16   ` Peter Ujfalusi [this message]
2019-12-10 12:33 ` [PATCH 3/6] dmaengine: imx-sdma: rename function Sascha Hauer
2019-12-10 12:33 ` [PATCH 4/6] dmaengine: imx-sdma: find desc first in sdma_tx_status Sascha Hauer
2019-12-10 12:33 ` [PATCH 5/6] dmaengine: imx-sdma: Fix memory leak Sascha Hauer
2019-12-10 12:33 ` [PATCH 6/6] ARM: imx_v6_v7_defconfig: Enable NFS_V4_1 and NFS_V4_2 support Sascha Hauer
2019-12-10 13:56   ` 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=6fd01a9e-9eda-b1a3-88e3-893d2c3ee70a@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).