VM: add "vm_munmap()" helper function
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 20 Apr 2012 23:20:01 +0000 (16:20 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 21 Apr 2012 00:29:13 +0000 (17:29 -0700)
Like the vm_brk() function, this is the same as "do_munmap()", except it
does the VM locking for the caller.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
arch/ia64/kernel/perfmon.c
arch/sparc/kernel/sys_sparc_64.c
arch/x86/kvm/x86.c
drivers/gpu/drm/i810/i810_dma.c
fs/aio.c
include/linux/mm.h
mm/mmap.c
mm/nommu.c

index 9d0fd7d5bb82c03d65820a01b1af673c7b0c7c7e..2777310b698b4ceccc49d6da9eda608e8d14e1e9 100644 (file)
@@ -605,9 +605,9 @@ pfm_unprotect_ctx_ctxsw(pfm_context_t *x, unsigned long f)
 }
 
 static inline unsigned int
-pfm_do_munmap(struct mm_struct *mm, unsigned long addr, size_t len, int acct)
+pfm_vm_munmap(struct mm_struct *mm, unsigned long addr, size_t len)
 {
-       return do_munmap(mm, addr, len);
+       return vm_munmap(mm, addr, len);
 }
 
 static inline unsigned long 
@@ -1473,13 +1473,8 @@ pfm_remove_smpl_mapping(struct task_struct *task, void *vaddr, unsigned long siz
        /*
         * does the actual unmapping
         */
-       down_write(&task->mm->mmap_sem);
-
-       DPRINT(("down_write done smpl_vaddr=%p size=%lu\n", vaddr, size));
+       r = pfm_vm_munmap(task->mm, (unsigned long)vaddr, size);
 
-       r = pfm_do_munmap(task->mm, (unsigned long)vaddr, size, 0);
-
-       up_write(&task->mm->mmap_sem);
        if (r !=0) {
                printk(KERN_ERR "perfmon: [%d] unable to unmap sampling buffer @%p size=%lu\n", task_pid_nr(task), vaddr, size);
        }
index 232df9949530f3d95c3c95385a62d45402c6d042..022e57aadf5d5826ef4aed10d8c5c7da2e9031b9 100644 (file)
@@ -566,15 +566,10 @@ out:
 
 SYSCALL_DEFINE2(64_munmap, unsigned long, addr, size_t, len)
 {
-       long ret;
-
        if (invalid_64bit_range(addr, len))
                return -EINVAL;
 
-       down_write(&current->mm->mmap_sem);
-       ret = do_munmap(current->mm, addr, len);
-       up_write(&current->mm->mmap_sem);
-       return ret;
+       return vm_munmap(current->mm, addr, len);
 }
 
 extern unsigned long do_mremap(unsigned long addr,
index 4044ce0bf7c1e7741620b8fcda9a78c9cb1bc775..8beb9ce793640446adafc4373e6be1f6e6f9d759 100644 (file)
@@ -6366,10 +6366,8 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
        if (!user_alloc && !old.user_alloc && old.rmap && !npages) {
                int ret;
 
-               down_write(&current->mm->mmap_sem);
-               ret = do_munmap(current->mm, old.userspace_addr,
+               ret = vm_munmap(current->mm, old.userspace_addr,
                                old.npages * PAGE_SIZE);
-               up_write(&current->mm->mmap_sem);
                if (ret < 0)
                        printk(KERN_WARNING
                               "kvm_vm_ioctl_set_memory_region: "
index 2c8a60c3b98eacdbeac6673e75f763dff8e065da..b85337f06fbf8a2b4534142c1bce506e38e1d57b 100644 (file)
@@ -157,11 +157,9 @@ static int i810_unmap_buffer(struct drm_buf *buf)
        if (buf_priv->currently_mapped != I810_BUF_MAPPED)
                return -EINVAL;
 
-       down_write(&current->mm->mmap_sem);
-       retcode = do_munmap(current->mm,
+       retcode = vm_munmap(current->mm,
                            (unsigned long)buf_priv->virtual,
                            (size_t) buf->total);
-       up_write(&current->mm->mmap_sem);
 
        buf_priv->currently_mapped = I810_BUF_UNMAPPED;
        buf_priv->virtual = NULL;
index da887604dfc51929cd4cc17b10a943645b4618ef..99bd790e8cd253479befd5013d6b38a5781d3927 100644 (file)
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -92,11 +92,8 @@ static void aio_free_ring(struct kioctx *ctx)
        for (i=0; i<info->nr_pages; i++)
                put_page(info->ring_pages[i]);
 
-       if (info->mmap_size) {
-               down_write(&ctx->mm->mmap_sem);
-               do_munmap(ctx->mm, info->mmap_base, info->mmap_size);
-               up_write(&ctx->mm->mmap_sem);
-       }
+       if (info->mmap_size)
+               vm_munmap(ctx->mm, info->mmap_base, info->mmap_size);
 
        if (info->ring_pages && info->ring_pages != info->internal_pages)
                kfree(info->ring_pages);
index bfee4ad6680ba590a6a8d374f975bf09412cd339..cb61950a3aa17e08c7291242abf261ce06e6606e 100644 (file)
@@ -1417,6 +1417,7 @@ extern int do_munmap(struct mm_struct *, unsigned long, size_t);
 
 /* These take the mm semaphore themselves */
 extern unsigned long vm_brk(unsigned long, unsigned long);
+extern int vm_munmap(struct mm_struct *, unsigned long, size_t);
 
 /* truncate.c */
 extern void truncate_inode_pages(struct address_space *, loff_t);
index df51891c8646faf350c264024cad06a7e3532e90..4af45f519f19f98e5b45f5e598b3d876ed0aea1a 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2107,21 +2107,24 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
 
        return 0;
 }
-
 EXPORT_SYMBOL(do_munmap);
 
-SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
+int vm_munmap(struct mm_struct *mm, unsigned long start, size_t len)
 {
        int ret;
-       struct mm_struct *mm = current->mm;
-
-       profile_munmap(addr);
 
        down_write(&mm->mmap_sem);
-       ret = do_munmap(mm, addr, len);
+       ret = do_munmap(mm, start, len);
        up_write(&mm->mmap_sem);
        return ret;
 }
+EXPORT_SYMBOL(vm_munmap);
+
+SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
+{
+       profile_munmap(addr);
+       return vm_munmap(current->mm, addr, len);
+}
 
 static inline void verify_mm_writelocked(struct mm_struct *mm)
 {
index 634193324a6b128c9680f4d45bfa4ed6e48fea20..11a69b22bd4b55f809a2eade75467e68e75cae58 100644 (file)
@@ -1709,16 +1709,21 @@ erase_whole_vma:
 }
 EXPORT_SYMBOL(do_munmap);
 
-SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
+int vm_munmap(struct mm_struct *mm, unsigned long addr, size_t len)
 {
        int ret;
-       struct mm_struct *mm = current->mm;
 
        down_write(&mm->mmap_sem);
        ret = do_munmap(mm, addr, len);
        up_write(&mm->mmap_sem);
        return ret;
 }
+EXPORT_SYMBOL(vm_munmap);
+
+SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
+{
+       return vm_munmap(current->mm, addr, len);
+}
 
 /*
  * release all the mappings made in a process's VM space