dmaengine Archive on
 help / color / Atom feed
From: Sascha Hauer <>
Cc: Peter Ujfalusi <>,
	Robert Jarzmik <>,
	Vinod Koul <>,
Subject: vchan helper broken wrt locking
Date: Tue, 3 Dec 2019 12:50:50 +0100
Message-ID: <> (raw)

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;
-               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.

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.

I think vc->desc_free() being called under a spin_lock is unfortunate as
the i.MX SDMA driver does a dma_free_coherent() there which is required
to be called with interrupts enabled.

I am not sure where to go from here hence I'm writing this mail. Do we
agree that vc->desc_free() should be called without lock?


Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       |  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

             reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-03 11:50 Sascha Hauer [this message]
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

Reply instructions:

You may reply publically 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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

dmaengine Archive on

Archives are clonable:
	git clone --mirror dmaengine/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dmaengine dmaengine/ \
	public-inbox-index dmaengine

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone