diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2012-05-30 20:17:35 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2012-06-01 10:37:18 -0400 |
commit | eb36c5873b96e8c7376768d3906da74aae6e3839 (patch) | |
tree | 01c5290ed4c55fea85e0dc3f8d70eeaab44678cf /mm | |
parent | dc982501d9643ab0c117e7d87562857ce234652d (diff) |
new helper: vm_mmap_pgoff()
take it to mm/util.c, convert vm_mmap() to use of that one and
take it to mm/util.c as well, convert both sys_mmap_pgoff() to
use of vm_mmap_pgoff()
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/internal.h | 4 | ||||
-rw-r--r-- | mm/mmap.c | 30 | ||||
-rw-r--r-- | mm/nommu.c | 29 | ||||
-rw-r--r-- | mm/util.c | 30 |
4 files changed, 36 insertions, 57 deletions
diff --git a/mm/internal.h b/mm/internal.h index aee4761cf9a9..5307a0227317 100644 --- a/mm/internal.h +++ b/mm/internal.h | |||
@@ -342,3 +342,7 @@ extern u64 hwpoison_filter_flags_mask; | |||
342 | extern u64 hwpoison_filter_flags_value; | 342 | extern u64 hwpoison_filter_flags_value; |
343 | extern u64 hwpoison_filter_memcg; | 343 | extern u64 hwpoison_filter_memcg; |
344 | extern u32 hwpoison_filter_enable; | 344 | extern u32 hwpoison_filter_enable; |
345 | |||
346 | extern unsigned long vm_mmap_pgoff(struct file *, unsigned long, | ||
347 | unsigned long, unsigned long, | ||
348 | unsigned long, unsigned long); | ||
@@ -1102,28 +1102,6 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr, | |||
1102 | return mmap_region(file, addr, len, flags, vm_flags, pgoff); | 1102 | return mmap_region(file, addr, len, flags, vm_flags, pgoff); |
1103 | } | 1103 | } |
1104 | 1104 | ||
1105 | unsigned long vm_mmap(struct file *file, unsigned long addr, | ||
1106 | unsigned long len, unsigned long prot, | ||
1107 | unsigned long flag, unsigned long offset) | ||
1108 | { | ||
1109 | unsigned long ret; | ||
1110 | struct mm_struct *mm = current->mm; | ||
1111 | |||
1112 | if (unlikely(offset + PAGE_ALIGN(len) < offset)) | ||
1113 | return -EINVAL; | ||
1114 | if (unlikely(offset & ~PAGE_MASK)) | ||
1115 | return -EINVAL; | ||
1116 | |||
1117 | ret = security_mmap_file(file, prot, flag); | ||
1118 | if (!ret) { | ||
1119 | down_write(&mm->mmap_sem); | ||
1120 | ret = do_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT); | ||
1121 | up_write(&mm->mmap_sem); | ||
1122 | } | ||
1123 | return ret; | ||
1124 | } | ||
1125 | EXPORT_SYMBOL(vm_mmap); | ||
1126 | |||
1127 | SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len, | 1105 | SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len, |
1128 | unsigned long, prot, unsigned long, flags, | 1106 | unsigned long, prot, unsigned long, flags, |
1129 | unsigned long, fd, unsigned long, pgoff) | 1107 | unsigned long, fd, unsigned long, pgoff) |
@@ -1155,13 +1133,7 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len, | |||
1155 | 1133 | ||
1156 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | 1134 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); |
1157 | 1135 | ||
1158 | retval = security_mmap_file(file, prot, flags); | 1136 | retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff); |
1159 | if (!retval) { | ||
1160 | down_write(¤t->mm->mmap_sem); | ||
1161 | retval = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
1162 | up_write(¤t->mm->mmap_sem); | ||
1163 | } | ||
1164 | |||
1165 | if (file) | 1137 | if (file) |
1166 | fput(file); | 1138 | fput(file); |
1167 | out: | 1139 | out: |
diff --git a/mm/nommu.c b/mm/nommu.c index e6123a5b2cc1..c4acfbc09972 100644 --- a/mm/nommu.c +++ b/mm/nommu.c | |||
@@ -1470,28 +1470,6 @@ error_getting_region: | |||
1470 | return -ENOMEM; | 1470 | return -ENOMEM; |
1471 | } | 1471 | } |
1472 | 1472 | ||
1473 | unsigned long vm_mmap(struct file *file, unsigned long addr, | ||
1474 | unsigned long len, unsigned long prot, | ||
1475 | unsigned long flag, unsigned long offset) | ||
1476 | { | ||
1477 | unsigned long ret; | ||
1478 | struct mm_struct *mm = current->mm; | ||
1479 | |||
1480 | if (unlikely(offset + PAGE_ALIGN(len) < offset)) | ||
1481 | return -EINVAL; | ||
1482 | if (unlikely(offset & ~PAGE_MASK)) | ||
1483 | return -EINVAL; | ||
1484 | |||
1485 | ret = security_mmap_file(file, prot, flag); | ||
1486 | if (!ret) { | ||
1487 | down_write(&mm->mmap_sem); | ||
1488 | ret = do_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT); | ||
1489 | up_write(&mm->mmap_sem); | ||
1490 | } | ||
1491 | return ret; | ||
1492 | } | ||
1493 | EXPORT_SYMBOL(vm_mmap); | ||
1494 | |||
1495 | SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len, | 1473 | SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len, |
1496 | unsigned long, prot, unsigned long, flags, | 1474 | unsigned long, prot, unsigned long, flags, |
1497 | unsigned long, fd, unsigned long, pgoff) | 1475 | unsigned long, fd, unsigned long, pgoff) |
@@ -1508,12 +1486,7 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len, | |||
1508 | 1486 | ||
1509 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | 1487 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); |
1510 | 1488 | ||
1511 | ret = security_mmap_file(file, prot, flags); | 1489 | ret = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff); |
1512 | if (!ret) { | ||
1513 | down_write(¤t->mm->mmap_sem); | ||
1514 | retval = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
1515 | up_write(¤t->mm->mmap_sem); | ||
1516 | } | ||
1517 | 1490 | ||
1518 | if (file) | 1491 | if (file) |
1519 | fput(file); | 1492 | fput(file); |
@@ -4,6 +4,7 @@ | |||
4 | #include <linux/export.h> | 4 | #include <linux/export.h> |
5 | #include <linux/err.h> | 5 | #include <linux/err.h> |
6 | #include <linux/sched.h> | 6 | #include <linux/sched.h> |
7 | #include <linux/security.h> | ||
7 | #include <asm/uaccess.h> | 8 | #include <asm/uaccess.h> |
8 | 9 | ||
9 | #include "internal.h" | 10 | #include "internal.h" |
@@ -341,6 +342,35 @@ int __attribute__((weak)) get_user_pages_fast(unsigned long start, | |||
341 | } | 342 | } |
342 | EXPORT_SYMBOL_GPL(get_user_pages_fast); | 343 | EXPORT_SYMBOL_GPL(get_user_pages_fast); |
343 | 344 | ||
345 | unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr, | ||
346 | unsigned long len, unsigned long prot, | ||
347 | unsigned long flag, unsigned long pgoff) | ||
348 | { | ||
349 | unsigned long ret; | ||
350 | struct mm_struct *mm = current->mm; | ||
351 | |||
352 | ret = security_mmap_file(file, prot, flag); | ||
353 | if (!ret) { | ||
354 | down_write(&mm->mmap_sem); | ||
355 | ret = do_mmap_pgoff(file, addr, len, prot, flag, pgoff); | ||
356 | up_write(&mm->mmap_sem); | ||
357 | } | ||
358 | return ret; | ||
359 | } | ||
360 | |||
361 | unsigned long vm_mmap(struct file *file, unsigned long addr, | ||
362 | unsigned long len, unsigned long prot, | ||
363 | unsigned long flag, unsigned long offset) | ||
364 | { | ||
365 | if (unlikely(offset + PAGE_ALIGN(len) < offset)) | ||
366 | return -EINVAL; | ||
367 | if (unlikely(offset & ~PAGE_MASK)) | ||
368 | return -EINVAL; | ||
369 | |||
370 | return vm_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT); | ||
371 | } | ||
372 | EXPORT_SYMBOL(vm_mmap); | ||
373 | |||
344 | /* Tracepoints definitions. */ | 374 | /* Tracepoints definitions. */ |
345 | EXPORT_TRACEPOINT_SYMBOL(kmalloc); | 375 | EXPORT_TRACEPOINT_SYMBOL(kmalloc); |
346 | EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc); | 376 | EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc); |