[ARM] Do not call flush_cache_user_range with mmap_sem held
authorDima Zavin <dima@android.com>
Wed, 28 Apr 2010 03:57:04 +0000 (20:57 -0700)
committerDima Zavin <dima@android.com>
Wed, 5 May 2010 01:02:20 +0000 (18:02 -0700)
We can't be holding the mmap_sem while calling flush_cache_user_range
because the flush can fault. If we fault on a user address, the
page fault handler will try to take mmap_sem again. Since both places
acquire the read lock, most of the time it succeeds. However, if another
thread tries to acquire the write lock on the mmap_sem (e.g. mmap) in
between the call to flush_cache_user_range and the fault, the down_read
in do_page_fault will deadlock.

Also, since we really can't be holding the mmap_sem while calling
flush_cache_user_range AND vma is actually unused by the flush itself,
get rid of vma as an argument.

Change-Id: If55409bde41ad1060fa4fe7cbd4ac530d4d9a106
Signed-off-by: Dima Zavin <dima@android.com>
arch/arm/include/asm/cacheflush.h
arch/arm/kernel/traps.c

index 3d0cdd21b882d1d39cade901827b17509c63e06e..3e32991c04fa40ff8a6252980f2e6fdee7edb4de 100644 (file)
@@ -381,7 +381,7 @@ extern void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
  * Harvard caches are synchronised for the user space address range.
  * This is used for the ARM private sys_cacheflush system call.
  */
-#define flush_cache_user_range(vma,start,end) \
+#define flush_cache_user_range(start,end) \
        __cpuc_coherent_user_range((start) & PAGE_MASK, PAGE_ALIGN(end))
 
 /*
index c1750dd70ab6ca0a1a584d863d79d8e3ee0f46ae..14abab76019accaf91300b5dde6a034fc9d221ef 100644 (file)
@@ -438,7 +438,9 @@ do_cache_op(unsigned long start, unsigned long end, int flags)
                if (end > vma->vm_end)
                        end = vma->vm_end;
 
-               flush_cache_user_range(vma, start, end);
+               up_read(&mm->mmap_sem);
+               flush_cache_user_range(start, end);
+               return;
        }
        up_read(&mm->mmap_sem);
 }