Linux MultiMedia Card development
 help / color / mirror / Atom feed
* [PATCH v2 0/2] mmc: renesas_sdhi and tmio: bugfixes for v4.14
@ 2017-10-20  3:12 Yoshihiro Shimoda
  2017-10-20  3:12 ` [PATCH v2 1/2] mmc: tmio: fix swiotlb buffer is full Yoshihiro Shimoda
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Yoshihiro Shimoda @ 2017-10-20  3:12 UTC (permalink / raw)
  To: wsa+renesas, ulf.hansson; +Cc: linux-mmc, linux-renesas-soc, Yoshihiro Shimoda

This patch set is based on mainline v4.14-rc5.

Changes from v1:
 - Calculate the max size of swiotlb memory instead of hardcoded value
   in patch 1.
 - Add Reviewed-by from Geert-san in patch 2. (Geert-san, thanks!)

Yoshihiro Shimoda (2):
  mmc: tmio: fix swiotlb buffer is full
  mmc: renesas_sdhi: fix kernel panic in _internal_dmac.c

 drivers/mmc/host/renesas_sdhi_internal_dmac.c | 17 ++++++++++-------
 drivers/mmc/host/tmio_mmc_core.c              | 13 +++++++++++++
 2 files changed, 23 insertions(+), 7 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/2] mmc: tmio: fix swiotlb buffer is full
  2017-10-20  3:12 [PATCH v2 0/2] mmc: renesas_sdhi and tmio: bugfixes for v4.14 Yoshihiro Shimoda
@ 2017-10-20  3:12 ` Yoshihiro Shimoda
  2017-10-20  4:00   ` Wolfram Sang
  2017-10-20  7:29   ` Geert Uytterhoeven
  2017-10-20  3:12 ` [PATCH v2 2/2] mmc: renesas_sdhi: fix kernel panic in _internal_dmac.c Yoshihiro Shimoda
  2017-10-20 10:03 ` [PATCH v2 0/2] mmc: renesas_sdhi and tmio: bugfixes for v4.14 Ulf Hansson
  2 siblings, 2 replies; 7+ messages in thread
From: Yoshihiro Shimoda @ 2017-10-20  3:12 UTC (permalink / raw)
  To: wsa+renesas, ulf.hansson; +Cc: linux-mmc, linux-renesas-soc, Yoshihiro Shimoda

Since the commit de3ee99b097d ("mmc: Delete bounce buffer handling")
deletes the bounce buffer handling, a request data size will be referred
to max_{req,seg}_size instead of MMC_QUEUE_BOUNCESZ (64k bytes).

In other hand, renesas_sdhi_internal_dmac.c will set very big value of
max_{req,seg}_size because the max_blk_count is set to 0xffffffff.
And then, "swiotlb buffer is full" happens because swiotlb can handle
a memory size up to 256k bytes only (IO_TLB_SEGSIZE = 128 and
IO_TLB_SHIFT = 11).

So, as a workaround, this patch avoids the issue by setting
the max_{req,seg}_size up to 256k bytes if swiotlb is running.

Reported-by: Dirk Behme <dirk.behme@de.bosch.com>
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 drivers/mmc/host/tmio_mmc_core.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/mmc/host/tmio_mmc_core.c b/drivers/mmc/host/tmio_mmc_core.c
index a7293e1..9c4e619 100644
--- a/drivers/mmc/host/tmio_mmc_core.c
+++ b/drivers/mmc/host/tmio_mmc_core.c
@@ -47,6 +47,7 @@
 #include <linux/mmc/sdio.h>
 #include <linux/scatterlist.h>
 #include <linux/spinlock.h>
+#include <linux/swiotlb.h>
 #include <linux/workqueue.h>
 
 #include "tmio_mmc.h"
@@ -1215,6 +1216,18 @@ int tmio_mmc_host_probe(struct tmio_mmc_host *_host,
 	mmc->max_blk_count = pdata->max_blk_count ? :
 		(PAGE_SIZE / mmc->max_blk_size) * mmc->max_segs;
 	mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
+	/*
+	 * Since swiotlb has memory size limitation, this will calculate
+	 * the maximum size locally (because we don't have any APIs for it now)
+	 * and check the current max_req_size. And then, this will update
+	 * the max_req_size if needed as a workaround.
+	 */
+	if (swiotlb_max_segment()) {
+		unsigned int max_size = (1 << IO_TLB_SHIFT) * IO_TLB_SEGSIZE;
+
+		if (mmc->max_req_size > max_size)
+			mmc->max_req_size = max_size;
+	}
 	mmc->max_seg_size = mmc->max_req_size;
 
 	_host->native_hotplug = !(pdata->flags & TMIO_MMC_USE_GPIO_CD ||
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/2] mmc: renesas_sdhi: fix kernel panic in _internal_dmac.c
  2017-10-20  3:12 [PATCH v2 0/2] mmc: renesas_sdhi and tmio: bugfixes for v4.14 Yoshihiro Shimoda
  2017-10-20  3:12 ` [PATCH v2 1/2] mmc: tmio: fix swiotlb buffer is full Yoshihiro Shimoda
@ 2017-10-20  3:12 ` Yoshihiro Shimoda
  2017-10-20  4:00   ` Wolfram Sang
  2017-10-20 10:03 ` [PATCH v2 0/2] mmc: renesas_sdhi and tmio: bugfixes for v4.14 Ulf Hansson
  2 siblings, 1 reply; 7+ messages in thread
From: Yoshihiro Shimoda @ 2017-10-20  3:12 UTC (permalink / raw)
  To: wsa+renesas, ulf.hansson; +Cc: linux-mmc, linux-renesas-soc, Yoshihiro Shimoda

Since this driver checks if the return value of dma_map_sg() is minus
or not and keeps to enable the DMAC, it may cause kernel panic when
the dma_map_sg() returns 0. So, this patch fixes the issue.

Reported-by: Dirk Behme <dirk.behme@de.bosch.com>
Fixes: 2a68ea7896e3 ("mmc: renesas-sdhi: add support for R-Car Gen3 SDHI DMAC")
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/mmc/host/renesas_sdhi_internal_dmac.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/mmc/host/renesas_sdhi_internal_dmac.c b/drivers/mmc/host/renesas_sdhi_internal_dmac.c
index f905f23..8bae88a 100644
--- a/drivers/mmc/host/renesas_sdhi_internal_dmac.c
+++ b/drivers/mmc/host/renesas_sdhi_internal_dmac.c
@@ -146,11 +146,8 @@
 	WARN_ON(host->sg_len > 1);
 
 	/* This DMAC cannot handle if buffer is not 8-bytes alignment */
-	if (!IS_ALIGNED(sg->offset, 8)) {
-		host->force_pio = true;
-		renesas_sdhi_internal_dmac_enable_dma(host, false);
-		return;
-	}
+	if (!IS_ALIGNED(sg->offset, 8))
+		goto force_pio;
 
 	if (data->flags & MMC_DATA_READ) {
 		dtran_mode |= DTRAN_MODE_CH_NUM_CH1;
@@ -163,8 +160,8 @@
 	}
 
 	ret = dma_map_sg(&host->pdev->dev, sg, host->sg_len, dir);
-	if (ret < 0)
-		return;
+	if (ret == 0)
+		goto force_pio;
 
 	renesas_sdhi_internal_dmac_enable_dma(host, true);
 
@@ -176,6 +173,12 @@
 					    dtran_mode);
 	renesas_sdhi_internal_dmac_dm_write(host, DM_DTRAN_ADDR,
 					    sg->dma_address);
+
+	return;
+
+force_pio:
+	host->force_pio = true;
+	renesas_sdhi_internal_dmac_enable_dma(host, false);
 }
 
 static void renesas_sdhi_internal_dmac_issue_tasklet_fn(unsigned long arg)
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] mmc: tmio: fix swiotlb buffer is full
  2017-10-20  3:12 ` [PATCH v2 1/2] mmc: tmio: fix swiotlb buffer is full Yoshihiro Shimoda
@ 2017-10-20  4:00   ` Wolfram Sang
  2017-10-20  7:29   ` Geert Uytterhoeven
  1 sibling, 0 replies; 7+ messages in thread
From: Wolfram Sang @ 2017-10-20  4:00 UTC (permalink / raw)
  To: Yoshihiro Shimoda; +Cc: wsa+renesas, ulf.hansson, linux-mmc, linux-renesas-soc

[-- Attachment #1: Type: text/plain, Size: 1147 bytes --]

On Fri, Oct 20, 2017 at 12:12:41PM +0900, Yoshihiro Shimoda wrote:
> Since the commit de3ee99b097d ("mmc: Delete bounce buffer handling")
> deletes the bounce buffer handling, a request data size will be referred
> to max_{req,seg}_size instead of MMC_QUEUE_BOUNCESZ (64k bytes).
> 
> In other hand, renesas_sdhi_internal_dmac.c will set very big value of
> max_{req,seg}_size because the max_blk_count is set to 0xffffffff.
> And then, "swiotlb buffer is full" happens because swiotlb can handle
> a memory size up to 256k bytes only (IO_TLB_SEGSIZE = 128 and
> IO_TLB_SHIFT = 11).
> 
> So, as a workaround, this patch avoids the issue by setting
> the max_{req,seg}_size up to 256k bytes if swiotlb is running.
> 
> Reported-by: Dirk Behme <dirk.behme@de.bosch.com>
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>

For the issues we are seeing with v4.14, I think this fix is good. We
plan to fully fix this issue at a more generic level, then this addition
can go again. But we are not there yet, and likely need some additional
API, so:

Acked-by: Wolfram Sang <wsa+renesas@sang-engineering.com>


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] mmc: renesas_sdhi: fix kernel panic in _internal_dmac.c
  2017-10-20  3:12 ` [PATCH v2 2/2] mmc: renesas_sdhi: fix kernel panic in _internal_dmac.c Yoshihiro Shimoda
@ 2017-10-20  4:00   ` Wolfram Sang
  0 siblings, 0 replies; 7+ messages in thread
From: Wolfram Sang @ 2017-10-20  4:00 UTC (permalink / raw)
  To: Yoshihiro Shimoda; +Cc: wsa+renesas, ulf.hansson, linux-mmc, linux-renesas-soc

[-- Attachment #1: Type: text/plain, Size: 610 bytes --]

On Fri, Oct 20, 2017 at 12:12:42PM +0900, Yoshihiro Shimoda wrote:
> Since this driver checks if the return value of dma_map_sg() is minus
> or not and keeps to enable the DMAC, it may cause kernel panic when
> the dma_map_sg() returns 0. So, this patch fixes the issue.
> 
> Reported-by: Dirk Behme <dirk.behme@de.bosch.com>
> Fixes: 2a68ea7896e3 ("mmc: renesas-sdhi: add support for R-Car Gen3 SDHI DMAC")
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Acked-by: Wolfram Sang <wsa+renesas@sang-engineering.com>


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] mmc: tmio: fix swiotlb buffer is full
  2017-10-20  3:12 ` [PATCH v2 1/2] mmc: tmio: fix swiotlb buffer is full Yoshihiro Shimoda
  2017-10-20  4:00   ` Wolfram Sang
@ 2017-10-20  7:29   ` Geert Uytterhoeven
  1 sibling, 0 replies; 7+ messages in thread
From: Geert Uytterhoeven @ 2017-10-20  7:29 UTC (permalink / raw)
  To: Yoshihiro Shimoda
  Cc: Wolfram Sang, Ulf Hansson, Linux MMC List, Linux-Renesas

On Fri, Oct 20, 2017 at 5:12 AM, Yoshihiro Shimoda
<yoshihiro.shimoda.uh@renesas.com> wrote:
> Since the commit de3ee99b097d ("mmc: Delete bounce buffer handling")
> deletes the bounce buffer handling, a request data size will be referred
> to max_{req,seg}_size instead of MMC_QUEUE_BOUNCESZ (64k bytes).
>
> In other hand, renesas_sdhi_internal_dmac.c will set very big value of
> max_{req,seg}_size because the max_blk_count is set to 0xffffffff.
> And then, "swiotlb buffer is full" happens because swiotlb can handle
> a memory size up to 256k bytes only (IO_TLB_SEGSIZE = 128 and
> IO_TLB_SHIFT = 11).
>
> So, as a workaround, this patch avoids the issue by setting
> the max_{req,seg}_size up to 256k bytes if swiotlb is running.
>
> Reported-by: Dirk Behme <dirk.behme@de.bosch.com>
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 0/2] mmc: renesas_sdhi and tmio: bugfixes for v4.14
  2017-10-20  3:12 [PATCH v2 0/2] mmc: renesas_sdhi and tmio: bugfixes for v4.14 Yoshihiro Shimoda
  2017-10-20  3:12 ` [PATCH v2 1/2] mmc: tmio: fix swiotlb buffer is full Yoshihiro Shimoda
  2017-10-20  3:12 ` [PATCH v2 2/2] mmc: renesas_sdhi: fix kernel panic in _internal_dmac.c Yoshihiro Shimoda
@ 2017-10-20 10:03 ` Ulf Hansson
  2 siblings, 0 replies; 7+ messages in thread
From: Ulf Hansson @ 2017-10-20 10:03 UTC (permalink / raw)
  To: Yoshihiro Shimoda; +Cc: Wolfram Sang, linux-mmc@vger.kernel.org, Linux-Renesas

On 20 October 2017 at 05:12, Yoshihiro Shimoda
<yoshihiro.shimoda.uh@renesas.com> wrote:
> This patch set is based on mainline v4.14-rc5.
>
> Changes from v1:
>  - Calculate the max size of swiotlb memory instead of hardcoded value
>    in patch 1.
>  - Add Reviewed-by from Geert-san in patch 2. (Geert-san, thanks!)
>
> Yoshihiro Shimoda (2):
>   mmc: tmio: fix swiotlb buffer is full
>   mmc: renesas_sdhi: fix kernel panic in _internal_dmac.c
>
>  drivers/mmc/host/renesas_sdhi_internal_dmac.c | 17 ++++++++++-------
>  drivers/mmc/host/tmio_mmc_core.c              | 13 +++++++++++++
>  2 files changed, 23 insertions(+), 7 deletions(-)
>
> --
> 1.9.1
>

Thanks, applied for fixes!

Kind regards
Uffe

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-10-20 10:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-20  3:12 [PATCH v2 0/2] mmc: renesas_sdhi and tmio: bugfixes for v4.14 Yoshihiro Shimoda
2017-10-20  3:12 ` [PATCH v2 1/2] mmc: tmio: fix swiotlb buffer is full Yoshihiro Shimoda
2017-10-20  4:00   ` Wolfram Sang
2017-10-20  7:29   ` Geert Uytterhoeven
2017-10-20  3:12 ` [PATCH v2 2/2] mmc: renesas_sdhi: fix kernel panic in _internal_dmac.c Yoshihiro Shimoda
2017-10-20  4:00   ` Wolfram Sang
2017-10-20 10:03 ` [PATCH v2 0/2] mmc: renesas_sdhi and tmio: bugfixes for v4.14 Ulf Hansson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox