1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter.git synced 2025-03-09 15:40:20 +00:00

Fix DMA leaks on RPI4

This commit is contained in:
Ycarus (Yannick Chabanois) 2019-08-20 17:22:45 +02:00
parent 2983359abc
commit 40dca34792
2 changed files with 68 additions and 11 deletions

View file

@ -1,11 +0,0 @@
################################################################################
# Bootloader configuration - config.txt
################################################################################
################################################################################
# For overclocking and various other settings, see:
# https://www.raspberrypi.org/documentation/configuration/config-txt/README.md
################################################################################
# Force aarch64
arm_64bit=1

View file

@ -0,0 +1,68 @@
From d9aa3902c1fb7163edf1812dd0e03ed5a7e129ed Mon Sep 17 00:00:00 2001
From: Yaroslav Rosomakho <yaroslavros@gmail.com>
Date: Mon, 19 Aug 2019 01:26:13 +0200
Subject: [PATCH] This should fix DMA leaks that lead to swiotlb buffer
overflow errors on bcm2835-mmc under ARM64.
Signed-off-by: Yaroslav Rosomakho <yaroslavros@gmail.com>
---
drivers/mmc/host/bcm2835-mmc.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/drivers/mmc/host/bcm2835-mmc.c b/drivers/mmc/host/bcm2835-mmc.c
index 68daa59d313b4..1311c8268e83e 100644
--- a/drivers/mmc/host/bcm2835-mmc.c
+++ b/drivers/mmc/host/bcm2835-mmc.c
@@ -38,6 +38,7 @@
#include <linux/dmaengine.h>
#include <linux/dma-mapping.h>
#include <linux/of_dma.h>
+#include <linux/swiotlb.h>
#include "sdhci.h"
@@ -344,16 +345,17 @@ static void bcm2835_mmc_dma_complete(void *param)
host->use_dma = false;
- if (host->data && !(host->data->flags & MMC_DATA_WRITE)) {
- /* otherwise handled in SDHCI IRQ */
+ if (host->data) {
dma_chan = host->dma_chan_rxtx;
- dir_data = DMA_FROM_DEVICE;
-
+ if (host->data->flags & MMC_DATA_WRITE)
+ dir_data = DMA_TO_DEVICE;
+ else
+ dir_data = DMA_FROM_DEVICE;
dma_unmap_sg(dma_chan->device->dev,
host->data->sg, host->data->sg_len,
dir_data);
-
- bcm2835_mmc_finish_data(host);
+ if (! (host->data->flags & MMC_DATA_WRITE))
+ bcm2835_mmc_finish_data(host);
} else if (host->wait_for_dma) {
host->wait_for_dma = false;
tasklet_schedule(&host->finish_tasklet);
@@ -539,6 +541,8 @@ static void bcm2835_mmc_transfer_dma(struct bcm2835_host *host)
spin_unlock_irqrestore(&host->lock, flags);
dmaengine_submit(desc);
dma_async_issue_pending(dma_chan);
+ } else {
+ dma_unmap_sg(dma_chan->device->dev, host->data->sg, len, dir_data);
}
}
@@ -1374,7 +1378,10 @@ static int bcm2835_mmc_add_host(struct bcm2835_host *host)
}
#endif
mmc->max_segs = 128;
- mmc->max_req_size = 524288;
+ if (swiotlb_max_segment())
+ mmc->max_req_size = (1 << IO_TLB_SHIFT) * IO_TLB_SEGSIZE;
+ else
+ mmc->max_req_size = 524288;
mmc->max_seg_size = mmc->max_req_size;
mmc->max_blk_size = 512;
mmc->max_blk_count = 65535;