linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3]nds32: Correct the cache operation for catch aliasing case
@ 2018-05-15  8:46 Vincent Chen
  2018-05-15  8:46 ` [PATCH 1/3] nds32: Correct flush_dcache_page function Vincent Chen
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Vincent Chen @ 2018-05-15  8:46 UTC (permalink / raw)
  To: linux-kernel, green.hu, greentime, arnd; +Cc: deanbo422, vincentc

The following 3 issues are fixed in this patchset

1. In function flush_dacache_page and copy_user_highpage, the local irq is
enabled when the cache of the page at address page_address(page) is written
back to memory. It possibly causes data corruption. To fix this problem,
the local irq is disabled before executing d-cache write-back and
invalidate in this patchset.

2. According to Documentation/cachetlb.txt, the cache of the page at vmaddr
shall be flushed in flush_anon_page instead of the cache of the page at
page_address(page). We correct it and add the modification to this
patchset.

3. Removing unneeded cache invalidation in copy_user_highpage function.


Vincent Chen (3):
  nds32: Correct flush_dcache_page function
  nds32: Flush the cache of the page at vmaddr instead of kaddr in
    flush_anon_page
  nds32: Disable local irq before calling cpu_dcache_wb_page in
    copy_user_highpage

 arch/nds32/mm/cacheflush.c |   34 ++++++++++++++++++++--------------
 1 files changed, 20 insertions(+), 14 deletions(-)

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

* [PATCH 1/3] nds32: Correct flush_dcache_page function
  2018-05-15  8:46 [PATCH 0/3]nds32: Correct the cache operation for catch aliasing case Vincent Chen
@ 2018-05-15  8:46 ` Vincent Chen
  2018-05-15  8:46 ` [PATCH 2/3] nds32: Flush the cache of the page at vmaddr instead of kaddr in flush_anon_page Vincent Chen
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Vincent Chen @ 2018-05-15  8:46 UTC (permalink / raw)
  To: linux-kernel, green.hu, greentime, arnd; +Cc: deanbo422, vincentc

1. Disable local irq before d-cache write-back and invalidate.
   The cpu_dcache_wbinval_page function is composed of d-cache
write-back and invalidate. If the local irq is enabled when calling
cpu_dcache_wbinval_page, the content of d-cache is possibly updated
between write-back and invalidate. In this case, the updated data will
be dropped due to the following d-cache invalidation. Therefore, we
disable the local irq before calling cpu_dcache_wbinval_page.

2. Correct the data write-back for page aliasing case.
   Only the page whose (page->index << PAGE_SHIFT) is located at the
same page color as page_address(page) needs to execute data write-back
in flush_dcache_page function.

Signed-off-by: Vincent Chen <vincentc@andestech.com>
---
 arch/nds32/mm/cacheflush.c |   21 ++++++++++++---------
 1 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/arch/nds32/mm/cacheflush.c b/arch/nds32/mm/cacheflush.c
index 6eb786a..288cf10 100644
--- a/arch/nds32/mm/cacheflush.c
+++ b/arch/nds32/mm/cacheflush.c
@@ -198,17 +198,20 @@ void flush_dcache_page(struct page *page)
 	if (mapping && !mapping_mapped(mapping))
 		set_bit(PG_dcache_dirty, &page->flags);
 	else {
-		int i, pc;
-		unsigned long vto, kaddr, flags;
+		unsigned long kaddr, flags;
+
 		kaddr = (unsigned long)page_address(page);
-		cpu_dcache_wbinval_page(kaddr);
-		pc = CACHE_SET(DCACHE) * CACHE_LINE_SIZE(DCACHE) / PAGE_SIZE;
 		local_irq_save(flags);
-		for (i = 0; i < pc; i++) {
-			vto =
-			    kremap0(kaddr + i * PAGE_SIZE, page_to_phys(page));
-			cpu_dcache_wbinval_page(vto);
-			kunmap01(vto);
+		cpu_dcache_wbinval_page(kaddr);
+		if (mapping) {
+			unsigned long vaddr, kto;
+
+			vaddr = page->index << PAGE_SHIFT;
+			if (aliasing(vaddr, kaddr)) {
+				kto = kremap0(vaddr, page_to_phys(page));
+				cpu_dcache_wbinval_page(kto);
+				kunmap01(kto);
+			}
 		}
 		local_irq_restore(flags);
 	}
-- 
1.7.1

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

* [PATCH 2/3] nds32: Flush the cache of the page at vmaddr instead of kaddr in flush_anon_page
  2018-05-15  8:46 [PATCH 0/3]nds32: Correct the cache operation for catch aliasing case Vincent Chen
  2018-05-15  8:46 ` [PATCH 1/3] nds32: Correct flush_dcache_page function Vincent Chen
@ 2018-05-15  8:46 ` Vincent Chen
  2018-05-15  8:46 ` [PATCH 3/3] nds32: Disable local irq before calling cpu_dcache_wb_page in copy_user_highpage Vincent Chen
  2018-05-17  6:58 ` [PATCH 0/3]nds32: Correct the cache operation for catch aliasing case Greentime Hu
  3 siblings, 0 replies; 5+ messages in thread
From: Vincent Chen @ 2018-05-15  8:46 UTC (permalink / raw)
  To: linux-kernel, green.hu, greentime, arnd; +Cc: deanbo422, vincentc

According to Documentation/cachetlb.txt, the cache of the page at vmaddr
shall be flushed in flush_anon_page instead of the cache of the page at
page_address(page).

Signed-off-by: Vincent Chen <vincentc@andestech.com>
---
 arch/nds32/mm/cacheflush.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/nds32/mm/cacheflush.c b/arch/nds32/mm/cacheflush.c
index 288cf10..acfdb45 100644
--- a/arch/nds32/mm/cacheflush.c
+++ b/arch/nds32/mm/cacheflush.c
@@ -254,7 +254,7 @@ void copy_from_user_page(struct vm_area_struct *vma, struct page *page,
 void flush_anon_page(struct vm_area_struct *vma,
 		     struct page *page, unsigned long vaddr)
 {
-	unsigned long flags;
+	unsigned long kaddr, flags, ktmp;
 	if (!PageAnon(page))
 		return;
 
@@ -264,7 +264,12 @@ void flush_anon_page(struct vm_area_struct *vma,
 	local_irq_save(flags);
 	if (vma->vm_flags & VM_EXEC)
 		cpu_icache_inval_page(vaddr & PAGE_MASK);
-	cpu_dcache_wbinval_page((unsigned long)page_address(page));
+	kaddr = (unsigned long)page_address(page);
+	if (aliasing(vaddr, kaddr)) {
+		ktmp = kremap0(vaddr, page_to_phys(page));
+		cpu_dcache_wbinval_page(ktmp);
+		kunmap01(ktmp);
+	}
 	local_irq_restore(flags);
 }
 
-- 
1.7.1

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

* [PATCH 3/3] nds32: Disable local irq before calling cpu_dcache_wb_page in copy_user_highpage
  2018-05-15  8:46 [PATCH 0/3]nds32: Correct the cache operation for catch aliasing case Vincent Chen
  2018-05-15  8:46 ` [PATCH 1/3] nds32: Correct flush_dcache_page function Vincent Chen
  2018-05-15  8:46 ` [PATCH 2/3] nds32: Flush the cache of the page at vmaddr instead of kaddr in flush_anon_page Vincent Chen
@ 2018-05-15  8:46 ` Vincent Chen
  2018-05-17  6:58 ` [PATCH 0/3]nds32: Correct the cache operation for catch aliasing case Greentime Hu
  3 siblings, 0 replies; 5+ messages in thread
From: Vincent Chen @ 2018-05-15  8:46 UTC (permalink / raw)
  To: linux-kernel, green.hu, greentime, arnd; +Cc: deanbo422, vincentc

In order to ensure that all data in source page has been written back
to memory before copy_page, the local irq shall be disabled before
calling cpu_dcache_wb_page(). In addition, removing unneeded page
invalidation for 'to' page.

Signed-off-by: Vincent Chen <vincentc@andestech.com>
---
 arch/nds32/mm/cacheflush.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/arch/nds32/mm/cacheflush.c b/arch/nds32/mm/cacheflush.c
index acfdb45..c97caaf 100644
--- a/arch/nds32/mm/cacheflush.c
+++ b/arch/nds32/mm/cacheflush.c
@@ -156,11 +156,9 @@ void copy_user_highpage(struct page *to, struct page *from,
 	pto = page_to_phys(to);
 	pfrom = page_to_phys(from);
 
+	local_irq_save(flags);
 	if (aliasing(vaddr, (unsigned long)kfrom))
 		cpu_dcache_wb_page((unsigned long)kfrom);
-	if (aliasing(vaddr, (unsigned long)kto))
-		cpu_dcache_inval_page((unsigned long)kto);
-	local_irq_save(flags);
 	vto = kremap0(vaddr, pto);
 	vfrom = kremap1(vaddr, pfrom);
 	copy_page((void *)vto, (void *)vfrom);
-- 
1.7.1

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

* Re: [PATCH 0/3]nds32: Correct the cache operation for catch aliasing case
  2018-05-15  8:46 [PATCH 0/3]nds32: Correct the cache operation for catch aliasing case Vincent Chen
                   ` (2 preceding siblings ...)
  2018-05-15  8:46 ` [PATCH 3/3] nds32: Disable local irq before calling cpu_dcache_wb_page in copy_user_highpage Vincent Chen
@ 2018-05-17  6:58 ` Greentime Hu
  3 siblings, 0 replies; 5+ messages in thread
From: Greentime Hu @ 2018-05-17  6:58 UTC (permalink / raw)
  To: Vincent Chen
  Cc: Linux Kernel Mailing List, Greentime, Arnd Bergmann, Vincent Chen

2018-05-15 16:46 GMT+08:00 Vincent Chen <vincentc@andestech.com>:
> The following 3 issues are fixed in this patchset
>
> 1. In function flush_dacache_page and copy_user_highpage, the local irq is
> enabled when the cache of the page at address page_address(page) is written
> back to memory. It possibly causes data corruption. To fix this problem,
> the local irq is disabled before executing d-cache write-back and
> invalidate in this patchset.
>
> 2. According to Documentation/cachetlb.txt, the cache of the page at vmaddr
> shall be flushed in flush_anon_page instead of the cache of the page at
> page_address(page). We correct it and add the modification to this
> patchset.
>
> 3. Removing unneeded cache invalidation in copy_user_highpage function.
>
>
> Vincent Chen (3):
>   nds32: Correct flush_dcache_page function
>   nds32: Flush the cache of the page at vmaddr instead of kaddr in
>     flush_anon_page
>   nds32: Disable local irq before calling cpu_dcache_wb_page in
>     copy_user_highpage
>
>  arch/nds32/mm/cacheflush.c |   34 ++++++++++++++++++++--------------
>  1 files changed, 20 insertions(+), 14 deletions(-)
>

Thank you, Vincent.
Reviewed-by: Greentime Hu <greentime@andestech.com>

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

end of thread, other threads:[~2018-05-17  6:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-15  8:46 [PATCH 0/3]nds32: Correct the cache operation for catch aliasing case Vincent Chen
2018-05-15  8:46 ` [PATCH 1/3] nds32: Correct flush_dcache_page function Vincent Chen
2018-05-15  8:46 ` [PATCH 2/3] nds32: Flush the cache of the page at vmaddr instead of kaddr in flush_anon_page Vincent Chen
2018-05-15  8:46 ` [PATCH 3/3] nds32: Disable local irq before calling cpu_dcache_wb_page in copy_user_highpage Vincent Chen
2018-05-17  6:58 ` [PATCH 0/3]nds32: Correct the cache operation for catch aliasing case Greentime Hu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).