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) <[email protected]> Signed-off-by: Sarthak Sharma <[email protected]> --- 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/selftests/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) @@ -61,7 +54,7 @@ enum { }; static uint32_t *pattern; -static size_t pattern_size; +static const size_t pattern_size = _2GB; #define PTE page_size @@ -895,19 +888,13 @@ static void mremap_move_multi_invalid_vmas(FILE *maps_fp, unsigned long page_siz } #endif /* __NR_userfaultfd */ -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 = NULL; long long align_mask, offset; int ret = 0; - unsigned long long threshold; char *preamble_pattern; - if (threshold_mb == VALIDATION_NO_THRESHOLD) - threshold = c.region_size; - else - threshold = MIN(threshold_mb * _1MB, c.region_size); - src_addr = get_source_mapping(c); if (!src_addr) { ret = -1; @@ -915,7 +902,7 @@ static int remap_region(struct config c, unsigned int threshold_mb) } /* Set byte pattern for source block. */ - memcpy(src_addr, pattern, threshold); + memcpy(src_addr, pattern, c.region_size); /* Mask to zero out lower bits of address for alignment */ align_mask = ~(c.dest_alignment - 1); @@ -970,7 +957,7 @@ static int remap_region(struct config c, unsigned int threshold_mb) } /* 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 = -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); } -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 = remap_region(test_case.config, threshold_mb); + int ret = remap_region(test_case.config); if (ret < 0) { if (test_case.expect_failure) @@ -1079,38 +1065,6 @@ static void run_mremap_test_case(struct test test_case, } } -static void usage(const char *cmd) -{ - ksft_print_msg("Usage: %s [-t <threshold_mb>]\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 = getopt(argc, argv, "t:")) != -1) { - switch (opt) { - case 't': - *threshold_mb = 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 page_size) { size_t nr_pages = pattern_size / page_size; @@ -1127,16 +1081,9 @@ static void fill_pattern(uint32_t *pattern, size_t pattern_size, size_t page_siz } #define MAX_TEST 15 -int main(int argc, char **argv) +int main(void) { unsigned int i; - unsigned int threshold_mb = VALIDATION_DEFAULT_THRESHOLD; - - /* hard-coded test configs */ - size_t max_test_variable_region_size = _2GB; - size_t max_test_constant_region_size = _2MB; - size_t dest_preamble_size = 10 * _4MB; - int num_expand_tests = 2; int num_misc_tests = 9; struct test test_cases[MAX_TEST] = {}; @@ -1147,24 +1094,9 @@ int main(int argc, char **argv) get_mmap_min_addr(); - 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=%u\n", threshold_mb); - /* * Set a preallocated array where page[i] contains i+1 */ - if (!threshold_mb) - pattern_size = MAX(max_test_variable_region_size, - max_test_constant_region_size); - else - pattern_size = MAX(MIN(threshold_mb * _1MB, - max_test_variable_region_size), - max_test_constant_region_size); - pattern_size = MAX(dest_preamble_size, pattern_size); - pattern = mmap(NULL, pattern_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (pattern == 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); for (i = 0; i < ARRAY_SIZE(test_cases); i++) - run_mremap_test_case(test_cases[i], threshold_mb); + run_mremap_test_case(test_cases[i]); maps_fp = fopen("/proc/self/maps", "r"); -- 2.53.0

