diff options
author | Jörn Engel <joern@logfs.org> | 2013-07-08 19:00:26 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-07-09 13:33:24 -0400 |
commit | 493af578040e690f93f0fc8d9e7667ffff8155bb (patch) | |
tree | e49d75486f13a427edf6ea89486bb4b2298e9c2f /mm | |
parent | 918fc718c5922520c499ad60f61b8df86b998ae9 (diff) |
mmap: allow MAP_HUGETLB for hugetlbfs files v2
It is counterintuitive at best that mmap'ing a hugetlbfs file with
MAP_HUGETLB fails, while mmap'ing it without will a) succeed and b)
return huge pages.
v2: use is_file_hugepages(), as suggested by Jianguo
Signed-off-by: Joern Engel <joern@logfs.org>
Cc: Jianguo Wu <wujianguo@huawei.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/mmap.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -1358,13 +1358,14 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len, | |||
1358 | 1358 | ||
1359 | if (!(flags & MAP_ANONYMOUS)) { | 1359 | if (!(flags & MAP_ANONYMOUS)) { |
1360 | audit_mmap_fd(fd, flags); | 1360 | audit_mmap_fd(fd, flags); |
1361 | if (unlikely(flags & MAP_HUGETLB)) | ||
1362 | return -EINVAL; | ||
1363 | file = fget(fd); | 1361 | file = fget(fd); |
1364 | if (!file) | 1362 | if (!file) |
1365 | goto out; | 1363 | goto out; |
1366 | if (is_file_hugepages(file)) | 1364 | if (is_file_hugepages(file)) |
1367 | len = ALIGN(len, huge_page_size(hstate_file(file))); | 1365 | len = ALIGN(len, huge_page_size(hstate_file(file))); |
1366 | retval = -EINVAL; | ||
1367 | if (unlikely(flags & MAP_HUGETLB && !is_file_hugepages(file))) | ||
1368 | goto out_fput; | ||
1368 | } else if (flags & MAP_HUGETLB) { | 1369 | } else if (flags & MAP_HUGETLB) { |
1369 | struct user_struct *user = NULL; | 1370 | struct user_struct *user = NULL; |
1370 | struct hstate *hs = hstate_sizelog((flags >> MAP_HUGE_SHIFT) & | 1371 | struct hstate *hs = hstate_sizelog((flags >> MAP_HUGE_SHIFT) & |
@@ -1391,6 +1392,7 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len, | |||
1391 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | 1392 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); |
1392 | 1393 | ||
1393 | retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff); | 1394 | retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff); |
1395 | out_fput: | ||
1394 | if (file) | 1396 | if (file) |
1395 | fput(file); | 1397 | fput(file); |
1396 | out: | 1398 | out: |