selftests/mm: drop global hpage_size in uffd tests
authorPeter Xu <peterx@redhat.com>
Wed, 12 Apr 2023 16:43:33 +0000 (12:43 -0400)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 18 Apr 2023 23:30:06 +0000 (16:30 -0700)
hpage_size was wrongly used.  Sometimes it means hugetlb default size,
sometimes it was used as thp size.

Remove the global variable and use the right one at each place.

Link: https://lkml.kernel.org/r/20230412164333.328596-1-peterx@redhat.com
Signed-off-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Dmitry Safonov <0x7f454c46@gmail.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Zach O'Keefe <zokeefe@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/testing/selftests/mm/uffd-common.c
tools/testing/selftests/mm/uffd-common.h
tools/testing/selftests/mm/uffd-stress.c

index b1617f5d451794c14145b2ab8352f9910ec64c74..f02dfcf107149b69536a1840ea1f7469c23a30ef 100644 (file)
@@ -10,7 +10,7 @@
 #define BASE_PMD_ADDR ((void *)(1UL << 30))
 
 volatile bool test_uffdio_copy_eexist = true;
-unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size, hpage_size;
+unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size;
 char *area_src, *area_src_alias, *area_dst, *area_dst_alias, *area_remap;
 int uffd = -1, uffd_flags, finished, *pipefd, test_type;
 bool map_shared, test_collapse, test_dev_userfaultfd;
@@ -115,7 +115,7 @@ static void shmem_release_pages(char *rel_area)
 static void shmem_allocate_area(void **alloc_area, bool is_src)
 {
        void *area_alias = NULL;
-       size_t bytes = nr_pages * page_size;
+       size_t bytes = nr_pages * page_size, hpage_size = read_pmd_pagesize();
        unsigned long offset = is_src ? 0 : bytes;
        char *p = NULL, *p_alias = NULL;
        int mem_fd = uffd_mem_fd_create(bytes * 2, false);
@@ -159,7 +159,8 @@ static void shmem_alias_mapping(__u64 *start, size_t len, unsigned long offset)
 
 static void shmem_check_pmd_mapping(void *p, int expect_nr_hpages)
 {
-       if (!check_huge_shmem(area_dst_alias, expect_nr_hpages, hpage_size))
+       if (!check_huge_shmem(area_dst_alias, expect_nr_hpages,
+                             read_pmd_pagesize()))
                err("Did not find expected %d number of hugepages",
                    expect_nr_hpages);
 }
index 0dfab7057295608cbe298ec6d3f7e48ad0a896b1..47565b2f2dee11b21e01b70ef543544a2c1707f1 100644 (file)
@@ -85,7 +85,7 @@ struct uffd_test_ops {
 };
 typedef struct uffd_test_ops uffd_test_ops_t;
 
-extern unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size, hpage_size;
+extern unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size;
 extern char *area_src, *area_src_alias, *area_dst, *area_dst_alias, *area_remap;
 extern int uffd, uffd_flags, finished, *pipefd, test_type;
 extern bool map_shared, test_collapse, test_dev_userfaultfd;
index 4eca1a0276c2ec7d3b549c83e79bbc5772703f61..54fc9b4ffa3c26652ab67eba53e8eed4fa15ea64 100644 (file)
@@ -655,7 +655,7 @@ static int userfaultfd_minor_test(void)
 
                uffd_test_ops->check_pmd_mapping(area_dst,
                                                 nr_pages * page_size /
-                                                hpage_size);
+                                                read_pmd_pagesize());
                /*
                 * This won't cause uffd-fault - it purely just makes sure there
                 * was no corruption.
@@ -997,7 +997,7 @@ static void parse_test_type_arg(const char *raw_type)
                err("Unsupported test: %s", raw_type);
 
        if (test_type == TEST_HUGETLB)
-               page_size = hpage_size;
+               page_size = default_huge_page_size();
        else
                page_size = sysconf(_SC_PAGE_SIZE);
 
@@ -1035,6 +1035,7 @@ static void sigalrm(int sig)
 int main(int argc, char **argv)
 {
        size_t bytes;
+       size_t hpage_size = read_pmd_pagesize();
 
        if (argc < 4)
                usage();
@@ -1043,7 +1044,6 @@ int main(int argc, char **argv)
                err("failed to arm SIGALRM");
        alarm(ALARM_INTERVAL_SECS);
 
-       hpage_size = default_huge_page_size();
        parse_test_type_arg(argv[1]);
        bytes = atol(argv[2]) * 1024 * 1024;