aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests
diff options
context:
space:
mode:
authorDavid Rientjes <rientjes@google.com>2015-04-15 19:14:29 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-04-15 19:35:19 -0400
commit215ba78115f82ad5f8faedac98cc42e572733b8a (patch)
treea3fba3474be13c9f9002118f4bb81b6e15e18c3c /tools/testing/selftests
parent80d6b94bd69a7a49b52bf503ef6a841f43cf5bbb (diff)
mm, selftests: test return value of munmap for MAP_HUGETLB memory
When MAP_HUGETLB memory is unmapped, the length must be hugepage aligned, otherwise it fails with -EINVAL. All tests currently behave correctly, but it's better to explcitly test the return value for completeness and document the requirement, especially if users copy map_hugetlb.c as a sample implementation. Signed-off-by: David Rientjes <rientjes@google.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Davide Libenzi <davidel@xmailserver.org> Cc: Luiz Capitulino <lcapitulino@redhat.com> Cc: Shuah Khan <shuahkh@osg.samsung.com> Cc: Hugh Dickins <hughd@google.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Joern Engel <joern@logfs.org> Cc: Jianguo Wu <wujianguo@huawei.com> Cc: Eric B Munson <emunson@akamai.com> Acked-by: Michael Ellerman <mpe@ellerman.id.au> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'tools/testing/selftests')
-rw-r--r--tools/testing/selftests/powerpc/mm/hugetlb_vs_thp_test.c8
-rw-r--r--tools/testing/selftests/vm/hugetlbfstest.c4
-rw-r--r--tools/testing/selftests/vm/map_hugetlb.c6
3 files changed, 14 insertions, 4 deletions
diff --git a/tools/testing/selftests/powerpc/mm/hugetlb_vs_thp_test.c b/tools/testing/selftests/powerpc/mm/hugetlb_vs_thp_test.c
index 3d8e5b033e1d..49003674de4f 100644
--- a/tools/testing/selftests/powerpc/mm/hugetlb_vs_thp_test.c
+++ b/tools/testing/selftests/powerpc/mm/hugetlb_vs_thp_test.c
@@ -21,9 +21,13 @@ static int test_body(void)
21 * Typically the mmap will fail because no huge pages are 21 * Typically the mmap will fail because no huge pages are
22 * allocated on the system. But if there are huge pages 22 * allocated on the system. But if there are huge pages
23 * allocated the mmap will succeed. That's fine too, we just 23 * allocated the mmap will succeed. That's fine too, we just
24 * munmap here before continuing. 24 * munmap here before continuing. munmap() length of
25 * MAP_HUGETLB memory must be hugepage aligned.
25 */ 26 */
26 munmap(addr, SIZE); 27 if (munmap(addr, SIZE)) {
28 perror("munmap");
29 return 1;
30 }
27 } 31 }
28 32
29 p = mmap(addr, SIZE, PROT_READ | PROT_WRITE, 33 p = mmap(addr, SIZE, PROT_READ | PROT_WRITE,
diff --git a/tools/testing/selftests/vm/hugetlbfstest.c b/tools/testing/selftests/vm/hugetlbfstest.c
index ea40ff8c2391..02e1072ec187 100644
--- a/tools/testing/selftests/vm/hugetlbfstest.c
+++ b/tools/testing/selftests/vm/hugetlbfstest.c
@@ -34,6 +34,7 @@ static void do_mmap(int fd, int extra_flags, int unmap)
34 int *p; 34 int *p;
35 int flags = MAP_PRIVATE | MAP_POPULATE | extra_flags; 35 int flags = MAP_PRIVATE | MAP_POPULATE | extra_flags;
36 u64 before, after; 36 u64 before, after;
37 int ret;
37 38
38 before = read_rss(); 39 before = read_rss();
39 p = mmap(NULL, length, PROT_READ | PROT_WRITE, flags, fd, 0); 40 p = mmap(NULL, length, PROT_READ | PROT_WRITE, flags, fd, 0);
@@ -44,7 +45,8 @@ static void do_mmap(int fd, int extra_flags, int unmap)
44 !"rss didn't grow as expected"); 45 !"rss didn't grow as expected");
45 if (!unmap) 46 if (!unmap)
46 return; 47 return;
47 munmap(p, length); 48 ret = munmap(p, length);
49 assert(!ret || !"munmap returned an unexpected error");
48 after = read_rss(); 50 after = read_rss();
49 assert(llabs(after - before) < 0x40000 || 51 assert(llabs(after - before) < 0x40000 ||
50 !"rss didn't shrink as expected"); 52 !"rss didn't shrink as expected");
diff --git a/tools/testing/selftests/vm/map_hugetlb.c b/tools/testing/selftests/vm/map_hugetlb.c
index ac56639dd4a9..addcd6fc1ecc 100644
--- a/tools/testing/selftests/vm/map_hugetlb.c
+++ b/tools/testing/selftests/vm/map_hugetlb.c
@@ -73,7 +73,11 @@ int main(void)
73 write_bytes(addr); 73 write_bytes(addr);
74 ret = read_bytes(addr); 74 ret = read_bytes(addr);
75 75
76 munmap(addr, LENGTH); 76 /* munmap() length of MAP_HUGETLB memory must be hugepage aligned */
77 if (munmap(addr, LENGTH)) {
78 perror("munmap");
79 exit(1);
80 }
77 81
78 return ret; 82 return ret;
79} 83}