Skip to contentSkip to conversation

mmc: dw_mmc: Round up descriptor end to nearest multiple of cacheline size

PATCH New Marek Vasut 2 participants 5 messages Mar 23, 2019 – Apr 2, 2019 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: dw_mmc: Round up descriptor end to nearest multiple of cacheline size

The driver currently calculates the end address of cache flush operation for the DMA descriptors by adding cacheline size to the start address of the last DMA descriptor. This is not safe, as the cacheline size may be, in some unlikely cases, smaller than the DMA descriptor size. Replace the addition with roundup() applied on the end address of the last DMA descriptor to round it up to the nearest cacheline size multiple.

Cc Jaehoon Chung <[email protected]>
Cc Simon Glass <[email protected]>
---
 drivers/mmc/dw_mmc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/dw_mmc.c +2 -2
index 72570235cb..bec30b1479 100644
@@ -74,15 +74,15 @@ static void dwmci_prepare_data(struct dwmci_host *host,
 		dwmci_set_idma_desc(cur_idmac, flags, cnt,
 				    (ulong)bounce_buffer + (i * PAGE_SIZE));
 
+		cur_idmac++;
 		if (blk_cnt <= 8)
 			break;
 		blk_cnt -= 8;
-		cur_idmac++;
 		i++;
 	} while(1);
 
 	data_end = (ulong)cur_idmac;
-	flush_dcache_range(data_start, data_end + ARCH_DMA_MINALIGN);
+	flush_dcache_range(data_start, roundup(data_end, ARCH_DMA_MINALIGN));
 
 	ctrl = dwmci_readl(host, DWMCI_CTRL);
 	ctrl |= DWMCI_IDMAC_EN | DWMCI_DMA_EN;
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/1 mmc: dw_mmc: Round up descriptor end to nearest multiple of cacheline size

Hi Marek,

Quoted 20 lines · Marek Vasut

The driver currently calculates the end address of cache flush operation for the DMA descriptors by adding cacheline size to the start address of the last DMA descriptor. This is not safe, as the cacheline size may be, in some unlikely cases, smaller than the DMA descriptor size. Replace the addition with roundup() applied on the end address of the last DMA descriptor to round it up to the nearest cacheline size multiple.

Cc Jaehoon Chung <[email protected]>
Cc Simon Glass <[email protected]>
---
 drivers/mmc/dw_mmc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/dw_mmc.c +0 -0
index 72570235cb..bec30b1479 100644

drivers/mmc/dw_mmc.c static void dwmci_prepare_data(struct dwmci_host *host, · line 77

Quoted 4 lines
drivers/mmc/dw_mmc.c +1 -0
@@ -74,15 +74,15 @@ static void dwmci_prepare_data(struct dwmci_host *host,
                dwmci_set_idma_desc(cur_idmac, flags, cnt,
                                    (ulong)bounce_buffer + (i * PAGE_SIZE));
 
+               cur_idmac++;

What is this change for? I don't see it mentioned above.

Quoted 14 lines
drivers/mmc/dw_mmc.c +1 -3
                if (blk_cnt <= 8)
                        break;
                blk_cnt -= 8;
-               cur_idmac++;
                i++;
        } while(1);
 
        data_end = (ulong)cur_idmac;
-       flush_dcache_range(data_start, data_end + ARCH_DMA_MINALIGN);
+       flush_dcache_range(data_start, roundup(data_end, ARCH_DMA_MINALIGN));
 
        ctrl = dwmci_readl(host, DWMCI_CTRL);
        ctrl |= DWMCI_IDMAC_EN | DWMCI_DMA_EN;
--
Quoted 2 lines

2.20.1

Regards,
Simon

#2 lore raw

PATCH 1/1 mmc: dw_mmc: Round up descriptor end to nearest multiple of cacheline size

Quoted 26 lines · Simon Glass

Hi Marek,

Quoted 23 lines · Marek Vasut

The driver currently calculates the end address of cache flush operation for the DMA descriptors by adding cacheline size to the start address of the last DMA descriptor. This is not safe, as the cacheline size may be, in some unlikely cases, smaller than the DMA descriptor size. Replace the addition with roundup() applied on the end address of the last DMA descriptor to round it up to the nearest cacheline size multiple.

Cc Jaehoon Chung <[email protected]>
Cc Simon Glass <[email protected]>
---
 drivers/mmc/dw_mmc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/dw_mmc.c +0 -0
index 72570235cb..bec30b1479 100644
@@ -74,15 +74,15 @@ static void dwmci_prepare_data(struct dwmci_host *host,
                dwmci_set_idma_desc(cur_idmac, flags, cnt,
                                    (ulong)bounce_buffer + (i * PAGE_SIZE));
 
Quoted 3 lines

drivers/mmc/dw_mmc.c static void dwmci_prepare_data(struct dwmci_host *host, · line 77

Quoted 1 line
drivers/mmc/dw_mmc.c +1 -0
+               cur_idmac++;

What is this change for? I don't see it mentioned above.

AFAIR you need to increment the pointer to cur_idmac before breaking out of the loop, otherwise data_end might point a bit before the actual end of the buffer.

Quoted 20 lines
Quoted 14 lines
drivers/mmc/dw_mmc.c +1 -3
                if (blk_cnt <= 8)
                        break;
                blk_cnt -= 8;
-               cur_idmac++;
                i++;
        } while(1);
 
        data_end = (ulong)cur_idmac;
-       flush_dcache_range(data_start, data_end + ARCH_DMA_MINALIGN);
+       flush_dcache_range(data_start, roundup(data_end, ARCH_DMA_MINALIGN));
 
        ctrl = dwmci_readl(host, DWMCI_CTRL);
        ctrl |= DWMCI_IDMAC_EN | DWMCI_DMA_EN;
--
Quoted 2 lines

2.20.1

Regards,
Simon

Signature · 2 lines
Best regards,
Marek Vasut
#3 lore raw

PATCH 1/1 mmc: dw_mmc: Round up descriptor end to nearest multiple of cacheline size

Hi Marek,

Quoted 28 lines · Marek Vasut
Quoted 26 lines · Simon Glass

Hi Marek,

Quoted 23 lines · Marek Vasut

The driver currently calculates the end address of cache flush operation for the DMA descriptors by adding cacheline size to the start address of the last DMA descriptor. This is not safe, as the cacheline size may be, in some unlikely cases, smaller than the DMA descriptor size. Replace the addition with roundup() applied on the end address of the last DMA descriptor to round it up to the nearest cacheline size multiple.

Cc Jaehoon Chung <[email protected]>
Cc Simon Glass <[email protected]>
---
 drivers/mmc/dw_mmc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/dw_mmc.c +0 -0
index 72570235cb..bec30b1479 100644
@@ -74,15 +74,15 @@ static void dwmci_prepare_data(struct dwmci_host *host,
                dwmci_set_idma_desc(cur_idmac, flags, cnt,
                                    (ulong)bounce_buffer + (i * PAGE_SIZE));
 
Quoted 7 lines
Quoted 3 lines

drivers/mmc/dw_mmc.c static void dwmci_prepare_data(struct dwmci_host *host, · line 77

Quoted 1 line
drivers/mmc/dw_mmc.c +1 -0
+               cur_idmac++;

What is this change for? I don't see it mentioned above.

AFAIR you need to increment the pointer to cur_idmac before breaking out of the loop, otherwise data_end might point a bit before the actual end of the buffer.

OK is that fixing a bug? Should it be in a different commit, or mentioned in this commit message?

Regards,
Simon

#4 lore raw

PATCH 1/1 mmc: dw_mmc: Round up descriptor end to nearest multiple of cacheline size

Quoted 35 lines · Simon Glass

Hi Marek,

Quoted 32 lines · Marek Vasut
Quoted 29 lines · Simon Glass

Hi Marek,

Quoted 20 lines · Marek Vasut

The driver currently calculates the end address of cache flush operation for the DMA descriptors by adding cacheline size to the start address of the last DMA descriptor. This is not safe, as the cacheline size may be, in some unlikely cases, smaller than the DMA descriptor size. Replace the addition with roundup() applied on the end address of the last DMA descriptor to round it up to the nearest cacheline size multiple.

Cc Jaehoon Chung <[email protected]>
Cc Simon Glass <[email protected]>
---
 drivers/mmc/dw_mmc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/dw_mmc.c +0 -0
index 72570235cb..bec30b1479 100644

drivers/mmc/dw_mmc.c static void dwmci_prepare_data(struct dwmci_host *host, · line 77

Quoted 4 lines
drivers/mmc/dw_mmc.c +1 -0
@@ -74,15 +74,15 @@ static void dwmci_prepare_data(struct dwmci_host *host,
                dwmci_set_idma_desc(cur_idmac, flags, cnt,
                                    (ulong)bounce_buffer + (i * PAGE_SIZE));
 
+               cur_idmac++;

What is this change for? I don't see it mentioned above.

Quoted 6 lines
Quoted 3 lines

AFAIR you need to increment the pointer to cur_idmac before breaking out of the loop, otherwise data_end might point a bit before the actual end of the buffer.

OK is that fixing a bug? Should it be in a different commit, or mentioned in this commit message?

I think if you have a really small cachelines, smaller than the idmac structure, this will trigger a bug.

Signature · 2 lines
Best regards,
Marek Vasut