Skip to content

Commit 5bb23ed

Browse files
CmdrMoozytorvalds
authored andcommitted
userfaultfd/selftests: create alias mappings in the shmem test
Previously, we just allocated two shm areas: area_src and area_dst. With this commit, change this so we also allocate area_src_alias, and area_dst_alias. area_*_alias and area_* (respectively) point to the same underlying physical pages, but are different VMAs. In a future commit in this series, we'll leverage this setup to exercise minor fault handling support for shmem, just like we do in the hugetlb_shared test. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Axel Rasmussen <[email protected]> Reviewed-by: Peter Xu <[email protected]> Cc: Alexander Viro <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Brian Geffon <[email protected]> Cc: "Dr . David Alan Gilbert" <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Jerome Glisse <[email protected]> Cc: Joe Perches <[email protected]> Cc: Kirill A. Shutemov <[email protected]> Cc: Lokesh Gidra <[email protected]> Cc: Mike Kravetz <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Mina Almasry <[email protected]> Cc: Oliver Upton <[email protected]> Cc: Shaohua Li <[email protected]> Cc: Shuah Khan <[email protected]> Cc: Stephen Rothwell <[email protected]> Cc: Wang Qing <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent fa2c2b5 commit 5bb23ed

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

tools/testing/selftests/vm/userfaultfd.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,29 @@ static void shmem_release_pages(char *rel_area)
278278

279279
static void shmem_allocate_area(void **alloc_area)
280280
{
281-
unsigned long offset =
282-
alloc_area == (void **)&area_src ? 0 : nr_pages * page_size;
281+
void *area_alias = NULL;
282+
bool is_src = alloc_area == (void **)&area_src;
283+
unsigned long offset = is_src ? 0 : nr_pages * page_size;
283284

284285
*alloc_area = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE,
285286
MAP_SHARED, shm_fd, offset);
286287
if (*alloc_area == MAP_FAILED)
287288
err("mmap of memfd failed");
289+
290+
area_alias = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE,
291+
MAP_SHARED, shm_fd, offset);
292+
if (area_alias == MAP_FAILED)
293+
err("mmap of memfd alias failed");
294+
295+
if (is_src)
296+
area_src_alias = area_alias;
297+
else
298+
area_dst_alias = area_alias;
299+
}
300+
301+
static void shmem_alias_mapping(__u64 *start, size_t len, unsigned long offset)
302+
{
303+
*start = (unsigned long)area_dst_alias + offset;
288304
}
289305

290306
struct uffd_test_ops {
@@ -314,7 +330,7 @@ static struct uffd_test_ops shmem_uffd_test_ops = {
314330
.expected_ioctls = SHMEM_EXPECTED_IOCTLS,
315331
.allocate_area = shmem_allocate_area,
316332
.release_pages = shmem_release_pages,
317-
.alias_mapping = noop_alias_mapping,
333+
.alias_mapping = shmem_alias_mapping,
318334
};
319335

320336
static struct uffd_test_ops hugetlb_uffd_test_ops = {

0 commit comments

Comments
 (0)