Skip to content

Commit 7062387

Browse files
lorenzo-stoakesakpm00
authored andcommitted
tools/testing/selftests: test MREMAP_DONTUNMAP on multiple VMA move
We support MREMAP_MAYMOVE | MREMAP_FIXED | MREMAP_DONTUNMAP for moving multiple VMAs via mremap(), so assert that the tests pass with both MREMAP_DONTUNMAP set and not set. Additionally, add success = false settings when mremap() fails. This is something that cannot realistically happen, so in no way impacted test outcome, but it is incorrect to indicate a test pass when something has failed. Link: https://lkml.kernel.org/r/d7359941981e4e44c774753b3e364d1c54928e6a.1753119043.git.lorenzo.stoakes@oracle.com Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: Jann Horn <jannh@google.com> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 10aed7d commit 7062387

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

tools/testing/selftests/mm/mremap_test.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -406,14 +406,19 @@ static bool is_multiple_vma_range_ok(unsigned int pattern_seed,
406406
}
407407

408408
static void mremap_move_multiple_vmas(unsigned int pattern_seed,
409-
unsigned long page_size)
409+
unsigned long page_size,
410+
bool dont_unmap)
410411
{
412+
int mremap_flags = MREMAP_FIXED | MREMAP_MAYMOVE;
411413
char *test_name = "mremap move multiple vmas";
412414
const size_t size = 11 * page_size;
413415
bool success = true;
414416
char *ptr, *tgt_ptr;
415417
int i;
416418

419+
if (dont_unmap)
420+
mremap_flags |= MREMAP_DONTUNMAP;
421+
417422
ptr = mmap(NULL, size, PROT_READ | PROT_WRITE,
418423
MAP_PRIVATE | MAP_ANON, -1, 0);
419424
if (ptr == MAP_FAILED) {
@@ -467,8 +472,7 @@ static void mremap_move_multiple_vmas(unsigned int pattern_seed,
467472
}
468473

469474
/* First, just move the whole thing. */
470-
if (mremap(ptr, size, size,
471-
MREMAP_MAYMOVE | MREMAP_FIXED, tgt_ptr) == MAP_FAILED) {
475+
if (mremap(ptr, size, size, mremap_flags, tgt_ptr) == MAP_FAILED) {
472476
perror("mremap");
473477
success = false;
474478
goto out_unmap;
@@ -480,9 +484,10 @@ static void mremap_move_multiple_vmas(unsigned int pattern_seed,
480484
}
481485

482486
/* Move next to itself. */
483-
if (mremap(tgt_ptr, size, size,
484-
MREMAP_MAYMOVE | MREMAP_FIXED, &tgt_ptr[size]) == MAP_FAILED) {
487+
if (mremap(tgt_ptr, size, size, mremap_flags,
488+
&tgt_ptr[size]) == MAP_FAILED) {
485489
perror("mremap");
490+
success = false;
486491
goto out_unmap;
487492
}
488493
/* Check that the move is ok. */
@@ -500,8 +505,9 @@ static void mremap_move_multiple_vmas(unsigned int pattern_seed,
500505
}
501506
/* Move and overwrite. */
502507
if (mremap(&tgt_ptr[size], size, size,
503-
MREMAP_MAYMOVE | MREMAP_FIXED, tgt_ptr) == MAP_FAILED) {
508+
mremap_flags, tgt_ptr) == MAP_FAILED) {
504509
perror("mremap");
510+
success = false;
505511
goto out_unmap;
506512
}
507513
/* Check that the move is ok. */
@@ -518,9 +524,11 @@ static void mremap_move_multiple_vmas(unsigned int pattern_seed,
518524

519525
out:
520526
if (success)
521-
ksft_test_result_pass("%s\n", test_name);
527+
ksft_test_result_pass("%s%s\n", test_name,
528+
dont_unmap ? " [dontunnmap]" : "");
522529
else
523-
ksft_test_result_fail("%s\n", test_name);
530+
ksft_test_result_fail("%s%s\n", test_name,
531+
dont_unmap ? " [dontunnmap]" : "");
524532
}
525533

526534
static void mremap_shrink_multiple_vmas(unsigned long page_size,
@@ -943,7 +951,7 @@ int main(int argc, char **argv)
943951
char *rand_addr;
944952
size_t rand_size;
945953
int num_expand_tests = 2;
946-
int num_misc_tests = 5;
954+
int num_misc_tests = 6;
947955
struct test test_cases[MAX_TEST] = {};
948956
struct test perf_test_cases[MAX_PERF_TEST];
949957
int page_size;
@@ -1070,9 +1078,10 @@ int main(int argc, char **argv)
10701078

10711079
mremap_move_within_range(pattern_seed, rand_addr);
10721080
mremap_move_1mb_from_start(pattern_seed, rand_addr);
1073-
mremap_move_multiple_vmas(pattern_seed, page_size);
10741081
mremap_shrink_multiple_vmas(page_size, /* inplace= */true);
10751082
mremap_shrink_multiple_vmas(page_size, /* inplace= */false);
1083+
mremap_move_multiple_vmas(pattern_seed, page_size, /* dontunmap= */ false);
1084+
mremap_move_multiple_vmas(pattern_seed, page_size, /* dontunmap= */ true);
10761085

10771086
if (run_perf_tests) {
10781087
ksft_print_msg("\n%s\n",

0 commit comments

Comments
 (0)