From nobody Thu Sep 24 13:41:51 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E3F2323EA97; Thu, 24 Sep 2026 05:00:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790226030; cv=none; b=fqUDZO8jAgKsQFlEIDWNZO1ythKP8AqVJnr+qatZdJDzs/MEr9tEexpDp6q6ObFMEwd/hkGkWM7FKzKw83LcGrt5AFgZZaeYq7KlA4T/UGtezd2JqhJyjSeBy5jdDAJ9mpRoh+riqgDZCmcCSTwBbkLsXEvYX5bkBvtW1Z15k4U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790226030; c=relaxed/simple; bh=L5nbF/ygM6HuNIxRHOeNyQy+FvjqCDI9Shi/Z/9m0n0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mIuYl4X5RlvMxaLeI8YXrPq8kxbBHaELYWbhBZdoy1zJHQ+OAhtHeJRWPKgoz3tvTvFxRh9dPjqhoN7/8iqeklBkgxnGMJjko4CGGlaOUprxtzq3MDa1Ze40GQaRDbz6kURTRbr2hQx6XPF80463OXTmI2mM9KEPivxOVGEtZTU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=sUqoY4g1; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="sUqoY4g1" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7926D152B; Wed, 23 Sep 2026 22:00:23 -0700 (PDT) Received: from a081061.blr.arm.com (a081061.arm.com [10.164.19.84]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1DF093F86C; Wed, 23 Sep 2026 22:00:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1790226026; bh=L5nbF/ygM6HuNIxRHOeNyQy+FvjqCDI9Shi/Z/9m0n0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sUqoY4g1iDVZAm6TWIuCJmbh07Q5QN8TEO4xBsJ7QVQmebsW15rffjh4/wrP02cTI ADwQCRcFifn1lZoETVo+UhbMBubrJD8rhrOOdMnK0saJOtMEtGpNIe2MZ5UPaufEHH ulGcOYHhCHt0mXgOKliL4UXNqEtkQlHQ9Qrtivrg= From: Sarthak Sharma To: Andrew Morton , David Hildenbrand Cc: Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Shuah Khan , John Hubbard , Kalesh Singh , Anshuman Khandual , Park Tae-sun , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Sarthak Sharma Subject: [PATCH RESEND 1/9] selftests/mm: mremap_test: use kselftest helpers Date: Thu, 24 Sep 2026 10:30:01 +0530 Message-ID: <20260924050009.19974-2-sarthak.sharma@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260924050009.19974-1-sarthak.sharma@arm.com> References: <20260924050009.19974-1-sarthak.sharma@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" mremap_test currently uses a lot of fprintf() and perror() calls. It also uses a variable "failures" to track the number of failed table driven tests. Use ksft_print_msg() and ksft_perror() for diagnostics. Remove the variable "failures" and let kselftest counters handle the final exit status. Use ksft_finished() at the end instead of manually checking if failures > 0. Replace if (success) ksft_test_result_pass(...); else ksft_test_result_fail(...); calls with ksft_test_result(success, ...); Also correct the duplicated "mremap" in "mremap move within range" and the spelling of "dontunmap". Signed-off-by: Sarthak Sharma --- tools/testing/selftests/mm/mremap_test.c | 222 +++++++++-------------- 1 file changed, 89 insertions(+), 133 deletions(-) diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selft= ests/mm/mremap_test.c index 97abf4713cc5..5532d3151ed0 100644 --- a/tools/testing/selftests/mm/mremap_test.c +++ b/tools/testing/selftests/mm/mremap_test.c @@ -257,10 +257,7 @@ static void mremap_expand_merge(FILE *maps_fp, unsigne= d long page_size) munmap(start, 3 * page_size); =20 out: - if (success) - ksft_test_result_pass("%s\n", test_name); - else - ksft_test_result_fail("%s\n", test_name); + ksft_test_result(success, "%s\n", test_name); } =20 /* @@ -297,10 +294,7 @@ static void mremap_expand_merge_offset(FILE *maps_fp, = unsigned long page_size) munmap(start, 3 * page_size); =20 out: - if (success) - ksft_test_result_pass("%s\n", test_name); - else - ksft_test_result_fail("%s\n", test_name); + ksft_test_result(success, "%s\n", test_name); } =20 /* @@ -319,7 +313,7 @@ static void mremap_expand_merge_offset(FILE *maps_fp, u= nsigned long page_size) */ static void mremap_move_within_range(unsigned int pattern_seed, char *rand= _addr) { - char *test_name =3D "mremap mremap move within range"; + char *test_name =3D "mremap move within range"; void *src, *dest; unsigned int i, success =3D 1; =20 @@ -327,7 +321,7 @@ static void mremap_move_within_range(unsigned int patte= rn_seed, char *rand_addr) void *ptr =3D mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (ptr =3D=3D MAP_FAILED) { - perror("mmap"); + ksft_perror("mmap"); success =3D 0; goto out; } @@ -344,7 +338,7 @@ static void mremap_move_within_range(unsigned int patte= rn_seed, char *rand_addr) void *new_ptr =3D mremap(src + SIZE_MB(1), SIZE_MB(1), SIZE_MB(1), MREMAP_MAYMOVE | MREMAP_FIXED, dest + SIZE_MB(1)); if (new_ptr =3D=3D MAP_FAILED) { - perror("mremap"); + ksft_perror("mremap"); success =3D 0; goto out; } @@ -365,12 +359,9 @@ static void mremap_move_within_range(unsigned int patt= ern_seed, char *rand_addr) =20 out: if (munmap(ptr, size) =3D=3D -1) - perror("munmap"); + ksft_perror("munmap"); =20 - if (success) - ksft_test_result_pass("%s\n", test_name); - else - ksft_test_result_fail("%s\n", test_name); + ksft_test_result(success, "%s\n", test_name); } =20 static bool is_multiple_vma_range_ok(unsigned int pattern_seed, @@ -415,7 +406,7 @@ static void mremap_move_multiple_vmas(unsigned int patt= ern_seed, ptr =3D mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); if (ptr =3D=3D MAP_FAILED) { - perror("mmap"); + ksft_perror("mmap"); success =3D false; goto out; } @@ -423,12 +414,12 @@ static void mremap_move_multiple_vmas(unsigned int pa= ttern_seed, tgt_ptr =3D mmap(NULL, 2 * size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); if (tgt_ptr =3D=3D MAP_FAILED) { - perror("mmap"); + ksft_perror("mmap"); success =3D false; goto out; } if (munmap(tgt_ptr, 2 * size)) { - perror("munmap"); + ksft_perror("munmap"); success =3D false; goto out_unmap; } @@ -446,7 +437,7 @@ static void mremap_move_multiple_vmas(unsigned int patt= ern_seed, continue; =20 if (munmap(&ptr[i * page_size], page_size)) { - perror("munmap"); + ksft_perror("munmap"); success =3D false; goto out_unmap; } @@ -466,7 +457,7 @@ static void mremap_move_multiple_vmas(unsigned int patt= ern_seed, =20 /* First, just move the whole thing. */ if (mremap(ptr, size, size, mremap_flags, tgt_ptr) =3D=3D MAP_FAILED) { - perror("mremap"); + ksft_perror("mremap"); success =3D false; goto out_unmap; } @@ -479,7 +470,7 @@ static void mremap_move_multiple_vmas(unsigned int patt= ern_seed, /* Move next to itself. */ if (mremap(tgt_ptr, size, size, mremap_flags, &tgt_ptr[size]) =3D=3D MAP_FAILED) { - perror("mremap"); + ksft_perror("mremap"); success =3D false; goto out_unmap; } @@ -492,14 +483,14 @@ static void mremap_move_multiple_vmas(unsigned int pa= ttern_seed, /* Map a range to overwrite. */ if (mmap(tgt_ptr, size, PROT_NONE, MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0) =3D=3D MAP_FAILED) { - perror("mmap tgt"); + ksft_perror("mmap tgt"); success =3D false; goto out_unmap; } /* Move and overwrite. */ if (mremap(&tgt_ptr[size], size, size, mremap_flags, tgt_ptr) =3D=3D MAP_FAILED) { - perror("mremap"); + ksft_perror("mremap"); success =3D false; goto out_unmap; } @@ -511,17 +502,12 @@ static void mremap_move_multiple_vmas(unsigned int pa= ttern_seed, =20 out_unmap: if (munmap(tgt_ptr, 2 * size)) - perror("munmap tgt"); + ksft_perror("munmap tgt"); if (munmap(ptr, size)) - perror("munmap src"); + ksft_perror("munmap src"); =20 out: - if (success) - ksft_test_result_pass("%s%s\n", test_name, - dont_unmap ? " [dontunnmap]" : ""); - else - ksft_test_result_fail("%s%s\n", test_name, - dont_unmap ? " [dontunnmap]" : ""); + ksft_test_result(success, "%s%s\n", test_name, dont_unmap ? " [dontunmap]= " : ""); } =20 static void mremap_shrink_multiple_vmas(unsigned long page_size, @@ -537,7 +523,7 @@ static void mremap_shrink_multiple_vmas(unsigned long p= age_size, ptr =3D mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); if (ptr =3D=3D MAP_FAILED) { - perror("mmap"); + ksft_perror("mmap"); success =3D false; goto out; } @@ -545,12 +531,12 @@ static void mremap_shrink_multiple_vmas(unsigned long= page_size, tgt_ptr =3D mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); if (tgt_ptr =3D=3D MAP_FAILED) { - perror("mmap"); + ksft_perror("mmap"); success =3D false; goto out; } if (munmap(tgt_ptr, size)) { - perror("munmap"); + ksft_perror("munmap"); success =3D false; goto out_unmap; } @@ -564,7 +550,7 @@ static void mremap_shrink_multiple_vmas(unsigned long p= age_size, */ for (i =3D 1; i < 10; i +=3D 2) { if (munmap(&ptr[i * page_size], page_size)) { - perror("munmap"); + ksft_perror("munmap"); success =3D false; goto out_unmap; } @@ -584,23 +570,18 @@ static void mremap_shrink_multiple_vmas(unsigned long= page_size, tgt_ptr); =20 if (res =3D=3D MAP_FAILED) { - perror("mremap"); + ksft_perror("mremap"); success =3D false; goto out_unmap; } =20 out_unmap: if (munmap(tgt_ptr, size)) - perror("munmap tgt"); + ksft_perror("munmap tgt"); if (munmap(ptr, size)) - perror("munmap src"); + ksft_perror("munmap src"); out: - if (success) - ksft_test_result_pass("%s%s\n", test_name, - inplace ? " [inplace]" : ""); - else - ksft_test_result_fail("%s%s\n", test_name, - inplace ? " [inplace]" : ""); + ksft_test_result(success, "%s%s\n", test_name, inplace ? " [inplace]" : "= "); } =20 static void mremap_move_multiple_vmas_split(unsigned int pattern_seed, @@ -620,7 +601,7 @@ static void mremap_move_multiple_vmas_split(unsigned in= t pattern_seed, ptr =3D mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); if (ptr =3D=3D MAP_FAILED) { - perror("mmap"); + ksft_perror("mmap"); success =3D false; goto out; } @@ -628,12 +609,12 @@ static void mremap_move_multiple_vmas_split(unsigned = int pattern_seed, tgt_ptr =3D mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); if (tgt_ptr =3D=3D MAP_FAILED) { - perror("mmap"); + ksft_perror("mmap"); success =3D false; goto out; } if (munmap(tgt_ptr, size)) { - perror("munmap"); + ksft_perror("munmap"); success =3D false; goto out_unmap; } @@ -647,7 +628,7 @@ static void mremap_move_multiple_vmas_split(unsigned in= t pattern_seed, * 0 1 2 3 4 5 6 7 8 9 pattern offset */ if (munmap(&ptr[5 * page_size], page_size)) { - perror("munmap"); + ksft_perror("munmap"); success =3D false; goto out_unmap; } @@ -683,7 +664,7 @@ static void mremap_move_multiple_vmas_split(unsigned in= t pattern_seed, */ if (mremap(&ptr[2 * page_size], size - 3 * page_size, size - 3 * page_siz= e, mremap_flags, tgt_ptr) =3D=3D MAP_FAILED) { - perror("mremap"); + ksft_perror("mremap"); success =3D false; goto out_unmap; } @@ -714,16 +695,11 @@ static void mremap_move_multiple_vmas_split(unsigned = int pattern_seed, =20 out_unmap: if (munmap(tgt_ptr, size)) - perror("munmap tgt"); + ksft_perror("munmap tgt"); if (munmap(ptr, size)) - perror("munmap src"); + ksft_perror("munmap src"); out: - if (success) - ksft_test_result_pass("%s%s\n", test_name, - dont_unmap ? " [dontunnmap]" : ""); - else - ksft_test_result_fail("%s%s\n", test_name, - dont_unmap ? " [dontunnmap]" : ""); + ksft_test_result(success, "%s%s\n", test_name, dont_unmap ? " [dontunmap]= " : ""); } =20 #ifdef __NR_userfaultfd @@ -744,16 +720,16 @@ static void mremap_move_multi_invalid_vmas(FILE *maps= _fp, uffd =3D syscall(__NR_userfaultfd, O_NONBLOCK); if (uffd =3D=3D -1) { err =3D errno; - perror("userfaultfd"); + ksft_perror("userfaultfd"); if (err =3D=3D EPERM) { - ksft_test_result_skip("%s - missing uffd", test_name); + ksft_test_result_skip("%s - missing uffd\n", test_name); return; } success =3D false; goto out; } if (ioctl(uffd, UFFDIO_API, &api)) { - perror("ioctl UFFDIO_API"); + ksft_perror("ioctl UFFDIO_API"); success =3D false; goto out_close_uffd; } @@ -761,19 +737,19 @@ static void mremap_move_multi_invalid_vmas(FILE *maps= _fp, ptr =3D mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); if (ptr =3D=3D MAP_FAILED) { - perror("mmap"); + ksft_perror("mmap"); success =3D false; goto out_close_uffd; } =20 tgt_ptr =3D mmap(NULL, size, PROT_NONE, MAP_PRIVATE | MAP_ANON, -1, 0); if (tgt_ptr =3D=3D MAP_FAILED) { - perror("mmap"); + ksft_perror("mmap"); success =3D false; goto out_close_uffd; } if (munmap(tgt_ptr, size)) { - perror("munmap"); + ksft_perror("munmap"); success =3D false; goto out_unmap; } @@ -799,12 +775,12 @@ static void mremap_move_multi_invalid_vmas(FILE *maps= _fp, }; =20 if (ioctl(uffd, UFFDIO_REGISTER, ®) =3D=3D -1) { - perror("ioctl UFFDIO_REGISTER"); + ksft_perror("ioctl UFFDIO_REGISTER"); success =3D false; goto out_unmap; } if (munmap(unmap_ptr, page_size)) { - perror("munmap"); + ksft_perror("munmap"); success =3D false; goto out_unmap; } @@ -819,19 +795,18 @@ static void mremap_move_multi_invalid_vmas(FILE *maps= _fp, res =3D mremap(ptr, size, size, MREMAP_MAYMOVE | MREMAP_FIXED, tgt_ptr); err =3D errno; if (res !=3D MAP_FAILED) { - fprintf(stderr, "mremap() succeeded for multi VMA uffd armed\n"); + ksft_print_msg("mremap() succeeded for multi VMA uffd armed\n"); success =3D false; goto out_unmap; } if (err !=3D EFAULT) { errno =3D err; - perror("mremap() unexpected error"); + ksft_perror("mremap() unexpected error"); success =3D false; goto out_unmap; } if (is_ptr_mapped(maps_fp, tgt_ptr, page_size)) { - fprintf(stderr, - "Invalid uffd-armed VMA at start of multi range moved\n"); + ksft_print_msg("Invalid uffd-armed VMA at start of multi range moved\n"); success =3D false; goto out_unmap; } @@ -843,7 +818,7 @@ static void mremap_move_multi_invalid_vmas(FILE *maps_f= p, res =3D mremap(ptr, page_size, page_size, MREMAP_MAYMOVE | MREMAP_FIXED, tgt_ptr); if (res =3D=3D MAP_FAILED) { - perror("mremap single invalid-multi VMA"); + ksft_perror("mremap single invalid-multi VMA"); success =3D false; goto out_unmap; } @@ -853,14 +828,14 @@ static void mremap_move_multi_invalid_vmas(FILE *maps= _fp, * move valid) VMA at the start of ptr range. */ if (munmap(tgt_ptr, page_size)) { - perror("munmap"); + ksft_perror("munmap"); success =3D false; goto out_unmap; } res =3D mmap(ptr, page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0); if (res =3D=3D MAP_FAILED) { - perror("mmap"); + ksft_perror("mmap"); success =3D false; goto out_unmap; } @@ -872,18 +847,18 @@ static void mremap_move_multi_invalid_vmas(FILE *maps= _fp, res =3D mremap(ptr, size, size, MREMAP_MAYMOVE | MREMAP_FIXED, tgt_ptr); err =3D errno; if (res !=3D MAP_FAILED) { - fprintf(stderr, "mremap() succeeded for multi VMA uffd armed\n"); + ksft_print_msg("mremap() succeeded for multi VMA uffd armed\n"); success =3D false; goto out_unmap; } if (err !=3D EFAULT) { errno =3D err; - perror("mremap() unexpected error"); + ksft_perror("mremap() unexpected error"); success =3D false; goto out_unmap; } if (!is_ptr_mapped(maps_fp, tgt_ptr, page_size)) { - fprintf(stderr, "Valid VMA not moved\n"); + ksft_print_msg("Valid VMA not moved\n"); success =3D false; goto out_unmap; } @@ -894,12 +869,12 @@ static void mremap_move_multi_invalid_vmas(FILE *maps= _fp, * multi-move VMAs. */ if (munmap(tgt_ptr, page_size)) { - perror("munmap"); + ksft_perror("munmap"); success =3D false; goto out_unmap; } if (munmap(ptr, size - 2 * page_size)) { - perror("munmap"); + ksft_perror("munmap"); success =3D false; goto out_unmap; } @@ -908,7 +883,7 @@ static void mremap_move_multi_invalid_vmas(FILE *maps_f= p, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0); if (res =3D=3D MAP_FAILED) { - perror("mmap"); + ksft_perror("mmap"); success =3D false; goto out_unmap; } @@ -921,13 +896,13 @@ static void mremap_move_multi_invalid_vmas(FILE *maps= _fp, res =3D mremap(ptr, size, size, MREMAP_MAYMOVE | MREMAP_FIXED, tgt_ptr); err =3D errno; if (res !=3D MAP_FAILED) { - fprintf(stderr, "mremap() succeeded for multi VMA uffd armed\n"); + ksft_print_msg("mremap() succeeded for multi VMA uffd armed\n"); success =3D false; goto out_unmap; } if (err !=3D EFAULT) { errno =3D err; - perror("mremap() unexpected error"); + ksft_perror("mremap() unexpected error"); success =3D false; goto out_unmap; } @@ -937,11 +912,11 @@ static void mremap_move_multi_invalid_vmas(FILE *maps= _fp, &tgt_ptr[i * page_size], page_size); =20 if (i < 8 && !is_mapped) { - fprintf(stderr, "Valid VMA not moved at %d\n", i); + ksft_print_msg("Valid VMA not moved at %d\n", i); success =3D false; goto out_unmap; } else if (i =3D=3D 8 && is_mapped) { - fprintf(stderr, "Invalid VMA moved at %d\n", i); + ksft_print_msg("Invalid VMA moved at %d\n", i); success =3D false; goto out_unmap; } @@ -949,23 +924,20 @@ static void mremap_move_multi_invalid_vmas(FILE *maps= _fp, =20 out_unmap: if (munmap(tgt_ptr, size)) - perror("munmap tgt"); + ksft_perror("munmap tgt"); if (munmap(ptr, size)) - perror("munmap src"); + ksft_perror("munmap src"); out_close_uffd: close(uffd); out: - if (success) - ksft_test_result_pass("%s\n", test_name); - else - ksft_test_result_fail("%s\n", test_name); + ksft_test_result(success, "%s\n", test_name); } #else static void mremap_move_multi_invalid_vmas(FILE *maps_fp, unsigned long pa= ge_size) { char *test_name =3D "mremap move multiple invalid vmas"; =20 - ksft_test_result_skip("%s - missing uffd", test_name); + ksft_test_result_skip("%s - missing uffd\n", test_name); } #endif /* __NR_userfaultfd */ =20 @@ -1124,7 +1096,7 @@ static void mremap_move_1mb_from_start(unsigned int p= attern_seed, void *new_ptr =3D mremap(src + SIZE_MB(1), SIZE_MB(1), SIZE_MB(1), MREMAP_MAYMOVE | MREMAP_FIXED, dest + SIZE_MB(1)); if (new_ptr =3D=3D MAP_FAILED) { - perror("mremap"); + ksft_perror("mremap"); success =3D 0; goto out; } @@ -1145,59 +1117,49 @@ static void mremap_move_1mb_from_start(unsigned int= pattern_seed, =20 out: if (src && munmap(src, c.region_size) =3D=3D -1) - perror("munmap src"); + ksft_perror("munmap src"); =20 if (dest && munmap(dest, c.region_size) =3D=3D -1) - perror("munmap dest"); + ksft_perror("munmap dest"); =20 - if (success) - ksft_test_result_pass("%s\n", test_name); - else - ksft_test_result_fail("%s\n", test_name); + ksft_test_result(success, "%s\n", test_name); } =20 -static void run_mremap_test_case(struct test test_case, int *failures, - unsigned int threshold_mb, +static void run_mremap_test_case(struct test test_case, unsigned int thres= hold_mb, char *rand_addr) { long long remap_time =3D remap_region(test_case.config, threshold_mb, rand_addr); =20 if (remap_time < 0) { - if (test_case.expect_failure) { - ksft_print_msg("%s: expected mremap failure\n", - test_case.name); - ksft_test_result_xfail("%s\n", test_case.name); - } else { + if (test_case.expect_failure) + ksft_test_result_xfail("%s: expected mremap failure\n", + test_case.name); + else ksft_test_result_fail("%s\n", test_case.name); - *failures +=3D 1; - } } else { /* * Comparing mremap time is only applicable if entire region * was faulted in. */ if (threshold_mb =3D=3D VALIDATION_NO_THRESHOLD || - test_case.config.region_size <=3D threshold_mb * _1MB) { - ksft_print_msg("%s: mremap time: %12lldns\n", - test_case.name, remap_time); + test_case.config.region_size <=3D threshold_mb * _1MB) + ksft_test_result_pass("%s: mremap time: %12lldns\n", + test_case.name, remap_time); + else ksft_test_result_pass("%s\n", test_case.name); - } else { - ksft_test_result_pass("%s\n", test_case.name); - } } } =20 static void usage(const char *cmd) { - fprintf(stderr, - "Usage: %s [[-t ] [-p ]]\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.\n" - " \t The default threshold used is 4MB.\n" - "-p\t provide a seed to generate the random pattern for\n" - " \t validating the remapped region.\n", cmd); + ksft_print_msg("Usage: %s [[-t ] [-p ]]\n", c= md); + ksft_print_msg("-t\t only validate threshold_mb of the remapped region\n"= ); + ksft_print_msg(" \t if 0 is supplied no threshold is used; all tests\n"); + ksft_print_msg(" \t are run and remapped regions validated fully.\n"); + ksft_print_msg(" \t The default threshold used is 4MB.\n"); + ksft_print_msg("-p\t provide a seed to generate the random pattern for\n"= ); + ksft_print_msg(" \t validating the remapped region.\n"); } =20 static int parse_args(int argc, char **argv, unsigned int *threshold_mb, @@ -1232,7 +1194,6 @@ static int parse_args(int argc, char **argv, unsigned= int *threshold_mb, #define MAX_PERF_TEST 3 int main(int argc, char **argv) { - int failures =3D 0; unsigned int i; int run_perf_tests; unsigned int threshold_mb =3D VALIDATION_DEFAULT_THRESHOLD; @@ -1260,7 +1221,7 @@ int main(int argc, char **argv) pattern_seed =3D (unsigned int) time(&t); =20 if (parse_args(argc, argv, &threshold_mb, &pattern_seed) < 0) - exit(EXIT_FAILURE); + ksft_exit_fail_msg("Invalid arguments\n"); =20 ksft_print_msg("Test configs:\n"); ksft_print_msg("threshold_mb=3D%u\n", threshold_mb); @@ -1282,7 +1243,7 @@ int main(int argc, char **argv) rand_addr =3D (char *)mmap(NULL, rand_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (rand_addr =3D=3D MAP_FAILED) { - perror("mmap"); + ksft_perror("mmap"); ksft_exit_fail_msg("cannot mmap rand_addr\n"); } =20 @@ -1361,8 +1322,7 @@ int main(int argc, char **argv) ARRAY_SIZE(perf_test_cases) : 0) + num_expand_tests + num_misc_tes= ts); =20 for (i =3D 0; i < ARRAY_SIZE(test_cases); i++) - run_mremap_test_case(test_cases[i], &failures, threshold_mb, - rand_addr); + run_mremap_test_case(test_cases[i], threshold_mb, rand_addr); =20 maps_fp =3D fopen("/proc/self/maps", "r"); =20 @@ -1387,18 +1347,14 @@ int main(int argc, char **argv) fclose(maps_fp); =20 if (run_perf_tests) { - ksft_print_msg("\n%s\n", - "mremap HAVE_MOVE_PMD/PUD optimization time comparison for 1GB region:"= ); + ksft_print_msg("%s\n", + "mremap HAVE_MOVE_PMD/PUD optimization time comparison for 1GB r= egion:"); for (i =3D 0; i < ARRAY_SIZE(perf_test_cases); i++) - run_mremap_test_case(perf_test_cases[i], &failures, - threshold_mb, + run_mremap_test_case(perf_test_cases[i], threshold_mb, rand_addr); } =20 munmap(rand_addr, rand_size); =20 - if (failures > 0) - ksft_exit_fail(); - else - ksft_exit_pass(); + ksft_finished(); } --=20 2.53.0 From nobody Thu Sep 24 13:41:51 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 29EE3357D07; Thu, 24 Sep 2026 05:00:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790226034; cv=none; b=rWiN8SXvT8Vt0sH6H9s8wm5J7TFo+JCwjsFljuNpvnjd8JfihQaChVyw/ZhTLMmVP8qsbNLctyfquUlh+Yz6Nd4JuNr2B2u595OcznE3rgq1gbFpDzINWoipKJ8r1Q0dB+61IpUC9HzTrN/dNDHPrFVVtosPhRDV8yl9Ozg9oIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790226034; c=relaxed/simple; bh=byGcsqmsm/N1R0xTXpl1j3TGY+DHgMvLIEITNN4nqJw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F5grEns3kveURVvjAwVouKe58+QEjat7qXmq9Dt0hTPwoCcmb57oCcfWaVPT9EAMidTJcr2vkVhf5yLBKrKTCkPH+sN91qYrsXkZhYgANMM2pNI5JAbCwZ7e5ssSJni7oTsuDMcLRbf8RjEnalNDm4Y25eexgBBPVatjkvvYMUo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=LuFybSna; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="LuFybSna" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 986F01650; Wed, 23 Sep 2026 22:00:28 -0700 (PDT) Received: from a081061.blr.arm.com (a081061.arm.com [10.164.19.84]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6D7A93F86C; Wed, 23 Sep 2026 22:00:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1790226032; bh=byGcsqmsm/N1R0xTXpl1j3TGY+DHgMvLIEITNN4nqJw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LuFybSnaBK6aX9A1irXAYXSeNMGzh4XW6ctNbILwMrWmmAnlhIn77jfPGpRYPkd7A RqxBLqNFn91VSuvKtcW7w9vDPCCRho8LPF1Cqfao4evfSKjU1lUzqVLmAxCi48iGOD DaAMkeqiYABjim6BmgEzJZFnhZyAjA2oYemwlcX8= From: Sarthak Sharma To: Andrew Morton , David Hildenbrand Cc: Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Shuah Khan , John Hubbard , Kalesh Singh , Anshuman Khandual , Park Tae-sun , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Sarthak Sharma Subject: [PATCH RESEND 2/9] selftests/mm: mremap_test: skip test when userfaultfd is unavailable Date: Thu, 24 Sep 2026 10:30:02 +0530 Message-ID: <20260924050009.19974-3-sarthak.sharma@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260924050009.19974-1-sarthak.sharma@arm.com> References: <20260924050009.19974-1-sarthak.sharma@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The userfaultfd syscall can return ENOSYS even when __NR_userfaultfd is defined by the architecture headers, for example when the kernel is built without CONFIG_USERFAULTFD. The test currently skips for EPERM when the caller lacks permission to use userfaultfd but treats ENOSYS as a failure. Handle ENOSYS like EPERM and skip the mremap_move_multi_invalid_vmas() test when userfaultfd syscall is not implemented. Fixes: 742d3663a577 ("selftests/mm: add test for invalid multi VMA operatio= ns") Signed-off-by: Sarthak Sharma --- tools/testing/selftests/mm/mremap_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selft= ests/mm/mremap_test.c index 5532d3151ed0..a5813a5e8f5b 100644 --- a/tools/testing/selftests/mm/mremap_test.c +++ b/tools/testing/selftests/mm/mremap_test.c @@ -721,7 +721,7 @@ static void mremap_move_multi_invalid_vmas(FILE *maps_f= p, if (uffd =3D=3D -1) { err =3D errno; ksft_perror("userfaultfd"); - if (err =3D=3D EPERM) { + if (err =3D=3D EPERM || err =3D=3D ENOSYS) { ksft_test_result_skip("%s - missing uffd\n", test_name); return; } --=20 2.53.0 From nobody Thu Sep 24 13:41:51 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CA7A02C11E4; Thu, 24 Sep 2026 05:00:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790226039; cv=none; b=ChyYZ3G0cIZi2RRGxdceVCBGs6Zy/f1Au19cqsLOvr1PS6eBUdl5J2JtrFEGb+qeOXgcRGdyWop0tFUvg6p7HNOLxMMaRaBe+yNgD6WOKIq2jwLDJh9T6LltU4+gAa0Pyamomw+ZhzGHt/MPPQDcpdd+bvy8BQa94KvRWRj/PQ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790226039; c=relaxed/simple; bh=8FIDVRnmopNIAGdnpQIyQoSfJVd6Jc6AKeojxfKddjA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HKfVOvvBWI+f2QCmAGzf4TtBw+4JNyIP99X4LTRc59hbdHkL2s4IzlwjAJ8RgM0p9ZS0jQYIiS6bM2Oou6hbJZFBpP1Vx+gRpFH/ZJVvxZmOpDVHZLfAq5SO+m7dy+a+Oxk8HORTCw7kLuR3ByV6rKMGZS1/OHcPPMP3+J17Xd4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=WPI4qLvw; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="WPI4qLvw" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 95EF11682; Wed, 23 Sep 2026 22:00:33 -0700 (PDT) Received: from a081061.blr.arm.com (a081061.arm.com [10.164.19.84]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8C1ED3F86C; Wed, 23 Sep 2026 22:00:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1790226037; bh=8FIDVRnmopNIAGdnpQIyQoSfJVd6Jc6AKeojxfKddjA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WPI4qLvwdUzdDaAcHsYAnuy46GwN3Scp+FIR9nAF8J8yclUql//QYe1+s5aFc7zvD X/ZhT7lbND1uaA60GzejcJFO5ly9j1U33hHCgBzWA6BwGZ2jztR5JpNh9RdWVyhq3J uH2JDurHmjmfc74vC3p4am9hwXvvm/FM3KAYKEQE= From: Sarthak Sharma To: Andrew Morton , David Hildenbrand Cc: Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Shuah Khan , John Hubbard , Kalesh Singh , Anshuman Khandual , Park Tae-sun , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Sarthak Sharma Subject: [PATCH RESEND 3/9] selftests/mm: mremap_test: fail unexpected mremap successes Date: Thu, 24 Sep 2026 10:30:03 +0530 Message-ID: <20260924050009.19974-4-sarthak.sharma@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260924050009.19974-1-sarthak.sharma@arm.com> References: <20260924050009.19974-1-sarthak.sharma@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" run_mremap_test_case() reports a test as pass when remap_region() succeeds. But if the test was expecting failure and remap succeeds, it should be treated as a failure and not a success. Check test_case.expect_failure on the successful remap path. If it expected failure, report a failure instead of success. Fixes: 7df666253f26 ("kselftests: vm: add mremap tests") Signed-off-by: Sarthak Sharma --- tools/testing/selftests/mm/mremap_test.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selft= ests/mm/mremap_test.c index a5813a5e8f5b..ba9b7f7566d0 100644 --- a/tools/testing/selftests/mm/mremap_test.c +++ b/tools/testing/selftests/mm/mremap_test.c @@ -1138,12 +1138,15 @@ static void run_mremap_test_case(struct test test_c= ase, unsigned int threshold_m else ksft_test_result_fail("%s\n", test_case.name); } else { + if (test_case.expect_failure) + ksft_test_result_fail("%s: unexpected mremap success\n", + test_case.name); /* * Comparing mremap time is only applicable if entire region * was faulted in. */ - if (threshold_mb =3D=3D VALIDATION_NO_THRESHOLD || - test_case.config.region_size <=3D threshold_mb * _1MB) + else if (threshold_mb =3D=3D VALIDATION_NO_THRESHOLD || + test_case.config.region_size <=3D threshold_mb * _1MB) ksft_test_result_pass("%s: mremap time: %12lldns\n", test_case.name, remap_time); else --=20 2.53.0 From nobody Thu Sep 24 13:41:51 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 84EA9388E55; Thu, 24 Sep 2026 05:00:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790226047; cv=none; b=A9gSu+9nrRruk1bt/8Nc7tqYO4M3rRTNdnZcMWRav6EZRCyJ8J1VgxgijuUeO1Apnt52vYtVerq9ToX3QJlZ5YwO794NeE0vZXF+jab002i47yJB9nP+pcp81wdy4MZXnJm0KwLBFm150wPGvVV77Fkge0BIGS0z1Frkxx3B3y0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790226047; c=relaxed/simple; bh=EmkguL785IIXMYOOGQrzJ/6/Y6ZZO1ERK0FFTi6WP+s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HVZF/Fao1f8xFnka3hYK62zCN8nm8ldgRkqyxOX5vgc5ezLjaJ2JxuZX1to1vx7G6X1MOi0kNRO2ZumL+jjKbmSoXJSaMYyNZfYBjwqmvI5RaupRo4vbVRZ0O8CCwhRc/XSSq8twUCqDlDXVpgCeURfMp6W4d9oCzwaDGvcDSso= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=VoQ3Sil+; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="VoQ3Sil+" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DA0191476; Wed, 23 Sep 2026 22:00:38 -0700 (PDT) Received: from a081061.blr.arm.com (a081061.arm.com [10.164.19.84]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A171A3F86C; Wed, 23 Sep 2026 22:00:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1790226042; bh=EmkguL785IIXMYOOGQrzJ/6/Y6ZZO1ERK0FFTi6WP+s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VoQ3Sil+u+bZMg3gQzQxSDAl5ZC1MWS/6iqveSX+OWgskIoqG3Ry90TTIuPJS8Cn6 i7jwJdERAIbLo+84agDoFnJTIV0pU5Yti+FWAWyXM8OA1nzzLZwAbALQKXmfP+YJb5 LpEYezMaDIsIuuEYUagvFmvju0a9K7vjwJJ0NBag= From: Sarthak Sharma To: Andrew Morton , David Hildenbrand Cc: Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Shuah Khan , John Hubbard , Kalesh Singh , Anshuman Khandual , Park Tae-sun , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Sarthak Sharma Subject: [PATCH RESEND 4/9] selftests/mm: mremap_test: correct multiple VMA range size Date: Thu, 24 Sep 2026 10:30:04 +0530 Message-ID: <20260924050009.19974-5-sarthak.sharma@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260924050009.19974-1-sarthak.sharma@arm.com> References: <20260924050009.19974-1-sarthak.sharma@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In the test mremap_move_multiple_vmas(), pages 4 to 6 form a single VMA. But the helper function is_multiple_vma_range_ok() checks pages 4 and 5 as one range and treats page 6 separately. Check all three pages as a single range and skip the page 6 iteration to match the actual VMA layout. Fixes: d53f248258e1 ("tools/testing/selftests: extend mremap_test to test m= ulti-VMA mremap") Signed-off-by: Sarthak Sharma --- tools/testing/selftests/mm/mremap_test.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selft= ests/mm/mremap_test.c index ba9b7f7566d0..869df22d46db 100644 --- a/tools/testing/selftests/mm/mremap_test.c +++ b/tools/testing/selftests/mm/mremap_test.c @@ -373,7 +373,10 @@ static bool is_multiple_vma_range_ok(unsigned int patt= ern_seed, for (i =3D 0; i <=3D 10; i +=3D 2) { int j; char *buf =3D &ptr[i * page_size]; - size_t size =3D i =3D=3D 4 ? 2 * page_size : page_size; + size_t size =3D i =3D=3D 4 ? 3 * page_size : page_size; + + if (i =3D=3D 6) + continue; =20 for (j =3D 0; j < size; j++) { char chr =3D rand(); --=20 2.53.0 From nobody Thu Sep 24 13:41:51 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0A29839DBCB; Thu, 24 Sep 2026 05:00:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790226049; cv=none; b=ZedzdQfwefiVJfaW2TVK736Q0dyWry2wO+GESXNSN7M9fHzDyHLjFFYv12jfxAaRnD3tt73nvdSXlTFGjZTaMew0SvtJiZSOxY62iWBPsyg5FuNq3nTv4/+jEs4d22RM4RF0bS4tAf2TNq0wQSrZZcCKNwiHcFN1UmyIxkGJy7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790226049; c=relaxed/simple; bh=EBDy9kiw0ETUnAFTA1nwc+a5WpGr3AW/5ybohYQb77I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fD1sC6DybzzOYXIBz6hcZ4+SgWdd079C0KyG7L0MTvn0I/ya6J+dGuzPXEy9TTMpf/mENyz9fg+BsojwjKo1V3IjQJjPm2Q5EYkeGA2B6Dd0U96BN023GL71YJ245tpLH/MtKgqxgYBvATww7ilnEfbFvDLSsObc06IboUVbW0g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=Map4q1no; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="Map4q1no" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E2C251476; Wed, 23 Sep 2026 22:00:43 -0700 (PDT) Received: from a081061.blr.arm.com (a081061.arm.com [10.164.19.84]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C034F3F86C; Wed, 23 Sep 2026 22:00:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1790226047; bh=EBDy9kiw0ETUnAFTA1nwc+a5WpGr3AW/5ybohYQb77I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Map4q1noY0JZiQg7ztyHbCyb1VVRiWXb3iObj+Jv7GRIRqudDYzFyY2KII51sgmAN g20uQxA6AwB+YZCD7D4HOIdsj6OvV644C5IpYIiFpG/hL+j2xeq7Vz08nqaRVACKUT jkSnuOUmBJZa7Jsf5TZV91aoPhsVSa3FjiH3X5FA= From: Sarthak Sharma To: Andrew Morton , David Hildenbrand Cc: Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Shuah Khan , John Hubbard , Kalesh Singh , Anshuman Khandual , Park Tae-sun , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Sarthak Sharma Subject: [PATCH RESEND 5/9] selftests/mm: mremap_test: fail on data corruption Date: Thu, 24 Sep 2026 10:30:05 +0530 Message-ID: <20260924050009.19974-6-sarthak.sharma@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260924050009.19974-1-sarthak.sharma@arm.com> References: <20260924050009.19974-1-sarthak.sharma@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In mremap_move_multiple_vmas_split(), if data is corrupted after mremap, the control jumps to cleanup without marking the test as failed. Set success to false before moving to cleanup. Fixes: 7d6597dfef11 ("tools/testing/selftests: explicitly test split multi = VMA mremap move") Signed-off-by: Sarthak Sharma --- tools/testing/selftests/mm/mremap_test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selft= ests/mm/mremap_test.c index 869df22d46db..3b42c4f2473c 100644 --- a/tools/testing/selftests/mm/mremap_test.c +++ b/tools/testing/selftests/mm/mremap_test.c @@ -691,6 +691,7 @@ static void mremap_move_multiple_vmas_split(unsigned in= t pattern_seed, if (chr !=3D buf[j]) { ksft_print_msg("page %d offset %d corrupted, expected %d got %d\n", i, j, chr, buf[j]); + success =3D false; goto out_unmap; } } --=20 2.53.0 From nobody Thu Sep 24 13:41:51 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B6A08388E55; Thu, 24 Sep 2026 05:00:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790226056; cv=none; b=Ber7NCdpZ4f8C6bR2by4ewqPr5NQco4keaPtywQRRTh3uHUa+PSgK3wUqJvrBGHBhX58/DyyHOoBKM29JIc9Fa8ql4sP4zYbfG9puzJejBy46DFBB1C+f8UY2UxN3MCK5k6tsV9nHpquG7r0jhDrCKfoQU4k80nGJhfNP2NvAiY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790226056; c=relaxed/simple; bh=2cBUq/RyqEl4FzDlVIUl5oTNJJOUqwf4dolbxhXqgjs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qiurNtT+AYcrQf2hfGGFmWN+jRKOKMCwPTio8NIpFR+5eMtUEQBIbBdjsXi0F1iwm582fE+SjsoKbBJ0e8jMwWoVho6fPcN6asn0LlzXkGeLh6QeZKAThDvUc5996CcjpbsYmvVlkCSEvZsnIp8gNCZQzKIbWGw1jEupQNvLjqk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=h/TrDPNj; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="h/TrDPNj" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4BB52152B; Wed, 23 Sep 2026 22:00:49 -0700 (PDT) Received: from a081061.blr.arm.com (a081061.arm.com [10.164.19.84]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DFCE33F86C; Wed, 23 Sep 2026 22:00:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1790226052; bh=2cBUq/RyqEl4FzDlVIUl5oTNJJOUqwf4dolbxhXqgjs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h/TrDPNj0hljjPhrR4BnFfBuYIzT73Til+wVHNZKASNH+lHFqQr0AUXkqdSRCNxPY 9+0vDMnwT5O3/h34o7HfHqO8x591fMXT9Rb7tN8VhwRsz7thZhtSKhhsiT4xbSPHZG oye8UFPY279A+1mwKzIRTYef1htfqW/gkhN2KZTE= From: Sarthak Sharma To: Andrew Morton , David Hildenbrand Cc: Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Shuah Khan , John Hubbard , Kalesh Singh , Anshuman Khandual , Park Tae-sun , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Sarthak Sharma Subject: [PATCH RESEND 6/9] selftests/mm: mremap_test: replace random data with deterministic pattern Date: Thu, 24 Sep 2026 10:30:06 +0530 Message-ID: <20260924050009.19974-7-sarthak.sharma@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260924050009.19974-1-sarthak.sharma@arm.com> References: <20260924050009.19974-1-sarthak.sharma@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" mremap_test uses a random data stream to detect corruption after remap operations. This requires seed handling and byte by byte validation, which is inefficient. Replace it with a deterministic pattern where every word in a page contains its one-based page index. Use memcpy() and memcmp() to initialize and validate the mappings. Remove the pattern seed and its command line option. Also update the comment diagrams to reflect the new deterministic pattern. Suggested-by: David Hildenbrand (Arm) Signed-off-by: Sarthak Sharma --- tools/testing/selftests/mm/mremap_test.c | 251 +++++++++-------------- 1 file changed, 95 insertions(+), 156 deletions(-) diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selft= ests/mm/mremap_test.c index 3b42c4f2473c..7b4c9ab3bf14 100644 --- a/tools/testing/selftests/mm/mremap_test.c +++ b/tools/testing/selftests/mm/mremap_test.c @@ -15,6 +15,7 @@ #include #include #include +#include =20 #include "kselftest.h" =20 @@ -61,6 +62,9 @@ enum { PUD =3D _1GB, }; =20 +static uint32_t *pattern; +static size_t pattern_size; + #define PTE page_size =20 #define MAKE_TEST(source_align, destination_align, size, \ @@ -311,11 +315,11 @@ static void mremap_expand_merge_offset(FILE *maps_fp,= unsigned long page_size) * * |DDDDddddSSSSssss| */ -static void mremap_move_within_range(unsigned int pattern_seed, char *rand= _addr) +static void mremap_move_within_range(void) { char *test_name =3D "mremap move within range"; void *src, *dest; - unsigned int i, success =3D 1; + unsigned int success =3D 1; =20 size_t size =3D SIZE_MB(20); void *ptr =3D mmap(NULL, size, PROT_READ | PROT_WRITE, @@ -331,12 +335,12 @@ static void mremap_move_within_range(unsigned int pat= tern_seed, char *rand_addr) src =3D (void *)((unsigned long)src & ~(SIZE_MB(2) - 1)); =20 /* Set byte pattern for source block. */ - memcpy(src, rand_addr, SIZE_MB(2)); + memcpy(src, (char *)pattern + SIZE_MB(2), SIZE_MB(2)); =20 dest =3D src - SIZE_MB(2); =20 void *new_ptr =3D mremap(src + SIZE_MB(1), SIZE_MB(1), SIZE_MB(1), - MREMAP_MAYMOVE | MREMAP_FIXED, dest + SIZE_MB(1)); + MREMAP_MAYMOVE | MREMAP_FIXED, dest + SIZE_MB(1)); if (new_ptr =3D=3D MAP_FAILED) { ksft_perror("mremap"); success =3D 0; @@ -344,17 +348,9 @@ static void mremap_move_within_range(unsigned int patt= ern_seed, char *rand_addr) } =20 /* Verify byte pattern after remapping */ - srand(pattern_seed); - for (i =3D 0; i < SIZE_MB(1); i++) { - char c =3D (char) rand(); - - if (((char *)src)[i] !=3D c) { - ksft_print_msg("Data at src at %d got corrupted due to unrelated mremap= \n", - i); - ksft_print_msg("Expected: %#x\t Got: %#x\n", c & 0xff, - ((char *) src)[i] & 0xff); - success =3D 0; - } + if (memcmp(src, (char *)pattern + SIZE_MB(2), SIZE_MB(1))) { + ksft_print_msg("Source data was corrupted\n"); + success =3D 0; } =20 out: @@ -364,37 +360,27 @@ static void mremap_move_within_range(unsigned int pat= tern_seed, char *rand_addr) ksft_test_result(success, "%s\n", test_name); } =20 -static bool is_multiple_vma_range_ok(unsigned int pattern_seed, - char *ptr, unsigned long page_size) +static bool is_multiple_vma_range_ok(char *ptr, unsigned long page_size) { int i; =20 - srand(pattern_seed); for (i =3D 0; i <=3D 10; i +=3D 2) { - int j; - char *buf =3D &ptr[i * page_size]; size_t size =3D i =3D=3D 4 ? 3 * page_size : page_size; =20 if (i =3D=3D 6) continue; =20 - for (j =3D 0; j < size; j++) { - char chr =3D rand(); - - if (chr !=3D buf[j]) { - ksft_print_msg("page %d offset %d corrupted, expected %d got %d\n", - i, j, chr, buf[j]); - return false; - } + if (memcmp(ptr + i * page_size, (char *)pattern + i * page_size, + size)) { + ksft_print_msg("Data in VMA starting at page %d got corrupted\n", + i); + return false; } } - return true; } =20 -static void mremap_move_multiple_vmas(unsigned int pattern_seed, - unsigned long page_size, - bool dont_unmap) +static void mremap_move_multiple_vmas(unsigned long page_size, bool dont_u= nmap) { int mremap_flags =3D MREMAP_FIXED | MREMAP_MAYMOVE; char *test_name =3D "mremap move multiple vmas"; @@ -427,13 +413,15 @@ static void mremap_move_multiple_vmas(unsigned int pa= ttern_seed, goto out_unmap; } =20 + memcpy(ptr, pattern, size); + /* * Unmap so we end up with: * * 0 2 4 5 6 8 10 offset in buffer * |*| |*| |*****| |*| |*| * |*| |*| |*****| |*| |*| - * 0 1 2 3 4 5 6 pattern offset + * 0 2 4 5 6 8 10 pattern offset */ for (i =3D 1; i < 10; i +=3D 2) { if (i =3D=3D 5) @@ -446,18 +434,6 @@ static void mremap_move_multiple_vmas(unsigned int pat= tern_seed, } } =20 - srand(pattern_seed); - - /* Set up random patterns. */ - for (i =3D 0; i <=3D 10; i +=3D 2) { - int j; - size_t size =3D i =3D=3D 4 ? 2 * page_size : page_size; - char *buf =3D &ptr[i * page_size]; - - for (j =3D 0; j < size; j++) - buf[j] =3D rand(); - } - /* First, just move the whole thing. */ if (mremap(ptr, size, size, mremap_flags, tgt_ptr) =3D=3D MAP_FAILED) { ksft_perror("mremap"); @@ -465,7 +441,7 @@ static void mremap_move_multiple_vmas(unsigned int patt= ern_seed, goto out_unmap; } /* Check move was ok. */ - if (!is_multiple_vma_range_ok(pattern_seed, tgt_ptr, page_size)) { + if (!is_multiple_vma_range_ok(tgt_ptr, page_size)) { success =3D false; goto out_unmap; } @@ -478,7 +454,7 @@ static void mremap_move_multiple_vmas(unsigned int patt= ern_seed, goto out_unmap; } /* Check that the move is ok. */ - if (!is_multiple_vma_range_ok(pattern_seed, &tgt_ptr[size], page_size)) { + if (!is_multiple_vma_range_ok(&tgt_ptr[size], page_size)) { success =3D false; goto out_unmap; } @@ -498,7 +474,7 @@ static void mremap_move_multiple_vmas(unsigned int patt= ern_seed, goto out_unmap; } /* Check that the move is ok. */ - if (!is_multiple_vma_range_ok(pattern_seed, tgt_ptr, page_size)) { + if (!is_multiple_vma_range_ok(tgt_ptr, page_size)) { success =3D false; goto out_unmap; } @@ -587,8 +563,7 @@ static void mremap_shrink_multiple_vmas(unsigned long p= age_size, ksft_test_result(success, "%s%s\n", test_name, inplace ? " [inplace]" : "= "); } =20 -static void mremap_move_multiple_vmas_split(unsigned int pattern_seed, - unsigned long page_size, +static void mremap_move_multiple_vmas_split(unsigned long page_size, bool dont_unmap) { char *test_name =3D "mremap move multiple vmas split"; @@ -622,13 +597,15 @@ static void mremap_move_multiple_vmas_split(unsigned = int pattern_seed, goto out_unmap; } =20 + memcpy(ptr, pattern, size); + /* * Unmap so we end up with: * * 0 1 2 3 4 5 6 7 8 9 10 offset in buffer * |**********| |*******| * |**********| |*******| - * 0 1 2 3 4 5 6 7 8 9 pattern offset + * 0 1 2 3 4 5 6 7 8 9 10 pattern offset */ if (munmap(&ptr[5 * page_size], page_size)) { ksft_perror("munmap"); @@ -636,19 +613,6 @@ static void mremap_move_multiple_vmas_split(unsigned i= nt pattern_seed, goto out_unmap; } =20 - /* Set up random patterns. */ - srand(pattern_seed); - for (i =3D 0; i < 10; i++) { - int j; - char *buf =3D &ptr[i * page_size]; - - if (i =3D=3D 5) - continue; - - for (j =3D 0; j < page_size; j++) - buf[j] =3D rand(); - } - /* * Move the below: * @@ -656,14 +620,14 @@ static void mremap_move_multiple_vmas_split(unsigned = int pattern_seed, * 0 1 2 3 4 5 6 7 8 9 10 offset in buffer * |**********| |*******| * |**********| |*******| - * 0 1 2 3 4 5 6 7 8 9 pattern offset + * 0 1 2 3 4 5 6 7 8 9 10 pattern offset * * Into: * * 0 1 2 3 4 5 6 7 offset in buffer * |*****| |*****| * |*****| |*****| - * 2 3 4 5 6 7 pattern offset + * 2 3 4 5 6 7 8 9 pattern offset */ if (mremap(&ptr[2 * page_size], size - 3 * page_size, size - 3 * page_siz= e, mremap_flags, tgt_ptr) =3D=3D MAP_FAILED) { @@ -672,28 +636,16 @@ static void mremap_move_multiple_vmas_split(unsigned = int pattern_seed, goto out_unmap; } =20 - /* Offset into random pattern. */ - srand(pattern_seed); - for (i =3D 0; i < 2 * page_size; i++) - rand(); - /* Check pattern. */ for (i =3D 0; i < 7; i++) { - int j; - char *buf =3D &tgt_ptr[i * page_size]; - if (i =3D=3D 3) continue; =20 - for (j =3D 0; j < page_size; j++) { - char chr =3D rand(); - - if (chr !=3D buf[j]) { - ksft_print_msg("page %d offset %d corrupted, expected %d got %d\n", - i, j, chr, buf[j]); - success =3D false; - goto out_unmap; - } + if (memcmp(tgt_ptr + i * page_size, + (char *)pattern + (i + 2) * page_size, page_size)) { + ksft_print_msg("Data in page %d got corrupted\n", i + 2); + success =3D false; + goto out_unmap; } } =20 @@ -946,13 +898,13 @@ static void mremap_move_multi_invalid_vmas(FILE *maps= _fp, unsigned long page_siz #endif /* __NR_userfaultfd */ =20 /* Returns the time taken for the remap on success else returns -1. */ -static long long remap_region(struct config c, unsigned int threshold_mb, - char *rand_addr) +static long long remap_region(struct config c, unsigned int threshold_mb) { void *addr, *tmp_addr, *src_addr, *dest_addr, *dest_preamble_addr =3D NUL= L; struct timespec t_start =3D {0, 0}, t_end =3D {0, 0}; long long start_ns, end_ns, align_mask, ret, offset; unsigned long long threshold; + char *preamble_pattern; =20 if (threshold_mb =3D=3D VALIDATION_NO_THRESHOLD) threshold =3D c.region_size; @@ -966,7 +918,7 @@ static long long remap_region(struct config c, unsigned= int threshold_mb, } =20 /* Set byte pattern for source block. */ - memcpy(src_addr, rand_addr, threshold); + memcpy(src_addr, pattern, threshold); =20 /* Mask to zero out lower bits of address for alignment */ align_mask =3D ~(c.dest_alignment - 1); @@ -1006,8 +958,9 @@ static long long remap_region(struct config c, unsigne= d int threshold_mb, goto clean_up_src; } =20 + preamble_pattern =3D (char *)pattern + pattern_size - c.dest_preamble_si= ze; /* Set byte pattern for the dest preamble block. */ - memcpy(dest_preamble_addr, rand_addr, c.dest_preamble_size); + memcpy(dest_preamble_addr, preamble_pattern, c.dest_preamble_size); } =20 clock_gettime(CLOCK_MONOTONIC, &t_start); @@ -1022,7 +975,7 @@ static long long remap_region(struct config c, unsigne= d int threshold_mb, } =20 /* Verify byte pattern after remapping */ - if (memcmp(dest_addr, rand_addr, threshold)) { + if (memcmp(dest_addr, pattern, threshold)) { ksft_print_msg("Data after remap doesn't match\n"); ret =3D -1; goto clean_up_dest; @@ -1030,7 +983,7 @@ static long long remap_region(struct config c, unsigne= d int threshold_mb, =20 /* Verify the dest preamble byte pattern after remapping */ if (c.dest_preamble_size && - memcmp(dest_preamble_addr, rand_addr, c.dest_preamble_size)) { + memcmp(dest_preamble_addr, preamble_pattern, c.dest_preamble_size)) { ksft_print_msg("Preamble data after remap doesn't match\n"); ret =3D -1; goto clean_up_dest; @@ -1062,12 +1015,11 @@ static long long remap_region(struct config c, unsi= gned int threshold_mb, * the beginning of the mapping just because the aligned * down address landed on a mapping that maybe does not exist. */ -static void mremap_move_1mb_from_start(unsigned int pattern_seed, - char *rand_addr) +static void mremap_move_1mb_from_start(void) { char *test_name =3D "mremap move 1mb from start at 1MB+256KB aligned src"; void *src =3D NULL, *dest =3D NULL; - unsigned int i, success =3D 1; + unsigned int success =3D 1; =20 /* Config to reuse get_source_mapping() to do an aligned mmap. */ struct config c =3D { @@ -1089,7 +1041,7 @@ static void mremap_move_1mb_from_start(unsigned int p= attern_seed, } =20 /* Set byte pattern for source block. */ - memcpy(src, rand_addr, SIZE_MB(2)); + memcpy(src, pattern, SIZE_MB(2)); =20 /* * Unmap the beginning of dest so that the aligned address @@ -1098,7 +1050,7 @@ static void mremap_move_1mb_from_start(unsigned int p= attern_seed, munmap(dest, SIZE_MB(1)); =20 void *new_ptr =3D mremap(src + SIZE_MB(1), SIZE_MB(1), SIZE_MB(1), - MREMAP_MAYMOVE | MREMAP_FIXED, dest + SIZE_MB(1)); + MREMAP_MAYMOVE | MREMAP_FIXED, dest + SIZE_MB(1)); if (new_ptr =3D=3D MAP_FAILED) { ksft_perror("mremap"); success =3D 0; @@ -1106,17 +1058,9 @@ static void mremap_move_1mb_from_start(unsigned int = pattern_seed, } =20 /* Verify byte pattern after remapping */ - srand(pattern_seed); - for (i =3D 0; i < SIZE_MB(1); i++) { - char c =3D (char) rand(); - - if (((char *)src)[i] !=3D c) { - ksft_print_msg("Data at src at %d got corrupted due to unrelated mremap= \n", - i); - ksft_print_msg("Expected: %#x\t Got: %#x\n", c & 0xff, - ((char *) src)[i] & 0xff); - success =3D 0; - } + if (memcmp(src, pattern, SIZE_MB(1))) { + ksft_print_msg("Data before the remapped range was corrupted\n"); + success =3D 0; } =20 out: @@ -1129,11 +1073,10 @@ static void mremap_move_1mb_from_start(unsigned int= pattern_seed, ksft_test_result(success, "%s\n", test_name); } =20 -static void run_mremap_test_case(struct test test_case, unsigned int thres= hold_mb, - char *rand_addr) +static void run_mremap_test_case(struct test test_case, + unsigned int threshold_mb) { - long long remap_time =3D remap_region(test_case.config, threshold_mb, - rand_addr); + long long remap_time =3D remap_region(test_case.config, threshold_mb); =20 if (remap_time < 0) { if (test_case.expect_failure) @@ -1160,29 +1103,22 @@ static void run_mremap_test_case(struct test test_c= ase, unsigned int threshold_m =20 static void usage(const char *cmd) { - ksft_print_msg("Usage: %s [[-t ] [-p ]]\n", c= md); + ksft_print_msg("Usage: %s [-t ]\n", cmd); ksft_print_msg("-t\t only validate threshold_mb of the remapped region\n"= ); ksft_print_msg(" \t if 0 is supplied no threshold is used; all tests\n"); ksft_print_msg(" \t are run and remapped regions validated fully.\n"); ksft_print_msg(" \t The default threshold used is 4MB.\n"); - ksft_print_msg("-p\t provide a seed to generate the random pattern for\n"= ); - ksft_print_msg(" \t validating the remapped region.\n"); } =20 -static int parse_args(int argc, char **argv, unsigned int *threshold_mb, - unsigned int *pattern_seed) +static int parse_args(int argc, char **argv, unsigned int *threshold_mb) { - const char *optstr =3D "t:p:"; int opt; =20 - while ((opt =3D getopt(argc, argv, optstr)) !=3D -1) { + while ((opt =3D getopt(argc, argv, "t:")) !=3D -1) { switch (opt) { case 't': *threshold_mb =3D atoi(optarg); break; - case 'p': - *pattern_seed =3D atoi(optarg); - break; default: usage(argv[0]); return -1; @@ -1197,6 +1133,21 @@ static int parse_args(int argc, char **argv, unsigne= d int *threshold_mb, return 0; } =20 +static void fill_pattern(uint32_t *pattern, size_t pattern_size, size_t pa= ge_size) +{ + size_t nr_pages =3D pattern_size / page_size; + size_t words_per_page =3D page_size / sizeof(uint32_t); + size_t page, word; + + for (page =3D 0; page < nr_pages; page++) { + uint32_t *page_addr =3D pattern + page * words_per_page; + uint32_t val =3D page + 1; + + for (word =3D 0; word < words_per_page; word++) + page_addr[word] =3D val; + } +} + #define MAX_TEST 15 #define MAX_PERF_TEST 3 int main(int argc, char **argv) @@ -1210,57 +1161,46 @@ int main(int argc, char **argv) size_t max_test_constant_region_size =3D _2MB; size_t dest_preamble_size =3D 10 * _4MB; =20 - unsigned int pattern_seed; - char *rand_addr; - size_t rand_size; int num_expand_tests =3D 2; int num_misc_tests =3D 9; struct test test_cases[MAX_TEST] =3D {}; struct test perf_test_cases[MAX_PERF_TEST]; int page_size; - time_t t; FILE *maps_fp; =20 ksft_print_header(); =20 get_mmap_min_addr(); =20 - pattern_seed =3D (unsigned int) time(&t); - - if (parse_args(argc, argv, &threshold_mb, &pattern_seed) < 0) + if (parse_args(argc, argv, &threshold_mb) < 0) ksft_exit_fail_msg("Invalid arguments\n"); =20 ksft_print_msg("Test configs:\n"); ksft_print_msg("threshold_mb=3D%u\n", threshold_mb); - ksft_print_msg("pattern_seed=3D%u\n", pattern_seed); =20 /* - * set preallocated random array according to test configs; see the - * functions for the logic of setting the size + * Set a preallocated array where page[i] contains i+1 */ if (!threshold_mb) - rand_size =3D MAX(max_test_variable_region_size, - max_test_constant_region_size); + pattern_size =3D MAX(max_test_variable_region_size, + max_test_constant_region_size); else - rand_size =3D MAX(MIN(threshold_mb * _1MB, - max_test_variable_region_size), - max_test_constant_region_size); - rand_size =3D MAX(dest_preamble_size, rand_size); - - rand_addr =3D (char *)mmap(NULL, rand_size, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (rand_addr =3D=3D MAP_FAILED) { + pattern_size =3D MAX(MIN(threshold_mb * _1MB, + max_test_variable_region_size), + max_test_constant_region_size); + pattern_size =3D MAX(dest_preamble_size, pattern_size); + + pattern =3D mmap(NULL, pattern_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (pattern =3D=3D MAP_FAILED) { ksft_perror("mmap"); - ksft_exit_fail_msg("cannot mmap rand_addr\n"); + ksft_exit_fail_msg("cannot mmap pattern\n"); } =20 - /* fill stream of random bytes */ - srand(pattern_seed); - for (unsigned long i =3D 0; i < rand_size; ++i) - rand_addr[i] =3D (char) rand(); - page_size =3D sysconf(_SC_PAGESIZE); =20 + fill_pattern(pattern, pattern_size, page_size); + /* Expected mremap failures */ test_cases[0] =3D MAKE_TEST(page_size, page_size, page_size, OVERLAPPING, EXPECT_FAILURE, @@ -1329,26 +1269,26 @@ int main(int argc, char **argv) ARRAY_SIZE(perf_test_cases) : 0) + num_expand_tests + num_misc_tes= ts); =20 for (i =3D 0; i < ARRAY_SIZE(test_cases); i++) - run_mremap_test_case(test_cases[i], threshold_mb, rand_addr); + run_mremap_test_case(test_cases[i], threshold_mb); =20 maps_fp =3D fopen("/proc/self/maps", "r"); =20 if (maps_fp =3D=3D NULL) { - munmap(rand_addr, rand_size); + munmap(pattern, pattern_size); ksft_exit_fail_msg("Failed to read /proc/self/maps: %s\n", strerror(errn= o)); } =20 mremap_expand_merge(maps_fp, page_size); mremap_expand_merge_offset(maps_fp, page_size); =20 - mremap_move_within_range(pattern_seed, rand_addr); - mremap_move_1mb_from_start(pattern_seed, rand_addr); + mremap_move_within_range(); + mremap_move_1mb_from_start(); mremap_shrink_multiple_vmas(page_size, /* inplace=3D */true); mremap_shrink_multiple_vmas(page_size, /* inplace=3D */false); - mremap_move_multiple_vmas(pattern_seed, page_size, /* dontunmap=3D */ fal= se); - mremap_move_multiple_vmas(pattern_seed, page_size, /* dontunmap=3D */ tru= e); - mremap_move_multiple_vmas_split(pattern_seed, page_size, /* dontunmap=3D = */ false); - mremap_move_multiple_vmas_split(pattern_seed, page_size, /* dontunmap=3D = */ true); + mremap_move_multiple_vmas(page_size, /* dontunmap=3D */ false); + mremap_move_multiple_vmas(page_size, /* dontunmap=3D */ true); + mremap_move_multiple_vmas_split(page_size, /* dontunmap=3D */ false); + mremap_move_multiple_vmas_split(page_size, /* dontunmap=3D */ true); mremap_move_multi_invalid_vmas(maps_fp, page_size); =20 fclose(maps_fp); @@ -1357,11 +1297,10 @@ int main(int argc, char **argv) ksft_print_msg("%s\n", "mremap HAVE_MOVE_PMD/PUD optimization time comparison for 1GB r= egion:"); for (i =3D 0; i < ARRAY_SIZE(perf_test_cases); i++) - run_mremap_test_case(perf_test_cases[i], threshold_mb, - rand_addr); + run_mremap_test_case(perf_test_cases[i], threshold_mb); } =20 - munmap(rand_addr, rand_size); + munmap(pattern, pattern_size); =20 ksft_finished(); } --=20 2.53.0 From nobody Thu Sep 24 13:41:51 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9F59335B65D; Thu, 24 Sep 2026 05:00:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790226060; cv=none; b=jh8/umdpW08foQcHISmSZc+8xS9nR8mL8Ui9ymjsdvGG79d5/R+To+nfUghpAlS5eQ92p+rvfZTUoqGDUvR+ZzEf4Is78oeM/8WkmQKpN37b4zmoA6TZu58nTGfXkUjMC52qY4/aGgI00W0yKjYo8Y+fWyhwsQyK5NOAdwtCOEY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790226060; c=relaxed/simple; bh=PEYyoFGukDb2bBQUvTSPCNCEuNRH1wR3RMvfZBD9GHI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uDJBuSepAD2LusRPMq1YXIEM6ZxDSJ6y/QEPG0XeQNrLxLxR0SAPJn/mmakvje/k9cFkYDEloLzc8dmK7BowRWW3jlS1SHGCy36WWOK3IMqqzJfiP1aTTt1dONIT4YeP3ms9TDPtjnCZxqD6A2CrawMVNPP1TqTEe3VBToUhJMM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=OPMSzIYM; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="OPMSzIYM" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5D2D81476; Wed, 23 Sep 2026 22:00:54 -0700 (PDT) Received: from a081061.blr.arm.com (a081061.arm.com [10.164.19.84]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 443633F86C; Wed, 23 Sep 2026 22:00:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1790226057; bh=PEYyoFGukDb2bBQUvTSPCNCEuNRH1wR3RMvfZBD9GHI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OPMSzIYMbgDKDfvMN4D4bdbM26PshsJcMRj5wa2xFHP3DMLKVW2KS/O3NZVZlsNu6 TDUrB7L4nm3GN4sL0Kb7X4BCQpCNrM0jGXqJ3PmCVTS8uoY17NsOSm4oyHZIilBlXq P5D6QrJu1jOJYJ1fRYFZMiNMzESzcOlt4LavkChg= From: Sarthak Sharma To: Andrew Morton , David Hildenbrand Cc: Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Shuah Khan , John Hubbard , Kalesh Singh , Anshuman Khandual , Park Tae-sun , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Sarthak Sharma Subject: [PATCH RESEND 7/9] selftests/mm: mremap_test: remove perf tests and timing Date: Thu, 24 Sep 2026 10:30:07 +0530 Message-ID: <20260924050009.19974-8-sarthak.sharma@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260924050009.19974-1-sarthak.sharma@arm.com> References: <20260924050009.19974-1-sarthak.sharma@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" mremap_test contains three perf tests that report the time taken to move 1GB mappings with different page table level alignments. Although they validate the remapped data, their main purpose it to report timing information. The recorded time also does not affect the test result. Also, they are skipped with the default validation threshold. Remove these tests and the timing infrastructure from mremap_test.c. The regular tests continue to cover PUD and PMD aligned remaps. Suggested-by: David Hildenbrand (Arm) Signed-off-by: Sarthak Sharma --- tools/testing/selftests/mm/mremap_test.c | 61 +++--------------------- 1 file changed, 7 insertions(+), 54 deletions(-) diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selft= ests/mm/mremap_test.c index 7b4c9ab3bf14..04ea072f8cd1 100644 --- a/tools/testing/selftests/mm/mremap_test.c +++ b/tools/testing/selftests/mm/mremap_test.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include =20 @@ -23,7 +22,6 @@ #define EXPECT_FAILURE 1 #define NON_OVERLAPPING 0 #define OVERLAPPING 1 -#define NS_PER_SEC 1000000000ULL #define VALIDATION_DEFAULT_THRESHOLD 4 /* 4MB */ #define VALIDATION_NO_THRESHOLD 0 /* Verify the entire region */ =20 @@ -897,12 +895,11 @@ static void mremap_move_multi_invalid_vmas(FILE *maps= _fp, unsigned long page_siz } #endif /* __NR_userfaultfd */ =20 -/* Returns the time taken for the remap on success else returns -1. */ -static long long remap_region(struct config c, unsigned int threshold_mb) +static int remap_region(struct config c, unsigned int threshold_mb) { void *addr, *tmp_addr, *src_addr, *dest_addr, *dest_preamble_addr =3D NUL= L; - struct timespec t_start =3D {0, 0}, t_end =3D {0, 0}; - long long start_ns, end_ns, align_mask, ret, offset; + long long align_mask, offset; + int ret =3D 0; unsigned long long threshold; char *preamble_pattern; =20 @@ -963,10 +960,8 @@ static long long remap_region(struct config c, unsigne= d int threshold_mb) memcpy(dest_preamble_addr, preamble_pattern, c.dest_preamble_size); } =20 - clock_gettime(CLOCK_MONOTONIC, &t_start); dest_addr =3D mremap(src_addr, c.region_size, c.region_size, MREMAP_MAYMOVE|MREMAP_FIXED, (char *) addr); - clock_gettime(CLOCK_MONOTONIC, &t_end); =20 if (dest_addr =3D=3D MAP_FAILED) { ksft_print_msg("mremap failed: %s\n", strerror(errno)); @@ -989,16 +984,7 @@ static long long remap_region(struct config c, unsigne= d int threshold_mb) goto clean_up_dest; } =20 - start_ns =3D t_start.tv_sec * NS_PER_SEC + t_start.tv_nsec; - end_ns =3D t_end.tv_sec * NS_PER_SEC + t_end.tv_nsec; - ret =3D end_ns - start_ns; - -/* - * Since the destination address is specified using MREMAP_FIXED, subseque= nt - * mremap will unmap any previous mapping at the address range specified by - * dest_addr and region_size. This significantly affects the remap time of - * subsequent tests. So we clean up mappings after each test. - */ +/* Clean up mappings after each test. */ clean_up_dest: munmap(dest_addr, c.region_size); clean_up_dest_preamble: @@ -1076,9 +1062,9 @@ static void mremap_move_1mb_from_start(void) static void run_mremap_test_case(struct test test_case, unsigned int threshold_mb) { - long long remap_time =3D remap_region(test_case.config, threshold_mb); + int ret =3D remap_region(test_case.config, threshold_mb); =20 - if (remap_time < 0) { + if (ret < 0) { if (test_case.expect_failure) ksft_test_result_xfail("%s: expected mremap failure\n", test_case.name); @@ -1088,14 +1074,6 @@ static void run_mremap_test_case(struct test test_ca= se, if (test_case.expect_failure) ksft_test_result_fail("%s: unexpected mremap success\n", test_case.name); - /* - * Comparing mremap time is only applicable if entire region - * was faulted in. - */ - else if (threshold_mb =3D=3D VALIDATION_NO_THRESHOLD || - test_case.config.region_size <=3D threshold_mb * _1MB) - ksft_test_result_pass("%s: mremap time: %12lldns\n", - test_case.name, remap_time); else ksft_test_result_pass("%s\n", test_case.name); } @@ -1149,11 +1127,9 @@ static void fill_pattern(uint32_t *pattern, size_t p= attern_size, size_t page_siz } =20 #define MAX_TEST 15 -#define MAX_PERF_TEST 3 int main(int argc, char **argv) { unsigned int i; - int run_perf_tests; unsigned int threshold_mb =3D VALIDATION_DEFAULT_THRESHOLD; =20 /* hard-coded test configs */ @@ -1164,7 +1140,6 @@ int main(int argc, char **argv) int num_expand_tests =3D 2; int num_misc_tests =3D 9; struct test test_cases[MAX_TEST] =3D {}; - struct test perf_test_cases[MAX_PERF_TEST]; int page_size; FILE *maps_fp; =20 @@ -1251,22 +1226,7 @@ int main(int argc, char **argv) "5MB mremap - Source 1MB-aligned, Dest 1MB-aligned with 40MB Preambl= e"); test_cases[14].config.dest_preamble_size =3D 10 * _4MB; =20 - perf_test_cases[0] =3D MAKE_TEST(page_size, page_size, _1GB, NON_OVERLAP= PING, EXPECT_SUCCESS, - "1GB mremap - Source PTE-aligned, Destination PTE-aligned"); - /* - * mremap 1GB region - Page table level aligned time - * comparison. - */ - perf_test_cases[1] =3D MAKE_TEST(PMD, PMD, _1GB, NON_OVERLAPPING, EXPECT_= SUCCESS, - "1GB mremap - Source PMD-aligned, Destination PMD-aligned"); - perf_test_cases[2] =3D MAKE_TEST(PUD, PUD, _1GB, NON_OVERLAPPING, EXPECT_= SUCCESS, - "1GB mremap - Source PUD-aligned, Destination PUD-aligned"); - - run_perf_tests =3D (threshold_mb =3D=3D VALIDATION_NO_THRESHOLD) || - (threshold_mb * _1MB >=3D _1GB); - - ksft_set_plan(ARRAY_SIZE(test_cases) + (run_perf_tests ? - ARRAY_SIZE(perf_test_cases) : 0) + num_expand_tests + num_misc_tes= ts); + ksft_set_plan(ARRAY_SIZE(test_cases) + num_expand_tests + num_misc_tests); =20 for (i =3D 0; i < ARRAY_SIZE(test_cases); i++) run_mremap_test_case(test_cases[i], threshold_mb); @@ -1293,13 +1253,6 @@ int main(int argc, char **argv) =20 fclose(maps_fp); =20 - if (run_perf_tests) { - ksft_print_msg("%s\n", - "mremap HAVE_MOVE_PMD/PUD optimization time comparison for 1GB r= egion:"); - for (i =3D 0; i < ARRAY_SIZE(perf_test_cases); i++) - run_mremap_test_case(perf_test_cases[i], threshold_mb); - } - munmap(pattern, pattern_size); =20 ksft_finished(); --=20 2.53.0 From nobody Thu Sep 24 13:41:51 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AD52838A29A; Thu, 24 Sep 2026 05:01:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790226066; cv=none; b=EJzyLjYsl/zjdqhkeldW2El/DE9g/Dd5ZygluGfdgn4xu5VZPdZQUSK6fVFGB9OMecoglfaJKV9gDm4n7P4jy2COqL6RqNuAlzSBCvAiu6gofn1V9NMkpVeNmTQxGPFfIZCeHjQI63IgrkVPe5mBYnSZoVDagzJVRpsbA9LsDlU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790226066; c=relaxed/simple; bh=HzYZit0ASTHY27nDidq+FbliWDAzksUkPY3TJYFzc8o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VJf8jpzMciA7Tz4QVzc8CvORdEf6qBmAAS9LZ/tvL6ohlYaUc2LBMuOh6hk92LlnnQ2jlqrYAsVedTDS9MY2xLyTpxQ7H0N7SwT8IyiLhRXTstpI+fIriFbfldxyWB/HO/+Qssmoip7s2YNcgUy3ro5W6rxnn9Ok40ihUDXm0D4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=CG74ej4k; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="CG74ej4k" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 770BB1682; Wed, 23 Sep 2026 22:00:59 -0700 (PDT) Received: from a081061.blr.arm.com (a081061.arm.com [10.164.19.84]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 59C403F86C; Wed, 23 Sep 2026 22:00:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1790226062; bh=HzYZit0ASTHY27nDidq+FbliWDAzksUkPY3TJYFzc8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CG74ej4kY84i60SFaf5y1GlGswZwFBPBJ6SmoImPZtM5mqWvD6CJmlCVei9haE7UD jG3rMEx8kz7HrwGVGb0dTEjgqVJXAr7MBe29ush6E75/G6JuZjUTThaHW82VeqHMPC b8T5boDrJGPpzMEt6AR2vdxbtixl4knR7ho4+Wjc= From: Sarthak Sharma To: Andrew Morton , David Hildenbrand Cc: Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Shuah Khan , John Hubbard , Kalesh Singh , Anshuman Khandual , Park Tae-sun , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Sarthak Sharma Subject: [PATCH RESEND 8/9] selftests/mm: mremap_test: remove validation threshold Date: Thu, 24 Sep 2026 10:30:08 +0530 Message-ID: <20260924050009.19974-9-sarthak.sharma@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260924050009.19974-1-sarthak.sharma@arm.com> References: <20260924050009.19974-1-sarthak.sharma@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" mremap_test validates only the first 4MB of large mappings by default. The amount of data validated can be changed using the -t command line option, with zero selecting the complete region. Remove the validation threshold and its command line option. Always initialize and validate the complete remapped region. Suggested-by: David Hildenbrand (Arm) Signed-off-by: Sarthak Sharma --- tools/testing/selftests/mm/mremap_test.c | 84 +++--------------------- 1 file changed, 8 insertions(+), 76 deletions(-) diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selft= ests/mm/mremap_test.c index 04ea072f8cd1..77e952556be1 100644 --- a/tools/testing/selftests/mm/mremap_test.c +++ b/tools/testing/selftests/mm/mremap_test.c @@ -22,13 +22,6 @@ #define EXPECT_FAILURE 1 #define NON_OVERLAPPING 0 #define OVERLAPPING 1 -#define VALIDATION_DEFAULT_THRESHOLD 4 /* 4MB */ -#define VALIDATION_NO_THRESHOLD 0 /* Verify the entire region */ - -#ifndef MIN -#define MIN(X, Y) ((X) < (Y) ? (X) : (Y)) -#define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) -#endif #define SIZE_MB(m) ((size_t)m * (1024 * 1024)) #define SIZE_KB(k) ((size_t)k * 1024) =20 @@ -61,7 +54,7 @@ enum { }; =20 static uint32_t *pattern; -static size_t pattern_size; +static const size_t pattern_size =3D _2GB; =20 #define PTE page_size =20 @@ -895,19 +888,13 @@ static void mremap_move_multi_invalid_vmas(FILE *maps= _fp, unsigned long page_siz } #endif /* __NR_userfaultfd */ =20 -static int remap_region(struct config c, unsigned int threshold_mb) +static int remap_region(struct config c) { void *addr, *tmp_addr, *src_addr, *dest_addr, *dest_preamble_addr =3D NUL= L; long long align_mask, offset; int ret =3D 0; - unsigned long long threshold; char *preamble_pattern; =20 - if (threshold_mb =3D=3D VALIDATION_NO_THRESHOLD) - threshold =3D c.region_size; - else - threshold =3D MIN(threshold_mb * _1MB, c.region_size); - src_addr =3D get_source_mapping(c); if (!src_addr) { ret =3D -1; @@ -915,7 +902,7 @@ static int remap_region(struct config c, unsigned int t= hreshold_mb) } =20 /* Set byte pattern for source block. */ - memcpy(src_addr, pattern, threshold); + memcpy(src_addr, pattern, c.region_size); =20 /* Mask to zero out lower bits of address for alignment */ align_mask =3D ~(c.dest_alignment - 1); @@ -970,7 +957,7 @@ static int remap_region(struct config c, unsigned int t= hreshold_mb) } =20 /* Verify byte pattern after remapping */ - if (memcmp(dest_addr, pattern, threshold)) { + if (memcmp(dest_addr, pattern, c.region_size)) { ksft_print_msg("Data after remap doesn't match\n"); ret =3D -1; goto clean_up_dest; @@ -1059,10 +1046,9 @@ static void mremap_move_1mb_from_start(void) ksft_test_result(success, "%s\n", test_name); } =20 -static void run_mremap_test_case(struct test test_case, - unsigned int threshold_mb) +static void run_mremap_test_case(struct test test_case) { - int ret =3D remap_region(test_case.config, threshold_mb); + int ret =3D remap_region(test_case.config); =20 if (ret < 0) { if (test_case.expect_failure) @@ -1079,38 +1065,6 @@ static void run_mremap_test_case(struct test test_ca= se, } } =20 -static void usage(const char *cmd) -{ - ksft_print_msg("Usage: %s [-t ]\n", cmd); - ksft_print_msg("-t\t only validate threshold_mb of the remapped region\n"= ); - ksft_print_msg(" \t if 0 is supplied no threshold is used; all tests\n"); - ksft_print_msg(" \t are run and remapped regions validated fully.\n"); - ksft_print_msg(" \t The default threshold used is 4MB.\n"); -} - -static int parse_args(int argc, char **argv, unsigned int *threshold_mb) -{ - int opt; - - while ((opt =3D getopt(argc, argv, "t:")) !=3D -1) { - switch (opt) { - case 't': - *threshold_mb =3D atoi(optarg); - break; - default: - usage(argv[0]); - return -1; - } - } - - if (optind < argc) { - usage(argv[0]); - return -1; - } - - return 0; -} - static void fill_pattern(uint32_t *pattern, size_t pattern_size, size_t pa= ge_size) { size_t nr_pages =3D pattern_size / page_size; @@ -1127,16 +1081,9 @@ static void fill_pattern(uint32_t *pattern, size_t p= attern_size, size_t page_siz } =20 #define MAX_TEST 15 -int main(int argc, char **argv) +int main(void) { unsigned int i; - unsigned int threshold_mb =3D VALIDATION_DEFAULT_THRESHOLD; - - /* hard-coded test configs */ - size_t max_test_variable_region_size =3D _2GB; - size_t max_test_constant_region_size =3D _2MB; - size_t dest_preamble_size =3D 10 * _4MB; - int num_expand_tests =3D 2; int num_misc_tests =3D 9; struct test test_cases[MAX_TEST] =3D {}; @@ -1147,24 +1094,9 @@ int main(int argc, char **argv) =20 get_mmap_min_addr(); =20 - if (parse_args(argc, argv, &threshold_mb) < 0) - ksft_exit_fail_msg("Invalid arguments\n"); - - ksft_print_msg("Test configs:\n"); - ksft_print_msg("threshold_mb=3D%u\n", threshold_mb); - /* * Set a preallocated array where page[i] contains i+1 */ - if (!threshold_mb) - pattern_size =3D MAX(max_test_variable_region_size, - max_test_constant_region_size); - else - pattern_size =3D MAX(MIN(threshold_mb * _1MB, - max_test_variable_region_size), - max_test_constant_region_size); - pattern_size =3D MAX(dest_preamble_size, pattern_size); - pattern =3D mmap(NULL, pattern_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (pattern =3D=3D MAP_FAILED) { @@ -1229,7 +1161,7 @@ int main(int argc, char **argv) ksft_set_plan(ARRAY_SIZE(test_cases) + num_expand_tests + num_misc_tests); =20 for (i =3D 0; i < ARRAY_SIZE(test_cases); i++) - run_mremap_test_case(test_cases[i], threshold_mb); + run_mremap_test_case(test_cases[i]); =20 maps_fp =3D fopen("/proc/self/maps", "r"); =20 --=20 2.53.0 From nobody Thu Sep 24 13:41:51 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 31F3B39DBCB; Thu, 24 Sep 2026 05:01:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790226071; cv=none; b=cgQSuiS7OPLop6z1I2f0NR0e2Tv5dvZLfm+aTqQ1DMpCcT7LD2RmMbGygLuUBaMST1iV7/UlvA/r6ZCKDzjtPS2Yn35WB72q+ugGKmwLewZ8vkOKj/cVq5ZDgpv182LAfOea/3utVP5gL4lRk9IP71L7HYI3KwdKQj9iEprl24Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790226071; c=relaxed/simple; bh=W0Ngv2ll7TrUzP/N5jQ6K1WGV1ebWdj2UDxJ7GFJJf0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Rdje3WfvRqAXGpnBm9CZ3vOv7q/CVy78DSrqB1J4iqpTHOyMOtfPXWWGbMmiOQQcCYXvvajyjbrNc9EsDKUMjzNcd7fPFL50+FZg9hfcbXqWpQMUf+7SibNcwE/Ui5e27tvK1RUxILdv1g/fD2/YsTmbA1+loQFnBesxX/xIGpI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=ldEN6qM/; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="ldEN6qM/" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7EDB61650; Wed, 23 Sep 2026 22:01:04 -0700 (PDT) Received: from a081061.blr.arm.com (a081061.arm.com [10.164.19.84]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6E2F53F86C; Wed, 23 Sep 2026 22:01:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1790226068; bh=W0Ngv2ll7TrUzP/N5jQ6K1WGV1ebWdj2UDxJ7GFJJf0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ldEN6qM/TEuJ+Ne6s9cE+AFLwyVgBplZwRpdhzAZH1uLLAvIIhItmnSTg/j4gUiNF IPwQzKMFnISlFzH0BsbH6VthJMwJh7efL/3aSAijSxXuPYlbKOq+CwIYHSRP7sRF+z sy9325g6rY2yhR6r8b5hoIVmEU0zJGdff7OdxGU0= From: Sarthak Sharma To: Andrew Morton , David Hildenbrand Cc: Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Shuah Khan , John Hubbard , Kalesh Singh , Anshuman Khandual , Park Tae-sun , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Sarthak Sharma Subject: [PATCH RESEND 9/9] selftests/mm: mremap_test: strengthen multi VMA validation Date: Thu, 24 Sep 2026 10:30:09 +0530 Message-ID: <20260924050009.19974-10-sarthak.sharma@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260924050009.19974-1-sarthak.sharma@arm.com> References: <20260924050009.19974-1-sarthak.sharma@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Tests in mremap_test.c where a multi VMA range is involved only check if the data remains consistent across mapped pages after remap. They do not verify the mapping state of gaps in the remapped range. Add helpers to check whether a range is mapped with the expected permissions using /proc/self/maps. Use them to verify that gaps remain unmapped after regular remaps and retain PROT_NONE permissions when remapping over an existing mapping with PROT_NONE permissions. Signed-off-by: Sarthak Sharma --- tools/testing/selftests/mm/mremap_test.c | 91 +++++++++++++++++++----- 1 file changed, 72 insertions(+), 19 deletions(-) diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selft= ests/mm/mremap_test.c index 77e952556be1..1d9934b9a60b 100644 --- a/tools/testing/selftests/mm/mremap_test.c +++ b/tools/testing/selftests/mm/mremap_test.c @@ -124,13 +124,15 @@ static unsigned long long get_mmap_min_addr(void) } =20 /* - * Using /proc/self/maps, assert that the specified address range is conta= ined - * within a single mapping. + * Using /proc/self/maps, check whether the specified address range is con= tained + * within a single mapping with the expected permissions, if supplied. */ -static bool is_range_mapped(FILE *maps_fp, unsigned long start, - unsigned long end) +static bool is_range_mapped_with_perms(FILE *maps_fp, unsigned long start, + unsigned long end, + const char *expected_perms) { char *line =3D NULL; + char perms[5]; size_t len =3D 0; bool success =3D false; unsigned long first_val, second_val; @@ -138,12 +140,13 @@ static bool is_range_mapped(FILE *maps_fp, unsigned l= ong start, rewind(maps_fp); =20 while (getline(&line, &len, maps_fp) !=3D -1) { - if (sscanf(line, "%lx-%lx", &first_val, &second_val) !=3D 2) { + if (sscanf(line, "%lx-%lx %4s", &first_val, &second_val, perms) !=3D 3) { ksft_exit_fail_msg("cannot parse /proc/self/maps\n"); break; } =20 - if (first_val <=3D start && second_val >=3D end) { + if (first_val <=3D start && second_val >=3D end && + (!expected_perms || !strcmp(perms, expected_perms))) { success =3D true; fflush(maps_fp); break; @@ -154,6 +157,12 @@ static bool is_range_mapped(FILE *maps_fp, unsigned lo= ng start, return success; } =20 +static bool is_range_mapped(FILE *maps_fp, unsigned long start, + unsigned long end) +{ + return is_range_mapped_with_perms(maps_fp, start, end, NULL); +} + /* Check if [ptr, ptr + size) mapped in /proc/self/maps. */ static bool is_ptr_mapped(FILE *maps_fp, void *ptr, unsigned long size) { @@ -163,6 +172,20 @@ static bool is_ptr_mapped(FILE *maps_fp, void *ptr, un= signed long size) return is_range_mapped(maps_fp, start, end); } =20 +/* + * Check if [ptr, ptr + size) is mapped with the required permissions in + * /proc/self/maps. + */ +static bool is_ptr_mapped_with_perms(FILE *maps_fp, void *ptr, + unsigned long size, + const char *expected_perms) +{ + unsigned long start =3D (unsigned long)ptr; + unsigned long end =3D start + size; + + return is_range_mapped_with_perms(maps_fp, start, end, expected_perms); +} + /* * Returns the start address of the mapping on success, else returns * NULL on failure. @@ -351,16 +374,37 @@ static void mremap_move_within_range(void) ksft_test_result(success, "%s\n", test_name); } =20 -static bool is_multiple_vma_range_ok(char *ptr, unsigned long page_size) +static bool is_multiple_vma_range_ok(FILE *maps_fp, char *ptr, + unsigned long page_size, bool expect_gaps_mapped) { int i; =20 - for (i =3D 0; i <=3D 10; i +=3D 2) { + for (i =3D 0; i <=3D 10; i++) { size_t size =3D i =3D=3D 4 ? 3 * page_size : page_size; =20 - if (i =3D=3D 6) + /* Pages 4, 5 and 6 are part of the same VMA. */ + if (i =3D=3D 5 || i =3D=3D 6) continue; =20 + /* Odd pages correspond to gaps between the source VMAs. */ + if (i & 1) { + if (expect_gaps_mapped) { + if (!is_ptr_mapped_with_perms(maps_fp, + ptr + i * page_size, + page_size, "---p")) { + ksft_print_msg("Page %d PROT_NONE mapping overwritten\n", + i); + return false; + } + } else if (is_ptr_mapped(maps_fp, ptr + i * page_size, + page_size)) { + ksft_print_msg("Page %d is unexpectedly mapped\n", i); + return false; + } + + continue; + } + if (memcmp(ptr + i * page_size, (char *)pattern + i * page_size, size)) { ksft_print_msg("Data in VMA starting at page %d got corrupted\n", @@ -371,7 +415,8 @@ static bool is_multiple_vma_range_ok(char *ptr, unsigne= d long page_size) return true; } =20 -static void mremap_move_multiple_vmas(unsigned long page_size, bool dont_u= nmap) +static void mremap_move_multiple_vmas(FILE *maps_fp, unsigned long page_si= ze, + bool dont_unmap) { int mremap_flags =3D MREMAP_FIXED | MREMAP_MAYMOVE; char *test_name =3D "mremap move multiple vmas"; @@ -432,7 +477,7 @@ static void mremap_move_multiple_vmas(unsigned long pag= e_size, bool dont_unmap) goto out_unmap; } /* Check move was ok. */ - if (!is_multiple_vma_range_ok(tgt_ptr, page_size)) { + if (!is_multiple_vma_range_ok(maps_fp, tgt_ptr, page_size, false)) { success =3D false; goto out_unmap; } @@ -445,7 +490,7 @@ static void mremap_move_multiple_vmas(unsigned long pag= e_size, bool dont_unmap) goto out_unmap; } /* Check that the move is ok. */ - if (!is_multiple_vma_range_ok(&tgt_ptr[size], page_size)) { + if (!is_multiple_vma_range_ok(maps_fp, &tgt_ptr[size], page_size, false))= { success =3D false; goto out_unmap; } @@ -465,7 +510,7 @@ static void mremap_move_multiple_vmas(unsigned long pag= e_size, bool dont_unmap) goto out_unmap; } /* Check that the move is ok. */ - if (!is_multiple_vma_range_ok(tgt_ptr, page_size)) { + if (!is_multiple_vma_range_ok(maps_fp, tgt_ptr, page_size, true)) { success =3D false; goto out_unmap; } @@ -554,7 +599,8 @@ static void mremap_shrink_multiple_vmas(unsigned long p= age_size, ksft_test_result(success, "%s%s\n", test_name, inplace ? " [inplace]" : "= "); } =20 -static void mremap_move_multiple_vmas_split(unsigned long page_size, +static void mremap_move_multiple_vmas_split(FILE *maps_fp, + unsigned long page_size, bool dont_unmap) { char *test_name =3D "mremap move multiple vmas split"; @@ -629,8 +675,15 @@ static void mremap_move_multiple_vmas_split(unsigned l= ong page_size, =20 /* Check pattern. */ for (i =3D 0; i < 7; i++) { - if (i =3D=3D 3) + if (i =3D=3D 3) { + if (is_ptr_mapped(maps_fp, tgt_ptr + i * page_size, + page_size)) { + ksft_print_msg("Page %d is unexpectedly mapped\n", i); + success =3D false; + goto out_unmap; + } continue; + } =20 if (memcmp(tgt_ptr + i * page_size, (char *)pattern + (i + 2) * page_size, page_size)) { @@ -1177,10 +1230,10 @@ int main(void) mremap_move_1mb_from_start(); mremap_shrink_multiple_vmas(page_size, /* inplace=3D */true); mremap_shrink_multiple_vmas(page_size, /* inplace=3D */false); - mremap_move_multiple_vmas(page_size, /* dontunmap=3D */ false); - mremap_move_multiple_vmas(page_size, /* dontunmap=3D */ true); - mremap_move_multiple_vmas_split(page_size, /* dontunmap=3D */ false); - mremap_move_multiple_vmas_split(page_size, /* dontunmap=3D */ true); + mremap_move_multiple_vmas(maps_fp, page_size, /* dontunmap=3D */ false); + mremap_move_multiple_vmas(maps_fp, page_size, /* dontunmap=3D */ true); + mremap_move_multiple_vmas_split(maps_fp, page_size, /* dontunmap=3D */ fa= lse); + mremap_move_multiple_vmas_split(maps_fp, page_size, /* dontunmap=3D */ tr= ue); mremap_move_multi_invalid_vmas(maps_fp, page_size); =20 fclose(maps_fp); --=20 2.53.0