Skip to content

Commit 6697255

Browse files
digetxvinodkoul
authored andcommitted
dmaengine: tegra-apb: Improve DMA synchronization
Boot CPU0 always handles DMA interrupts and under some rare circumstances it could stuck in uninterruptible state for a significant time (like in a case of KASAN + NFS root). In this case sibling CPU, which waits for DMA transfer completion, will get a DMA transfer timeout. In order to handle this rare condition, interrupt status needs to be polled until interrupt is handled. Signed-off-by: Dmitry Osipenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 6de88ea commit 6697255

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

drivers/dma/tegra20-apb-dma.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/pm_runtime.h>
2525
#include <linux/reset.h>
2626
#include <linux/slab.h>
27+
#include <linux/wait.h>
2728

2829
#include "dmaengine.h"
2930

@@ -202,6 +203,8 @@ struct tegra_dma_channel {
202203
unsigned int slave_id;
203204
struct dma_slave_config dma_sconfig;
204205
struct tegra_dma_channel_regs channel_reg;
206+
207+
struct wait_queue_head wq;
205208
};
206209

207210
/* tegra_dma: Tegra DMA specific information */
@@ -680,6 +683,7 @@ static irqreturn_t tegra_dma_isr(int irq, void *dev_id)
680683
tdc_write(tdc, TEGRA_APBDMA_CHAN_STATUS, status);
681684
tdc->isr_handler(tdc, false);
682685
tasklet_schedule(&tdc->tasklet);
686+
wake_up_all(&tdc->wq);
683687
spin_unlock(&tdc->lock);
684688
return IRQ_HANDLED;
685689
}
@@ -785,6 +789,7 @@ static int tegra_dma_terminate_all(struct dma_chan *dc)
785789
tegra_dma_resume(tdc);
786790

787791
pm_runtime_put(tdc->tdma->dev);
792+
wake_up_all(&tdc->wq);
788793

789794
skip_dma_stop:
790795
tegra_dma_abort_all(tdc);
@@ -800,10 +805,29 @@ static int tegra_dma_terminate_all(struct dma_chan *dc)
800805
return 0;
801806
}
802807

808+
static bool tegra_dma_eoc_interrupt_deasserted(struct tegra_dma_channel *tdc)
809+
{
810+
unsigned long flags;
811+
u32 status;
812+
813+
spin_lock_irqsave(&tdc->lock, flags);
814+
status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
815+
spin_unlock_irqrestore(&tdc->lock, flags);
816+
817+
return !(status & TEGRA_APBDMA_STATUS_ISE_EOC);
818+
}
819+
803820
static void tegra_dma_synchronize(struct dma_chan *dc)
804821
{
805822
struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
806823

824+
/*
825+
* CPU, which handles interrupt, could be busy in
826+
* uninterruptible state, in this case sibling CPU
827+
* should wait until interrupt is handled.
828+
*/
829+
wait_event(tdc->wq, tegra_dma_eoc_interrupt_deasserted(tdc));
830+
807831
tasklet_kill(&tdc->tasklet);
808832
}
809833

@@ -1498,6 +1522,7 @@ static int tegra_dma_probe(struct platform_device *pdev)
14981522
tasklet_init(&tdc->tasklet, tegra_dma_tasklet,
14991523
(unsigned long)tdc);
15001524
spin_lock_init(&tdc->lock);
1525+
init_waitqueue_head(&tdc->wq);
15011526

15021527
INIT_LIST_HEAD(&tdc->pending_sg_req);
15031528
INIT_LIST_HEAD(&tdc->free_sg_req);

0 commit comments

Comments
 (0)