From: Sascha Hauer <s.hauer@pengutronix.de>
To: Peter Ujfalusi <peter.ujfalusi@ti.com>
Cc: dmaengine@vger.kernel.org,
Robert Jarzmik <robert.jarzmik@free.fr>,
Vinod Koul <vkoul@kernel.org>,
kernel@pengutronix.de, Russell King <linux@armlinux.org.uk>
Subject: Re: vchan helper broken wrt locking
Date: Wed, 4 Dec 2019 16:51:16 +0100 [thread overview]
Message-ID: <20191204155116.uqxioshtombxfe5g@pengutronix.de> (raw)
In-Reply-To: <12ec3499-ac9a-2722-2052-02d77975c26c@ti.com>
On Wed, Dec 04, 2019 at 01:47:03PM +0200, Peter Ujfalusi wrote:
> Hi Sascha,
>
> On 03/12/2019 13.50, Sascha Hauer wrote:
> > Hi All,
> >
> > vc->desc_free() used to be called in non atomic context which makes
> > sense to me. This changed over time and now vc->desc_free() is sometimes
> > called in atomic context and sometimes not.
> >
> > The story starts with 13bb26ae8850 ("dmaengine: virt-dma: don't always
> > free descriptor upon completion"). This introduced a vc->desc_allocated
> > list which is mostly handled with the lock held, except in vchan_complete().
> > vchan_complete() moves the completed descs onto a separate list for the sake
> > of iterating over that list without the lock held allowing to call
> > vc->desc_free() without lock. 13bb26ae8850 changes this to:
> >
> > @@ -83,8 +110,10 @@ static void vchan_complete(unsigned long arg)
> > cb_data = vd->tx.callback_param;
> >
> > list_del(&vd->node);
> > -
> > - vc->desc_free(vd);
> > + if (dmaengine_desc_test_reuse(&vd->tx))
> > + list_add(&vd->node, &vc->desc_allocated);
> > + else
> > + vc->desc_free(vd);
> >
> > vc->desc_free() is still called without lock, but the list operation is done
> > without locking as well which is wrong.
>
> Hrm, yes all list operation against desc_* should be protected by the
> lock, it is a miss.
>
> > Now with 6af149d2b142 ("dmaengine: virt-dma: Add helper to free/reuse a
> > descriptor") the hunk above was moved to a separate function
> > (vchan_vdesc_fini()). With 1c7f072d94e8 ("dmaengine: virt-dma: Support for
> > race free transfer termination") the helper is started to be called with
> > lock held resulting in vc->desc_free() being called under the lock as
> > well. It is still called from vchan_complete() without lock.
>
> Right.
> I think the most elegant way to fix this would be to introduce a new
> list_head in virt_dma_chan, let's name it desc_terminated.
>
> We would add the descriptor to this within vchan_terminate_vdesc() (lock
> is held).
> In vchan_synchronize() we would
> list_splice_tail_init(&vc->desc_terminated, &head);
> with the lock held and outside of the lock we free them up.
>
> So we would put the terminated descs to the new list and free them up in
> synchronize.
>
> This way the vchan_vdesc_fini() would be only called without the lock held.
Ok, this sounds like a plan. I'll try and make up a patch for this.
Thanks,
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
prev parent reply other threads:[~2019-12-04 15:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-03 11:50 vchan helper broken wrt locking Sascha Hauer
2019-12-04 8:45 ` Robert Jarzmik
2019-12-04 11:47 ` Peter Ujfalusi
2019-12-04 14:01 ` Vinod Koul
2019-12-04 15:51 ` Sascha Hauer [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=20191204155116.uqxioshtombxfe5g@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=dmaengine@vger.kernel.org \
--cc=kernel@pengutronix.de \
--cc=linux@armlinux.org.uk \
--cc=peter.ujfalusi@ti.com \
--cc=robert.jarzmik@free.fr \
--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).