gup_test.c currently serves two distinct purposes: microbenchmarking (GUP_FAST_BENCHMARK, PIN_FAST_BENCHMARK, PIN_LONGTERM_BENCHMARK) and functional correctness testing (GUP_BASIC_TEST, PIN_BASIC_TEST, DUMP_USER_PAGES_TEST). Mixing these in a single binary means functional tests cannot be run or reported individually and run_vmtests.sh must invoke the binary multiple times with different flag combinations to cover all configurations.
This patch series separates the two concerns: tools/mm/gup_bench for benchmarking and tools/testing/selftests/mm/gup_test for functional testing. To avoid duplicating HugeTLB and related file helpers, the series first prepares the existing file helpers for sharing, then moves the common helper code to tools/lib/mm/ so it can be shared by both selftests and tools/mm. Patch 1 makes read_file(), write_file(), read_num() and write_num() in vm_util.c return errors to callers instead of exiting internally. Existing mm selftest callers are updated to report failures through kselftest helpers. This avoids carrying selftest-specific process-exit behaviour into the shared helper implementation moved in the next patch. Patch 2 adds tools/lib/mm/file_utils.[ch], moving read_file(), write_file(), read_num() and write_num() out of vm_util.c into a shared helper without a kselftest dependency. It keeps the helpers exposed to mm selftests through vm_util.h and adds tools/lib/mm/ to the MEMORY MANAGEMENT - MISC entry in MAINTAINERS. Patch 3 moves hugepage_settings.[ch] from selftests/mm to tools/lib/mm/. It keeps the helper visible to selftests through vm_util.h where possible, uses direct <mm/hugepage_settings.h> includes for users that do not include vm_util.h, and removes the remaining kselftest dependency from the implementation. The existing HugeTLB diagnostic messages are preserved as TAP-comment-style fprintf(stderr, ...) diagnostics. The explicit x86 protection_keys 32-bit and 64-bit build rules are also updated to preserve prerequisite paths after the source move. Patch 4 adds tools/mm/gup_bench.c, a standalone microbenchmark for GUP_FAST, PIN_FAST and PIN_LONGTERM via the CONFIG_GUP_TEST debugfs interface. It runs the same matrix of configurations as the old run_gup_matrix() shell function (all three commands, read/write, private/shared, four page counts, THP on/off, hugetlb), but as a standalone C program under tools/mm using the shared tools/lib/mm helpers. It also restores HugeTLB settings after each hugetlb benchmark run and validates numeric command-line arguments instead of relying on atoi(). Patch 5 rewrites gup_test.c as a kselftest harness-based selftest. It covers all five GUP kernel functions (get_user_pages, get_user_pages_fast, pin_user_pages, pin_user_pages_fast, pin_user_pages with FOLL_LONGTERM) plus DUMP_USER_PAGES_TEST, across 12 mapping configurations (THP on, THP off and hugetlb, each across private/shared and read/write variants) and four batch sizes (1, 512, 123, all pages). It also preserves the old sparse dump coverage for pages 0, 19 and 0x1000. Results are reported as standard TAP output with no command-line arguments required. --- These patches apply on top of mm/mm-new. Changes in v4: - Address review feedback from Mike and Sashiko - Add a preparatory patch so shared file helpers return errors instead of exiting - Reduce include churn by keeping shared helpers exposed through vm_util.h - Preserve HugeTLB diagnostics and restore HugeTLB state more carefully - Fix selftests/mm build details after moving helpers to tools/lib/mm - Tighten gup_bench argument handling and gup_test setup/sparse-dump coverage Changes in v3: - Address v2 feedback from Sashiko - Add shared file_utils helpers under tools/lib/mm - Move hugepage_settings out of selftests and into tools/lib/mm - Convert gup_bench to use the shared tools/lib/mm helpers - Guard against invalid thread counts in gup_bench - Handle thread-array allocation failure cleanly in gup_bench - Restore hugetlb settings on setup failure in gup_test - Add sparse DUMP_USER_PAGES_TEST coverage for pages 0, 19 and 0x1000 in gup_test Changes in v2: - Address v1 feedback from Sashiko - Add fast and longterm GUP/PUP coverage - Sweep nr_pages_per_call over 1, 512, 123 and all pages - Call madvise(MADV_NOHUGEPAGE) in non-THP variants - Use 256 MB for hugetlb fixtures - Use hugetlb_restore_settings() in FIXTURE_TEARDOWN instead of atexit() - Add TH_LOG to report nr_pages_per_call for each iteration - Update Documentation/core-api/pin_user_pages.rst unit testing section Previous versions: v3: https://lore.kernel.org/all/[email protected]/ v2: https://lore.kernel.org/all/[email protected]/ v1: https://lore.kernel.org/all/[email protected]/ --- Sarthak Sharma (5): selftests/mm: make file helpers return errors tools/lib/mm: add shared file helpers tools/lib/mm: move hugepage_settings out of selftests tools/mm: add a standalone GUP microbenchmark selftests/mm: rewrite gup_test as a standalone harness-based selftest Documentation/core-api/pin_user_pages.rst | 12 +- MAINTAINERS | 2 + tools/lib/mm/file_utils.c | 82 +++ tools/lib/mm/file_utils.h | 12 + .../selftests => lib}/mm/hugepage_settings.c | 103 ++- .../selftests => lib}/mm/hugepage_settings.h | 0 tools/mm/.gitignore | 2 + tools/mm/Makefile | 10 +- tools/mm/gup_bench.c | 433 +++++++++++++ tools/testing/selftests/mm/Makefile | 12 +- tools/testing/selftests/mm/compaction_test.c | 2 +- tools/testing/selftests/mm/cow.c | 1 - .../selftests/mm/folio_split_race_test.c | 1 - tools/testing/selftests/mm/guard-regions.c | 1 - tools/testing/selftests/mm/gup_longterm.c | 1 - tools/testing/selftests/mm/gup_test.c | 606 +++++++++++------- tools/testing/selftests/mm/hmm-tests.c | 6 +- tools/testing/selftests/mm/hugetlb-madvise.c | 1 - tools/testing/selftests/mm/hugetlb-mmap.c | 1 - tools/testing/selftests/mm/hugetlb-mremap.c | 1 - tools/testing/selftests/mm/hugetlb-shm.c | 1 - .../selftests/mm/hugetlb-soft-offline.c | 2 +- tools/testing/selftests/mm/hugetlb-vmemmap.c | 1 - tools/testing/selftests/mm/hugetlb_dio.c | 1 - .../selftests/mm/hugetlb_fault_after_madv.c | 1 - .../selftests/mm/hugetlb_madv_vs_map.c | 1 - tools/testing/selftests/mm/khugepaged.c | 14 +- tools/testing/selftests/mm/ksm_tests.c | 1 - tools/testing/selftests/mm/migration.c | 5 +- tools/testing/selftests/mm/pagemap_ioctl.c | 1 - .../testing/selftests/mm/prctl_thp_disable.c | 1 - tools/testing/selftests/mm/protection_keys.c | 2 +- tools/testing/selftests/mm/run_vmtests.sh | 37 +- tools/testing/selftests/mm/soft-dirty.c | 1 - .../selftests/mm/split_huge_page_test.c | 6 +- tools/testing/selftests/mm/thuge-gen.c | 1 - tools/testing/selftests/mm/transhuge-stress.c | 1 - tools/testing/selftests/mm/uffd-common.h | 1 - tools/testing/selftests/mm/uffd-wp-mremap.c | 2 +- .../selftests/mm/va_high_addr_switch.c | 1 - tools/testing/selftests/mm/vm_util.c | 82 +-- tools/testing/selftests/mm/vm_util.h | 7 +- 42 files changed, 1067 insertions(+), 392 deletions(-) create mode 100644 tools/lib/mm/file_utils.c create mode 100644 tools/lib/mm/file_utils.h rename tools/{testing/selftests => lib}/mm/hugepage_settings.c (89%) rename tools/{testing/selftests => lib}/mm/hugepage_settings.h (100%) create mode 100644 tools/mm/gup_bench.c base-commit: da0a06486ac3ce47c6ffb603d2fd332229d41592 -- 2.39.5

