87b4e9b58af75f4feb9bcadb7813119a63885a8c
[openwrt/staging/linusw.git] /
1 From 7bfcb31431f06efc233e4cc4d7ab65e10a6522cd Mon Sep 17 00:00:00 2001
2 From: Yaroslav Rosomakho <yaroslavros@gmail.com>
3 Date: Fri, 23 Aug 2019 11:02:22 +0200
4 Subject: [PATCH] Limit max_req_size under arm64 (or any other platform
5 that uses swiotlb) to prevent potential buffer overflow due to bouncing.
6
7 Signed-off-by: Yaroslav Rosomakho <yaroslavros@gmail.com>
8 ---
9 drivers/mmc/host/bcm2835-mmc.c | 6 +++++-
10 1 file changed, 5 insertions(+), 1 deletion(-)
11
12 --- a/drivers/mmc/host/bcm2835-mmc.c
13 +++ b/drivers/mmc/host/bcm2835-mmc.c
14 @@ -38,6 +38,7 @@
15 #include <linux/dmaengine.h>
16 #include <linux/dma-mapping.h>
17 #include <linux/of_dma.h>
18 +#include <linux/swiotlb.h>
19
20 #include "sdhci.h"
21
22 @@ -1374,7 +1375,10 @@ static int bcm2835_mmc_add_host(struct b
23 }
24 #endif
25 mmc->max_segs = 128;
26 - mmc->max_req_size = 524288;
27 + if (swiotlb_max_segment())
28 + mmc->max_req_size = (1 << IO_TLB_SHIFT) * IO_TLB_SEGSIZE;
29 + else
30 + mmc->max_req_size = 524288;
31 mmc->max_seg_size = mmc->max_req_size;
32 mmc->max_blk_size = 512;
33 mmc->max_blk_count = 65535;