diff options
Diffstat (limited to 'tools/testing/selftests/vm/userfaultfd.c')
-rw-r--r-- | tools/testing/selftests/vm/userfaultfd.c | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c index d753a9161411..a5e5808c86cd 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -101,8 +101,9 @@ pthread_attr_t attr; ~(unsigned long)(sizeof(unsigned long long) \ - 1))) -#ifndef HUGETLB_TEST +#if !defined(HUGETLB_TEST) && !defined(SHMEM_TEST) +/* Anonymous memory */ #define EXPECTED_IOCTLS ((1 << _UFFDIO_WAKE) | \ (1 << _UFFDIO_COPY) | \ (1 << _UFFDIO_ZEROPAGE)) @@ -127,10 +128,13 @@ static void allocate_area(void **alloc_area) } } -#else /* HUGETLB_TEST */ +#else /* HUGETLB_TEST or SHMEM_TEST */ #define EXPECTED_IOCTLS UFFD_API_RANGE_IOCTLS_BASIC +#ifdef HUGETLB_TEST + +/* HugeTLB memory */ static int release_pages(char *rel_area) { int ret = 0; @@ -162,8 +166,37 @@ static void allocate_area(void **alloc_area) huge_fd_off0 = *alloc_area; } +#elif defined(SHMEM_TEST) + +/* Shared memory */ +static int release_pages(char *rel_area) +{ + int ret = 0; + + if (madvise(rel_area, nr_pages * page_size, MADV_REMOVE)) { + perror("madvise"); + ret = 1; + } + + return ret; +} + +static void allocate_area(void **alloc_area) +{ + *alloc_area = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_SHARED, -1, 0); + if (*alloc_area == MAP_FAILED) { + fprintf(stderr, "shared memory mmap failed\n"); + *alloc_area = NULL; + } +} + +#else /* SHMEM_TEST */ +#error "Undefined test type" #endif /* HUGETLB_TEST */ +#endif /* !defined(HUGETLB_TEST) && !defined(SHMEM_TEST) */ + static int my_bcmp(char *str1, char *str2, size_t n) { unsigned long i; |