From 99710e00ec5505159b768907e0f4490262ea5320 Mon Sep 17 00:00:00 2001 From: Andy Lutomirski Date: Thu, 5 Jul 2012 16:00:11 -0700 Subject: [PATCH] --- yaml --- r: 311707 b: refs/heads/master c: 9ab4233dd08036fe34a89c7dc6f47a8bf2eb29eb h: refs/heads/master i: 311705: 5502ff0ca3683aa25f692053f5b00ef87d2ec1bb 311703: 7e2e907463126a1f7ea7c0009a77e69a40127bab v: v3 --- [refs] | 2 +- trunk/mm/madvise.c | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/[refs] b/[refs] index 5811c46225b8..0c7ab3e636af 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 1b7fa4c27111757789b21bb78543317dad4cfd08 +refs/heads/master: 9ab4233dd08036fe34a89c7dc6f47a8bf2eb29eb diff --git a/trunk/mm/madvise.c b/trunk/mm/madvise.c index deff1b64a08c..14d260fa0d17 100644 --- a/trunk/mm/madvise.c +++ b/trunk/mm/madvise.c @@ -15,6 +15,7 @@ #include #include #include +#include /* * Any behaviour which results in changes to the vma->vm_flags needs to @@ -204,14 +205,16 @@ static long madvise_remove(struct vm_area_struct *vma, { loff_t offset; int error; + struct file *f; *prev = NULL; /* tell sys_madvise we drop mmap_sem */ if (vma->vm_flags & (VM_LOCKED|VM_NONLINEAR|VM_HUGETLB)) return -EINVAL; - if (!vma->vm_file || !vma->vm_file->f_mapping - || !vma->vm_file->f_mapping->host) { + f = vma->vm_file; + + if (!f || !f->f_mapping || !f->f_mapping->host) { return -EINVAL; } @@ -221,11 +224,18 @@ static long madvise_remove(struct vm_area_struct *vma, offset = (loff_t)(start - vma->vm_start) + ((loff_t)vma->vm_pgoff << PAGE_SHIFT); - /* filesystem's fallocate may need to take i_mutex */ + /* + * Filesystem's fallocate may need to take i_mutex. We need to + * explicitly grab a reference because the vma (and hence the + * vma's reference to the file) can go away as soon as we drop + * mmap_sem. + */ + get_file(f); up_read(¤t->mm->mmap_sem); - error = do_fallocate(vma->vm_file, + error = do_fallocate(f, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, offset, end - start); + fput(f); down_read(¤t->mm->mmap_sem); return error; }