Commit 265818ef authored by Peter Xu's avatar Peter Xu Committed by Andrew Morton
Browse files

selftests/mm: drop global hpage_size in uffd tests

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: default avatarPeter Xu <peterx@redhat.com>
Reviewed-by: default avatarMike 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: default avatarAndrew Morton <akpm@linux-foundation.org>
parent c5cb9036
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -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);
}
+1 −1
Original line number Diff line number Diff line
@@ -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;
+3 −3
Original line number Diff line number Diff line
@@ -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;