patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / arch / arm / mm / fault-armv.c
index 4d5c586..d03940c 100644 (file)
@@ -8,12 +8,14 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
+#include <linux/module.h>
 #include <linux/sched.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/bitops.h>
 #include <linux/vmalloc.h>
 #include <linux/init.h>
+#include <linux/pagemap.h>
 
 #include <asm/cacheflush.h>
 #include <asm/pgtable.h>
@@ -74,11 +76,14 @@ no_pmd:
        return 0;
 }
 
-void __flush_dcache_page(struct page *page)
+static void __flush_dcache_page(struct page *page)
 {
        struct address_space *mapping = page_mapping(page);
        struct mm_struct *mm = current->active_mm;
-       struct list_head *l;
+       struct vm_area_struct *mpnt = NULL;
+       struct prio_tree_iter iter;
+       unsigned long offset;
+       pgoff_t pgoff;
 
        __cpuc_flush_dcache_page(page_address(page));
 
@@ -89,36 +94,44 @@ void __flush_dcache_page(struct page *page)
         * With a VIVT cache, we need to also write back
         * and invalidate any user data.
         */
-       list_for_each(l, &mapping->i_mmap_shared) {
-               struct vm_area_struct *mpnt;
-               unsigned long off;
-
-               mpnt = list_entry(l, struct vm_area_struct, shared);
+       pgoff = page->index << (PAGE_CACHE_SHIFT - PAGE_SHIFT);
 
+       flush_dcache_mmap_lock(mapping);
+       while ((mpnt = vma_prio_tree_next(mpnt, &mapping->i_mmap,
+                                       &iter, pgoff, pgoff)) != NULL) {
                /*
                 * If this VMA is not in our MM, we can ignore it.
                 */
                if (mpnt->vm_mm != mm)
                        continue;
-
-               if (page->index < mpnt->vm_pgoff)
+               if (!(mpnt->vm_flags & VM_MAYSHARE))
                        continue;
+               offset = (pgoff - mpnt->vm_pgoff) << PAGE_SHIFT;
+               flush_cache_page(mpnt, mpnt->vm_start + offset);
+       }
+       flush_dcache_mmap_unlock(mapping);
+}
 
-               off = page->index - mpnt->vm_pgoff;
-               if (off >= (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT)
-                       continue;
+void flush_dcache_page(struct page *page)
+{
+       struct address_space *mapping = page_mapping(page);
 
-               flush_cache_page(mpnt, mpnt->vm_start + (off << PAGE_SHIFT));
-       }
+       if (mapping && !mapping_mapped(mapping))
+               set_bit(PG_dcache_dirty, &page->flags);
+       else
+               __flush_dcache_page(page);
 }
+EXPORT_SYMBOL(flush_dcache_page);
 
 static void
 make_coherent(struct vm_area_struct *vma, unsigned long addr, struct page *page, int dirty)
 {
        struct address_space *mapping = page_mapping(page);
-       struct list_head *l;
        struct mm_struct *mm = vma->vm_mm;
-       unsigned long pgoff;
+       struct vm_area_struct *mpnt = NULL;
+       struct prio_tree_iter iter;
+       unsigned long offset;
+       pgoff_t pgoff;
        int aliases = 0;
 
        if (!mapping)
@@ -131,12 +144,9 @@ make_coherent(struct vm_area_struct *vma, unsigned long addr, struct page *page,
         * space, then we need to handle them specially to maintain
         * cache coherency.
         */
-       list_for_each(l, &mapping->i_mmap_shared) {
-               struct vm_area_struct *mpnt;
-               unsigned long off;
-
-               mpnt = list_entry(l, struct vm_area_struct, shared);
-
+       flush_dcache_mmap_lock(mapping);
+       while ((mpnt = vma_prio_tree_next(mpnt, &mapping->i_mmap,
+                                       &iter, pgoff, pgoff)) != NULL) {
                /*
                 * If this VMA is not in our MM, we can ignore it.
                 * Note that we intentionally mask out the VMA
@@ -144,24 +154,12 @@ make_coherent(struct vm_area_struct *vma, unsigned long addr, struct page *page,
                 */
                if (mpnt->vm_mm != mm || mpnt == vma)
                        continue;
-
-               /*
-                * If the page isn't in this VMA, we can also ignore it.
-                */
-               if (pgoff < mpnt->vm_pgoff)
-                       continue;
-
-               off = pgoff - mpnt->vm_pgoff;
-               if (off >= (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT)
+               if (!(mpnt->vm_flags & VM_MAYSHARE))
                        continue;
-
-               off = mpnt->vm_start + (off << PAGE_SHIFT);
-
-               /*
-                * Ok, it is within mpnt.  Fix it up.
-                */
-               aliases += adjust_pte(mpnt, off);
+               offset = (pgoff - mpnt->vm_pgoff) << PAGE_SHIFT;
+               aliases += adjust_pte(mpnt, mpnt->vm_start + offset);
        }
+       flush_dcache_mmap_unlock(mapping);
        if (aliases)
                adjust_pte(vma, addr);
        else