aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mm/madvise.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/mm/madvise.c b/mm/madvise.c
index 77916e9fc52b..603c5257ed6e 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -159,9 +159,10 @@ static long madvise_remove(struct vm_area_struct *vma,
159 unsigned long start, unsigned long end) 159 unsigned long start, unsigned long end)
160{ 160{
161 struct address_space *mapping; 161 struct address_space *mapping;
162 loff_t offset, endoff; 162 loff_t offset, endoff;
163 int error;
163 164
164 *prev = vma; 165 *prev = NULL; /* tell sys_madvise we drop mmap_sem */
165 166
166 if (vma->vm_flags & (VM_LOCKED|VM_NONLINEAR|VM_HUGETLB)) 167 if (vma->vm_flags & (VM_LOCKED|VM_NONLINEAR|VM_HUGETLB))
167 return -EINVAL; 168 return -EINVAL;
@@ -180,7 +181,12 @@ static long madvise_remove(struct vm_area_struct *vma,
180 + ((loff_t)vma->vm_pgoff << PAGE_SHIFT); 181 + ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
181 endoff = (loff_t)(end - vma->vm_start - 1) 182 endoff = (loff_t)(end - vma->vm_start - 1)
182 + ((loff_t)vma->vm_pgoff << PAGE_SHIFT); 183 + ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
183 return vmtruncate_range(mapping->host, offset, endoff); 184
185 /* vmtruncate_range needs to take i_mutex and i_alloc_sem */
186 up_write(&current->mm->mmap_sem);
187 error = vmtruncate_range(mapping->host, offset, endoff);
188 down_write(&current->mm->mmap_sem);
189 return error;
184} 190}
185 191
186static long 192static long
@@ -315,12 +321,15 @@ asmlinkage long sys_madvise(unsigned long start, size_t len_in, int behavior)
315 if (error) 321 if (error)
316 goto out; 322 goto out;
317 start = tmp; 323 start = tmp;
318 if (start < prev->vm_end) 324 if (prev && start < prev->vm_end)
319 start = prev->vm_end; 325 start = prev->vm_end;
320 error = unmapped_error; 326 error = unmapped_error;
321 if (start >= end) 327 if (start >= end)
322 goto out; 328 goto out;
323 vma = prev->vm_next; 329 if (prev)
330 vma = prev->vm_next;
331 else /* madvise_remove dropped mmap_sem */
332 vma = find_vma(current->mm, start);
324 } 333 }
325out: 334out:
326 up_write(&current->mm->mmap_sem); 335 up_write(&current->mm->mmap_sem);