lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 11 Apr 2023 13:41:30 +0300
From:   Mike Rapoport <rppt@...ux.ibm.com>
To:     Peter Xu <peterx@...hat.com>
Cc:     linux-kernel@...r.kernel.org, linux-mm@...ck.org,
        Mike Kravetz <mike.kravetz@...cle.com>,
        Mike Rapoport <rppt@...ux.vnet.ibm.com>,
        Andrea Arcangeli <aarcange@...hat.com>,
        Leonardo Bras Soares Passos <lsoaresp@...hat.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        David Hildenbrand <david@...hat.com>,
        Axel Rasmussen <axelrasmussen@...gle.com>,
        Nadav Amit <nadav.amit@...il.com>
Subject: Re: [PATCH 18/29] selftests/mm: Drop global hpage_size in uffd tests

On Thu, Mar 30, 2023 at 12:08:09PM -0400, Peter Xu wrote:
> 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.
> 
> Signed-off-by: Peter Xu <peterx@...hat.com>

Reviewed-by: Mike Rapoport (IBM) <rppt@...nel.org>

> ---
>  tools/testing/selftests/mm/uffd-common.c | 7 ++++---
>  tools/testing/selftests/mm/uffd-common.h | 2 +-
>  tools/testing/selftests/mm/uffd-stress.c | 6 +++---
>  3 files changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c
> index a2b6e4957d0f..025e40ffc7bf 100644
> --- a/tools/testing/selftests/mm/uffd-common.c
> +++ b/tools/testing/selftests/mm/uffd-common.c
> @@ -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);
>  }
> diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h
> index 0dfab7057295..47565b2f2dee 100644
> --- a/tools/testing/selftests/mm/uffd-common.h
> +++ b/tools/testing/selftests/mm/uffd-common.h
> @@ -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;
> diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c
> index 4eca1a0276c2..54fc9b4ffa3c 100644
> --- a/tools/testing/selftests/mm/uffd-stress.c
> +++ b/tools/testing/selftests/mm/uffd-stress.c
> @@ -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;
> 
> -- 
> 2.39.1
> 

-- 
Sincerely yours,
Mike.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ