aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2012-05-30 20:17:35 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2012-06-01 10:37:18 -0400
commiteb36c5873b96e8c7376768d3906da74aae6e3839 (patch)
tree01c5290ed4c55fea85e0dc3f8d70eeaab44678cf
parentdc982501d9643ab0c117e7d87562857ce234652d (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>
-rw-r--r--mm/internal.h4
-rw-r--r--mm/mmap.c30
-rw-r--r--mm/nommu.c29
-rw-r--r--mm/util.c30
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;
342extern u64 hwpoison_filter_flags_value; 342extern u64 hwpoison_filter_flags_value;
343extern u64 hwpoison_filter_memcg; 343extern u64 hwpoison_filter_memcg;
344extern u32 hwpoison_filter_enable; 344extern u32 hwpoison_filter_enable;
345
346extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
347 unsigned long, unsigned long,
348 unsigned long, unsigned long);
diff --git a/mm/mmap.c b/mm/mmap.c
index 538c905d6d9b..98ef8a6c2cd8 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -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
1105unsigned 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}
1125EXPORT_SYMBOL(vm_mmap);
1126
1127SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len, 1105SYSCALL_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(&current->mm->mmap_sem);
1161 retval = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
1162 up_write(&current->mm->mmap_sem);
1163 }
1164
1165 if (file) 1137 if (file)
1166 fput(file); 1138 fput(file);
1167out: 1139out:
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
1473unsigned 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}
1493EXPORT_SYMBOL(vm_mmap);
1494
1495SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len, 1473SYSCALL_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(&current->mm->mmap_sem);
1514 retval = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
1515 up_write(&current->mm->mmap_sem);
1516 }
1517 1490
1518 if (file) 1491 if (file)
1519 fput(file); 1492 fput(file);
diff --git a/mm/util.c b/mm/util.c
index ae962b31de88..8c7265afa29f 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -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}
342EXPORT_SYMBOL_GPL(get_user_pages_fast); 343EXPORT_SYMBOL_GPL(get_user_pages_fast);
343 344
345unsigned 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
361unsigned 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}
372EXPORT_SYMBOL(vm_mmap);
373
344/* Tracepoints definitions. */ 374/* Tracepoints definitions. */
345EXPORT_TRACEPOINT_SYMBOL(kmalloc); 375EXPORT_TRACEPOINT_SYMBOL(kmalloc);
346EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc); 376EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc);