mmc: dw_mmc: Round up descriptor end to nearest multiple of cacheline size
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.
--- drivers/mmc/dw_mmc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/dw_mmc.c +2 -2
@@ -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
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.Signed-off-by Marek Vasut <[email protected]>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
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
-3if (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
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.Signed-off-by Marek Vasut <[email protected]>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@@ -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
-3if (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
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.Signed-off-by Marek Vasut <[email protected]>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@@ -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_idmacbefore breaking out of the loop, otherwisedata_endmight 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
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.Signed-off-by Marek Vasut <[email protected]>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
-0drivers/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_idmacbefore breaking out of the loop, otherwisedata_endmight 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