~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/mm/uffd-common.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  * Userfaultfd tests common header
  4  *
  5  * Copyright (C) 2015-2023  Red Hat, Inc.
  6  */
  7 #ifndef __UFFD_COMMON_H__
  8 #define __UFFD_COMMON_H__
  9 
 10 #define _GNU_SOURCE
 11 #define __SANE_USERSPACE_TYPES__ // Use ll64
 12 #include <stdio.h>
 13 #include <errno.h>
 14 #include <unistd.h>
 15 #include <stdlib.h>
 16 #include <sys/types.h>
 17 #include <sys/stat.h>
 18 #include <fcntl.h>
 19 #include <time.h>
 20 #include <signal.h>
 21 #include <poll.h>
 22 #include <string.h>
 23 #include <linux/mman.h>
 24 #include <sys/mman.h>
 25 #include <sys/syscall.h>
 26 #include <sys/ioctl.h>
 27 #include <sys/wait.h>
 28 #include <pthread.h>
 29 #include <linux/userfaultfd.h>
 30 #include <setjmp.h>
 31 #include <stdbool.h>
 32 #include <assert.h>
 33 #include <inttypes.h>
 34 #include <stdint.h>
 35 #include <sys/random.h>
 36 
 37 #include "../kselftest.h"
 38 #include "vm_util.h"
 39 
 40 #define UFFD_FLAGS      (O_CLOEXEC | O_NONBLOCK | UFFD_USER_MODE_ONLY)
 41 
 42 #define _err(fmt, ...)                                          \
 43         do {                                                    \
 44                 int ret = errno;                                \
 45                 fprintf(stderr, "ERROR: " fmt, ##__VA_ARGS__);  \
 46                 fprintf(stderr, " (errno=%d, @%s:%d)\n",        \
 47                         ret, __FILE__, __LINE__);               \
 48         } while (0)
 49 
 50 #define errexit(exitcode, fmt, ...)             \
 51         do {                                    \
 52                 _err(fmt, ##__VA_ARGS__);       \
 53                 exit(exitcode);                 \
 54         } while (0)
 55 
 56 #define err(fmt, ...) errexit(1, fmt, ##__VA_ARGS__)
 57 
 58 /* pthread_mutex_t starts at page offset 0 */
 59 #define area_mutex(___area, ___nr)                                      \
 60         ((pthread_mutex_t *) ((___area) + (___nr)*page_size))
 61 /*
 62  * count is placed in the page after pthread_mutex_t naturally aligned
 63  * to avoid non alignment faults on non-x86 archs.
 64  */
 65 #define area_count(___area, ___nr)                                      \
 66         ((volatile unsigned long long *) ((unsigned long)               \
 67                                  ((___area) + (___nr)*page_size +       \
 68                                   sizeof(pthread_mutex_t) +             \
 69                                   sizeof(unsigned long long) - 1) &     \
 70                                  ~(unsigned long)(sizeof(unsigned long long) \
 71                                                   -  1)))
 72 
 73 /* Userfaultfd test statistics */
 74 struct uffd_args {
 75         int cpu;
 76         /* Whether apply wr-protects when installing pages */
 77         bool apply_wp;
 78         unsigned long missing_faults;
 79         unsigned long wp_faults;
 80         unsigned long minor_faults;
 81 
 82         /* A custom fault handler; defaults to uffd_handle_page_fault. */
 83         void (*handle_fault)(struct uffd_msg *msg, struct uffd_args *args);
 84 };
 85 
 86 struct uffd_test_ops {
 87         int (*allocate_area)(void **alloc_area, bool is_src);
 88         void (*release_pages)(char *rel_area);
 89         void (*alias_mapping)(__u64 *start, size_t len, unsigned long offset);
 90         void (*check_pmd_mapping)(void *p, int expect_nr_hpages);
 91 };
 92 typedef struct uffd_test_ops uffd_test_ops_t;
 93 
 94 struct uffd_test_case_ops {
 95         int (*pre_alloc)(const char **errmsg);
 96         int (*post_alloc)(const char **errmsg);
 97 };
 98 typedef struct uffd_test_case_ops uffd_test_case_ops_t;
 99 
100 extern unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size;
101 extern char *area_src, *area_src_alias, *area_dst, *area_dst_alias, *area_remap;
102 extern int uffd, uffd_flags, finished, *pipefd, test_type;
103 extern bool map_shared;
104 extern bool test_uffdio_wp;
105 extern unsigned long long *count_verify;
106 extern volatile bool test_uffdio_copy_eexist;
107 extern pthread_barrier_t ready_for_fork;
108 
109 extern uffd_test_ops_t anon_uffd_test_ops;
110 extern uffd_test_ops_t shmem_uffd_test_ops;
111 extern uffd_test_ops_t hugetlb_uffd_test_ops;
112 extern uffd_test_ops_t *uffd_test_ops;
113 extern uffd_test_case_ops_t *uffd_test_case_ops;
114 
115 void uffd_stats_report(struct uffd_args *args, int n_cpus);
116 int uffd_test_ctx_init(uint64_t features, const char **errmsg);
117 void uffd_test_ctx_clear(void);
118 int userfaultfd_open(uint64_t *features);
119 int uffd_read_msg(int ufd, struct uffd_msg *msg);
120 void wp_range(int ufd, __u64 start, __u64 len, bool wp);
121 void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_args *args);
122 int __copy_page(int ufd, unsigned long offset, bool retry, bool wp);
123 int copy_page(int ufd, unsigned long offset, bool wp);
124 int move_page(int ufd, unsigned long offset, unsigned long len);
125 void *uffd_poll_thread(void *arg);
126 
127 int uffd_open_dev(unsigned int flags);
128 int uffd_open_sys(unsigned int flags);
129 int uffd_open(unsigned int flags);
130 int uffd_get_features(uint64_t *features);
131 
132 #define TEST_ANON       1
133 #define TEST_HUGETLB    2
134 #define TEST_SHMEM      3
135 
136 #endif
137 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php