diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-04-20 19:20:01 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-04-20 20:29:13 -0400 |
commit | a46ef99d80817a167477ed1c8b4d90ee0c2e726f (patch) | |
tree | 3d8c980c627e8b9c009dbf63628a9be8b8d1069f | |
parent | e4eb1ff61b323d6141614e5458a1f53c7046ff8e (diff) |
VM: add "vm_munmap()" helper function
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>
-rw-r--r-- | arch/ia64/kernel/perfmon.c | 11 | ||||
-rw-r--r-- | arch/sparc/kernel/sys_sparc_64.c | 7 | ||||
-rw-r--r-- | arch/x86/kvm/x86.c | 4 | ||||
-rw-r--r-- | drivers/gpu/drm/i810/i810_dma.c | 4 | ||||
-rw-r--r-- | fs/aio.c | 7 | ||||
-rw-r--r-- | include/linux/mm.h | 1 | ||||
-rw-r--r-- | mm/mmap.c | 15 | ||||
-rw-r--r-- | mm/nommu.c | 9 |
8 files changed, 25 insertions, 33 deletions
diff --git a/arch/ia64/kernel/perfmon.c b/arch/ia64/kernel/perfmon.c index 9d0fd7d5bb82..2777310b698b 100644 --- a/arch/ia64/kernel/perfmon.c +++ b/arch/ia64/kernel/perfmon.c | |||
@@ -605,9 +605,9 @@ pfm_unprotect_ctx_ctxsw(pfm_context_t *x, unsigned long f) | |||
605 | } | 605 | } |
606 | 606 | ||
607 | static inline unsigned int | 607 | static inline unsigned int |
608 | pfm_do_munmap(struct mm_struct *mm, unsigned long addr, size_t len, int acct) | 608 | pfm_vm_munmap(struct mm_struct *mm, unsigned long addr, size_t len) |
609 | { | 609 | { |
610 | return do_munmap(mm, addr, len); | 610 | return vm_munmap(mm, addr, len); |
611 | } | 611 | } |
612 | 612 | ||
613 | static inline unsigned long | 613 | static inline unsigned long |
@@ -1473,13 +1473,8 @@ pfm_remove_smpl_mapping(struct task_struct *task, void *vaddr, unsigned long siz | |||
1473 | /* | 1473 | /* |
1474 | * does the actual unmapping | 1474 | * does the actual unmapping |
1475 | */ | 1475 | */ |
1476 | down_write(&task->mm->mmap_sem); | 1476 | r = pfm_vm_munmap(task->mm, (unsigned long)vaddr, size); |
1477 | |||
1478 | DPRINT(("down_write done smpl_vaddr=%p size=%lu\n", vaddr, size)); | ||
1479 | 1477 | ||
1480 | r = pfm_do_munmap(task->mm, (unsigned long)vaddr, size, 0); | ||
1481 | |||
1482 | up_write(&task->mm->mmap_sem); | ||
1483 | if (r !=0) { | 1478 | if (r !=0) { |
1484 | printk(KERN_ERR "perfmon: [%d] unable to unmap sampling buffer @%p size=%lu\n", task_pid_nr(task), vaddr, size); | 1479 | printk(KERN_ERR "perfmon: [%d] unable to unmap sampling buffer @%p size=%lu\n", task_pid_nr(task), vaddr, size); |
1485 | } | 1480 | } |
diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c index 232df9949530..022e57aadf5d 100644 --- a/arch/sparc/kernel/sys_sparc_64.c +++ b/arch/sparc/kernel/sys_sparc_64.c | |||
@@ -566,15 +566,10 @@ out: | |||
566 | 566 | ||
567 | SYSCALL_DEFINE2(64_munmap, unsigned long, addr, size_t, len) | 567 | SYSCALL_DEFINE2(64_munmap, unsigned long, addr, size_t, len) |
568 | { | 568 | { |
569 | long ret; | ||
570 | |||
571 | if (invalid_64bit_range(addr, len)) | 569 | if (invalid_64bit_range(addr, len)) |
572 | return -EINVAL; | 570 | return -EINVAL; |
573 | 571 | ||
574 | down_write(¤t->mm->mmap_sem); | 572 | return vm_munmap(current->mm, addr, len); |
575 | ret = do_munmap(current->mm, addr, len); | ||
576 | up_write(¤t->mm->mmap_sem); | ||
577 | return ret; | ||
578 | } | 573 | } |
579 | 574 | ||
580 | extern unsigned long do_mremap(unsigned long addr, | 575 | extern unsigned long do_mremap(unsigned long addr, |
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 4044ce0bf7c1..8beb9ce79364 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -6366,10 +6366,8 @@ void kvm_arch_commit_memory_region(struct kvm *kvm, | |||
6366 | if (!user_alloc && !old.user_alloc && old.rmap && !npages) { | 6366 | if (!user_alloc && !old.user_alloc && old.rmap && !npages) { |
6367 | int ret; | 6367 | int ret; |
6368 | 6368 | ||
6369 | down_write(¤t->mm->mmap_sem); | 6369 | ret = vm_munmap(current->mm, old.userspace_addr, |
6370 | ret = do_munmap(current->mm, old.userspace_addr, | ||
6371 | old.npages * PAGE_SIZE); | 6370 | old.npages * PAGE_SIZE); |
6372 | up_write(¤t->mm->mmap_sem); | ||
6373 | if (ret < 0) | 6371 | if (ret < 0) |
6374 | printk(KERN_WARNING | 6372 | printk(KERN_WARNING |
6375 | "kvm_vm_ioctl_set_memory_region: " | 6373 | "kvm_vm_ioctl_set_memory_region: " |
diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c index 2c8a60c3b98e..b85337f06fbf 100644 --- a/drivers/gpu/drm/i810/i810_dma.c +++ b/drivers/gpu/drm/i810/i810_dma.c | |||
@@ -157,11 +157,9 @@ static int i810_unmap_buffer(struct drm_buf *buf) | |||
157 | if (buf_priv->currently_mapped != I810_BUF_MAPPED) | 157 | if (buf_priv->currently_mapped != I810_BUF_MAPPED) |
158 | return -EINVAL; | 158 | return -EINVAL; |
159 | 159 | ||
160 | down_write(¤t->mm->mmap_sem); | 160 | retcode = vm_munmap(current->mm, |
161 | retcode = do_munmap(current->mm, | ||
162 | (unsigned long)buf_priv->virtual, | 161 | (unsigned long)buf_priv->virtual, |
163 | (size_t) buf->total); | 162 | (size_t) buf->total); |
164 | up_write(¤t->mm->mmap_sem); | ||
165 | 163 | ||
166 | buf_priv->currently_mapped = I810_BUF_UNMAPPED; | 164 | buf_priv->currently_mapped = I810_BUF_UNMAPPED; |
167 | buf_priv->virtual = NULL; | 165 | buf_priv->virtual = NULL; |
@@ -92,11 +92,8 @@ static void aio_free_ring(struct kioctx *ctx) | |||
92 | for (i=0; i<info->nr_pages; i++) | 92 | for (i=0; i<info->nr_pages; i++) |
93 | put_page(info->ring_pages[i]); | 93 | put_page(info->ring_pages[i]); |
94 | 94 | ||
95 | if (info->mmap_size) { | 95 | if (info->mmap_size) |
96 | down_write(&ctx->mm->mmap_sem); | 96 | vm_munmap(ctx->mm, info->mmap_base, info->mmap_size); |
97 | do_munmap(ctx->mm, info->mmap_base, info->mmap_size); | ||
98 | up_write(&ctx->mm->mmap_sem); | ||
99 | } | ||
100 | 97 | ||
101 | if (info->ring_pages && info->ring_pages != info->internal_pages) | 98 | if (info->ring_pages && info->ring_pages != info->internal_pages) |
102 | kfree(info->ring_pages); | 99 | kfree(info->ring_pages); |
diff --git a/include/linux/mm.h b/include/linux/mm.h index bfee4ad6680b..cb61950a3aa1 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h | |||
@@ -1417,6 +1417,7 @@ extern int do_munmap(struct mm_struct *, unsigned long, size_t); | |||
1417 | 1417 | ||
1418 | /* These take the mm semaphore themselves */ | 1418 | /* These take the mm semaphore themselves */ |
1419 | extern unsigned long vm_brk(unsigned long, unsigned long); | 1419 | extern unsigned long vm_brk(unsigned long, unsigned long); |
1420 | extern int vm_munmap(struct mm_struct *, unsigned long, size_t); | ||
1420 | 1421 | ||
1421 | /* truncate.c */ | 1422 | /* truncate.c */ |
1422 | extern void truncate_inode_pages(struct address_space *, loff_t); | 1423 | extern void truncate_inode_pages(struct address_space *, loff_t); |
@@ -2107,21 +2107,24 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len) | |||
2107 | 2107 | ||
2108 | return 0; | 2108 | return 0; |
2109 | } | 2109 | } |
2110 | |||
2111 | EXPORT_SYMBOL(do_munmap); | 2110 | EXPORT_SYMBOL(do_munmap); |
2112 | 2111 | ||
2113 | SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len) | 2112 | int vm_munmap(struct mm_struct *mm, unsigned long start, size_t len) |
2114 | { | 2113 | { |
2115 | int ret; | 2114 | int ret; |
2116 | struct mm_struct *mm = current->mm; | ||
2117 | |||
2118 | profile_munmap(addr); | ||
2119 | 2115 | ||
2120 | down_write(&mm->mmap_sem); | 2116 | down_write(&mm->mmap_sem); |
2121 | ret = do_munmap(mm, addr, len); | 2117 | ret = do_munmap(mm, start, len); |
2122 | up_write(&mm->mmap_sem); | 2118 | up_write(&mm->mmap_sem); |
2123 | return ret; | 2119 | return ret; |
2124 | } | 2120 | } |
2121 | EXPORT_SYMBOL(vm_munmap); | ||
2122 | |||
2123 | SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len) | ||
2124 | { | ||
2125 | profile_munmap(addr); | ||
2126 | return vm_munmap(current->mm, addr, len); | ||
2127 | } | ||
2125 | 2128 | ||
2126 | static inline void verify_mm_writelocked(struct mm_struct *mm) | 2129 | static inline void verify_mm_writelocked(struct mm_struct *mm) |
2127 | { | 2130 | { |
diff --git a/mm/nommu.c b/mm/nommu.c index 634193324a6b..11a69b22bd4b 100644 --- a/mm/nommu.c +++ b/mm/nommu.c | |||
@@ -1709,16 +1709,21 @@ erase_whole_vma: | |||
1709 | } | 1709 | } |
1710 | EXPORT_SYMBOL(do_munmap); | 1710 | EXPORT_SYMBOL(do_munmap); |
1711 | 1711 | ||
1712 | SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len) | 1712 | int vm_munmap(struct mm_struct *mm, unsigned long addr, size_t len) |
1713 | { | 1713 | { |
1714 | int ret; | 1714 | int ret; |
1715 | struct mm_struct *mm = current->mm; | ||
1716 | 1715 | ||
1717 | down_write(&mm->mmap_sem); | 1716 | down_write(&mm->mmap_sem); |
1718 | ret = do_munmap(mm, addr, len); | 1717 | ret = do_munmap(mm, addr, len); |
1719 | up_write(&mm->mmap_sem); | 1718 | up_write(&mm->mmap_sem); |
1720 | return ret; | 1719 | return ret; |
1721 | } | 1720 | } |
1721 | EXPORT_SYMBOL(vm_munmap); | ||
1722 | |||
1723 | SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len) | ||
1724 | { | ||
1725 | return vm_munmap(current->mm, addr, len); | ||
1726 | } | ||
1722 | 1727 | ||
1723 | /* | 1728 | /* |
1724 | * release all the mappings made in a process's VM space | 1729 | * release all the mappings made in a process's VM space |