Skip to contentSkip to conversation

nds32: To implement these icache invalidation APIs since nds32 cores don't snoop data cache. This issue is found by Guo Ren. Based on the Documentation/core-api/cachetlb.rst and it says:

PATCH Superseded Greentime Hu 2 participants 3 messages Jun 28, 2018 – Jul 2, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 nds32: To implement these icache invalidation APIs since nds32 cores don't snoop data cache. This issue is found by Guo Ren. Based on the Documentation/core-api/cachetlb.rst and it says:

"Any necessary cache flushing or other coherency operations that need to occur should happen here. If the processor's instruction cache does not snoop cpu stores, it is very likely that you will need to flush the instruction cache for copy_to_user_page()."

"If the icache does not snoop stores then this
routine(flush_icache_range) will need
to flush it."

---
 arch/nds32/include/asm/cacheflush.h |  9 +++++--
 arch/nds32/mm/cacheflush.c          | 49 +++++++++++++++++++++----------------
 2 files changed, 35 insertions(+), 23 deletions(-)
arch/nds32/include/asm/cacheflush.h +7 -2
index 10b48f0d8e85..8b26198d51bb 100644
@@ -8,6 +8,8 @@
 
 #define PG_dcache_dirty PG_arch_1
 
+void flush_icache_range(unsigned long start, unsigned long end);
+void flush_icache_page(struct vm_area_struct *vma, struct page *page);
 #ifdef CONFIG_CPU_CACHE_ALIASING
 void flush_cache_mm(struct mm_struct *mm);
 void flush_cache_dup_mm(struct mm_struct *mm);
@@ -34,13 +36,16 @@ void flush_anon_page(struct vm_area_struct *vma,
 void flush_kernel_dcache_page(struct page *page);
 void flush_kernel_vmap_range(void *addr, int size);
 void invalidate_kernel_vmap_range(void *addr, int size);
-void flush_icache_range(unsigned long start, unsigned long end);
-void flush_icache_page(struct vm_area_struct *vma, struct page *page);
 #define flush_dcache_mmap_lock(mapping)   xa_lock_irq(&(mapping)->i_pages)
 #define flush_dcache_mmap_unlock(mapping) xa_unlock_irq(&(mapping)->i_pages)
 
 #else
 #include <asm-generic/cacheflush.h>
+#undef flush_icache_range
+#undef flush_icache_page
+#undef flush_icache_user_range
+void flush_icache_user_range(struct vm_area_struct *vma, struct page *page,
+	                     unsigned long addr, int len);
 #endif
 
 #endif /* __NDS32_CACHEFLUSH_H__ */
arch/nds32/mm/cacheflush.c +28 -21

61 lines not on this page · raw message

Signature · 1 line
1.9.5
#1 lore raw

arch/nds32/mm/cacheflush.c line 37

Quoted 10 lines · Greentime Hu
arch/nds32/mm/cacheflush.c +10 -0
+void flush_icache_page(struct vm_area_struct *vma, struct page *page)
+{
+	unsigned long flags;
+	local_irq_save(flags);
+	cpu_cache_wbinval_page((unsigned long)page_address(page),
+			       vma->vm_flags & VM_EXEC);
+	local_irq_restore(flags);
+}
+EXPORT_SYMBOL(flush_icache_page);
+

I'm afraid that the page_address(page) will return NULL for non-mapped page.

So I use kmap_atomic/kunmap_atomic here.

ref: https://github.com/c-sky/csky-linux/blob/master/arch/csky/abiv2/cacheflush.c

arch/nds32/mm/cacheflush.c line 43

Quoted 6 lines
arch/nds32/mm/cacheflush.c +6 -0
+void flush_icache_user_range(struct vm_area_struct *vma, struct page *page,
+	                     unsigned long addr, int len)
+{
+	unsigned long _addr = (unsigned long) page_address(page) + (addr & ~PAGE_MASK);
+	flush_icache_range(_addr, _addr + len);
+}

The same as above.

Guo Ren

#2 lore raw

Guo Ren <[email protected]> 於 2018年6月29日 週五 下午4:46寫道:

Quoted 18 lines · Greentime Hu

arch/nds32/mm/cacheflush.c line 37

Quoted 10 lines
arch/nds32/mm/cacheflush.c +10 -0
+void flush_icache_page(struct vm_area_struct *vma, struct page *page)
+{
+     unsigned long flags;
+     local_irq_save(flags);
+     cpu_cache_wbinval_page((unsigned long)page_address(page),
+                            vma->vm_flags & VM_EXEC);
+     local_irq_restore(flags);
+}
+EXPORT_SYMBOL(flush_icache_page);
+

I'm afraid that the page_address(page) will return NULL for non-mapped page.

So I use kmap_atomic/kunmap_atomic here.

ref: https://github.com/c-sky/csky-linux/blob/master/arch/csky/abiv2/cacheflush.c

Quoted 8 lines

arch/nds32/mm/cacheflush.c line 43

Quoted 6 lines
arch/nds32/mm/cacheflush.c +6 -0
+void flush_icache_user_range(struct vm_area_struct *vma, struct page *page,
+                          unsigned long addr, int len)
+{
+     unsigned long _addr = (unsigned long) page_address(page) + (addr & ~PAGE_MASK);
+     flush_icache_range(_addr, _addr + len);
+}

The same as above.

Thank you, Ren.
I will prepare the next version patch to use
kmap_atomic/kunmap_atomic to fix this issue.