aboutsummaryrefslogtreecommitdiffstats
path: root/mm/madvise.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/madvise.c')
-rw-r--r--mm/madvise.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/mm/madvise.c b/mm/madvise.c
index 4e196155a0c3..603c5257ed6e 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -155,10 +155,14 @@ static long madvise_dontneed(struct vm_area_struct * vma,
155 * Other filesystems return -ENOSYS. 155 * Other filesystems return -ENOSYS.
156 */ 156 */
157static long madvise_remove(struct vm_area_struct *vma, 157static long madvise_remove(struct vm_area_struct *vma,
158 struct vm_area_struct **prev,
158 unsigned long start, unsigned long end) 159 unsigned long start, unsigned long end)
159{ 160{
160 struct address_space *mapping; 161 struct address_space *mapping;
161 loff_t offset, endoff; 162 loff_t offset, endoff;
163 int error;
164
165 *prev = NULL; /* tell sys_madvise we drop mmap_sem */
162 166
163 if (vma->vm_flags & (VM_LOCKED|VM_NONLINEAR|VM_HUGETLB)) 167 if (vma->vm_flags & (VM_LOCKED|VM_NONLINEAR|VM_HUGETLB))
164 return -EINVAL; 168 return -EINVAL;
@@ -177,7 +181,12 @@ static long madvise_remove(struct vm_area_struct *vma,
177 + ((loff_t)vma->vm_pgoff << PAGE_SHIFT); 181 + ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
178 endoff = (loff_t)(end - vma->vm_start - 1) 182 endoff = (loff_t)(end - vma->vm_start - 1)
179 + ((loff_t)vma->vm_pgoff << PAGE_SHIFT); 183 + ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
180 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;
181} 190}
182 191
183static long 192static long
@@ -199,7 +208,7 @@ madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev,
199 error = madvise_behavior(vma, prev, start, end, behavior); 208 error = madvise_behavior(vma, prev, start, end, behavior);
200 break; 209 break;
201 case MADV_REMOVE: 210 case MADV_REMOVE:
202 error = madvise_remove(vma, start, end); 211 error = madvise_remove(vma, prev, start, end);
203 break; 212 break;
204 213
205 case MADV_WILLNEED: 214 case MADV_WILLNEED:
@@ -312,12 +321,15 @@ asmlinkage long sys_madvise(unsigned long start, size_t len_in, int behavior)
312 if (error) 321 if (error)
313 goto out; 322 goto out;
314 start = tmp; 323 start = tmp;
315 if (start < prev->vm_end) 324 if (prev && start < prev->vm_end)
316 start = prev->vm_end; 325 start = prev->vm_end;
317 error = unmapped_error; 326 error = unmapped_error;
318 if (start >= end) 327 if (start >= end)
319 goto out; 328 goto out;
320 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);
321 } 333 }
322out: 334out:
323 up_write(&current->mm->mmap_sem); 335 up_write(&current->mm->mmap_sem);