OSDN Git Service

dmaengine: at_hdmac: Fix deadlocks
authorTudor Ambarus <tudor.ambarus@microchip.com>
Thu, 23 Jan 2020 14:03:11 +0000 (14:03 +0000)
committerVinod Koul <vkoul@kernel.org>
Tue, 25 Feb 2020 05:57:27 +0000 (11:27 +0530)
commit078a6506141a4ce76bee6c257e9b14f5c606ee4c
tree03227350ce44872ded5f4aa3c138c933e11c99ae
parent247b4d83d6525d04278333cf201d6e3b066c9ca5
dmaengine: at_hdmac: Fix deadlocks

Fix the following deadlocks:
1/ atc_handle_cyclic() and atc_chain_complete() called
dmaengine_desc_get_callback_invoke() while wrongly holding the
atchan->lock. Clients can set the callback to dmaengine_terminate_sync()
which will end up trying to get the same lock, thus a deadlock occurred.
2/ dma_run_dependencies() was called with the atchan->lock held, but the
method calls device_issue_pending() which tries to get the same lock,
and so a deadlock occurred.

The driver must not hold the lock when invoking the callback or when
running dependencies. Releasing the spinlock within a called function
before calling the callback is not a nice thing to do -> called functions
become non-atomic when called within an atomic region. Thus the lock is
now taken in the child routines whereever is needed.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Acked-by: Ludovic Desroches <ludovic.desroches@microchip.com>
Link: https://lore.kernel.org/r/20200123140237.125799-6-tudor.ambarus@microchip.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/dma/at_hdmac.c