[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-mips-cvs
Subject:    [MIPS] Fix COW D-cache aliasing on fork
From:       linux-mips () linux-mips ! org
Date:       2006-08-31 20:32:39
Message-ID: S20037621AbWHaUco/20060831203244Z+5697 () ftp ! linux-mips ! org
[Download RAW message or body]

Author: Atsushi Nemoto <anemo@mba.ocn.ne.jp> Thu Aug 24 00:31:30 2006 +0900
Comitter: Ralf Baechle <ralf@linux-mips.org> Thu Aug 31 19:50:02 2006 +0100
Commit: b895b66990f22a8a030c41390c538660a02bb97f
Gitweb: http://www.linux-mips.org/g/linux/b895b669
Branch: master

Problem:

1. There is a process containing two thread (T1 and T2).  The
   thread T1 calls fork().  Then dup_mmap() function called on T1 context.

static inline int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
	...
	flush_cache_mm(current->mm);
	...	/* A */
	(write-protect all Copy-On-Write pages)
	...	/* B */
	flush_tlb_mm(current->mm);
	...

2. When preemption happens between A and B (or on SMP kernel), the
   thread T2 can run and modify data on COW pages without page fault
   (modified data will stay in cache).

3. Some time after fork() completed, the thread T2 may cause a page
   fault by write-protect on a COW page.

4. Then data of the COW page will be copied to newly allocated
   physical page (copy_cow_page()).  It reads data via kernel mapping.
   The kernel mapping can have different 'color' with user space
   mapping of the thread T2 (dcache aliasing).  Therefore
   copy_cow_page() will copy stale data.  Then the modified data in
   cache will be lost.

This patch fixes above problems using custom copy_user_highpage().  It
uses kmap_coherent() to map an user page for kernel with same color.
Also copy_to_user_page() and copy_from_user_page() are rewritten using
the kmap_coherent() to avoid extra cache flushing.

To make copy_user_highpage() more effective, the argument "vma" is
added to the function and cow_user_page().

The main part of this patch was originally written by Ralf Baechle.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

---

 arch/mips/mm/init.c           |  213 ++++++++++++++++++++++++++++++++++++++++-
 arch/mips/mm/pgtable-32.c     |    7 +
 arch/mips/mm/pgtable-64.c     |   11 ++
 include/asm-mips/cacheflush.h |   19 +---
 include/asm-mips/fixmap.h     |   14 ++-
 include/asm-mips/page.h       |   17 +--
 include/linux/highmem.h       |    7 +
 mm/memory.c                   |   10 +-
 8 files changed, 253 insertions(+), 45 deletions(-)

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic