Projectname
large_stringclasses
15 values
Filepath
large_stringlengths
4
106
⌀
Function
large_stringlengths
11
3.45k
Label
list
Linux Kernel
tools/testing/selftests/vm/compaction_test.c
int main(int argc, char **argv) { struct rlimit lim; struct map_list *list, *entry; size_t page_size, i; void *map = NULL; unsigned long mem_free = 0; unsigned long hugepage_size = 0; long mem_fragmentable_MB = 0; if (prereq() != 0) { printf("Either the sysctl compact_unevictable_allowed is not\n" ...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/cow.c
static void detect_thpsize(void) { int fd = open("/sys/kernel/mm/transparent_hugepage/hpage_pmd_size", O_RDONLY); size_t size = 0; char buf[15]; int ret; if (fd < 0) return; ret = pread(fd, buf, sizeof(buf), 0); if (ret > 0 && ret < sizeof(buf)) { buf[ret] = 0; size = strtoul(buf, NULL, 10...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/cow.c
static void detect_huge_zeropage(void) { int fd = open("/sys/kernel/mm/transparent_hugepage/use_zero_page", O_RDONLY); size_t enabled = 0; char buf[15]; int ret; if (fd < 0) return; ret = pread(fd, buf, sizeof(buf), 0); if (ret > 0 && ret < sizeof(buf)) { buf[ret] = 0; enabled = strtoul(bu...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/cow.c
static int setup_comm_pipes(struct comm_pipes *comm_pipes) { if (pipe(comm_pipes->child_ready) < 0) return -errno; if (pipe(comm_pipes->parent_ready) < 0) { close(comm_pipes->child_ready[0]); close(comm_pipes->child_ready[1]); return -errno; } return 0; }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/cow.c
static void close_comm_pipes(struct comm_pipes *comm_pipes) { close(comm_pipes->child_ready[0]); close(comm_pipes->child_ready[1]); close(comm_pipes->parent_ready[0]); close(comm_pipes->parent_ready[1]); }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/cow.c
static int child_vmsplice_memcmp_fn(char *mem, size_t size, struct comm_pipes *comm_pipes) { struct iovec iov = { .iov_base = mem, .iov_len = size, }; ssize_t cur, total, transferred; char *old, *new; int fds[2]; char buf; old = malloc(size); new = malloc...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/cow.c
static void test_cow_in_parent(char *mem, size_t size) { do_test_cow_in_parent(mem, size, false, child_memcmp_fn); }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/cow.c
static void test_vmsplice_after_fork(char *mem, size_t size) { do_test_vmsplice_in_parent(mem, size, false); } #ifdef LOCAL_CONFIG_HAVE_LIBURING
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/cow.c
static void test_ro_fast_pin_on_ro_exclusive(char *mem, size_t size) { do_test_ro_pin(mem, size, RO_PIN_TEST_RO_EXCLUSIVE, true); }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/cow.c
static void run_with_base_page(test_fn fn, const char *desc) { ksft_print_msg("[RUN] %s ... with base page\n", desc); do_run_with_base_page(fn, false); }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/cow.c
static void run_with_pte_mapped_thp_swap(test_fn fn, const char *desc) { ksft_print_msg("[RUN] %s ... with swapped-out, PTE-mapped THP\n", desc); do_run_with_thp(fn, THP_RUN_PTE_SWAPOUT); }
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/cow.c
static void run_with_partial_shared_thp(test_fn fn, const char *desc) { ksft_print_msg("[RUN] %s ... with partially shared THP\n", desc); do_run_with_thp(fn, THP_RUN_PARTIAL_SHARED); }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/cow.c
static void run_with_hugetlb(test_fn fn, const char *desc, size_t hugetlbsize) { int flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB; char *mem, *dummy; ksft_print_msg("[RUN] %s ... with hugetlb (%zu kB)\n", desc, hugetlbsize / 1024); flags |= __builtin_ctzll(hugetlbsize) << MAP_HUGE_SHIFT;...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/cow.c
static int tests_per_anon_test_case(void) { int tests = 2 + nr_hugetlbsizes; if (thpsize) tests += 8; return tests; }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/cow.c
static void test_ro_pin(char *mem, const char *smem, size_t size) { do_test_ro_pin(mem, size, RO_PIN_TEST, false); }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/cow.c
static void test_ro_fast_pin(char *mem, const char *smem, size_t size) { do_test_ro_pin(mem, size, RO_PIN_TEST, true); }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/cow.c
static void run_with_memfd(non_anon_test_fn fn, const char *desc) { char *mem, *smem, tmp; int fd; ksft_print_msg("[RUN] %s ... with memfd\n", desc); fd = memfd_create("test", 0); if (fd < 0) { ksft_test_result_fail("memfd_create() failed\n"); return; } if (fallocate(fd, 0, 0, pagesize)) { ...
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/cow.c
static void run_with_tmpfile(non_anon_test_fn fn, const char *desc) { char *mem, *smem, tmp; FILE *file; int fd; ksft_print_msg("[RUN] %s ... with tmpfile\n", desc); file = tmpfile(); if (!file) { ksft_test_result_fail("tmpfile() failed\n"); return; } fd = fileno(file); if (fd < 0) { ks...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/cow.c
static void run_non_anon_test_cases(void) { int i; ksft_print_msg("[RUN] Non-anonymous memory tests in private mappings\n"); for (i = 0; i < ARRAY_SIZE(non_anon_test_cases); i++) run_non_anon_test_case(&non_anon_test_cases[i]); }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/cow.c
static int tests_per_non_anon_test_case(void) { int tests = 3 + nr_hugetlbsizes; if (thpsize) tests += 1; return tests; }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/cow.c
int main(int argc, char **argv) { int err; pagesize = getpagesize(); detect_thpsize(); detect_hugetlbsizes(); detect_huge_zeropage(); ksft_print_header(); ksft_set_plan(ARRAY_SIZE(anon_test_cases) * tests_per_anon_test_case() + ARRAY_SIZE(non_anon_test_cases) * tests...
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/gup_test.c
void *gup_thread(void *data) { struct gup_test gup = *(struct gup_test *)data; int i; if ((cmd == PIN_FAST_BENCHMARK) || (cmd == GUP_FAST_BENCHMARK) || (cmd == PIN_LONGTERM_BENCHMARK)) { for (i = 0; i < repeats; i++) { gup.size = size; if (ioctl(gup_fd, cmd, &gup)) perror("ioctl"), ...
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/hmm-tests.c
static unsigned int hmm_random(void) { static int fd = -1; unsigned int r; if (fd < 0) { fd = open("/dev/urandom", O_RDONLY); if (fd < 0) { fprintf(stderr, "%s:%d failed to open /dev/urandom\n", __FILE__, __LINE__); return ~0U; } } read(fd, &r, sizeof(r)); return r; }
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/hugepage-mremap.c
static int read_bytes(char *addr, size_t len) { unsigned long i; check_bytes(addr); for (i = 0; i < len; i++) if (*(addr + i) != (char)i) { printf("Mismatch at %lu\n", i); return 1; } return 0; }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/hugepage-mremap.c
static void register_region_with_uffd(char *addr, size_t len) { long uffd; struct uffdio_api uffdio_api; struct uffdio_register uffdio_register; /* Create and enable userfaultfd object. */ uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK); if (uffd == -1) { perror("userfaultfd"); exit(1); ...
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/hugetlb-madvise.c
unsigned long default_huge_page_size(void) { unsigned long hps = 0; char *line = NULL; size_t linelen = 0; FILE *f = fopen("/proc/meminfo", "r"); if (!f) return 0; while (getline(&line, &linelen, f) > 0) { if (sscanf(line, "Hugepagesize: %lu kB", &hps) == 1) { hps <<= 10; break; ...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/khugepaged.c
static int read_string(const char *name, const char *strings[]) { char path[PATH_MAX]; char buf[256]; char *c; int ret; ret = snprintf(path, PATH_MAX, THP_SYSFS "%s", name); if (ret >= PATH_MAX) { printf("%s: Pathname is too long\n", __func__); exit(EXIT_FAILURE); } if (!read_file(path, buf, ...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/khugepaged.c
static void fill_memory(int *p, unsigned long start, unsigned long end) { int i; for (i = start / page_size; i < end / page_size; i++) p[i * page_size / sizeof(*p)] = i + 0xdead0000; }
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/khugepaged.c
static int madvise_collapse_retry(void *p, unsigned long size) { bool retry = true; int ret; retry: ret = madvise(p, size, MADV_COLLAPSE); if (ret && errno == EAGAIN && retry) { retry = false; goto retry; } return ret; }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/khugepaged.c
static bool anon_check_huge(void *addr, int nr_hpages) { return check_huge_anon(addr, nr_hpages, hpage_pmd_size); }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/khugepaged.c
static void *file_setup_area(int nr_hpages) { int fd; void *p; unsigned long size; unlink(finfo.path); printf("Creating %s for collapse%s...", finfo.path, finfo.type == VMA_SHMEM ? " (tmpfs)" : ""); fd = open(finfo.path, O_DSYNC | O_CREAT | O_RDWR | O_TRUNC | O_EXCL, 777); if (fd < 0) { perr...
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/khugepaged.c
static void file_fault(void *p, unsigned long start, unsigned long end) { if (madvise(((char *)p) + start, end - start, MADV_POPULATE_READ)) { perror("madvise(MADV_POPULATE_READ"); exit(EXIT_FAILURE); } }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/khugepaged.c
static bool wait_for_scan(const char *msg, char *p, int nr_hpages, struct mem_ops *ops) { int full_scans; int timeout = 6; /* Sanity check */ if (!ops->check_huge(p, 0)) { printf("Unexpected huge page\n"); exit(EXIT_FAILURE); } madvise(p, nr_hpages * hpage_pmd_size, MADV_...
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/khugepaged.c
static void alloc_at_fault(void) { struct settings settings = *current_settings(); char *p; settings.thp_enabled = THP_ALWAYS; push_settings(&settings); p = alloc_mapping(1); *p = 1; printf("Allocate huge page on fault..."); if (check_huge_anon(p, 1, hpage_pmd_size)) success("OK"); else fai...
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/khugepaged.c
static void collapse_empty(struct collapse_context *c, struct mem_ops *ops) { void *p; p = ops->setup_area(1); c->collapse("Do not collapse empty PTE table", p, 1, ops, false); ops->cleanup_area(p, hpage_pmd_size); }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/khugepaged.c
static void collapse_max_ptes_swap(struct collapse_context *c, struct mem_ops *ops) { int max_ptes_swap = read_num("khugepaged/max_ptes_swap"); void *p; p = ops->setup_area(1); ops->fault(p, 0, hpage_pmd_size); printf("Swapout %d of %d pages...", max_ptes_swap + 1, hpage_...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/khugepaged.c
static void collapse_fork(struct collapse_context *c, struct mem_ops *ops) { int wstatus; void *p; p = ops->setup_area(1); printf("Allocate small page..."); ops->fault(p, 0, page_size); if (ops->check_huge(p, 0)) success("OK"); else fail("Fail"); printf("Share small page over fork()..."); i...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/khugepaged.c
static void madvise_collapse_existing_thps(struct collapse_context *c, struct mem_ops *ops) { void *p; p = ops->setup_area(1); ops->fault(p, 0, hpage_pmd_size); c->collapse("Collapse fully populated PTE table...", p, 1, ops, true); validate_memory(p, 0, hpage_pmd_si...
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/khugepaged.c
static void madvise_retracted_page_tables(struct collapse_context *c, struct mem_ops *ops) { void *p; int nr_hpages = 1; unsigned long size = nr_hpages * hpage_pmd_size; p = ops->setup_area(nr_hpages); ops->fault(p, 0, size); if (wait_for_scan("Collapse and leave ...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/ksm_functional_tests.c
static long ksm_get_full_scans(void) { char buf[10]; ssize_t ret; ret = pread(ksm_full_scans_fd, buf, sizeof(buf) - 1, 0); if (ret <= 0) return -errno; buf[ret] = 0; return strtol(buf, NULL, 10); }
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/ksm_functional_tests.c
static void test_unmerge(void) { const unsigned int size = 2 * MiB; char *map; ksft_print_msg("[RUN] %s\n", __func__); map = mmap_and_merge_range(0xcf, size); if (map == MAP_FAILED) return; if (madvise(map, size, MADV_UNMERGEABLE)) { ksft_test_result_fail("MADV_UNMERGEABLE failed\n"); goto u...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/ksm_functional_tests.c
int main(int argc, char **argv) { unsigned int tests = 2; int err; #ifdef __NR_userfaultfd tests++; #endif ksft_print_header(); ksft_set_plan(tests); pagesize = getpagesize(); ksm_fd = open("/sys/kernel/mm/ksm/run", O_RDWR); if (ksm_fd < 0) ksft_exit_skip("open(\"/sys/kernel/mm/ksm/run\") faile...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/ksm_tests.c
static int str_to_prot(char *prot_str) { int prot = 0; if ((strchr(prot_str, 'r')) != NULL) prot |= PROT_READ; if ((strchr(prot_str, 'w')) != NULL) prot |= PROT_WRITE; if ((strchr(prot_str, 'x')) != NULL) prot |= PROT_EXEC; return prot; }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/ksm_tests.c
static int ksm_do_scan(int scan_count, struct timespec start_time, int timeout) { struct timespec cur_time; unsigned long cur_scan, init_scan; if (ksm_read_sysfs(KSM_FP("full_scans"), &init_scan)) return 1; cur_scan = init_scan; while (cur_scan < init_scan + scan_count) { if ...
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/ksm_tests.c
static int get_first_mem_node(void) { return get_next_mem_node(numa_max_node()); }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/madv_populate.c
static void test_populate_read(void) { char *addr; int ret; ksft_print_msg("[RUN] %s\n", __func__); addr = mmap(0, SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0); if (addr == MAP_FAILED) ksft_exit_fail_msg("mmap failed\n"); ksft_test_result(range_is_not_populated(addr, SIZE), ...
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/madv_populate.c
static bool range_is_not_softdirty(char *start, ssize_t size) { int fd = open("/proc/self/pagemap", O_RDONLY); bool ret = true; if (fd < 0) ksft_exit_fail_msg("opening pagemap failed\n"); for (; size > 0 && ret; size -= pagesize, start += pagesize) if (pagemap_is_softdirty(fd, start)) ret = fals...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/map_hugetlb.c
static void check_bytes(char *addr) { printf("First hex is %x\n", *((unsigned int *)addr)); }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/map_hugetlb.c
static void write_bytes(char *addr, size_t length) { unsigned long i; for (i = 0; i < length; i++) *(addr + i) = (char)i; }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/map_hugetlb.c
static int read_bytes(char *addr, size_t length) { unsigned long i; check_bytes(addr); for (i = 0; i < length; i++) if (*(addr + i) != (char)i) { printf("Mismatch at %lu\n", i); return 1; } return 0; }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/map_populate.c
int main(int argc, char **argv) { int sock[2], child, ret; FILE *ftmp; unsigned long *smap; ftmp = tmpfile(); BUG_ON(ftmp == 0, "tmpfile()"); ret = ftruncate(fileno(ftmp), MMAP_SZ); BUG_ON(ret, "ftruncate()"); smap = mmap(0, MMAP_SZ, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(ftmp), 0); BUG_ON(smap...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/memfd_secret.c
static int memfd_secret(unsigned int flags) { return syscall(__NR_memfd_secret, flags); }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/memfd_secret.c
static void test_ptrace(int fd) { test_remote_access(fd, "ptrace", try_ptrace); }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/memfd_secret.c
static int set_cap_limits(rlim_t max) { struct rlimit new; cap_t cap = cap_init(); new.rlim_cur = max; new.rlim_max = max; if (setrlimit(RLIMIT_MEMLOCK, &new)) { perror("setrlimit() returns error"); return -1; } if (cap_set_proc(cap)) { perror("cap_set_proc() returns error"); return -2; ...
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/memfd_secret.c
int main(int argc, char *argv[]) { printf("skip: skipping memfd_secret test (missing __NR_memfd_secret)\n"); return KSFT_SKIP; }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/mlock2-tests.c
static bool is_vmflag_set(unsigned long addr, const char *vmflag) { char *line = NULL; char *flags; size_t size = 0; bool ret = false; FILE *smaps; smaps = seek_to_smaps_entry(addr); if (!smaps) { printf("Unable to parse /proc/self/smaps\n"); goto out; } while (getline(&line, &size, smaps) ...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/mlock2-tests.c
static int unlock_lock_check(char *map) { if (is_vmflag_set((unsigned long)map, LOCKED)) { printf("VMA flag %s is present on page 1 after unlock\n", LOCKED); return 1; } return 0; }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/mlock2-tests.c
static int test_lock_onfault_of_present() { char *map; int ret = 1; unsigned long page_size = getpagesize(); map = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); if (map == MAP_FAILED) { perror("test_mlock_locked mmap"); goto out; } *map = 'a...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/mlock2-tests.c
static int test_mlockall(int(test_function)(bool call_mlock)) { int ret = 1; if (mlockall(MCL_CURRENT | MCL_ONFAULT | MCL_FUTURE)) { perror("mlockall"); return ret; } ret = test_function(false); munlockall(); return ret; }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/mlock2-tests.c
int main(int argc, char **argv) { int ret = 0; ret += test_mlock_lock(); ret += test_mlock_onfault(); ret += test_munlockall(); ret += test_lock_onfault_of_present(); ret += test_vma_management(true); ret += test_mlockall(test_vma_management); return ret; }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/mrelease_test.c
static void run_negative_tests(int pidfd) { int res; if (!syscall(__NR_process_mrelease, pidfd, (unsigned int)-1) || errno != EINVAL) { res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); perror("process_mrelease with wrong flags"); exit(res); } /* * Test reaping while process is alive with n...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/mrelease_test.c
static int child_main(int pipefd[], size_t size) { int res; close(pipefd[0]); res = alloc_noexit(MB(size) / PAGE_SIZE, pipefd[1]); close(pipefd[1]); return res; }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/mremap_dontunmap.c
static void mremap_dontunmap_simple_fixed() { unsigned long num_pages = 5; // create a mapping up front. void *dest_mapping = mmap(NULL, num_pages * page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); BUG_ON(dest_mapping == MAP_FAILED, "mmap"); memset(dest_mapp...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/mremap_test.c
static void mremap_expand_merge(unsigned long page_size) { char *test_name = "mremap expand merge"; FILE *fp; char *line = NULL; size_t len = 0; bool success = false; char *start = mmap(NULL, 3 * page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); munmap(start + p...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/mremap_test.c
static void usage(const char *cmd) { fprintf(stderr, "Usage: %s [[-t <threshold_mb>] [-p <pattern_seed>]]\n" "-t\t only validate threshold_mb of the remapped region\n" " \t if 0 is supplied no threshold is used; all tests\n" " \t are run and remapped regions validated fully....
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/mremap_test.c
static int parse_args(int argc, char **argv, unsigned int *threshold_mb, unsigned int *pattern_seed) { const char *optstr = "t:p:"; int opt; while ((opt = getopt(argc, argv, optstr)) != -1) { switch (opt) { case 't': *threshold_mb = atoi(optarg); break; case 'p': ...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/on-fault-limit.c
static int test_limit(void) { int ret = 1; struct rlimit lims; void *map; if (getrlimit(RLIMIT_MEMLOCK, &lims)) { perror("getrlimit"); return ret; } if (mlockall(MCL_ONFAULT | MCL_FUTURE)) { perror("mlockall"); return ret; } map = mmap(NULL, 2 * lims.rlim_max, PROT_READ | PROT_WRITE,...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/pkey-helpers.h
static inline u64 set_pkey_bits(u64 reg, int pkey, u64 flags) { u32 shift = pkey_bit_position(pkey); reg &= ~((u64)PKEY_MASK << shift); /* OR in new bits for pkey */ reg |= (flags & PKEY_MASK) << shift; return reg; }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/pkey-helpers.h
static inline u32 *siginfo_get_pkey_ptr(siginfo_t *si) { #ifdef si_pkey return &si->si_pkey; #else return (u32 *)(((u8 *)si) + si_pkey_offset); #endif }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/pkey-helpers.h
static inline int kernel_has_pkeys(void) { int ret = sys_pkey_alloc(0, 0); if (ret <= 0) { return 0; } sys_pkey_free(ret); return 1; }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/pkey-powerpc.h
static inline void __write_pkey_reg(u64 pkey_reg) { u64 amr = pkey_reg; dprintf4("%s() changing %016llx to %016llx\n", __func__, __read_pkey_reg(), pkey_reg); asm volatile("isync; mtspr 0xd, %0; isync" : : "r"((unsigned long)(amr)) : "memory"); dprintf...
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/pkey-powerpc.h
void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 pkey) { void *ptr; int ret; dprintf1("doing %s(size=%ld, prot=0x%x, pkey=%d)\n", __func__, size, prot, pkey); pkey_assert(pkey < NR_PKEYS); ptr = mmap(NULL, size, prot, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); pkey_assert(ptr != (void ...
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/pkey-x86.h
static inline void __page_o_noops(void) { asm(".rept 512 ; nopl 0x7eeeeeee(%eax) ; .endr"); }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/pkey-x86.h
static inline void __write_pkey_reg(u64 pkey_reg) { unsigned int eax = pkey_reg; unsigned int ecx = 0; unsigned int edx = 0; dprintf4("%s() changing %016llx to %016llx\n", __func__, __read_pkey_reg(), pkey_reg); asm volatile(".byte 0x0f,0x01,0xef\n\t" : : "a"(eax), "c"(ecx), "d"(edx)); assert(pk...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/pkey-x86.h
static inline int cpu_has_pkeys(void) { unsigned int eax; unsigned int ebx; unsigned int ecx; unsigned int edx; __cpuid_count(0x7, 0x0, eax, ebx, ecx, edx); if (!(ecx & X86_FEATURE_PKU)) { dprintf2("cpu does not have PKU\n"); return 0; } if (!(ecx & X86_FEATURE_OSPKE)) { dprintf2("cpu doe...
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/pkey-x86.h
void expect_fault_on_read_execonly_key(void *p1, int pkey) { int ptr_contents; ptr_contents = read_ptr(p1); dprintf2("ptr (%p) contents@%d: %x\n", p1, __LINE__, ptr_contents); expected_pkey_fault(pkey); }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/pkey-x86.h
void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 pkey) { return PTR_ERR_ENOTSUP; }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
void lots_o_noops_around_write(int *write_to_me) { dprintf3("running %s()\n", __func__); __page_o_noops(); *write_to_me = __LINE__; /* pad out by another page: */ __page_o_noops(); dprintf3("%s() done\n", __func__); }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
static u32 hw_pkey_get(int pkey, unsigned long flags) { u64 pkey_reg = __read_pkey_reg(); dprintf1("%s(pkey=%d, flags=%lx) = %x / %d\n", __func__, pkey, flags, 0, 0); dprintf2("%s() raw pkey_reg: %016llx\n", __func__, pkey_reg); return (u32)get_pkey_bits(pkey_reg, pkey); }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
static int hw_pkey_set(int pkey, unsigned long rights, unsigned long flags) { u32 mask = (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE); u64 old_pkey_reg = __read_pkey_reg(); u64 new_pkey_reg; assert(!(rights & ~mask)); /* modify bits accordingly in old pkey_reg and assign it */ new_pkey_reg = set_pkey_bits(o...
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
void pkey_disable_set(int pkey, int flags) { unsigned long syscall_flags = 0; int ret; int pkey_rights; u64 orig_pkey_reg = read_pkey_reg(); dprintf1("START->%s(%d, 0x%x)\n", __func__, pkey, flags); pkey_assert(flags & (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE)); pkey_rights = hw_pkey_get(pkey, syscall_...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
void pkey_write_deny(int pkey) { pkey_disable_set(pkey, PKEY_DISABLE_WRITE); }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
void setup_sigsegv_handler(void) { int r, rs; struct sigaction newact; struct sigaction oldact; int signum = SIGSEGV; newact.sa_handler = 0; newact.sa_sigaction = signal_handler; /*sigset_t - signals to block while in the handler */ /* get the old signal mask. */ rs = sigprocmask(SIG_SETMASK, 0, &n...
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
int alloc_pkey(void) { int ret; unsigned long init_val = 0x0; dprintf1("%s()::%d, pkey_reg: 0x%016llx shadow: %016llx\n", __func__, __LINE__, __read_pkey_reg(), shadow_pkey_reg); ret = sys_pkey_alloc(0, init_val); dprintf4("%s()::%d, ret: %d pkey_reg: 0x%016llx" " shadow: 0x%016llx\n",...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
int sys_pkey_free(unsigned long pkey) { int ret = syscall(SYS_pkey_free, pkey); dprintf1("%s(pkey=%ld) syscall ret: %d\n", __func__, pkey, ret); return ret; }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
int mprotect_pkey(void *ptr, size_t size, unsigned long orig_prot, unsigned long pkey) { int nr_iterations = random() % 100; int ret; while (0) { int rpkey = alloc_random_pkey(); ret = sys_mprotect_pkey(ptr, size, orig_prot, pkey); dprintf1("sys_mprotect_pkey(%p, %zx, prot=0x%lx, p...
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
void *malloc_pkey_anon_huge(long size, int prot, u16 pkey) { int ret; void *ptr; dprintf1("doing %s(size=%ld, prot=0x%x, pkey=%d)\n", __func__, size, prot, pkey); size = ALIGN_UP(size, HPAGE_SIZE * 2); ptr = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); pkey_assert(ptr != (vo...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
void setup_hugetlbfs(void) { int err; int fd; char buf[256]; long hpagesz_kb; long hpagesz_mb; if (geteuid() != 0) { fprintf(stderr, "WARNING: not run as root, can not do hugetlb test\n"); return; } cat_into_file(__stringify(GET_NR_HUGE_PAGES), "/proc/sys/vm/nr_hugepages"); hpagesz_kb = HPA...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
void *malloc_pkey_hugetlb(long size, int prot, u16 pkey) { void *ptr; int flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_HUGETLB; if (!hugetlb_setup_ok) return PTR_ERR_ENOTSUP; dprintf1("doing %s(%ld, %x, %x)\n", __func__, size, prot, pkey); size = ALIGN_UP(size, HPAGE_SIZE * 2); pkey_assert(pkey < NR_PKE...
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
void *malloc_pkey(long size, int prot, u16 pkey) { void *ret; static int malloc_type; int nr_malloc_types = ARRAY_SIZE(pkey_malloc); pkey_assert(pkey < NR_PKEYS); while (1) { pkey_assert(malloc_type < nr_malloc_types); ret = pkey_malloc[malloc_type](size, prot, pkey); pkey_assert(ret != (void *...
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
void close_test_fds(void) { int i; for (i = 0; i < nr_test_fds; i++) { if (test_fds[i] < 0) continue; close(test_fds[i]); test_fds[i] = -1; } nr_test_fds = 0; } #define barrier() __asm__ __volatile__("" : : : "memory")
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
int read_ptr(int *ptr) { barrier(); return *ptr; }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
void test_read_of_access_disabled_region_with_page_already_mapped(int *ptr, u16 pkey) { int ptr_contents; dprintf1("disabling access to PKEY[%02d], doing read @ %p\n", pkey, ptr); ptr_contents = read_ptr(ptr); dprintf1("reading ptr before disab...
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
void test_write_of_access_disabled_region(int *ptr, u16 pkey) { dprintf1("disabling access to PKEY[%02d], doing write\n", pkey); pkey_access_deny(pkey); *ptr = __LINE__; expected_pkey_fault(pkey); }
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
void test_kernel_gup_write_to_write_disabled_region(int *ptr, u16 pkey) { int ignored = 0xdada; int futex_ret; int some_int = __LINE__; dprintf1("disabling write to PKEY[%02d], " "doing futex gunk in buffer\n", pkey); *ptr = some_int; pkey_write_deny(pkey); futex_ret = syscall(SYS_...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
void test_pkey_syscalls_on_non_allocated_pkey(int *ptr, u16 pkey) { int err; int i; for (i = 1; i < NR_PKEYS; i++) { if (pkey == i) continue; dprintf1("trying get/set/free to non-allocated pkey: %2d\n", i); err = sys_pkey_free(i); pkey_assert(err); err = sys_pkey_free(i); pkey_ass...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
void arch_force_pkey_reg_init(void) { #if defined(__i386__) || defined(__x86_64__) u64 *buf; /* * All keys should be allocated and set to allow reads and * writes, so the register should be all 0. If not, just * skip the test. */ if (read_pkey_reg()) return; /* * Just allocate an absurd ab...
[ 1, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
void test_pkey_init_state(int *ptr, u16 pkey) { int err; int allocated_pkeys[NR_PKEYS] = {0}; int nr_allocated_pkeys = 0; int i; for (i = 0; i < NR_PKEYS; i++) { int new_pkey = alloc_pkey(); if (new_pkey < 0) continue; allocated_pkeys[nr_allocated_pkeys++] = new_pkey; } dprintf3("%s()...
[ 0, 0 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
void test_mprotect_with_pkey_0(int *ptr, u16 pkey) { long size; int prot; assert(pkey_last_malloc_record); size = pkey_last_malloc_record->size; /* * This is a bit of a hack. But mprotect() requires * huge-page-aligned sizes when operating on hugetlbfs. * So, make sure that we use something that's ...
[ 0, 1 ]
Linux Kernel
tools/testing/selftests/vm/protection_keys.c
void test_executing_on_unreadable_memory(int *ptr, u16 pkey) { void *p1; int scratch; int ptr_contents; int ret; p1 = get_pointer_to_instructions(); lots_o_noops_around_write(&scratch); ptr_contents = read_ptr(p1); dprintf2("ptr (%p) contents@%d: %x\n", p1, __LINE__, ptr_contents); ret = mprotect_pk...
[ 0, 0 ]