]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
selftests/vm: use memfd for hugepage-mmap test
authorPeter Xu <peterx@redhat.com>
Thu, 17 Nov 2022 21:29:15 +0000 (16:29 -0500)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 30 Nov 2022 23:59:01 +0000 (15:59 -0800)
This test was overlooked with a hard-coded mntpoint path in test when
we're removing the hugetlb mntpoint in commit 0796c7b8be84.  Fix it up so
the test can keep running.

Link: https://lkml.kernel.org/r/Y3aojfUC2nSwbCzB@x1n
Fixes: 0796c7b8be84 ("selftests/vm: drop mnt point for hugetlb in run_vmtests.sh")
Signed-off-by: Peter Xu <peterx@redhat.com>
Reported-by: Joel Savitz <jsavitz@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/testing/selftests/vm/hugepage-mmap.c

index 93f9e7b813314e6637843f46d5042ebf6ddf2481..955ef87f382cb05c508d8990bf152be853511b8f 100644 (file)
  * range.
  * Other architectures, such as ppc64, i386 or x86_64 are not so constrained.
  */
-
+#define _GNU_SOURCE
 #include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/mman.h>
 #include <fcntl.h>
 
-#define FILE_NAME "huge/hugepagefile"
 #define LENGTH (256UL*1024*1024)
 #define PROTECTION (PROT_READ | PROT_WRITE)
 
@@ -67,16 +66,16 @@ int main(void)
        void *addr;
        int fd, ret;
 
-       fd = open(FILE_NAME, O_CREAT | O_RDWR, 0755);
+       fd = memfd_create("hugepage-mmap", MFD_HUGETLB);
        if (fd < 0) {
-               perror("Open failed");
+               perror("memfd_create() failed");
                exit(1);
        }
 
        addr = mmap(ADDR, LENGTH, PROTECTION, FLAGS, fd, 0);
        if (addr == MAP_FAILED) {
                perror("mmap");
-               unlink(FILE_NAME);
+               close(fd);
                exit(1);
        }
 
@@ -87,7 +86,6 @@ int main(void)
 
        munmap(addr, LENGTH);
        close(fd);
-       unlink(FILE_NAME);
 
        return ret;
 }