Re: [PATCH v2 6/9] userfaultfd/selftests: create alias mappings in the shmem test
From: Peter Xu
Date: Tue Apr 13 2021 - 16:17:59 EST
On Mon, Apr 12, 2021 at 10:17:18PM -0700, Axel Rasmussen wrote:
> static void shmem_allocate_area(void **alloc_area)
> {
> - unsigned long offset =
> - alloc_area == (void **)&area_src ? 0 : nr_pages * page_size;
> + void *area_alias = NULL;
> + bool is_src = alloc_area == (void **)&area_src;
> + unsigned long offset = is_src ? 0 : nr_pages * page_size;
>
> *alloc_area = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE,
> MAP_SHARED, shm_fd, offset);
> if (*alloc_area == MAP_FAILED)
> err("mmap of memfd failed");
> +
> + area_alias = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE,
> + MAP_SHARED, shm_fd, offset);
> + if (area_alias == MAP_FAILED)
> + err("mmap of memfd alias failed");
> +
> + if (is_src)
> + area_src_alias = area_alias;
> + else
> + area_dst_alias = area_alias;
> +}
It would be nice if shmem_allocate_area() could merge with
hugetlb_allocate_area() somehow, but not that urgent.
Reviewed-by: Peter Xu <peterx@xxxxxxxxxx>
--
Peter Xu