Lines Matching +full:wait +full:- +full:on +full:- +full:read

1 // SPDX-License-Identifier: GPL-2.0-only
3 * COW (Copy On Write) tests.
21 #include <sys/wait.h>
102 for (; size; addr += pagesize, size -= pagesize)
115 if (pipe(comm_pipes->child_ready) < 0)
116 return -errno;
117 if (pipe(comm_pipes->parent_ready) < 0) {
118 close(comm_pipes->child_ready[0]);
119 close(comm_pipes->child_ready[1]);
120 return -errno;
128 close(comm_pipes->child_ready[0]);
129 close(comm_pipes->child_ready[1]);
130 close(comm_pipes->parent_ready[0]);
131 close(comm_pipes->parent_ready[1]);
143 /* Wait until the parent modified the page. */
144 write(comm_pipes->child_ready[1], "0", 1);
145 while (read(comm_pipes->parent_ready[0], &buf, 1) != 1)
148 /* See if we still read the old values. */
171 return -errno;
173 /* Trigger a read-only pin. */
176 return -errno;
178 return -EINVAL;
182 return -errno;
184 /* Wait until the parent modified it. */
185 write(comm_pipes->child_ready[1], "0", 1);
186 while (read(comm_pipes->parent_ready[0], &buf, 1) != 1)
189 /* See if we still read the old values via the pipe. */
191 cur = read(fds[0], new + total, transferred - total);
193 return -errno;
222 while (read(comm_pipes.child_ready[0], &buf, 1) != 1)
228 * write-faults by directly mapping pages writable.
235 wait(&ret);
244 wait(&ret);
248 ret = -EINVAL;
332 while (read(comm_pipes.parent_ready[0], &buf, 1) != 1)
343 wait(&ret);
348 while (read(comm_pipes.child_ready[0], &buf, 1) != 1)
356 /* Wait until the child is done writing. */
357 wait(&ret);
359 ksft_test_result_fail("wait() failed\n");
363 /* See if we still read the old values. */
365 cur = read(fds[0], new + total, transferred - total);
367 ksft_test_result_fail("read() failed\n");
437 /* Skip on errors, as we might just lack kernel support. */
448 * Skip on errors, as we might just lack kernel support or might not
470 while (read(comm_pipes.parent_ready[0], &buf, 1) != 1)
475 while (read(comm_pipes.child_ready[0], &buf, 1) != 1)
518 if (cqe->res != size) {
524 /* Read back the file content to the temporary buffer. */
527 cur = pread(fd, tmp + total, size - total, total);
535 /* Finally, check if we read what we expected. */
542 wait(&ret);
616 while (read(comm_pipes.parent_ready[0], &buf, 1) != 1)
621 /* Wait until our child is ready. */
622 while (read(comm_pipes.child_ready[0], &buf, 1) != 1)
627 * Tell the child to quit now and wait until it quit.
632 wait(&ret);
634 ksft_print_msg("[INFO] wait() failed\n");
667 goto wait;
674 * Read back the content via the pin to the temporary buffer and
688 wait:
692 wait(&ret);
694 ksft_print_msg("[INFO] wait() failed\n");
747 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
754 /* Ignore if not around on a kernel. */
808 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
814 /* We need a THP-aligned memory area. */
815 mem = (char *)(((uintptr_t)mmap_mem + thpsize) & ~(thpsize - 1));
824 * Try to populate a THP. Touch the first sub-page and test if
825 * we get the last sub-page populated automatically.
828 if (!pagemap_is_populated(pagemap_fd, mem + thpsize - pagesize)) {
843 * Trigger PTE-mapping the THP by temporarily mapping a single
845 * therefore already PTE-mapped).
861 * Discard all but a single subpage of that PTE-mapped THP. What
864 ret = madvise(mem + pagesize, thpsize - pagesize, MADV_DONTNEED);
878 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
897 ret = madvise(mem + pagesize, thpsize - pagesize, MADV_DONTFORK);
909 wait(&ret);
911 ret = madvise(mem + pagesize, thpsize - pagesize, MADV_DOFORK);
951 ksft_print_msg("[RUN] %s ... with swapped-out THP (%zu kB)\n",
958 ksft_print_msg("[RUN] %s ... with PTE-mapped THP (%zu kB)\n",
965 ksft_print_msg("[RUN] %s ... with swapped-out, PTE-mapped THP (%zu kB)\n",
979 ksft_print_msg("[RUN] %s ... with single PTE of swapped-out THP (%zu kB)\n",
1008 mem = mmap(NULL, hugetlbsize, PROT_READ | PROT_WRITE, flags, -1, 0);
1021 dummy = mmap(NULL, hugetlbsize, PROT_READ | PROT_WRITE, flags, -1, 0);
1063 * This is CVE-2020-29374 reported by Jann Horn.
1098 * table to trigger a write fault on next access. When modifying the
1102 "R/O-mapping a page registered as iouring fixed buffer",
1117 * Take a R/O longterm pin on a R/O-mapped shared anonymous page.
1122 "R/O GUP pin on R/O-mapped shared page",
1125 /* Same as above, but using GUP-fast. */
1127 "R/O GUP-fast pin on R/O-mapped shared page",
1131 * Take a R/O longterm pin on a R/O-mapped exclusive anonymous page that
1136 "R/O GUP pin on R/O-mapped previously-shared page",
1139 /* Same as above, but using GUP-fast. */
1141 "R/O GUP-fast pin on R/O-mapped previously-shared page",
1145 * Take a R/O longterm pin on a R/O-mapped exclusive anonymous page.
1150 "R/O GUP pin on R/O-mapped exclusive page",
1153 /* Same as above, but using GUP-fast. */
1155 "R/O GUP-fast pin on R/O-mapped exclusive page",
1164 run_with_base_page(test_case->fn, test_case->desc);
1165 run_with_base_page_swap(test_case->fn, test_case->desc);
1175 run_with_thp(test_case->fn, test_case->desc, size);
1176 run_with_thp_swap(test_case->fn, test_case->desc, size);
1179 run_with_pte_mapped_thp(test_case->fn, test_case->desc, size);
1180 run_with_pte_mapped_thp_swap(test_case->fn, test_case->desc, size);
1181 run_with_single_pte_of_thp(test_case->fn, test_case->desc, size);
1182 run_with_single_pte_of_thp_swap(test_case->fn, test_case->desc, size);
1183 run_with_partial_mremap_thp(test_case->fn, test_case->desc, size);
1184 run_with_partial_shared_thp(test_case->fn, test_case->desc, size);
1189 run_with_hugetlb(test_case->fn, test_case->desc,
1234 * Trigger PTE-mapping the THP by temporarily mapping a single subpage
1250 /* Collapse before actually COW-sharing the page. */
1259 /* COW-share the full PTE-mapped THP. */
1262 /* Don't COW-share the upper part of the THP. */
1270 /* Don't COW-share the lower part of the THP. */
1303 while (read(comm_pipes.child_ready[0], &buf, 1) != 1)
1319 wait(&ret);
1324 /* Collapse before anyone modified the COW-shared page. */
1330 wait(&ret);
1342 wait(&ret);
1346 ret = -EINVAL;
1390 * Re-mapping a PTE-mapped anon THP using a single PMD ("in-place
1398 /* Basic COW test, but collapse after COW-sharing a full THP. */
1404 * Basic COW test, but collapse after COW-sharing the lower half of a
1412 * Basic COW test, but collapse after COW-sharing the upper half of a
1433 ksft_print_msg("[RUN] %s\n", test_case->desc);
1434 do_run_with_thp(test_case->fn, THP_RUN_PMD, pmdsize);
1455 /* See if we still read the old values via the other mapping. */
1478 MAP_PRIVATE | MAP_ANON, -1, 0);
1484 smem = mmap(NULL, pagesize, PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0);
1490 /* Read from the page to populate the shared zeropage. */
1517 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
1523 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
1529 /* We need a THP-aligned memory area. */
1530 mem = (char *)(((uintptr_t)mmap_mem + pmdsize) & ~(pmdsize - 1));
1531 smem = (char *)(((uintptr_t)mmap_smem + pmdsize) & ~(pmdsize - 1));
1541 * Read from the memory to populate the huge shared zeropage. Read from
1542 * the first sub-page and test if we get another sub-page populated
1732 /* Same as above, but using GUP-fast. */
1734 "R/O longterm GUP-fast pin",
1743 run_with_zeropage(test_case->fn, test_case->desc);
1744 run_with_memfd(test_case->fn, test_case->desc);
1745 run_with_tmpfile(test_case->fn, test_case->desc);
1747 run_with_huge_zeropage(test_case->fn, test_case->desc);
1749 run_with_memfd_hugetlb(test_case->fn, test_case->desc,
1757 ksft_print_msg("[RUN] Non-anonymous memory tests in private mappings\n");