Skip to contentSkip to conversation

csky: Fixup dma_rmb/wmb synchronization problem

PATCH In review [email protected] 3 participants 15 messages Jul 30, 2019 – Aug 6, 2019

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/4 csky: Fixup dma_rmb/wmb synchronization problem

From: Guo Ren <[email protected]>

If arch didn't define dma_r/wmb(), linux will use w/rmb instead. Csky use bar.xxx to implement mb() and that will cause problem when sync data with dma device, becasue bar.xxx couldn't guarantee bus transactions finished at outside bus level. We must use sync.s instead of bar.xxx for dma data synchronization and it will guarantee retirement after getting the bus bresponse.

---
 arch/csky/include/asm/barrier.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/csky/include/asm/barrier.h +6 -1
index 476eb78..061a633 100644
@@ -9,7 +9,9 @@
 #define nop()	asm volatile ("nop\n":::"memory")
 
 /*
- * sync:        completion barrier
+ * sync:        completion barrier, all sync.xx instructions
+ *              guarantee the last response recieved by bus transaction
+ *              made by ld/st instructions before sync.s
  * sync.s:      completion barrier and shareable to other cores
  * sync.i:      completion barrier with flush cpu pipeline
  * sync.is:     completion barrier with flush cpu pipeline and shareable to
@@ -31,6 +33,9 @@
 #define rmb()		asm volatile ("bar.brar\n":::"memory")
 #define wmb()		asm volatile ("bar.bwaw\n":::"memory")
 
+#define dma_rmb()	asm volatile ("sync.s\n":::"memory")
+#define dma_wmb()	asm volatile ("sync.s\n":::"memory")
+
 #ifdef CONFIG_SMP
 #define __smp_mb()	asm volatile ("bar.brwarws\n":::"memory")
 #define __smp_rmb()	asm volatile ("bar.brars\n":::"memory")
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

PATCH 2/4 csky: Fixup dma_alloc_coherent with PAGE_SO attribute

From: Guo Ren <[email protected]>

This bug is from commit: 2b070ccdf8c0 (fixup abiv2 mmap(... O_SYNC) failed). In that patch we remove the _PAGE_SO for memory noncache mapping and this will cause problem when drivers use dma descriptors to control the transcations without dma_w/rmb().

After referencing other archs' implementation, pgprot_writecombine is introduced for mmap(... O_SYNC).

---
 arch/csky/include/asm/pgtable.h | 10 ++++++++++
 arch/csky/mm/ioremap.c          |  6 ++----
 2 files changed, 12 insertions(+), 4 deletions(-)
arch/csky/include/asm/pgtable.h +10 -0
index c429a6f..fc19ba4 100644
@@ -258,6 +258,16 @@ static inline pgprot_t pgprot_noncached(pgprot_t _prot)
 {
 	unsigned long prot = pgprot_val(_prot);
 
+	prot = (prot & ~_CACHE_MASK) | _CACHE_UNCACHED | _PAGE_SO;
+
+	return __pgprot(prot);
+}
+
+#define pgprot_writecombine pgprot_writecombine
+static inline pgprot_t pgprot_writecombine(pgprot_t _prot)
+{
+	unsigned long prot = pgprot_val(_prot);
+
 	prot = (prot & ~_CACHE_MASK) | _CACHE_UNCACHED;
 
 	return __pgprot(prot);
arch/csky/mm/ioremap.c +2 -4
index 8473b6b..4853111 100644
@@ -29,8 +29,7 @@ void __iomem *ioremap(phys_addr_t addr, size_t size)
 
 	vaddr = (unsigned long)area->addr;
 
-	prot = __pgprot(_PAGE_PRESENT | __READABLE | __WRITEABLE |
-			_PAGE_GLOBAL | _CACHE_UNCACHED | _PAGE_SO);
+	prot = pgprot_noncached(PAGE_KERNEL);
 
 	if (ioremap_page_range(vaddr, vaddr + size, addr, prot)) {
 		free_vm_area(area);
@@ -51,10 +50,9 @@ pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
 			      unsigned long size, pgprot_t vma_prot)
 {
 	if (!pfn_valid(pfn)) {
-		vma_prot.pgprot |= _PAGE_SO;
 		return pgprot_noncached(vma_prot);
 	} else if (file->f_flags & O_SYNC) {
-		return pgprot_noncached(vma_prot);
+		return pgprot_writecombine(vma_prot);
 	}
 
 	return vma_prot;
Signature · 1 line
2.7.4
author maintainer
#2 lore raw

PATCH 3/4 csky/dma: Fixup cache_op failed when cross memory ZONEs

In reply to [email protected]

From: Guo Ren <[email protected]>

If the paddr and size are cross between NORMAL_ZONE and HIGHMEM_ZONE memory range, cache_op will panic in do_page_fault with bad_area.

Optimize the code to support the range which cross memory ZONEs.

---
 arch/csky/mm/dma-mapping.c | 73 +++++++++++++++++-----------------------------
 1 file changed, 27 insertions(+), 46 deletions(-)
arch/csky/mm/dma-mapping.c +27 -46
index 80783bb..3f1ff9d 100644
@@ -18,71 +18,52 @@ static int __init atomic_pool_init(void)
 {
 	return dma_atomic_pool_init(GFP_KERNEL, pgprot_noncached(PAGE_KERNEL));
 }
-postcore_initcall(atomic_pool_init);
-
-void arch_dma_prep_coherent(struct page *page, size_t size)
-{
-	if (PageHighMem(page)) {
-		unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT;
-
-		do {
-			void *ptr = kmap_atomic(page);
-			size_t _size = (size < PAGE_SIZE) ? size : PAGE_SIZE;
-
-			memset(ptr, 0, _size);
-			dma_wbinv_range((unsigned long)ptr,
-					(unsigned long)ptr + _size);
-
-			kunmap_atomic(ptr);
-
-			page++;
-			size -= PAGE_SIZE;
-			count--;
-		} while (count);
-	} else {
-		void *ptr = page_address(page);
-
-		memset(ptr, 0, size);
-		dma_wbinv_range((unsigned long)ptr, (unsigned long)ptr + size);
-	}
-}
+arch_initcall(atomic_pool_init);
 
 static inline void cache_op(phys_addr_t paddr, size_t size,
 			    void (*fn)(unsigned long start, unsigned long end))
 {
-	struct page *page = pfn_to_page(paddr >> PAGE_SHIFT);
-	unsigned int offset = paddr & ~PAGE_MASK;
-	size_t left = size;
-	unsigned long start;
+	struct page *page    = phys_to_page(paddr);
+	void *start          = __va(page_to_phys(page));
+	unsigned long offset = offset_in_page(paddr);
+	size_t left          = size;
 
 	do {
 		size_t len = left;
 
+		if (offset + len > PAGE_SIZE)
+			len = PAGE_SIZE - offset;
+
 		if (PageHighMem(page)) {
-			void *addr;
+			start = kmap_atomic(page);
 
-			if (offset + len > PAGE_SIZE) {
-				if (offset >= PAGE_SIZE) {
-					page += offset >> PAGE_SHIFT;
-					offset &= ~PAGE_MASK;
-				}
-				len = PAGE_SIZE - offset;
-			}
+			fn((unsigned long)start + offset,
+					(unsigned long)start + offset + len);
 
-			addr = kmap_atomic(page);
-			start = (unsigned long)(addr + offset);
-			fn(start, start + len);
-			kunmap_atomic(addr);
+			kunmap_atomic(start);
 		} else {
-			start = (unsigned long)phys_to_virt(paddr);
-			fn(start, start + size);
+			fn((unsigned long)start + offset,
+					(unsigned long)start + offset + len);
 		}
 		offset = 0;
+
 		page++;
+		start += PAGE_SIZE;
 		left -= len;
 	} while (left);
 }
 
+static void dma_wbinv_set_zero_range(unsigned long start, unsigned long end)
+{
+	memset((void *)start, 0, end - start);
+	dma_wbinv_range(start, end);
+}
+
+void arch_dma_prep_coherent(struct page *page, size_t size)
+{
+	cache_op(page_to_phys(page), size, dma_wbinv_set_zero_range);
+}
+
 void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr,
 			      size_t size, enum dma_data_direction dir)
 {
Signature · 1 line
2.7.4
#3 lore raw

Re: [PATCH 3/4] csky/dma: Fixup cache_op failed when cross memory ZONEs

arch/csky/mm/dma-mapping.c static int __init atomic_pool_init(void) · line 21

Quoted 9 lines · On Tue, Jul 30, 2019 at 08:15:44PM +0800, [email protected] wrote:
arch/csky/mm/dma-mapping.c +0 -1
index 80783bb..3f1ff9d 100644
@@ -18,71 +18,52 @@ static int __init atomic_pool_init(void)
 {
 	return dma_atomic_pool_init(GFP_KERNEL, pgprot_noncached(PAGE_KERNEL));
 }
-postcore_initcall(atomic_pool_init);

Please keep the postcore_initcall next to the function it calls.

In this particular case I also plan to remove the function for 5.4 by moving it to the common dma code, so it is more important than just style.

author maintainer
#4 lore raw

Re: [PATCH 3/4] csky/dma: Fixup cache_op failed when cross memory ZONEs

Quoted 13 lines · Christoph Hellwig

arch/csky/mm/dma-mapping.c static int __init atomic_pool_init(void) · line 21

Quoted 9 lines · On Tue, Jul 30, 2019 at 08:15:44PM +0800, [email protected] wrote:
arch/csky/mm/dma-mapping.c +0 -1
index 80783bb..3f1ff9d 100644
@@ -18,71 +18,52 @@ static int __init atomic_pool_init(void)
 {
      return dma_atomic_pool_init(GFP_KERNEL, pgprot_noncached(PAGE_KERNEL));
 }
-postcore_initcall(atomic_pool_init);

Please keep the postcore_initcall next to the function it calls.

Ok. Change arch_initcall back to postcore_initcall. :)

Signature · 4 lines
Best Regards
 Guo Ren

ML: https://lore.kernel.org/linux-csky/
#5 lore raw

Re: [PATCH 3/4] csky/dma: Fixup cache_op failed when cross memory ZONEs

Quoted 14 lines · Guo Ren
Quoted 13 lines · Christoph Hellwig

arch/csky/mm/dma-mapping.c static int __init atomic_pool_init(void) · line 21

Quoted 9 lines · On Tue, Jul 30, 2019 at 08:15:44PM +0800, [email protected] wrote:
arch/csky/mm/dma-mapping.c +0 -1
index 80783bb..3f1ff9d 100644
@@ -18,71 +18,52 @@ static int __init atomic_pool_init(void)
 {
      return dma_atomic_pool_init(GFP_KERNEL, pgprot_noncached(PAGE_KERNEL));
 }
-postcore_initcall(atomic_pool_init);

Please keep the postcore_initcall next to the function it calls.

Quoted 1 line

Ok. Change arch_initcall back to postcore_initcall. :)

Well, if you have a good reason to change it please keep the type init level change, but put it in a separate patch. But most importantly don't move the place where is called around.

author maintainer
#6 lore raw

PATCH 4/4 csky: Add dma_inv_range for DMA_FROM_DEVICE

In reply to [email protected]

From: Guo Ren <[email protected]>

DMA_FROM_DEVICE only need to read dma data of memory into CPU cache, so there is no need to clear cache before. Also clear + inv for DMA_FROM_DEVICE won't cause problem, because the memory range for dma won't be touched by software during dma working.

---
 arch/csky/include/asm/cache.h |  1 +
 arch/csky/mm/cachev1.c        |  7 ++++++-
 arch/csky/mm/cachev2.c        | 11 ++++++++++-
 arch/csky/mm/dma-mapping.c    |  4 ++++
 4 files changed, 21 insertions(+), 2 deletions(-)
arch/csky/include/asm/cache.h +1 -0
index d683734..1d5fc2f 100644
@@ -24,6 +24,7 @@ void cache_wbinv_range(unsigned long start, unsigned long end);
 void cache_wbinv_all(void);
 
 void dma_wbinv_range(unsigned long start, unsigned long end);
+void dma_inv_range(unsigned long start, unsigned long end);
 void dma_wb_range(unsigned long start, unsigned long end);
 
 #endif
arch/csky/mm/cachev1.c +6 -1
index b8a75cc..494ec91 100644
@@ -120,7 +120,12 @@ void dma_wbinv_range(unsigned long start, unsigned long end)
 	cache_op_range(start, end, DATA_CACHE|CACHE_CLR|CACHE_INV, 1);
 }
 
+void dma_inv_range(unsigned long start, unsigned long end)
+{
+	cache_op_range(start, end, DATA_CACHE|CACHE_CLR|CACHE_INV, 1);
+}
+
 void dma_wb_range(unsigned long start, unsigned long end)
 {
-	cache_op_range(start, end, DATA_CACHE|CACHE_INV, 1);
+	cache_op_range(start, end, DATA_CACHE|CACHE_CLR|CACHE_INV, 1);
 }
arch/csky/mm/cachev2.c +10 -1
index baaf05d..b61be65 100644
@@ -69,11 +69,20 @@ void dma_wbinv_range(unsigned long start, unsigned long end)
 	sync_is();
 }
 
+void dma_inv_range(unsigned long start, unsigned long end)
+{
+	unsigned long i = start & ~(L1_CACHE_BYTES - 1);
+
+	for (; i < end; i += L1_CACHE_BYTES)
+		asm volatile("dcache.iva %0\n"::"r"(i):"memory");
+	sync_is();
+}
+
 void dma_wb_range(unsigned long start, unsigned long end)
 {
 	unsigned long i = start & ~(L1_CACHE_BYTES - 1);
 
 	for (; i < end; i += L1_CACHE_BYTES)
-		asm volatile("dcache.civa %0\n"::"r"(i):"memory");
+		asm volatile("dcache.cva %0\n"::"r"(i):"memory");
 	sync_is();
 }
arch/csky/mm/dma-mapping.c +4 -0
index 3f1ff9d..d8f0f81 100644
@@ -72,6 +72,8 @@ void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr,
 		cache_op(paddr, size, dma_wb_range);
 		break;
 	case DMA_FROM_DEVICE:
+		cache_op(paddr, size, dma_inv_range);
+		break;
 	case DMA_BIDIRECTIONAL:
 		cache_op(paddr, size, dma_wbinv_range);
 		break;
@@ -88,6 +90,8 @@ void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr,
 		cache_op(paddr, size, dma_wb_range);
 		break;
 	case DMA_FROM_DEVICE:
+		cache_op(paddr, size, dma_inv_range);
+		break;
 	case DMA_BIDIRECTIONAL:
 		cache_op(paddr, size, dma_wbinv_range);
 		break;
Signature · 1 line
2.7.4
maintainer
#7 lore raw

Re: [PATCH 4/4] csky: Add dma_inv_range for DMA_FROM_DEVICE

Quoted 16 lines · On Tue, Jul 30, 2019 at 2:16 PM <[email protected]> wrote:

From: Guo Ren <[email protected]>

arch/csky/mm/dma-mapping.c +2 -0
index 3f1ff9d..d8f0f81 100644
@@ -72,6 +72,8 @@ void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr,
                cache_op(paddr, size, dma_wb_range);
                break;
        case DMA_FROM_DEVICE:
+               cache_op(paddr, size, dma_inv_range);
+               break;
        case DMA_BIDIRECTIONAL:
                cache_op(paddr, size, dma_wbinv_range);
                break;

arch/csky/mm/dma-mapping.c void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr, · line 97

Quoted 8 lines
arch/csky/mm/dma-mapping.c +2 -0
@@ -88,6 +90,8 @@ void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr,
                cache_op(paddr, size, dma_wb_range);
                break;
        case DMA_FROM_DEVICE:
+               cache_op(paddr, size, dma_inv_range);
+               break;
        case DMA_BIDIRECTIONAL:
                cache_op(paddr, size, dma_wbinv_range);
                break;

When syncing 'for_cpu', you should not need to write back, because there won't be any dirty cache lines.

If you have a CPU core that does not do speculative loads, you also don't need to invalidate here, because you have already done that in the _for_device() case, the only reason to invalidate the CPU cache again is if a speculative load created a stale cache line that now shadows the data received from the device.

Arnd

author maintainer
#8 lore raw

Re: [PATCH 4/4] csky: Add dma_inv_range for DMA_FROM_DEVICE

Thx Arnd,

Quoted 21 lines · Arnd Bergmann
Quoted 19 lines · On Tue, Jul 30, 2019 at 2:16 PM <[email protected]> wrote:

From: Guo Ren <[email protected]>

arch/csky/mm/dma-mapping.c +2 -0
index 3f1ff9d..d8f0f81 100644
@@ -72,6 +72,8 @@ void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr,
                cache_op(paddr, size, dma_wb_range);
                break;
        case DMA_FROM_DEVICE:
+               cache_op(paddr, size, dma_inv_range);
+               break;
        case DMA_BIDIRECTIONAL:
                cache_op(paddr, size, dma_wbinv_range);
                break;
@@ -88,6 +90,8 @@ void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr,
                cache_op(paddr, size, dma_wb_range);
                break;
        case DMA_FROM_DEVICE:
Quoted 8 lines

arch/csky/mm/dma-mapping.c void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr, · line 79

Quoted 5 lines
arch/csky/mm/dma-mapping.c +2 -0
+               cache_op(paddr, size, dma_inv_range);
+               break;
        case DMA_BIDIRECTIONAL:
                cache_op(paddr, size, dma_wbinv_range);
                break;

When syncing 'for_cpu', you should not need to write back, because there won't be any dirty cache lines.

I just follow the dma_data_direction param, seems dir param and function are a little bit duplicated. And our cpu won't clear clean cache line into memory, so dma_wb_page won't cause problem. Seems arch_sync_dma_for_cpu with dir=DMA_TO_DEVICE is self-contradictory.

Do you want me modfiy like these:
@@ -88,6 +90,8 @@ void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr,

        case DMA_TO_DEVICE:
        case DMA_FROM_DEVICE:
        case DMA_BIDIRECTIONAL:
               cache_op(paddr, size, dma_inv_range);
               break;

@@ -72,6 +72,8 @@ void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr,

        case DMA_TO_DEVICE:
                cache_op(paddr, size, dma_wb_range);
                break;
        case DMA_FROM_DEVICE:
        case DMA_BIDIRECTIONAL:
                cache_op(paddr, size, dma_wbinv_range);
                break;
Quoted 6 lines

If you have a CPU core that does not do speculative loads, you also don't need to invalidate here, because you have already done that in the _for_device() case, the only reason to invalidate the CPU cache again is if a speculative load created a stale cache line that now shadows the data received from the device.

Our CPU support speculative loads :)

Signature · 4 lines
Best Regards
 Guo Ren

ML: https://lore.kernel.org/linux-csky/
maintainer
#9 lore raw

Re: [PATCH 4/4] csky: Add dma_inv_range for DMA_FROM_DEVICE

Quoted 13 lines · Guo Ren
Quoted 4 lines
Quoted 4 lines
arch/csky/mm/dma-mapping.c +0 -0
                cache_op(paddr, size, dma_wb_range);
                break;
        case DMA_FROM_DEVICE:
Quoted 8 lines

arch/csky/mm/dma-mapping.c void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr, · line 79

Quoted 5 lines
arch/csky/mm/dma-mapping.c +2 -0
+               cache_op(paddr, size, dma_inv_range);
+               break;
        case DMA_BIDIRECTIONAL:
                cache_op(paddr, size, dma_wbinv_range);
                break;

When syncing 'for_cpu', you should not need to write back, because there won't be any dirty cache lines.

Quoted 5 lines

I just follow the dma_data_direction param, seems dir param and function are a little bit duplicated. And our cpu won't clear clean cache line into memory, so dma_wb_page won't cause problem. Seems arch_sync_dma_for_cpu with dir=DMA_TO_DEVICE is self-contradictory.

Right, you generally don't need to do cache management for that combination.

There might be other things to do here though, e.g. with a strict iommu implementation one could tear down the i/o page table entry to prevent the device from accessing a buffer while that is owned by the cpu.

Quoted 20 lines

Do you want me modfiy like these:

arch/csky/mm/dma-mapping.c +0 -0
@@ -88,6 +90,8 @@ void arch_sync_dma_for_cpu(struct device *dev,
 phys_addr_t paddr,
        case DMA_TO_DEVICE:
        case DMA_FROM_DEVICE:
        case DMA_BIDIRECTIONAL:
               cache_op(paddr, size, dma_inv_range);
               break;
@@ -72,6 +72,8 @@ void arch_sync_dma_for_device(struct device *dev,
 phys_addr_t paddr,
        case DMA_TO_DEVICE:
                cache_op(paddr, size, dma_wb_range);
                break;
        case DMA_FROM_DEVICE:
        case DMA_BIDIRECTIONAL:
                cache_op(paddr, size, dma_wbinv_range);
                break;
Quoted 2 lines
Quoted 6 lines
Quoted 5 lines

If you have a CPU core that does not do speculative loads, you also don't need to invalidate here, because you have already done that in the _for_device() case, the only reason to invalidate the CPU cache again is if a speculative load created a stale cache line that now shadows the data received from the device.

Our CPU support speculative loads :)

Ok, then you both invalidations are indeed needed. I was guessing that CK610 had no speculation.

Arnd

author maintainer
#10 lore raw

Re: [PATCH 4/4] csky: Add dma_inv_range for DMA_FROM_DEVICE

Thx Arnd,

Quoted 21 lines · Arnd Bergmann
Quoted 13 lines · Guo Ren
Quoted 4 lines
Quoted 4 lines
arch/csky/mm/dma-mapping.c +0 -0
                cache_op(paddr, size, dma_wb_range);
                break;
        case DMA_FROM_DEVICE:
Quoted 8 lines

arch/csky/mm/dma-mapping.c void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr, · line 79

Quoted 5 lines
arch/csky/mm/dma-mapping.c +2 -0
+               cache_op(paddr, size, dma_inv_range);
+               break;
        case DMA_BIDIRECTIONAL:
                cache_op(paddr, size, dma_wbinv_range);
                break;

When syncing 'for_cpu', you should not need to write back, because there won't be any dirty cache lines.

Quoted 5 lines

I just follow the dma_data_direction param, seems dir param and function are a little bit duplicated. And our cpu won't clear clean cache line into memory, so dma_wb_page won't cause problem. Seems arch_sync_dma_for_cpu with dir=DMA_TO_DEVICE is self-contradictory.

Quoted 7 lines

Right, you generally don't need to do cache management for that combination.

There might be other things to do here though, e.g. with a strict iommu implementation one could tear down the i/o page table entry to prevent the device from accessing a buffer while that is owned by the cpu.

Tear down i/o page table shouldn't be put here and it's for map/unmap(). And I think arch_sync_dma_for_cpu/device should only do cache issues.

--
Best Regards
Guo Ren

ML: https://lore.kernel.org/linux-csky/

#11 lore raw

Re: [PATCH 4/4] csky: Add dma_inv_range for DMA_FROM_DEVICE

In reply to Arnd Bergmann
Quoted 8 lines · Arnd Bergmann

When syncing 'for_cpu', you should not need to write back, because there won't be any dirty cache lines.

If you have a CPU core that does not do speculative loads, you also don't need to invalidate here, because you have already done that in the _for_device() case, the only reason to invalidate the CPU cache again is if a speculative load created a stale cache line that now shadows the data received from the device.

Yes. And that is one reason why I want to lift a set of common helpers for both the speculating and non-speculating case to the common code that just calls arch specific writeback/invalidate/writeback+invalidate helpers. It hasn't been a priotity so far, but maybe it becomes one now. Especially if I could draft someone else to help with it :)

maintainer
#12 lore raw
In reply to [email protected]
Quoted 11 lines · On Tue, Jul 30, 2019 at 2:15 PM <[email protected]> wrote:

From: Guo Ren <[email protected]>

If arch didn't define dma_r/wmb(), linux will use w/rmb instead. Csky use bar.xxx to implement mb() and that will cause problem when sync data with dma device, becasue bar.xxx couldn't guarantee bus transactions finished at outside bus level. We must use sync.s instead of bar.xxx for dma data synchronization and it will guarantee retirement after getting the bus bresponse.

This change looks good to me, but I think your regular barriers (mb, rmb, wmb) are still wrong: These are meant to be the superset of dma_{r,w}mb and smp_{,r,w}mb, and synchronize against both SMP and DMA interactions.

I suspect you can drop the '.s' for non-SMP builds. What I don't see is whether you might need to add '.i' for dma_wmb() or dma_rmb().

Arnd

author maintainer
#13 lore raw
Quoted 24 lines · Arnd Bergmann
Quoted 11 lines · On Tue, Jul 30, 2019 at 2:15 PM <[email protected]> wrote:

From: Guo Ren <[email protected]>

If arch didn't define dma_r/wmb(), linux will use w/rmb instead. Csky use bar.xxx to implement mb() and that will cause problem when sync data with dma device, becasue bar.xxx couldn't guarantee bus transactions finished at outside bus level. We must use sync.s instead of bar.xxx for dma data synchronization and it will guarantee retirement after getting the bus bresponse.

This change looks good to me, but I think your regular barriers (mb, rmb, wmb) are still wrong: These are meant to be the superset of dma_{r,w}mb and smp_{,r,w}mb, and synchronize against both SMP and DMA interactions.

I suspect you can drop the '.s' for non-SMP builds. What I don't see is whether you might need to add '.i' for dma_wmb() or dma_rmb().

Arnd

Signature · 4 lines
Best Regards
 Guo Ren

ML: https://lore.kernel.org/linux-csky/
author maintainer
#14 lore raw
In reply to Arnd Bergmann

Thx Arnd,

Quoted 12 lines · Arnd Bergmann
Quoted 10 lines · On Tue, Jul 30, 2019 at 2:15 PM <[email protected]> wrote:

From: Guo Ren <[email protected]>

If arch didn't define dma_r/wmb(), linux will use w/rmb instead. Csky use bar.xxx to implement mb() and that will cause problem when sync data with dma device, becasue bar.xxx couldn't guarantee bus transactions finished at outside bus level. We must use sync.s instead of bar.xxx for dma data synchronization and it will guarantee retirement after getting the bus bresponse.

Quoted 6 lines
Quoted 1 line

This change looks good to me, but I think your regular barriers (mb, rmb, wmb) are still wrong: These are meant to be the superset of dma_{r,w}mb and smp_{,r,w}mb, and synchronize against both SMP and DMA interactions.

Wow, thanks for correction, yes! mb, rmb, wmb is the superset of dma and smp, and I should use sync.s for mb.

I check the arm64, it use dsb for mb and dmb for smp_mb and dma_mb.

I also check the drivers, you are right , a lot of them use mb() to sync mem data with device.

Quoted 4 lines

I suspect you can drop the '.s' for non-SMP builds. What I don't see is whether you might need to add '.i' for dma_wmb() or dma_rmb().

It's no need for sky, when there is non-SMP, the cpu is in reset mode, and sync.s is equal to sync in efficient.

Signature · 4 lines
Best Regards
 Guo Ren

ML: https://lore.kernel.org/linux-csky/