dmaengine: pl330: Return DMA_PAUSED when transaction is paused
Subsystems (3)
PATCH 1/1 dmaengine: pl330: Return DMA_PAUSED when transaction is paused
pl330_pause() does not set anything to indicate paused condition which causes pl330_tx_status() to return DMA_IN_PROGRESS. This breaks 8250 DMA flush after the fix in commit 57e9af7831dc ("serial: 8250_dma: Fix DMA Rx rearm race"). The function comment for pl330_pause() claims pause is supported but resume is not which is enough for 8250 DMA flush to work as long as DMA status reports DMA_PAUSED when appropriate.
Add PAUSED state for descriptor and mark BUSY descriptors with PAUSED in pl330_pause(). Return DMA_PAUSED from pl330_tx_status() when the descriptor is PAUSED.
---
$ diff -u <(git grep -l -e '\.device_pause' -e '->device_pause') <(git grep -l DMA_PAUSED)
...tells there might a few other drivers which do not properly return DMA_PAUSED status despite having a pause function.
drivers/dma/pl330.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/dma/pl330.c +16 -2
@@ -403,6 +403,12 @@ enum desc_status {* of a channel can be BUSY at any time. */ BUSY , +/* +* Pause was called while descriptor was BUSY. Due to hardware +* limitations, only termination is possible for descriptors +* that have been paused. +*/ + PAUSED,/* * Sitting on the channel work_list but xfer done * by PL330 core
@@ -2041,7 +2047,7 @@ static inline void fill_queue(struct dma_pl330_chan *pch)list_for_each_entry (desc, &pch->work_list, node) {/* If already submitted */ -if (desc->status ==BUSY ) +if (desc->status ==BUSY || desc->status ==PAUSED )continue ; ret =pl330_submit_req (pch->thread, desc);
@@ -2326,6 +2332,7 @@ static int pl330_pause(struct dma_chan *chan) {struct dma_pl330_chan *pch =to_pchan (chan);struct pl330_dmac *pl330 = pch->dmac; +struct dma_pl330_desc *desc;unsigned long flags;pm_runtime_get_sync (pl330->ddma.dev);
@@ -2335,6 +2342,10 @@ static int pl330_pause(struct dma_chan *chan)_stop (pch->thread);spin_unlock (&pl330->lock); +list_for_each_entry (desc, &pch->work_list, node) { +if (desc->status ==BUSY ) + desc->status =PAUSED ; + }spin_unlock_irqrestore (&pch->lock, flags);pm_runtime_mark_last_busy (pl330->ddma.dev);pm_runtime_put_autosuspend (pl330->ddma.dev);
@@ -2425,7 +2436,7 @@ pl330_tx_status(struct dma_chan *chan, dma_cookie_t cookie,else if (running && desc == running) transferred =pl330_get_current_xferred_count (pch, desc); -else if (desc->status ==BUSY ) +else if (desc->status ==BUSY || desc->status ==PAUSED )/* * Busy but not running means either just enqueued, * or finished and not yet marked done
@@ -2442,6 +2453,9 @@ pl330_tx_status(struct dma_chan *chan, dma_cookie_t cookie,case DONE : ret =DMA_COMPLETE ;break ; +case PAUSED : + ret =DMA_PAUSED ; +break ;case PREP :case BUSY : ret =DMA_IN_PROGRESS ;
Signature · 1 line
2.30.2
Quoted 11 lines · Ilpo Järvinen
pl330_pause()does not set anything to indicate paused condition which causespl330_tx_status()to returnDMA_IN_PROGRESS. This breaks 8250 DMA flush after the fix in commit57e9af7831dc("serial: 8250_dma: Fix DMA Rx rearm race"). The function comment forpl330_pause()claims pause is supported but resume is not which is enough for 8250 DMA flush to work as long as DMA status reportsDMA_PAUSEDwhen appropriate.Add PAUSED state for descriptor and mark BUSY descriptors with PAUSED in
pl330_pause(). ReturnDMA_PAUSEDfrompl330_tx_status()when the descriptor is PAUSED.
Quoted 6 lines
Reported-by Richard Tresidder <[email protected]>Tested-by Richard Tresidder <[email protected]>Fixes 88987d2c7534 ("dmaengine: pl330: add DMA_PAUSE feature")Signed-off-by Ilpo Järvinen <[email protected]>
Ilpo, Vinod, Philipp: what happened to this? It seems this fix for a regression didn't make any progress since it was posted. Or am I missing something?
Ciao, Thorsten (wearing his 'the Linux kernel's regression tracker' hat) --
Everything you wanna know about Linux kernel regression tracking:
https://linux-regtracking.leemhuis.info/about/#tldr
If I did something stupid, please tell me, as explained on that page.
Quoted 74 lines
---
$ diff -u <(git grep -l -e '\.device_pause' -e '->device_pause') <(git grep -l DMA_PAUSED)...tells there might a few other drivers which do not properly return
DMA_PAUSEDstatus despite having a pause function.drivers/dma/pl330.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)drivers/dma/pl330.c +16
-2@@ -403,6 +403,12 @@ enum desc_status {* of a channel can be BUSY at any time. */ BUSY , +/* +* Pause was called while descriptor was BUSY. Due to hardware +* limitations, only termination is possible for descriptors +* that have been paused. +*/ + PAUSED,/* * Sitting on the channel work_list but xfer done * by PL330 core @@ -2041,7 +2047,7 @@ static inline void fill_queue(struct dma_pl330_chan *pch)list_for_each_entry (desc, &pch->work_list, node) {/* If already submitted */ -if (desc->status ==BUSY ) +if (desc->status ==BUSY || desc->status ==PAUSED )continue ; ret =pl330_submit_req (pch->thread, desc);@@ -2326,6 +2332,7 @@ static int pl330_pause(struct dma_chan *chan) {struct dma_pl330_chan *pch =to_pchan (chan);struct pl330_dmac *pl330 = pch->dmac; +struct dma_pl330_desc *desc;unsigned long flags;pm_runtime_get_sync (pl330->ddma.dev);@@ -2335,6 +2342,10 @@ static int pl330_pause(struct dma_chan *chan)_stop (pch->thread);spin_unlock (&pl330->lock); +list_for_each_entry (desc, &pch->work_list, node) { +if (desc->status ==BUSY ) + desc->status =PAUSED ; + }spin_unlock_irqrestore (&pch->lock, flags);pm_runtime_mark_last_busy (pl330->ddma.dev);pm_runtime_put_autosuspend (pl330->ddma.dev);@@ -2425,7 +2436,7 @@ pl330_tx_status(struct dma_chan *chan, dma_cookie_t cookie,else if (running && desc == running) transferred =pl330_get_current_xferred_count (pch, desc); -else if (desc->status ==BUSY ) +else if (desc->status ==BUSY || desc->status ==PAUSED )/* * Busy but not running means either just enqueued, * or finished and not yet marked done @@ -2442,6 +2453,9 @@ pl330_tx_status(struct dma_chan *chan, dma_cookie_t cookie,case DONE : ret =DMA_COMPLETE ;break ; +case PAUSED : + ret =DMA_PAUSED ; +break ;case PREP :case BUSY : ret =DMA_IN_PROGRESS ;
Vinod Koul
maintainerQuoted 10 lines · Ilpo Järvinen
pl330_pause()does not set anything to indicate paused condition which causespl330_tx_status()to returnDMA_IN_PROGRESS. This breaks 8250 DMA flush after the fix in commit57e9af7831dc("serial: 8250_dma: Fix DMA Rx rearm race"). The function comment forpl330_pause()claims pause is supported but resume is not which is enough for 8250 DMA flush to work as long as DMA status reportsDMA_PAUSEDwhen appropriate.Add PAUSED state for descriptor and mark BUSY descriptors with PAUSED in
pl330_pause(). ReturnDMA_PAUSEDfrompl330_tx_status()when the descriptor is PAUSED.
Have you noticed the comment in the code which reads:
/*
* We don't support DMA_RESUME command because of hardware
* limitations, so after pausing the channel we cannot restore
* it to active state. We have to terminate channel and setup
* DMA transfer again. This pause feature was implemented to
* allow safely read residue before channel termination. */
So driver just stops when in pause.
Now the commit 57e9af7831dc returns when in progress state, so am not sure how returning Paused would help here?
Quoted 83 lines
Reported-by Richard Tresidder <[email protected]>Tested-by Richard Tresidder <[email protected]>Fixes 88987d2c7534 ("dmaengine: pl330: add DMA_PAUSE feature")Signed-off-by Ilpo Järvinen <[email protected]>---
$ diff -u <(git grep -l -e '\.device_pause' -e '->device_pause') <(git grep -l DMA_PAUSED)...tells there might a few other drivers which do not properly return
DMA_PAUSEDstatus despite having a pause function.drivers/dma/pl330.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)drivers/dma/pl330.c +16
-2@@ -403,6 +403,12 @@ enum desc_status {* of a channel can be BUSY at any time. */ BUSY , +/* +* Pause was called while descriptor was BUSY. Due to hardware +* limitations, only termination is possible for descriptors +* that have been paused. +*/ + PAUSED,/* * Sitting on the channel work_list but xfer done * by PL330 core @@ -2041,7 +2047,7 @@ static inline void fill_queue(struct dma_pl330_chan *pch)list_for_each_entry (desc, &pch->work_list, node) {/* If already submitted */ -if (desc->status ==BUSY ) +if (desc->status ==BUSY || desc->status ==PAUSED )continue ; ret =pl330_submit_req (pch->thread, desc);@@ -2326,6 +2332,7 @@ static int pl330_pause(struct dma_chan *chan) {struct dma_pl330_chan *pch =to_pchan (chan);struct pl330_dmac *pl330 = pch->dmac; +struct dma_pl330_desc *desc;unsigned long flags;pm_runtime_get_sync (pl330->ddma.dev);@@ -2335,6 +2342,10 @@ static int pl330_pause(struct dma_chan *chan)_stop (pch->thread);spin_unlock (&pl330->lock); +list_for_each_entry (desc, &pch->work_list, node) { +if (desc->status ==BUSY ) + desc->status =PAUSED ; + }spin_unlock_irqrestore (&pch->lock, flags);pm_runtime_mark_last_busy (pl330->ddma.dev);pm_runtime_put_autosuspend (pl330->ddma.dev);@@ -2425,7 +2436,7 @@ pl330_tx_status(struct dma_chan *chan, dma_cookie_t cookie,else if (running && desc == running) transferred =pl330_get_current_xferred_count (pch, desc); -else if (desc->status ==BUSY ) +else if (desc->status ==BUSY || desc->status ==PAUSED )/* * Busy but not running means either just enqueued, * or finished and not yet marked done @@ -2442,6 +2453,9 @@ pl330_tx_status(struct dma_chan *chan, dma_cookie_t cookie,case DONE : ret =DMA_COMPLETE ;break ; +case PAUSED : + ret =DMA_PAUSED ; +break ;case PREP :case BUSY : ret =DMA_IN_PROGRESS ;Signature · 1 line
2.30.2
Signature · 1 line
~Vinod
Quoted 14 lines · Vinod Koul
Quoted 10 lines · Ilpo Järvinen
pl330_pause()does not set anything to indicate paused condition which causespl330_tx_status()to returnDMA_IN_PROGRESS. This breaks 8250 DMA flush after the fix in commit57e9af7831dc("serial: 8250_dma: Fix DMA Rx rearm race"). The function comment forpl330_pause()claims pause is supported but resume is not which is enough for 8250 DMA flush to work as long as DMA status reportsDMA_PAUSEDwhen appropriate.Add PAUSED state for descriptor and mark BUSY descriptors with PAUSED in
pl330_pause(). ReturnDMA_PAUSEDfrompl330_tx_status()when the descriptor is PAUSED.Have you noticed the comment in the code which reads:
Quoted 7 lines
/*
* We don't supportDMA_RESUMEcommand because of hardware
* limitations, so after pausing the channel we cannot restore
* it to active state. We have to terminate channel and setup
* DMA transfer again. This pause feature was implemented to
* allow safely read residue before channel termination. */
I'm aware of this limitation (and comment) but it's not causing a problem here since serial8250_rx_dma_flush() does not need to call resume, it requires only supporting pause + reading the state/status.
Quoted 1 line
So driver just stops when in pause.
It not only stops but keeps claiming it's still not stopped which causes the problem in 8250 code because 8250 DMA code assumes DMA side returns the correct status.
Quoted 2 lines
Now the commit
57e9af7831dcreturns when in progress state, so am not sure how returning Paused would help here?
In serial8250_rx_dma_flush() 8250 DMA code does this:
dmaengine_pause(dma->rxchan);
__dma_rx_complete(p);
dmaengine_terminate_async(dma->rxchan);As you can see, __dma_rx_complete() would not take that return when called from serial8250_rx_dma_flush() if correct DMA_* status would be returned.
The return in __dma_rx_complete() is meant for other paths (as shown in 57e9af7831dc's changelog) but is now currently taken also when called from serial8250_rx_dma_flush() because pl330 keeps returning DMA_IN_PROGRESS instead of DMA_PAUSED. Thus, I created this fix.
Signature · 1 line
i.
Quoted 84 lines
Quoted 82 lines
Reported-by Richard Tresidder <[email protected]>Tested-by Richard Tresidder <[email protected]>Fixes 88987d2c7534 ("dmaengine: pl330: add DMA_PAUSE feature")Signed-off-by Ilpo Järvinen <[email protected]>---
$ diff -u <(git grep -l -e '\.device_pause' -e '->device_pause') <(git grep -l DMA_PAUSED)...tells there might a few other drivers which do not properly return
DMA_PAUSEDstatus despite having a pause function.drivers/dma/pl330.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)drivers/dma/pl330.c +16
-2@@ -403,6 +403,12 @@ enum desc_status {* of a channel can be BUSY at any time. */ BUSY , +/* +* Pause was called while descriptor was BUSY. Due to hardware +* limitations, only termination is possible for descriptors +* that have been paused. +*/ + PAUSED,/* * Sitting on the channel work_list but xfer done * by PL330 core @@ -2041,7 +2047,7 @@ static inline void fill_queue(struct dma_pl330_chan *pch)list_for_each_entry (desc, &pch->work_list, node) {/* If already submitted */ -if (desc->status ==BUSY ) +if (desc->status ==BUSY || desc->status ==PAUSED )continue ; ret =pl330_submit_req (pch->thread, desc);@@ -2326,6 +2332,7 @@ static int pl330_pause(struct dma_chan *chan) {struct dma_pl330_chan *pch =to_pchan (chan);struct pl330_dmac *pl330 = pch->dmac; +struct dma_pl330_desc *desc;unsigned long flags;pm_runtime_get_sync (pl330->ddma.dev);@@ -2335,6 +2342,10 @@ static int pl330_pause(struct dma_chan *chan)_stop (pch->thread);spin_unlock (&pl330->lock); +list_for_each_entry (desc, &pch->work_list, node) { +if (desc->status ==BUSY ) + desc->status =PAUSED ; + }spin_unlock_irqrestore (&pch->lock, flags);pm_runtime_mark_last_busy (pl330->ddma.dev);pm_runtime_put_autosuspend (pl330->ddma.dev);@@ -2425,7 +2436,7 @@ pl330_tx_status(struct dma_chan *chan, dma_cookie_t cookie,else if (running && desc == running) transferred =pl330_get_current_xferred_count (pch, desc); -else if (desc->status ==BUSY ) +else if (desc->status ==BUSY || desc->status ==PAUSED )/* * Busy but not running means either just enqueued, * or finished and not yet marked done @@ -2442,6 +2453,9 @@ pl330_tx_status(struct dma_chan *chan, dma_cookie_t cookie,case DONE : ret =DMA_COMPLETE ;break ; +case PAUSED : + ret =DMA_PAUSED ; +break ;case PREP :case BUSY : ret =DMA_IN_PROGRESS ;Signature · 1 line
2.30.2
Quoted 8 lines · Ilpo Järvinen
pl330_pause()does not set anything to indicate paused condition which causespl330_tx_status()to returnDMA_IN_PROGRESS. This breaks 8250 DMA flush after the fix in commit57e9af7831dc("serial: 8250_dma: Fix DMA Rx rearm race"). The function comment forpl330_pause()claims pause is supported but resume is not which is enough for 8250 DMA flush to work as long as DMA status reportsDMA_PAUSEDwhen appropriate.[...]
Applied, thanks!
[1/1] dmaengine: pl330: Return DMA_PAUSED when transaction is paused
commit: 85648667b946069b2a3765577c418705c65c2ddf
Best regards,
Signature · 1 line
~Vinod