mirror of
https://github.com/hardkernel/linux.git
synced 2026-03-26 12:30:23 +09:00
FROMGIT: 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/20210302000133.272579-4-axelrasmussen@google.com Signed-off-by: Axel Rasmussen <axelrasmussen@google.com> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Brian Geffon <bgeffon@google.com> Cc: Cannon Matthews <cannonmatthews@google.com> Cc: David Rientjes <rientjes@google.com> Cc: "Dr . David Alan Gilbert" <dgilbert@redhat.com> Cc: Hugh Dickins <hughd@google.com> Cc: Jerome Glisse <jglisse@redhat.com> Cc: Joe Perches <joe@perches.com> Cc: Lokesh Gidra <lokeshgidra@google.com> Cc: Michel Lespinasse <walken@google.com> Cc: Mike Rapoport <rppt@linux.vnet.ibm.com> Cc: Mina Almasry <almasrymina@google.com> Cc: Oliver Upton <oupton@google.com> Cc: Peter Xu <peterx@redhat.com> Cc: Shaohua Li <shli@fb.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Wang Qing <wangqing@vivo.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au> (cherry picked from commit 8bc5e62208bcb9427ea6eed94ff1b152598da6f8 https: //git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git akpm) Link: https://lore.kernel.org/patchwork/patch/1388149/ Signed-off-by: Lokesh Gidra <lokeshgidra@google.com> Bug: 160737021 Bug: 169683130 Change-Id: I1605dba2d5f0e35bfd57bd9110bb54e950faab19
This commit is contained in:
committed by
Todd Kjos
parent
94f1573615
commit
4a460b5cba
@@ -289,8 +289,9 @@ static int shmem_release_pages(char *rel_area)
|
||||
|
||||
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);
|
||||
@@ -299,12 +300,34 @@ static void shmem_allocate_area(void **alloc_area)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
area_alias = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED, shm_fd, offset);
|
||||
if (area_alias == MAP_FAILED) {
|
||||
perror("mmap of memfd alias failed");
|
||||
goto fail_munmap;
|
||||
}
|
||||
|
||||
if (is_src)
|
||||
area_src_alias = area_alias;
|
||||
else
|
||||
area_dst_alias = area_alias;
|
||||
|
||||
return;
|
||||
|
||||
fail_munmap:
|
||||
if (munmap(*alloc_area, nr_pages * page_size) < 0) {
|
||||
perror("munmap of memfd failed\n");
|
||||
exit(1);
|
||||
}
|
||||
fail:
|
||||
*alloc_area = NULL;
|
||||
}
|
||||
|
||||
static void shmem_alias_mapping(__u64 *start, size_t len, unsigned long offset)
|
||||
{
|
||||
*start = (unsigned long)area_dst_alias + offset;
|
||||
}
|
||||
|
||||
struct uffd_test_ops {
|
||||
unsigned long expected_ioctls;
|
||||
void (*allocate_area)(void **alloc_area);
|
||||
@@ -332,7 +355,7 @@ static struct uffd_test_ops shmem_uffd_test_ops = {
|
||||
.expected_ioctls = SHMEM_EXPECTED_IOCTLS,
|
||||
.allocate_area = shmem_allocate_area,
|
||||
.release_pages = shmem_release_pages,
|
||||
.alias_mapping = noop_alias_mapping,
|
||||
.alias_mapping = shmem_alias_mapping,
|
||||
};
|
||||
|
||||
static struct uffd_test_ops hugetlb_uffd_test_ops = {
|
||||
|
||||
Reference in New Issue
Block a user