* [PATCH v2] dmaengine: edma: Implement device_synchronize callback
@ 2016-02-11 9:08 Peter Ujfalusi
2016-02-11 9:41 ` Lars-Peter Clausen
2016-02-22 2:51 ` Vinod Koul
0 siblings, 2 replies; 5+ messages in thread
From: Peter Ujfalusi @ 2016-02-11 9:08 UTC (permalink / raw)
To: linux-arm-kernel
We need the callback to support the dmaengine_terminate_sync().
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
drivers/dma/edma.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/dma/edma.c b/drivers/dma/edma.c
index 2dac314a2d7a..290e1a721c5b 100644
--- a/drivers/dma/edma.c
+++ b/drivers/dma/edma.c
@@ -869,6 +869,13 @@ static int edma_terminate_all(struct dma_chan *chan)
return 0;
}
+static void edma_synchronize(struct dma_chan *chan)
+{
+ struct edma_chan *echan = to_edma_chan(chan);
+
+ vchan_synchronize(&echan->vchan);
+}
+
static int edma_slave_config(struct dma_chan *chan,
struct dma_slave_config *cfg)
{
@@ -1808,6 +1815,7 @@ static void edma_dma_init(struct edma_cc *ecc, bool legacy_mode)
s_ddev->device_pause = edma_dma_pause;
s_ddev->device_resume = edma_dma_resume;
s_ddev->device_terminate_all = edma_terminate_all;
+ s_ddev->device_synchronize = edma_synchronize;
s_ddev->src_addr_widths = EDMA_DMA_BUSWIDTHS;
s_ddev->dst_addr_widths = EDMA_DMA_BUSWIDTHS;
@@ -1833,6 +1841,7 @@ static void edma_dma_init(struct edma_cc *ecc, bool legacy_mode)
m_ddev->device_pause = edma_dma_pause;
m_ddev->device_resume = edma_dma_resume;
m_ddev->device_terminate_all = edma_terminate_all;
+ m_ddev->device_synchronize = edma_synchronize;
m_ddev->src_addr_widths = EDMA_DMA_BUSWIDTHS;
m_ddev->dst_addr_widths = EDMA_DMA_BUSWIDTHS;
--
2.7.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2] dmaengine: edma: Implement device_synchronize callback
2016-02-11 9:08 [PATCH v2] dmaengine: edma: Implement device_synchronize callback Peter Ujfalusi
@ 2016-02-11 9:41 ` Lars-Peter Clausen
2016-02-11 11:12 ` Peter Ujfalusi
2016-02-22 2:51 ` Vinod Koul
1 sibling, 1 reply; 5+ messages in thread
From: Lars-Peter Clausen @ 2016-02-11 9:41 UTC (permalink / raw)
To: linux-arm-kernel
On 02/11/2016 10:08 AM, Peter Ujfalusi wrote:
> We need the callback to support the dmaengine_terminate_sync().
>
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
Looks good, but I noticed a slight race condition in
edma_completion_handler(). You need to fetch echan->desc while holding the
vchan.lock. Otherwise this can race against terminate_all() and the callback
might get scheduled even though terminate_all() completed and then there is
a race where the synchronize() operation could be called before the callback
gets scheduled, which means it doesn't do its intended job. Highly unlikely
to happen, but theoretically possible.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] dmaengine: edma: Implement device_synchronize callback
2016-02-11 9:41 ` Lars-Peter Clausen
@ 2016-02-11 11:12 ` Peter Ujfalusi
2016-02-11 12:13 ` Lars-Peter Clausen
0 siblings, 1 reply; 5+ messages in thread
From: Peter Ujfalusi @ 2016-02-11 11:12 UTC (permalink / raw)
To: linux-arm-kernel
On 02/11/2016 11:41 AM, Lars-Peter Clausen wrote:
> On 02/11/2016 10:08 AM, Peter Ujfalusi wrote:
>> We need the callback to support the dmaengine_terminate_sync().
>>
>> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
>
> Looks good, but I noticed a slight race condition in
> edma_completion_handler(). You need to fetch echan->desc while holding the
> vchan.lock. Otherwise this can race against terminate_all() and the callback
> might get scheduled even though terminate_all() completed and then there is
> a race where the synchronize() operation could be called before the callback
> gets scheduled, which means it doesn't do its intended job. Highly unlikely
> to happen, but theoretically possible.
Right, actually I had (have) another series fixing the very same race in a
different way - patching the terminate_all (series attached).
We have seen race with RT kernel on uniprocessor setup.
The tasklet_kill after the terminate_all will execute the scheduled task
unconditionally, so the vchan_complete() will run after we have terminated the
channel, which might be not what we want.
I have also seen a race condition as explained in the first patch. The only
way I was able to fix that by using the attached patches. Unfortunately I can
not test RT with mainline yet, so I'm not 100% sure if by using the
dmaengine_terminate_sync() in drivers will fix the issue.
--
P?ter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-dmaengine-virt-dma-Support-for-ignoring-callback-aft.patch
Type: text/x-patch
Size: 4081 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160211/26d818cd/attachment-0003.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-dmaengine-omap-dma-Prevent-race-between-vchan_comple.patch
Type: text/x-patch
Size: 1215 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160211/26d818cd/attachment-0004.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-dmaengine-edma-Prevent-race-between-vchan_complete-a.patch
Type: text/x-patch
Size: 1230 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160211/26d818cd/attachment-0005.bin>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] dmaengine: edma: Implement device_synchronize callback
2016-02-11 11:12 ` Peter Ujfalusi
@ 2016-02-11 12:13 ` Lars-Peter Clausen
0 siblings, 0 replies; 5+ messages in thread
From: Lars-Peter Clausen @ 2016-02-11 12:13 UTC (permalink / raw)
To: linux-arm-kernel
On 02/11/2016 12:12 PM, Peter Ujfalusi wrote:
> On 02/11/2016 11:41 AM, Lars-Peter Clausen wrote:
>> On 02/11/2016 10:08 AM, Peter Ujfalusi wrote:
>>> We need the callback to support the dmaengine_terminate_sync().
>>>
>>> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
>>
>> Looks good, but I noticed a slight race condition in
>> edma_completion_handler(). You need to fetch echan->desc while holding the
>> vchan.lock. Otherwise this can race against terminate_all() and the callback
>> might get scheduled even though terminate_all() completed and then there is
>> a race where the synchronize() operation could be called before the callback
>> gets scheduled, which means it doesn't do its intended job. Highly unlikely
>> to happen, but theoretically possible.
>
> Right, actually I had (have) another series fixing the very same race in a
> different way - patching the terminate_all (series attached).
> We have seen race with RT kernel on uniprocessor setup.
>
> The tasklet_kill after the terminate_all will execute the scheduled task
> unconditionally, so the vchan_complete() will run after we have terminated the
> channel, which might be not what we want.
> I have also seen a race condition as explained in the first patch. The only
> way I was able to fix that by using the attached patches. Unfortunately I can
> not test RT with mainline yet, so I'm not 100% sure if by using the
> dmaengine_terminate_sync() in drivers will fix the issue.
>
Yes, dmaengine_terminate_sync() is supposed to fix the same issue. One of
the problems when implementing this was that e.g. for audio it might happen
that we terminate the transfer from within the tasklet callback itself. In
that case doing tasklet_disable() will deadlock since it will wait until the
tasklet has finished from within the tasklet.
This is why the synchronize API has two primitives. Terminate and
synchronize, so you can split them if necessary.
The only thing you need to make sure is that the implementation of
synchronize() is correct. In the EDMA case echan->desc is read without
holding a lock which still keeps the race condition open.
- Lars
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] dmaengine: edma: Implement device_synchronize callback
2016-02-11 9:08 [PATCH v2] dmaengine: edma: Implement device_synchronize callback Peter Ujfalusi
2016-02-11 9:41 ` Lars-Peter Clausen
@ 2016-02-22 2:51 ` Vinod Koul
1 sibling, 0 replies; 5+ messages in thread
From: Vinod Koul @ 2016-02-22 2:51 UTC (permalink / raw)
To: linux-arm-kernel
On Thu, Feb 11, 2016 at 11:08:42AM +0200, Peter Ujfalusi wrote:
> We need the callback to support the dmaengine_terminate_sync().
Applied, thanks
--
~Vinod
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-02-22 2:51 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-11 9:08 [PATCH v2] dmaengine: edma: Implement device_synchronize callback Peter Ujfalusi
2016-02-11 9:41 ` Lars-Peter Clausen
2016-02-11 11:12 ` Peter Ujfalusi
2016-02-11 12:13 ` Lars-Peter Clausen
2016-02-22 2:51 ` Vinod Koul
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).