From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75C253CAA41; Wed, 30 Sep 2026 19:16:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790795801; cv=none; b=EYrQsJTfUIGaGrF+ivcsIKIQxcx7g6OICdo8xq0mtE782bIcwwKGwBlHpNexG+mqv4qRVJrb04ReO/YCuR2GPmK7D0qCLA2oFWZ9L2vlYRfsEzBadyQ2teY5UZcRRtt1nbOhoDb4zhPvZypXSCeLZs3KT6JZh5GmDry3BrM5tPY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790795801; c=relaxed/simple; bh=8t9qQHoJ2PwM9vk6OAVB5sYU+NgBVZ9HfeLkfGpugyQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EuTSO8zHlD8D6oHtdc4TG1OD5jCN+bTHjs3PkMkf61sNTX5h+KAeLSiPcYyzt+k+dKvoUKXxy3g+eaN81S08V8tvwTFM6BjtZIsjvKPyN+P8R9E08wkRHPB6LKahe7GBxlFkcVYx/plSGqzLkJA5w0+qjTCq8XrhqYRw0gyuslM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ftwwI8ne; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ftwwI8ne" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BC181F000FF; Wed, 30 Sep 2026 19:16:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790795799; bh=hyGQIG5U0lVwjSYDPfpPPzvjHbm0GgTfhJggRXIDjuo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ftwwI8neVnMJMA10cRbUVacJHWLL5XZGdIu/0RRfxiqVuo3BQUO2lpr3lcdo/xx4r 3xsj/sp6uH9nJIk/W/cqtasvZyMPbaEPCz7a21zLkhoK5r2dZxwCKvFd1aRimuvLXg ck1uxqLNWElD2JBkE1fRFmmoIO1d7g0+ORS4gqvE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sasha Levin Subject: [PATCH 6.6 0688/1193] Revert "selftests/mm: report unique test names for each cow test" Date: Wed, 30 Sep 2026 17:22:52 +0200 Message-ID: <20260930152449.533590169@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930152434.301151190@linuxfoundation.org> References: <20260930152434.301151190@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ This reverts commit 4498f617a4948e6dd8a8bf5e94c1920acafbe70b. Signed-off-by: Sasha Levin --- tools/testing/selftests/mm/cow.c | 333 +++++++++++-------------------- 1 file changed, 116 insertions(+), 217 deletions(-) diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c index 6da407f1728de..91fe96f11adf8 100644 --- a/tools/testing/selftests/mm/cow.c +++ b/tools/testing/selftests/mm/cow.c @@ -78,12 +78,9 @@ struct comm_pipes { static int setup_comm_pipes(struct comm_pipes *comm_pipes) { - if (pipe(comm_pipes->child_ready) < 0) { - ksft_perror("pipe()"); + if (pipe(comm_pipes->child_ready) < 0) return -errno; - } if (pipe(comm_pipes->parent_ready) < 0) { - ksft_perror("pipe()"); close(comm_pipes->child_ready[0]); close(comm_pipes->child_ready[1]); return -errno; @@ -176,14 +173,13 @@ static void do_test_cow_in_parent(char *mem, size_t size, bool do_mprotect, ret = setup_comm_pipes(&comm_pipes); if (ret) { - log_test_result(KSFT_FAIL); + ksft_test_result_fail("pipe() failed\n"); return; } ret = fork(); if (ret < 0) { - ksft_perror("fork() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("fork() failed\n"); goto close_comm_pipes; } else if (!ret) { exit(fn(mem, size, &comm_pipes)); @@ -198,18 +194,9 @@ static void do_test_cow_in_parent(char *mem, size_t size, bool do_mprotect, * write-faults by directly mapping pages writable. */ ret = mprotect(mem, size, PROT_READ); + ret |= mprotect(mem, size, PROT_READ|PROT_WRITE); if (ret) { - ksft_perror("mprotect() failed"); - log_test_result(KSFT_FAIL); - write(comm_pipes.parent_ready[1], "0", 1); - wait(&ret); - goto close_comm_pipes; - } - - ret = mprotect(mem, size, PROT_READ|PROT_WRITE); - if (ret) { - ksft_perror("mprotect() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("mprotect() failed\n"); write(comm_pipes.parent_ready[1], "0", 1); wait(&ret); goto close_comm_pipes; @@ -227,16 +214,16 @@ static void do_test_cow_in_parent(char *mem, size_t size, bool do_mprotect, ret = -EINVAL; if (!ret) { - log_test_result(KSFT_PASS); + ksft_test_result_pass("No leak from parent into child\n"); } else if (xfail) { /* * With hugetlb, some vmsplice() tests are currently expected to * fail because (a) harder to fix and (b) nobody really cares. * Flag them as expected failure for now. */ - log_test_result(KSFT_XFAIL); + ksft_test_result_xfail("Leak from parent into child\n"); } else { - log_test_result(KSFT_FAIL); + ksft_test_result_fail("Leak from parent into child\n"); } close_comm_pipes: close_comm_pipes(&comm_pipes); @@ -285,29 +272,26 @@ static void do_test_vmsplice_in_parent(char *mem, size_t size, ret = setup_comm_pipes(&comm_pipes); if (ret) { - log_test_result(KSFT_FAIL); + ksft_test_result_fail("pipe() failed\n"); goto free; } if (pipe(fds) < 0) { - ksft_perror("pipe() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("pipe() failed\n"); goto close_comm_pipes; } if (before_fork) { transferred = vmsplice(fds[1], &iov, 1, 0); if (transferred <= 0) { - ksft_print_msg("vmsplice() failed\n"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("vmsplice() failed\n"); goto close_pipe; } } ret = fork(); if (ret < 0) { - ksft_perror("fork() failed\n"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("fork() failed\n"); goto close_pipe; } else if (!ret) { write(comm_pipes.child_ready[1], "0", 1); @@ -321,8 +305,7 @@ static void do_test_vmsplice_in_parent(char *mem, size_t size, if (!before_fork) { transferred = vmsplice(fds[1], &iov, 1, 0); if (transferred <= 0) { - ksft_perror("vmsplice() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("vmsplice() failed\n"); wait(&ret); goto close_pipe; } @@ -331,8 +314,7 @@ static void do_test_vmsplice_in_parent(char *mem, size_t size, while (read(comm_pipes.child_ready[0], &buf, 1) != 1) ; if (munmap(mem, size) < 0) { - ksft_perror("munmap() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("munmap() failed\n"); goto close_pipe; } write(comm_pipes.parent_ready[1], "0", 1); @@ -340,8 +322,7 @@ static void do_test_vmsplice_in_parent(char *mem, size_t size, /* Wait until the child is done writing. */ wait(&ret); if (!WIFEXITED(ret)) { - ksft_perror("wait() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("wait() failed\n"); goto close_pipe; } @@ -349,23 +330,22 @@ static void do_test_vmsplice_in_parent(char *mem, size_t size, for (total = 0; total < transferred; total += cur) { cur = read(fds[0], new + total, transferred - total); if (cur < 0) { - ksft_perror("read() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("read() failed\n"); goto close_pipe; } } if (!memcmp(old, new, transferred)) { - log_test_result(KSFT_PASS); + ksft_test_result_pass("No leak from child into parent\n"); } else if (xfail) { /* * With hugetlb, some vmsplice() tests are currently expected to * fail because (a) harder to fix and (b) nobody really cares. * Flag them as expected failure for now. */ - log_test_result(KSFT_XFAIL); + ksft_test_result_xfail("Leak from child into parent\n"); } else { - log_test_result(KSFT_FAIL); + ksft_test_result_fail("Leak from child into parent\n"); } close_pipe: close(fds[0]); @@ -402,14 +382,13 @@ static void do_test_iouring(char *mem, size_t size, bool use_fork) ret = setup_comm_pipes(&comm_pipes); if (ret) { - log_test_result(KSFT_FAIL); + ksft_test_result_fail("pipe() failed\n"); return; } file = tmpfile(); if (!file) { - ksft_perror("tmpfile() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("tmpfile() failed\n"); goto close_comm_pipes; } fd = fileno(file); @@ -417,16 +396,14 @@ static void do_test_iouring(char *mem, size_t size, bool use_fork) tmp = malloc(size); if (!tmp) { - ksft_print_msg("malloc() failed\n"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("malloc() failed\n"); goto close_file; } /* Skip on errors, as we might just lack kernel support. */ ret = io_uring_queue_init(1, &ring, 0); if (ret < 0) { - ksft_print_msg("io_uring_queue_init() failed\n"); - log_test_result(KSFT_SKIP); + ksft_test_result_skip("io_uring_queue_init() failed\n"); goto free_tmp; } @@ -441,8 +418,7 @@ static void do_test_iouring(char *mem, size_t size, bool use_fork) iov.iov_len = size; ret = io_uring_register_buffers(&ring, &iov, 1); if (ret) { - ksft_print_msg("io_uring_register_buffers() failed\n"); - log_test_result(KSFT_SKIP); + ksft_test_result_skip("io_uring_register_buffers() failed\n"); goto queue_exit; } @@ -453,8 +429,7 @@ static void do_test_iouring(char *mem, size_t size, bool use_fork) */ ret = fork(); if (ret < 0) { - ksft_perror("fork() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("fork() failed\n"); goto unregister_buffers; } else if (!ret) { write(comm_pipes.child_ready[1], "0", 1); @@ -474,17 +449,10 @@ static void do_test_iouring(char *mem, size_t size, bool use_fork) * if the page is mapped R/O vs. R/W). */ ret = mprotect(mem, size, PROT_READ); - if (ret) { - ksft_perror("mprotect() failed"); - log_test_result(KSFT_FAIL); - goto unregister_buffers; - } - clear_softdirty(); - ret = mprotect(mem, size, PROT_READ | PROT_WRITE); + ret |= mprotect(mem, size, PROT_READ | PROT_WRITE); if (ret) { - ksft_perror("mprotect() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("mprotect() failed\n"); goto unregister_buffers; } } @@ -496,29 +464,25 @@ static void do_test_iouring(char *mem, size_t size, bool use_fork) memset(mem, 0xff, size); sqe = io_uring_get_sqe(&ring); if (!sqe) { - ksft_print_msg("io_uring_get_sqe() failed\n"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("io_uring_get_sqe() failed\n"); goto quit_child; } io_uring_prep_write_fixed(sqe, fd, mem, size, 0, 0); ret = io_uring_submit(&ring); if (ret < 0) { - ksft_print_msg("io_uring_submit() failed\n"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("io_uring_submit() failed\n"); goto quit_child; } ret = io_uring_wait_cqe(&ring, &cqe); if (ret < 0) { - ksft_print_msg("io_uring_wait_cqe() failed\n"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("io_uring_wait_cqe() failed\n"); goto quit_child; } if (cqe->res != size) { - ksft_print_msg("write_fixed failed\n"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("write_fixed failed\n"); goto quit_child; } io_uring_cqe_seen(&ring, cqe); @@ -528,18 +492,15 @@ static void do_test_iouring(char *mem, size_t size, bool use_fork) while (total < size) { cur = pread(fd, tmp + total, size - total, total); if (cur < 0) { - ksft_print_msg("pread() failed\n"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("pread() failed\n"); goto quit_child; } total += cur; } /* Finally, check if we read what we expected. */ - if (!memcmp(mem, tmp, size)) - log_test_result(KSFT_PASS); - else - log_test_result(KSFT_FAIL); + ksft_test_result(!memcmp(mem, tmp, size), + "Longterm R/W pin is reliable\n"); quit_child: if (use_fork) { @@ -587,21 +548,19 @@ static void do_test_ro_pin(char *mem, size_t size, enum ro_pin_test test, int ret; if (gup_fd < 0) { - ksft_print_msg("gup_test not available\n"); - log_test_result(KSFT_SKIP); + ksft_test_result_skip("gup_test not available\n"); return; } tmp = malloc(size); if (!tmp) { - ksft_print_msg("malloc() failed\n"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("malloc() failed\n"); return; } ret = setup_comm_pipes(&comm_pipes); if (ret) { - log_test_result(KSFT_FAIL); + ksft_test_result_fail("pipe() failed\n"); goto free_tmp; } @@ -616,8 +575,7 @@ static void do_test_ro_pin(char *mem, size_t size, enum ro_pin_test test, */ ret = fork(); if (ret < 0) { - ksft_perror("fork() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("fork() failed\n"); goto close_comm_pipes; } else if (!ret) { write(comm_pipes.child_ready[1], "0", 1); @@ -654,8 +612,7 @@ static void do_test_ro_pin(char *mem, size_t size, enum ro_pin_test test, clear_softdirty(); ret |= mprotect(mem, size, PROT_READ | PROT_WRITE); if (ret) { - ksft_perror("mprotect() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("mprotect() failed\n"); goto close_comm_pipes; } break; @@ -670,11 +627,9 @@ static void do_test_ro_pin(char *mem, size_t size, enum ro_pin_test test, ret = ioctl(gup_fd, PIN_LONGTERM_TEST_START, &args); if (ret) { if (errno == EINVAL) - ret = KSFT_SKIP; + ksft_test_result_skip("PIN_LONGTERM_TEST_START failed\n"); else - ret = KSFT_FAIL; - ksft_perror("PIN_LONGTERM_TEST_START failed"); - log_test_result(ret); + ksft_test_result_fail("PIN_LONGTERM_TEST_START failed\n"); goto wait; } @@ -687,26 +642,22 @@ static void do_test_ro_pin(char *mem, size_t size, enum ro_pin_test test, */ tmp_val = (__u64)(uintptr_t)tmp; ret = ioctl(gup_fd, PIN_LONGTERM_TEST_READ, &tmp_val); - if (ret) { - ksft_perror("PIN_LONGTERM_TEST_READ failed"); - log_test_result(KSFT_FAIL); - } else { - if (!memcmp(mem, tmp, size)) - log_test_result(KSFT_PASS); - else - log_test_result(KSFT_FAIL); - } + if (ret) + ksft_test_result_fail("PIN_LONGTERM_TEST_READ failed\n"); + else + ksft_test_result(!memcmp(mem, tmp, size), + "Longterm R/O pin is reliable\n"); ret = ioctl(gup_fd, PIN_LONGTERM_TEST_STOP); if (ret) - ksft_perror("PIN_LONGTERM_TEST_STOP failed"); + ksft_print_msg("[INFO] PIN_LONGTERM_TEST_STOP failed\n"); wait: switch (test) { case RO_PIN_TEST_SHARED: write(comm_pipes.parent_ready[1], "0", 1); wait(&ret); if (!WIFEXITED(ret)) - ksft_perror("wait() failed"); + ksft_print_msg("[INFO] wait() failed\n"); break; default: break; @@ -761,16 +712,14 @@ static void do_run_with_base_page(test_fn fn, bool swapout) mem = mmap(NULL, pagesize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (mem == MAP_FAILED) { - ksft_perror("mmap() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("mmap() failed\n"); return; } ret = madvise(mem, pagesize, MADV_NOHUGEPAGE); /* Ignore if not around on a kernel. */ if (ret && errno != EINVAL) { - ksft_perror("MADV_NOHUGEPAGE failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("MADV_NOHUGEPAGE failed\n"); goto munmap; } @@ -780,8 +729,7 @@ static void do_run_with_base_page(test_fn fn, bool swapout) if (swapout) { madvise(mem, pagesize, MADV_PAGEOUT); if (!pagemap_is_swapped(pagemap_fd, mem)) { - ksft_print_msg("MADV_PAGEOUT did not work, is swap enabled?\n"); - log_test_result(KSFT_SKIP); + ksft_test_result_skip("MADV_PAGEOUT did not work, is swap enabled?\n"); goto munmap; } } @@ -793,13 +741,13 @@ static void do_run_with_base_page(test_fn fn, bool swapout) static void run_with_base_page(test_fn fn, const char *desc) { - log_test_start("%s ... with base page", desc); + ksft_print_msg("[RUN] %s ... with base page\n", desc); do_run_with_base_page(fn, false); } static void run_with_base_page_swap(test_fn fn, const char *desc) { - log_test_start("%s ... with swapped out base page", desc); + ksft_print_msg("[RUN] %s ... with swapped out base page\n", desc); do_run_with_base_page(fn, true); } @@ -825,8 +773,7 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize) mmap_mem = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (mmap_mem == MAP_FAILED) { - ksft_perror("mmap() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("mmap() failed\n"); return; } @@ -835,8 +782,7 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize) ret = madvise(mem, thpsize, MADV_HUGEPAGE); if (ret) { - ksft_perror("MADV_HUGEPAGE failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("MADV_HUGEPAGE failed\n"); goto munmap; } @@ -846,8 +792,7 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize) */ mem[0] = 0; if (!pagemap_is_populated(pagemap_fd, mem + thpsize - pagesize)) { - ksft_print_msg("Did not get a THP populated\n"); - log_test_result(KSFT_SKIP); + ksft_test_result_skip("Did not get a THP populated\n"); goto munmap; } memset(mem, 0, thpsize); @@ -867,14 +812,12 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize) */ ret = mprotect(mem + pagesize, pagesize, PROT_READ); if (ret) { - ksft_perror("mprotect() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("mprotect() failed\n"); goto munmap; } ret = mprotect(mem + pagesize, pagesize, PROT_READ | PROT_WRITE); if (ret) { - ksft_perror("mprotect() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("mprotect() failed\n"); goto munmap; } break; @@ -886,8 +829,7 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize) */ ret = madvise(mem + pagesize, thpsize - pagesize, MADV_DONTNEED); if (ret) { - ksft_perror("MADV_DONTNEED failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("MADV_DONTNEED failed\n"); goto munmap; } size = pagesize; @@ -901,15 +843,13 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize) mremap_mem = mmap(NULL, mremap_size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (mremap_mem == MAP_FAILED) { - ksft_perror("mmap() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("mmap() failed\n"); goto munmap; } tmp = mremap(mem + mremap_size, mremap_size, mremap_size, MREMAP_MAYMOVE | MREMAP_FIXED, mremap_mem); if (tmp != mremap_mem) { - ksft_perror("mremap() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("mremap() failed\n"); goto munmap; } size = mremap_size; @@ -922,14 +862,12 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize) */ ret = madvise(mem + pagesize, thpsize - pagesize, MADV_DONTFORK); if (ret) { - ksft_perror("MADV_DONTFORK failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("MADV_DONTFORK failed\n"); goto munmap; } ret = fork(); if (ret < 0) { - ksft_perror("fork() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("fork() failed\n"); goto munmap; } else if (!ret) { exit(0); @@ -938,8 +876,7 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize) /* Allow for sharing all pages again. */ ret = madvise(mem + pagesize, thpsize - pagesize, MADV_DOFORK); if (ret) { - ksft_perror("MADV_DOFORK failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("MADV_DOFORK failed\n"); goto munmap; } break; @@ -953,8 +890,7 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize) case THP_RUN_SINGLE_PTE_SWAPOUT: madvise(mem, size, MADV_PAGEOUT); if (!range_is_swapped(mem, size)) { - ksft_print_msg("MADV_PAGEOUT did not work, is swap enabled?\n"); - log_test_result(KSFT_SKIP); + ksft_test_result_skip("MADV_PAGEOUT did not work, is swap enabled?\n"); goto munmap; } break; @@ -971,56 +907,56 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize) static void run_with_thp(test_fn fn, const char *desc, size_t size) { - log_test_start("%s ... with THP (%zu kB)", + ksft_print_msg("[RUN] %s ... with THP (%zu kB)\n", desc, size / 1024); do_run_with_thp(fn, THP_RUN_PMD, size); } static void run_with_thp_swap(test_fn fn, const char *desc, size_t size) { - log_test_start("%s ... with swapped-out THP (%zu kB)", + ksft_print_msg("[RUN] %s ... with swapped-out THP (%zu kB)\n", desc, size / 1024); do_run_with_thp(fn, THP_RUN_PMD_SWAPOUT, size); } static void run_with_pte_mapped_thp(test_fn fn, const char *desc, size_t size) { - log_test_start("%s ... with PTE-mapped THP (%zu kB)", + ksft_print_msg("[RUN] %s ... with PTE-mapped THP (%zu kB)\n", desc, size / 1024); do_run_with_thp(fn, THP_RUN_PTE, size); } static void run_with_pte_mapped_thp_swap(test_fn fn, const char *desc, size_t size) { - log_test_start("%s ... with swapped-out, PTE-mapped THP (%zu kB)", + ksft_print_msg("[RUN] %s ... with swapped-out, PTE-mapped THP (%zu kB)\n", desc, size / 1024); do_run_with_thp(fn, THP_RUN_PTE_SWAPOUT, size); } static void run_with_single_pte_of_thp(test_fn fn, const char *desc, size_t size) { - log_test_start("%s ... with single PTE of THP (%zu kB)", + ksft_print_msg("[RUN] %s ... with single PTE of THP (%zu kB)\n", desc, size / 1024); do_run_with_thp(fn, THP_RUN_SINGLE_PTE, size); } static void run_with_single_pte_of_thp_swap(test_fn fn, const char *desc, size_t size) { - log_test_start("%s ... with single PTE of swapped-out THP (%zu kB)", + ksft_print_msg("[RUN] %s ... with single PTE of swapped-out THP (%zu kB)\n", desc, size / 1024); do_run_with_thp(fn, THP_RUN_SINGLE_PTE_SWAPOUT, size); } static void run_with_partial_mremap_thp(test_fn fn, const char *desc, size_t size) { - log_test_start("%s ... with partially mremap()'ed THP (%zu kB)", + ksft_print_msg("[RUN] %s ... with partially mremap()'ed THP (%zu kB)\n", desc, size / 1024); do_run_with_thp(fn, THP_RUN_PARTIAL_MREMAP, size); } static void run_with_partial_shared_thp(test_fn fn, const char *desc, size_t size) { - log_test_start("%s ... with partially shared THP (%zu kB)", + ksft_print_msg("[RUN] %s ... with partially shared THP (%zu kB)\n", desc, size / 1024); do_run_with_thp(fn, THP_RUN_PARTIAL_SHARED, size); } @@ -1030,15 +966,14 @@ 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; - log_test_start("%s ... with hugetlb (%zu kB)", desc, + ksft_print_msg("[RUN] %s ... with hugetlb (%zu kB)\n", desc, hugetlbsize / 1024); flags |= __builtin_ctzll(hugetlbsize) << MAP_HUGE_SHIFT; mem = mmap(NULL, hugetlbsize, PROT_READ | PROT_WRITE, flags, -1, 0); if (mem == MAP_FAILED) { - ksft_perror("need more free huge pages"); - log_test_result(KSFT_SKIP); + ksft_test_result_skip("need more free huge pages\n"); return; } @@ -1051,8 +986,7 @@ static void run_with_hugetlb(test_fn fn, const char *desc, size_t hugetlbsize) */ dummy = mmap(NULL, hugetlbsize, PROT_READ | PROT_WRITE, flags, -1, 0); if (dummy == MAP_FAILED) { - ksft_perror("need more free huge pages"); - log_test_result(KSFT_SKIP); + ksft_test_result_skip("need more free huge pages\n"); goto munmap; } munmap(dummy, hugetlbsize); @@ -1245,7 +1179,7 @@ static void do_test_anon_thp_collapse(char *mem, size_t size, ret = setup_comm_pipes(&comm_pipes); if (ret) { - log_test_result(KSFT_FAIL); + ksft_test_result_fail("pipe() failed\n"); return; } @@ -1255,14 +1189,12 @@ static void do_test_anon_thp_collapse(char *mem, size_t size, */ ret = mprotect(mem + pagesize, pagesize, PROT_READ); if (ret) { - ksft_perror("mprotect() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("mprotect() failed\n"); goto close_comm_pipes; } ret = mprotect(mem + pagesize, pagesize, PROT_READ | PROT_WRITE); if (ret) { - ksft_perror("mprotect() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("mprotect() failed\n"); goto close_comm_pipes; } @@ -1271,8 +1203,8 @@ static void do_test_anon_thp_collapse(char *mem, size_t size, /* Collapse before actually COW-sharing the page. */ ret = madvise(mem, size, MADV_COLLAPSE); if (ret) { - ksft_perror("MADV_COLLAPSE failed"); - log_test_result(KSFT_SKIP); + ksft_test_result_skip("MADV_COLLAPSE failed: %s\n", + strerror(errno)); goto close_comm_pipes; } break; @@ -1283,8 +1215,7 @@ static void do_test_anon_thp_collapse(char *mem, size_t size, /* Don't COW-share the upper part of the THP. */ ret = madvise(mem + size / 2, size / 2, MADV_DONTFORK); if (ret) { - ksft_perror("MADV_DONTFORK failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("MADV_DONTFORK failed\n"); goto close_comm_pipes; } break; @@ -1292,8 +1223,7 @@ static void do_test_anon_thp_collapse(char *mem, size_t size, /* Don't COW-share the lower part of the THP. */ ret = madvise(mem, size / 2, MADV_DONTFORK); if (ret) { - ksft_perror("MADV_DONTFORK failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("MADV_DONTFORK failed\n"); goto close_comm_pipes; } break; @@ -1303,8 +1233,7 @@ static void do_test_anon_thp_collapse(char *mem, size_t size, ret = fork(); if (ret < 0) { - ksft_perror("fork() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("fork() failed\n"); goto close_comm_pipes; } else if (!ret) { switch (test) { @@ -1338,8 +1267,7 @@ static void do_test_anon_thp_collapse(char *mem, size_t size, */ ret = madvise(mem, size, MADV_DOFORK); if (ret) { - ksft_perror("MADV_DOFORK failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("MADV_DOFORK failed\n"); write(comm_pipes.parent_ready[1], "0", 1); wait(&ret); goto close_comm_pipes; @@ -1349,8 +1277,8 @@ static void do_test_anon_thp_collapse(char *mem, size_t size, /* Collapse before anyone modified the COW-shared page. */ ret = madvise(mem, size, MADV_COLLAPSE); if (ret) { - ksft_perror("MADV_COLLAPSE failed"); - log_test_result(KSFT_SKIP); + ksft_test_result_skip("MADV_COLLAPSE failed: %s\n", + strerror(errno)); write(comm_pipes.parent_ready[1], "0", 1); wait(&ret); goto close_comm_pipes; @@ -1370,10 +1298,7 @@ static void do_test_anon_thp_collapse(char *mem, size_t size, else ret = -EINVAL; - if (!ret) - log_test_result(KSFT_PASS); - else - log_test_result(KSFT_FAIL); + ksft_test_result(!ret, "No leak from parent into child\n"); close_comm_pipes: close_comm_pipes(&comm_pipes); } @@ -1458,7 +1383,7 @@ static void run_anon_thp_test_cases(void) for (i = 0; i < ARRAY_SIZE(anon_thp_test_cases); i++) { struct test_case const *test_case = &anon_thp_test_cases[i]; - log_test_start("%s", test_case->desc); + ksft_print_msg("[RUN] %s\n", test_case->desc); do_run_with_thp(test_case->fn, THP_RUN_PMD, pmdsize); } } @@ -1481,10 +1406,8 @@ static void test_cow(char *mem, const char *smem, size_t size) memset(mem, 0xff, size); /* See if we still read the old values via the other mapping. */ - if (!memcmp(smem, old, size)) - log_test_result(KSFT_PASS); - else - log_test_result(KSFT_FAIL); + ksft_test_result(!memcmp(smem, old, size), + "Other mapping not modified\n"); free(old); } @@ -1502,20 +1425,18 @@ static void run_with_zeropage(non_anon_test_fn fn, const char *desc) { char *mem, *smem, tmp; - log_test_start("%s ... with shared zeropage", desc); + ksft_print_msg("[RUN] %s ... with shared zeropage\n", desc); mem = mmap(NULL, pagesize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); if (mem == MAP_FAILED) { - ksft_perror("mmap() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("mmap() failed\n"); return; } smem = mmap(NULL, pagesize, PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0); if (smem == MAP_FAILED) { - ksft_perror("mmap() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("mmap() failed\n"); goto munmap; } @@ -1536,11 +1457,10 @@ static void run_with_huge_zeropage(non_anon_test_fn fn, const char *desc) size_t mmap_size; int ret; - log_test_start("%s ... with huge zeropage", desc); + ksft_print_msg("[RUN] %s ... with huge zeropage\n", desc); if (!has_huge_zeropage) { - ksft_print_msg("Huge zeropage not enabled\n"); - log_test_result(KSFT_SKIP); + ksft_test_result_skip("Huge zeropage not enabled\n"); return; } @@ -1549,15 +1469,13 @@ static void run_with_huge_zeropage(non_anon_test_fn fn, const char *desc) mmap_mem = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (mmap_mem == MAP_FAILED) { - ksft_perror("mmap() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("mmap() failed\n"); return; } mmap_smem = mmap(NULL, mmap_size, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (mmap_smem == MAP_FAILED) { - ksft_perror("mmap() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("mmap() failed\n"); goto munmap; } @@ -1566,15 +1484,9 @@ static void run_with_huge_zeropage(non_anon_test_fn fn, const char *desc) smem = (char *)(((uintptr_t)mmap_smem + pmdsize) & ~(pmdsize - 1)); ret = madvise(mem, pmdsize, MADV_HUGEPAGE); - if (ret != 0) { - ksft_perror("madvise()"); - log_test_result(KSFT_FAIL); - goto munmap; - } ret |= madvise(smem, pmdsize, MADV_HUGEPAGE); - if (ret != 0) { - ksft_perror("madvise()"); - log_test_result(KSFT_FAIL); + if (ret) { + ksft_test_result_fail("MADV_HUGEPAGE failed\n"); goto munmap; } @@ -1603,33 +1515,29 @@ static void run_with_memfd(non_anon_test_fn fn, const char *desc) char *mem, *smem, tmp; int fd; - log_test_start("%s ... with memfd", desc); + ksft_print_msg("[RUN] %s ... with memfd\n", desc); fd = memfd_create("test", 0); if (fd < 0) { - ksft_perror("memfd_create() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("memfd_create() failed\n"); return; } /* File consists of a single page filled with zeroes. */ if (fallocate(fd, 0, 0, pagesize)) { - ksft_perror("fallocate() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("fallocate() failed\n"); goto close; } /* Create a private mapping of the memfd. */ mem = mmap(NULL, pagesize, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); if (mem == MAP_FAILED) { - ksft_perror("mmap() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("mmap() failed\n"); goto close; } smem = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd, 0); if (smem == MAP_FAILED) { - ksft_perror("mmap() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("mmap() failed\n"); goto munmap; } @@ -1652,40 +1560,35 @@ static void run_with_tmpfile(non_anon_test_fn fn, const char *desc) FILE *file; int fd; - log_test_start("%s ... with tmpfile", desc); + ksft_print_msg("[RUN] %s ... with tmpfile\n", desc); file = tmpfile(); if (!file) { - ksft_perror("tmpfile() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("tmpfile() failed\n"); return; } fd = fileno(file); if (fd < 0) { - ksft_perror("fileno() failed"); - log_test_result(KSFT_SKIP); + ksft_test_result_skip("fileno() failed\n"); return; } /* File consists of a single page filled with zeroes. */ if (fallocate(fd, 0, 0, pagesize)) { - ksft_perror("fallocate() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("fallocate() failed\n"); goto close; } /* Create a private mapping of the memfd. */ mem = mmap(NULL, pagesize, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); if (mem == MAP_FAILED) { - ksft_perror("mmap() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("mmap() failed\n"); goto close; } smem = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd, 0); if (smem == MAP_FAILED) { - ksft_perror("mmap() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("mmap() failed\n"); goto munmap; } @@ -1709,22 +1612,20 @@ static void run_with_memfd_hugetlb(non_anon_test_fn fn, const char *desc, char *mem, *smem, tmp; int fd; - log_test_start("%s ... with memfd hugetlb (%zu kB)", desc, + ksft_print_msg("[RUN] %s ... with memfd hugetlb (%zu kB)\n", desc, hugetlbsize / 1024); flags |= __builtin_ctzll(hugetlbsize) << MFD_HUGE_SHIFT; fd = memfd_create("test", flags); if (fd < 0) { - ksft_perror("memfd_create() failed"); - log_test_result(KSFT_SKIP); + ksft_test_result_skip("memfd_create() failed\n"); return; } /* File consists of a single page filled with zeroes. */ if (fallocate(fd, 0, 0, hugetlbsize)) { - ksft_perror("need more free huge pages"); - log_test_result(KSFT_SKIP); + ksft_test_result_skip("need more free huge pages\n"); goto close; } @@ -1732,14 +1633,12 @@ static void run_with_memfd_hugetlb(non_anon_test_fn fn, const char *desc, mem = mmap(NULL, hugetlbsize, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); if (mem == MAP_FAILED) { - ksft_perror("need more free huge pages"); - log_test_result(KSFT_SKIP); + ksft_test_result_skip("need more free huge pages\n"); goto close; } smem = mmap(NULL, hugetlbsize, PROT_READ, MAP_SHARED, fd, 0); if (smem == MAP_FAILED) { - ksft_perror("mmap() failed"); - log_test_result(KSFT_FAIL); + ksft_test_result_fail("mmap() failed\n"); goto munmap; } -- 2.53.0