[MIPS] Fix buggy invocations of kmap_coherent()
authorRalf Baechle <ralf@linux-mips.org>
Sat, 16 Feb 2008 22:34:25 +0000 (22:34 +0000)
committerRalf Baechle <ralf@linux-mips.org>
Tue, 19 Feb 2008 17:01:31 +0000 (17:01 +0000)
kmap_coherent will only work correctly if the page it is called on is
not marked dirty.  If it's dirty the kernel address of the page should
be used instead of a temporary mapping.

Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
arch/mips/mm/cache.c
arch/mips/mm/init.c

index 81f30ac2bff95fe7c406e3dcf7429899c0e74380..6a24651971df0f6e361d110419c65ee46f5f241a 100644 (file)
@@ -92,12 +92,17 @@ EXPORT_SYMBOL(__flush_dcache_page);
 
 void __flush_anon_page(struct page *page, unsigned long vmaddr)
 {
-       if (pages_do_alias((unsigned long)page_address(page), vmaddr)) {
-               void *kaddr;
+       unsigned long addr = (unsigned long) page_address(page);
 
-               kaddr = kmap_coherent(page, vmaddr);
-               flush_data_cache_page((unsigned long)kaddr);
-               kunmap_coherent();
+       if (pages_do_alias(addr, vmaddr)) {
+               if (page_mapped(page) && !Page_dcache_dirty(page)) {
+                       void *kaddr;
+
+                       kaddr = kmap_coherent(page, vmaddr);
+                       flush_data_cache_page((unsigned long)kaddr);
+                       kunmap_coherent();
+               } else
+                       flush_data_cache_page(addr);
        }
 }
 
index 480dec04f552cbe086f6fa96aedbaf73ff09ff7c..c7aed133d11d586894b14bd3a349ec2ba088baad 100644 (file)
@@ -211,7 +211,8 @@ void copy_user_highpage(struct page *to, struct page *from,
        void *vfrom, *vto;
 
        vto = kmap_atomic(to, KM_USER1);
-       if (cpu_has_dc_aliases && page_mapped(from)) {
+       if (cpu_has_dc_aliases &&
+           page_mapped(from) && !Page_dcache_dirty(from)) {
                vfrom = kmap_coherent(from, vaddr);
                copy_page(vto, vfrom);
                kunmap_coherent();
@@ -234,7 +235,8 @@ void copy_to_user_page(struct vm_area_struct *vma,
        struct page *page, unsigned long vaddr, void *dst, const void *src,
        unsigned long len)
 {
-       if (cpu_has_dc_aliases && page_mapped(page)) {
+       if (cpu_has_dc_aliases &&
+           page_mapped(page) && !Page_dcache_dirty(page)) {
                void *vto = kmap_coherent(page, vaddr) + (vaddr & ~PAGE_MASK);
                memcpy(vto, src, len);
                kunmap_coherent();
@@ -253,7 +255,8 @@ void copy_from_user_page(struct vm_area_struct *vma,
        struct page *page, unsigned long vaddr, void *dst, const void *src,
        unsigned long len)
 {
-       if (cpu_has_dc_aliases && page_mapped(page)) {
+       if (cpu_has_dc_aliases &&
+           page_mapped(page) && !Page_dcache_dirty(page)) {
                void *vfrom = kmap_coherent(page, vaddr) + (vaddr & ~PAGE_MASK);
                memcpy(dst, vfrom, len);
                kunmap_coherent();