Lines Matching +full:wait +full:- +full:pin
1 // SPDX-License-Identifier: GPL-2.0-only
21 #include <sys/wait.h>
72 for (; size; addr += pagesize, size -= pagesize) in range_is_swapped()
85 if (pipe(comm_pipes->child_ready) < 0) { in setup_comm_pipes()
87 return -errno; in setup_comm_pipes()
89 if (pipe(comm_pipes->parent_ready) < 0) { in setup_comm_pipes()
91 close(comm_pipes->child_ready[0]); in setup_comm_pipes()
92 close(comm_pipes->child_ready[1]); in setup_comm_pipes()
93 return -errno; in setup_comm_pipes()
101 close(comm_pipes->child_ready[0]); in close_comm_pipes()
102 close(comm_pipes->child_ready[1]); in close_comm_pipes()
103 close(comm_pipes->parent_ready[0]); in close_comm_pipes()
104 close(comm_pipes->parent_ready[1]); in close_comm_pipes()
116 /* Wait until the parent modified the page. */ in child_memcmp_fn()
117 write(comm_pipes->child_ready[1], "0", 1); in child_memcmp_fn()
118 while (read(comm_pipes->parent_ready[0], &buf, 1) != 1) in child_memcmp_fn()
144 return -errno; in child_vmsplice_memcmp_fn()
146 /* Trigger a read-only pin. */ in child_vmsplice_memcmp_fn()
149 return -errno; in child_vmsplice_memcmp_fn()
151 return -EINVAL; in child_vmsplice_memcmp_fn()
155 return -errno; in child_vmsplice_memcmp_fn()
157 /* Wait until the parent modified it. */ in child_vmsplice_memcmp_fn()
158 write(comm_pipes->child_ready[1], "0", 1); in child_vmsplice_memcmp_fn()
159 while (read(comm_pipes->parent_ready[0], &buf, 1) != 1) in child_vmsplice_memcmp_fn()
164 cur = read(fds[0], new + total, transferred - total); in child_vmsplice_memcmp_fn()
166 return -errno; in child_vmsplice_memcmp_fn()
202 * write-faults by directly mapping pages writable. in do_test_cow_in_parent()
209 wait(&ret); in do_test_cow_in_parent()
218 wait(&ret); in do_test_cow_in_parent()
227 wait(&ret); in do_test_cow_in_parent()
231 ret = -EINVAL; in do_test_cow_in_parent()
332 wait(&ret); in do_test_vmsplice_in_parent()
346 /* Wait until the child is done writing. */ in do_test_vmsplice_in_parent()
347 wait(&ret); in do_test_vmsplice_in_parent()
349 ksft_perror("wait() failed"); in do_test_vmsplice_in_parent()
356 cur = read(fds[0], new + total, transferred - total); in do_test_vmsplice_in_parent()
502 * buffer pin to the file so we can verify it. in do_test_iouring()
527 if (cqe->res != size) { in do_test_iouring()
537 cur = pread(fd, tmp + total, size - total, total); in do_test_iouring()
550 ksft_print_msg("Longtom R/W pin is not reliable\n"); in do_test_iouring()
557 wait(&ret); in do_test_iouring()
639 /* Wait until our child is ready. */ in do_test_ro_pin()
645 * Tell the child to quit now and wait until it quit. in do_test_ro_pin()
650 wait(&ret); in do_test_ro_pin()
652 ksft_print_msg("[INFO] wait() failed\n"); in do_test_ro_pin()
676 /* Take a R/O pin. This should trigger unsharing. */ in do_test_ro_pin()
688 goto wait; in do_test_ro_pin()
695 * Read back the content via the pin to the temporary buffer and in do_test_ro_pin()
707 ksft_print_msg("Longterm R/O pin is not reliable\n"); in do_test_ro_pin()
715 wait: in do_test_ro_pin()
719 wait(&ret); in do_test_ro_pin()
721 ksft_perror("wait() failed"); in do_test_ro_pin()
774 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); in do_run_with_base_page()
838 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); in do_run_with_thp()
845 /* We need a THP-aligned memory area. */ in do_run_with_thp()
846 mem = (char *)(((uintptr_t)mmap_mem + thpsize) & ~(thpsize - 1)); in do_run_with_thp()
856 * Try to populate a THP. Touch the first sub-page and test if in do_run_with_thp()
857 * we get the last sub-page populated automatically. in do_run_with_thp()
860 if (!pagemap_is_populated(pagemap_fd, mem + thpsize - pagesize)) { in do_run_with_thp()
876 * Trigger PTE-mapping the THP by temporarily mapping a single in do_run_with_thp()
878 * therefore already PTE-mapped). in do_run_with_thp()
896 * Discard all but a single subpage of that PTE-mapped THP. What in do_run_with_thp()
899 ret = madvise(mem + pagesize, thpsize - pagesize, MADV_DONTNEED); in do_run_with_thp()
914 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); in do_run_with_thp()
935 ret = madvise(mem + pagesize, thpsize - pagesize, MADV_DONTFORK); in do_run_with_thp()
949 wait(&ret); in do_run_with_thp()
951 ret = madvise(mem + pagesize, thpsize - pagesize, MADV_DOFORK); in do_run_with_thp()
993 log_test_start("%s ... with swapped-out THP (%zu kB)", in run_with_thp_swap()
1000 log_test_start("%s ... with PTE-mapped THP (%zu kB)", in run_with_pte_mapped_thp()
1007 log_test_start("%s ... with swapped-out, PTE-mapped THP (%zu kB)", in run_with_pte_mapped_thp_swap()
1021 log_test_start("%s ... with single PTE of swapped-out THP (%zu kB)", in run_with_single_pte_of_thp_swap()
1050 mem = mmap(NULL, hugetlbsize, PROT_READ | PROT_WRITE, flags, -1, 0); in run_with_hugetlb()
1064 dummy = mmap(NULL, hugetlbsize, PROT_READ | PROT_WRITE, flags, -1, 0); in run_with_hugetlb()
1107 * This is CVE-2020-29374 reported by Jann Horn.
1141 * Take a R/W longterm pin and then map the page R/O into the page
1143 * page, the page content must be visible via the pin.
1146 "R/O-mapping a page registered as iouring fixed buffer",
1150 * Take a R/W longterm pin and then fork() a child. When modifying the
1151 * page, the page content must be visible via the pin. We expect the
1161 * Take a R/O longterm pin on a R/O-mapped shared anonymous page.
1163 * must be visible via the pin.
1166 "R/O GUP pin on R/O-mapped shared page",
1169 /* Same as above, but using GUP-fast. */
1171 "R/O GUP-fast pin on R/O-mapped shared page",
1175 * Take a R/O longterm pin on a R/O-mapped exclusive anonymous page that
1177 * the page content change must be visible via the pin.
1180 "R/O GUP pin on R/O-mapped previously-shared page",
1183 /* Same as above, but using GUP-fast. */
1185 "R/O GUP-fast pin on R/O-mapped previously-shared page",
1189 * Take a R/O longterm pin on a R/O-mapped exclusive anonymous page.
1191 * must be visible via the pin.
1194 "R/O GUP pin on R/O-mapped exclusive page",
1197 /* Same as above, but using GUP-fast. */
1199 "R/O GUP-fast pin on R/O-mapped exclusive page",
1208 run_with_base_page(test_case->fn, test_case->desc); in run_anon_test_case()
1209 run_with_base_page_swap(test_case->fn, test_case->desc); in run_anon_test_case()
1219 run_with_thp(test_case->fn, test_case->desc, size); in run_anon_test_case()
1220 run_with_thp_swap(test_case->fn, test_case->desc, size); in run_anon_test_case()
1223 run_with_pte_mapped_thp(test_case->fn, test_case->desc, size); in run_anon_test_case()
1224 run_with_pte_mapped_thp_swap(test_case->fn, test_case->desc, size); in run_anon_test_case()
1225 run_with_single_pte_of_thp(test_case->fn, test_case->desc, size); in run_anon_test_case()
1226 run_with_single_pte_of_thp_swap(test_case->fn, test_case->desc, size); in run_anon_test_case()
1227 run_with_partial_mremap_thp(test_case->fn, test_case->desc, size); in run_anon_test_case()
1228 run_with_partial_shared_thp(test_case->fn, test_case->desc, size); in run_anon_test_case()
1233 run_with_hugetlb(test_case->fn, test_case->desc, in run_anon_test_case()
1278 * Trigger PTE-mapping the THP by temporarily mapping a single subpage in do_test_anon_thp_collapse()
1296 /* Collapse before actually COW-sharing the page. */ in do_test_anon_thp_collapse()
1305 /* COW-share the full PTE-mapped THP. */ in do_test_anon_thp_collapse()
1308 /* Don't COW-share the upper part of the THP. */ in do_test_anon_thp_collapse()
1317 /* Don't COW-share the lower part of the THP. */ in do_test_anon_thp_collapse()
1369 wait(&ret); in do_test_anon_thp_collapse()
1374 /* Collapse before anyone modified the COW-shared page. */ in do_test_anon_thp_collapse()
1380 wait(&ret); in do_test_anon_thp_collapse()
1392 wait(&ret); in do_test_anon_thp_collapse()
1396 ret = -EINVAL; in do_test_anon_thp_collapse()
1445 * Re-mapping a PTE-mapped anon THP using a single PMD ("in-place
1453 /* Basic COW test, but collapse after COW-sharing a full THP. */
1459 * Basic COW test, but collapse after COW-sharing the lower half of a
1467 * Basic COW test, but collapse after COW-sharing the upper half of a
1488 log_test_start("%s", test_case->desc); in run_anon_thp_test_cases()
1489 do_run_with_thp(test_case->fn, THP_RUN_PMD, pmdsize); in run_anon_thp_test_cases()
1537 MAP_PRIVATE | MAP_ANON, -1, 0); in run_with_zeropage()
1544 smem = mmap(NULL, pagesize, PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0); in run_with_zeropage()
1579 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); in run_with_huge_zeropage()
1586 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); in run_with_huge_zeropage()
1593 /* We need a THP-aligned memory area. */ in run_with_huge_zeropage()
1594 mem = (char *)(((uintptr_t)mmap_mem + pmdsize) & ~(pmdsize - 1)); in run_with_huge_zeropage()
1595 smem = (char *)(((uintptr_t)mmap_smem + pmdsize) & ~(pmdsize - 1)); in run_with_huge_zeropage()
1612 * the first sub-page and test if we get another sub-page populated in run_with_huge_zeropage()
1808 * Take a R/O longterm pin. When modifying the page via the page table,
1809 * the page content change must be visible via the pin.
1812 "R/O longterm GUP pin",
1815 /* Same as above, but using GUP-fast. */
1817 "R/O longterm GUP-fast pin",
1826 run_with_zeropage(test_case->fn, test_case->desc); in run_non_anon_test_case()
1827 run_with_memfd(test_case->fn, test_case->desc); in run_non_anon_test_case()
1828 run_with_tmpfile(test_case->fn, test_case->desc); in run_non_anon_test_case()
1830 run_with_huge_zeropage(test_case->fn, test_case->desc); in run_non_anon_test_case()
1832 run_with_memfd_hugetlb(test_case->fn, test_case->desc, in run_non_anon_test_case()
1840 ksft_print_msg("[RUN] Non-anonymous memory tests in private mappings\n"); in run_non_anon_test_cases()