selftests/mm: Some cleanups from trying to run them
Subsystems (5)
v4 cover selftests/mm: Some cleanups from trying to run them
I never had much luck running mm selftests so I spent a few hours digging into why.
Looks like most of the reason is missing SKIP checks, so this series is just adding a bunch of those that I found. I did not do anything like all of them, just the ones I spotted in gup_longterm, gup_test, mmap, userfaultfd and memfd_secret.
It's a bit unfortunate to have to skip those tests when ftruncate() fails, but I don't have time to dig deep enough into it to actually make them pass. I have observed the issue on 9pfs and heard rumours that NFS has a similar problem.
I'm now able to run these test groups successfully:
- mmap
- gup_test
- compaction
- migration
- page_frag
- userfaultfd
- mlock
I've never gone past "Waiting for hugetlb memory to get depleted", in the hugetlb tests. I don't know if they are stuck or if they would eventually work if I was patient enough (testing on a 1G machine). I have not investigated further.
I had some issues with mlock tests failing due to -ENOSRCH from mlock2(), I can no longer reproduce that though, things work OK now.
Of the remaining tests there may be others that work fine, but there's no convenient way to survey the whole output of run_vmtests.sh so I'm just going test by test here.
In my spare moments I am slowly chipping away at a setup to run these tests continuously in a reasonably hermetic QEMU environment via virtme-ng:
https://github.com/bjackman/linux/blob/5fad4b9c592290f38e0f8bc73c9abb9c99d8787c/README.md
Hopefully that will eventually offer a way to provide a "canned" environment where the tests are known to work, which can be fairly easily reproduced by any developer.
---
Changes in v4:
- NOT ADDRESSED: still using errno==ENOENT as a hacky way to detect
buggy filesystems:
https://lore.kernel.org/all/CA+i-1C3srkh44tN8dMQ5aD-jhoksUkdEpa+mMfdDtDrPAUv7gQ@mail.gmail.com/
- Added some incomplete cleanups for the mlock tests.
- Fixed divide-by-zero error when running uffd-stress on <32cpu systems.
- Fixed misnamed nr_threads variable (now nr_parallel).
- Fixed reporting io_uring errors (retval instead of errno).
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Added fix for userfaultfd tests.
- Dropped attempts to use sudo.
- Fixed garbage printf in uffd-stress.
(Added EXTRA_CFLAGS=-Werror FORCE_TARGETS=1 to my scripts to prevent
such errors happening again).
- Fixed missing newlines in ksft_test_result_skip() calls.
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2 (Thanks to Dev for the reviews):
- Improve and cleanup some error messages
- Add some extra SKIPs
- Fix misnaming of nr_cpus variable in uffd tests
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Brendan Jackman (12):
selftests/mm: Report errno when things fail in gup_longterm selftests/mm: Skip uffd-stress if userfaultfd not available selftests/mm: Skip uffd-wp-mremap if userfaultfd not available selftests/mm/uffd: Rename nr_cpus -> nr_parallel selftests/mm: Print some details when uffd-stress gets bad params selftests/mm: Don't fail uffd-stress if too many CPUs selftests/mm: Skip map_populate on weird filesystems selftests/mm: Skip gup_longterm tests on weird filesystems selftests/mm: Drop unnecessary sudo usage selftests/mm: Ensure uffd-wp-mremap gets pages of each size selftests/mm: Skip mlock tests if nobody user can't read it selftests/mm/mlock: Print error on failure
tools/testing/selftests/mm/gup_longterm.c | 45 +++++++++++++++++--------- tools/testing/selftests/mm/map_populate.c | 7 ++++ tools/testing/selftests/mm/mlock-random-test.c | 4 +-- tools/testing/selftests/mm/mlock2.h | 8 ++++- tools/testing/selftests/mm/run_vmtests.sh | 27 ++++++++++++++-- tools/testing/selftests/mm/uffd-common.c | 8 ++--- tools/testing/selftests/mm/uffd-common.h | 2 +- tools/testing/selftests/mm/uffd-stress.c | 42 +++++++++++++++--------- tools/testing/selftests/mm/uffd-unit-tests.c | 2 +- tools/testing/selftests/mm/uffd-wp-mremap.c | 5 ++- 10 files changed, 105 insertions(+), 45 deletions(-)
---
base-commit: dcb38e6757f1b7944af9347ce6b54263d3666478
change-id: 20250220-mm-selftests-2d7d0542face
Best regards,
Signature · 1 line
Brendan Jackman <[email protected]>
PATCH v4 1/12 selftests/mm: Report errno when things fail in gup_longterm
Just reporting failure doesn't tell you what went wrong. This can fail in different ways so report errno to help the reader get started debugging.
--- tools/testing/selftests/mm/gup_longterm.c | 37 ++++++++++++++++++------------- 1 file changed, 21 insertions(+), 16 deletions(-)
tools/testing/selftests/mm/gup_longterm.c +21 -16
@@ -96,13 +96,13 @@ static void do_test(int fd, size_t size, enum test_type type, bool shared)int ret;if (ftruncate (fd, size)) { -ksft_test_result_fail ("ftruncate() failed\n" ); +ksft_test_result_fail ("ftruncate() failed (%s)\n" ,strerror (errno));return ; }if (fallocate (fd,0 ,0 , size)) {if (size == pagesize) -ksft_test_result_fail ("fallocate() failed\n" ); +ksft_test_result_fail ("fallocate() failed (%s)\n" ,strerror (errno));else ksft_test_result_skip ("need more free huge pages\n" );return ;
@@ -112,7 +112,7 @@ static void do_test(int fd, size_t size, enum test_type type, bool shared) shared ? MAP_SHARED : MAP_PRIVATE, fd, 0);if (mem ==MAP_FAILED ) {if (size == pagesize || shared) -ksft_test_result_fail ("mmap() failed\n" ); +ksft_test_result_fail ("mmap() failed (%s)\n" ,strerror (errno));else ksft_test_result_skip ("need more free huge pages\n" );return ;
@@ -130,7 +130,7 @@ static void do_test(int fd, size_t size, enum test_type type, bool shared)*/ ret =mprotect (mem, size,PROT_READ );if (ret) { -ksft_test_result_fail ("mprotect() failed\n" ); +ksft_test_result_fail ("mprotect() failed (%s)\n" ,strerror (errno)); goto munmap; }/* FALLTHROUGH */
@@ -165,18 +165,20 @@ static void do_test(int fd, size_t size, enum test_type type, bool shared) args.flags |= rw ?PIN_LONGTERM_TEST_FLAG_USE_WRITE :0 ; ret =ioctl (gup_fd,PIN_LONGTERM_TEST_START , &args);if (ret && errno ==EINVAL ) { -ksft_test_result_skip ("PIN_LONGTERM_TEST_START failed\n" ); +ksft_test_result_skip ("PIN_LONGTERM_TEST_START failed (EINVAL)n" );break ; }else if (ret && errno ==EFAULT ) {ksft_test_result (!should_work,"Should have failed\n" );break ; }else if (ret) { -ksft_test_result_fail ("PIN_LONGTERM_TEST_START failed\n" ); +ksft_test_result_fail ("PIN_LONGTERM_TEST_START failed (%s)\n" , +strerror (errno));break ; }if (ioctl (gup_fd,PIN_LONGTERM_TEST_STOP )) -ksft_print_msg ("[INFO] PIN_LONGTERM_TEST_STOP failed\n" ); +ksft_print_msg ("[INFO] PIN_LONGTERM_TEST_STOP failed (%s)\n" , +strerror (errno));/* * TODO: if the kernel ever supports long-term R/W pinning on
@@ -202,7 +204,8 @@ static void do_test(int fd, size_t size, enum test_type type, bool shared)/* Skip on errors, as we might just lack kernel support. */ ret =io_uring_queue_init (1 , &ring,0 );if (ret <0 ) { -ksft_test_result_skip ("io_uring_queue_init() failed\n" ); +ksft_test_result_skip ("io_uring_queue_init() failed (%s)\n" , +strerror (-ret));break ; }/*
@@ -215,13 +218,15 @@ static void do_test(int fd, size_t size, enum test_type type, bool shared)/* Only new kernels return EFAULT. */ if (ret && (errno ==ENOSPC || errno ==EOPNOTSUPP || errno ==EFAULT )) { -ksft_test_result (!should_work,"Should have failed\n" ); +ksft_test_result (!should_work,"Should have failed (%s)\n" , +strerror (errno)); }else if (ret) {/* * We might just lack support or have insufficient * MEMLOCK limits. */ -ksft_test_result_skip ("io_uring_register_buffers() failed\n" ); +ksft_test_result_skip ("io_uring_register_buffers() failed (%s)\n" , +strerror (-ret)); }else {ksft_test_result (should_work,"Should have worked\n" );io_uring_unregister_buffers (&ring);
@@ -249,7 +254,7 @@ static void run_with_memfd(test_fn fn, const char *desc) fd =memfd_create ("test" ,0 );if (fd <0 ) { -ksft_test_result_fail ("memfd_create() failed\n" ); +ksft_test_result_fail ("memfd_create() failed (%s)\n" ,strerror (errno));return ; }
@@ -266,13 +271,13 @@ static void run_with_tmpfile(test_fn fn, const char *desc) file =tmpfile ();if (!file) { -ksft_test_result_fail ("tmpfile() failed\n" ); +ksft_test_result_fail ("tmpfile() failed (%s)\n" ,strerror (errno));return ; } fd =fileno (file);if (fd <0 ) { -ksft_test_result_fail ("fileno() failed\n" ); +ksft_test_result_fail ("fileno() failed (%s)\n" ,strerror (errno)); goto close; }
@@ -290,12 +295,12 @@ static void run_with_local_tmpfile(test_fn fn, const char *desc) fd =mkstemp (filename);if (fd <0 ) { -ksft_test_result_fail ("mkstemp() failed\n" ); +ksft_test_result_fail ("mkstemp() failed (%s)\n" ,strerror (errno));return ; }if (unlink (filename)) { -ksft_test_result_fail ("unlink() failed\n" ); +ksft_test_result_fail ("unlink() failed (%s)\n" ,strerror (errno)); goto close; }
@@ -317,7 +322,7 @@ static void run_with_memfd_hugetlb(test_fn fn, const char *desc, fd =memfd_create ("test" , flags);if (fd <0 ) { -ksft_test_result_skip ("memfd_create() failed\n" ); +ksft_test_result_skip ("memfd_create() failed (%s)\n" ,strerror (errno));return ; }
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
PATCH v4 2/12 selftests/mm: Skip uffd-stress if userfaultfd not available
In reply to Brendan JackmanIt's pretty obvious that the test wouldn't work if you don't have the feature enabled. But, it's still useful to SKIP instead of failing so the reader can immediately tell that this is the reason why.
--- tools/testing/selftests/mm/uffd-stress.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/mm/uffd-stress.c +2 -2
@@ -412,8 +412,8 @@ static void parse_test_type_arg(const char *raw_type)* feature. */ -if (uffd_get_features (&features)) -err ("failed to get available features" ); +if (uffd_get_features (&features) && errno ==ENOENT ) +ksft_exit_skip ("failed to get available features (%d)\n" , errno); test_uffdio_wp = test_uffdio_wp && (features &UFFD_FEATURE_PAGEFAULT_FLAG_WP );
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
PATCH v4 3/12 selftests/mm: Skip uffd-wp-mremap if userfaultfd not available
In reply to Brendan JackmanIt's obvious that this should fail in that case, but still, save the reader the effort of figuring out that they've run into this by just SKIPping
--- tools/testing/selftests/mm/uffd-wp-mremap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/testing/selftests/mm/uffd-wp-mremap.c +4 -1
@@ -182,7 +182,10 @@ static void test_one_folio(size_t size, bool private, bool swapout, bool hugetlb/* Register range for uffd-wp. */ if (userfaultfd_open (&features)) { -ksft_test_result_fail ("userfaultfd_open() failed\n" ); +if (errno ==ENOENT ) +ksft_test_result_skip ("userfaultfd not available\n" ); +else +ksft_test_result_fail ("userfaultfd_open() failed\n" ); goto out; }if (uffd_register (uffd, mem, size, false, true, false)) {
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
PATCH v4 4/12 selftests/mm/uffd: Rename nr_cpus -> nr_parallel
In reply to Brendan JackmanA later commit will bound this variable so it no longer necessarily matches the number of CPUs. Rename it appropriately.
--- tools/testing/selftests/mm/uffd-common.c | 8 ++++---- tools/testing/selftests/mm/uffd-common.h | 2 +- tools/testing/selftests/mm/uffd-stress.c | 28 ++++++++++++++-------------- tools/testing/selftests/mm/uffd-unit-tests.c | 2 +- 4 files changed, 20 insertions(+), 20 deletions(-)
tools/testing/selftests/mm/uffd-common.c +4 -4
@@ -10,7 +10,7 @@#define BASE_PMD_ADDR ((void *)(1UL << 30))volatile bool test_uffdio_copy_eexist = true; -unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size; +unsigned long nr_parallel, nr_pages, nr_pages_per_cpu, page_size;char *area_src, *area_src_alias, *area_dst, *area_dst_alias, *area_remap;int uffd =-1 , uffd_flags, finished, *pipefd, test_type;bool map_shared;
@@ -269,7 +269,7 @@ void uffd_test_ctx_clear(void)size_t i;if (pipefd) { -for (i =0 ; i < nr_cpus *2 ; ++i) { +for (i =0 ; i < nr_parallel *2 ; ++i) {if (close (pipefd[i]))err ("close pipefd" ); }
@@ -365,10 +365,10 @@ int uffd_test_ctx_init(uint64_t features, const char **errmsg)*/ uffd_test_ops->release_pages (area_dst); - pipefd =malloc (sizeof (int ) * nr_cpus *2 ); + pipefd =malloc (sizeof (int ) * nr_parallel *2 );if (!pipefd)err ("pipefd" ); -for (cpu =0 ; cpu < nr_cpus; cpu++) +for (cpu =0 ; cpu < nr_parallel; cpu++)if (pipe2 (&pipefd[cpu *2 ],O_CLOEXEC |O_NONBLOCK ))err ("pipe" );
tools/testing/selftests/mm/uffd-common.h +1 -1
@@ -98,7 +98,7 @@ struct uffd_test_case_ops { };typedef struct uffd_test_case_ops uffd_test_case_ops_t ; -extern unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size; +extern unsigned long nr_parallel, nr_pages, nr_pages_per_cpu, page_size;extern char *area_src, *area_src_alias, *area_dst, *area_dst_alias, *area_remap;extern int uffd, uffd_flags, finished, *pipefd, test_type;extern bool map_shared;
tools/testing/selftests/mm/uffd-stress.c +14 -14
@@ -180,12 +180,12 @@ static void *background_thread(void *arg)static int stress (struct uffd_args *args) {unsigned long cpu; -pthread_t locking_threads[nr_cpus]; -pthread_t uffd_threads[nr_cpus]; -pthread_t background_threads[nr_cpus]; +pthread_t locking_threads[nr_parallel]; +pthread_t uffd_threads[nr_parallel]; +pthread_t background_threads[nr_parallel]; finished =0 ; -for (cpu =0 ; cpu < nr_cpus; cpu++) { +for (cpu =0 ; cpu < nr_parallel; cpu++) {if (pthread_create (&locking_threads[cpu], &attr, locking_thread, (void *)cpu))return 1 ;
@@ -203,7 +203,7 @@ static int stress(struct uffd_args *args) background_thread, (void *)cpu))return 1 ; } -for (cpu =0 ; cpu < nr_cpus; cpu++) +for (cpu =0 ; cpu < nr_parallel; cpu++)if (pthread_join (background_threads[cpu],NULL ))return 1 ;
@@ -219,11 +219,11 @@ static int stress(struct uffd_args *args) uffd_test_ops->release_pages (area_src); finished =1 ; -for (cpu =0 ; cpu < nr_cpus; cpu++) +for (cpu =0 ; cpu < nr_parallel; cpu++)if (pthread_join (locking_threads[cpu],NULL ))return 1 ; -for (cpu =0 ; cpu < nr_cpus; cpu++) { +for (cpu =0 ; cpu < nr_parallel; cpu++) {char c;if (bounces &BOUNCE_POLL ) {if (write (pipefd[cpu*2 +1 ], &c,1 ) !=1 )
@@ -246,11 +246,11 @@ static int userfaultfd_stress(void) {void *area;unsigned long nr; -struct uffd_args args[nr_cpus]; +struct uffd_args args[nr_parallel];uint64_t mem_size = nr_pages * page_size;int flags =0 ; -memset (args,0 ,sizeof (struct uffd_args ) * nr_cpus); +memset (args,0 ,sizeof (struct uffd_args ) * nr_parallel);if (features &UFFD_FEATURE_WP_UNPOPULATED && test_type ==TEST_ANON ) flags =UFFD_FEATURE_WP_UNPOPULATED ;
@@ -325,7 +325,7 @@ static int userfaultfd_stress(void)*/ uffd_test_ops->release_pages (area_dst); -uffd_stats_reset (args, nr_cpus); +uffd_stats_reset (args, nr_parallel);/* bounce pass */ if (stress (args)) {
@@ -359,7 +359,7 @@ static int userfaultfd_stress(void)swap (area_src_alias, area_dst_alias); -uffd_stats_report (args, nr_cpus); +uffd_stats_report (args, nr_parallel); }uffd_test_ctx_clear ();
@@ -453,9 +453,9 @@ int main(int argc, char **argv)return KSFT_SKIP ; } - nr_cpus =sysconf (_SC_NPROCESSORS_ONLN); + nr_parallel =sysconf (_SC_NPROCESSORS_ONLN); - nr_pages_per_cpu = bytes / page_size / nr_cpus; + nr_pages_per_cpu = bytes / page_size / nr_parallel;if (!nr_pages_per_cpu) {_err ("invalid MiB" );usage ();
@@ -466,7 +466,7 @@ int main(int argc, char **argv)_err ("invalid bounces" );usage (); } - nr_pages = nr_pages_per_cpu * nr_cpus; + nr_pages = nr_pages_per_cpu * nr_parallel;printf ("nr_pages: %lu, nr_pages_per_cpu: %lu\n" , nr_pages, nr_pages_per_cpu);
tools/testing/selftests/mm/uffd-unit-tests.c +1 -1
@@ -198,7 +198,7 @@ uffd_setup_environment(uffd_test_args_t *args, uffd_test_case_t *test, nr_pages =UFFD_TEST_MEM_SIZE / page_size;/* TODO: remove this global var.. it's so ugly */ - nr_cpus =1 ; + nr_parallel =1 ;/* Initialize test arguments */ args->mem_type = mem_type;
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
PATCH v4 5/12 selftests/mm: Print some details when uffd-stress gets bad params
In reply to Brendan JackmanSo this can be debugged more easily.
--- tools/testing/selftests/mm/uffd-stress.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/mm/uffd-stress.c +2 -1
@@ -457,7 +457,8 @@ int main(int argc, char **argv) nr_pages_per_cpu = bytes / page_size / nr_parallel;if (!nr_pages_per_cpu) { -_err ("invalid MiB" ); +_err ("pages_per_cpu = 0, cannot test (%lu / %lu / %lu)" , + bytes, page_size, nr_parallel);usage (); }
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
PATCH v4 6/12 selftests/mm: Don't fail uffd-stress if too many CPUs
In reply to Brendan JackmanThis calculation divides a fixed parameter by an environment-dependent parameter i.e. the number of CPUs.
The simple way to avoid machine-specific failures here is to just put a cap on the max value of the latter.
--- tools/testing/selftests/mm/uffd-stress.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
tools/testing/selftests/mm/uffd-stress.c +10 -1
@@ -435,6 +435,7 @@ static void sigalrm(int sig)int main (int argc,char **argv) { +unsigned long nr_cpus;size_t bytes;if (argc <4 )
@@ -453,7 +454,15 @@ int main(int argc, char **argv)return KSFT_SKIP ; } - nr_parallel =sysconf (_SC_NPROCESSORS_ONLN); + nr_cpus =sysconf (_SC_NPROCESSORS_ONLN); +if (nr_cpus >32 ) { +/* Don't let calculation below go to zero. */ +ksft_print_msg ("_SC_NPROCESSORS_ONLN (%lu) too large, capping nr_threads to 32\n" , + nr_cpus); + nr_parallel =32 ; + }else { + nr_parallel = nr_cpus; + } nr_pages_per_cpu = bytes / page_size / nr_parallel;if (!nr_pages_per_cpu) {
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
PATCH v4 7/12 selftests/mm: Skip map_populate on weird filesystems
In reply to Brendan JackmanIt seems that 9pfs does not allow truncating unlinked files, Mark Brown has noted that NFS may also behave this way.
It doesn't seem quite right to call this a "bug" but it's probably a special enough case that it makes sense for the test to just SKIP if it happens.
--- tools/testing/selftests/mm/map_populate.c | 7 +++++++ 1 file changed, 7 insertions(+)
tools/testing/selftests/mm/map_populate.c +7 -0
@@ -87,6 +87,13 @@ int main(int argc, char **argv)BUG_ON (!ftmp,"tmpfile()" ); ret =ftruncate (fileno (ftmp),MMAP_SZ ); +if (ret <0 && errno ==ENOENT ) { +/* +* This probably means tmpfile() made a file on a filesystem +* that doesn't handle temporary files the way we want. +*/ +ksft_exit_skip ("ftruncate(fileno(tmpfile())) gave ENOENT, weird filesystem?\n" ); + }BUG_ON (ret,"ftruncate()" ); smap = mmap(0, MMAP_SZ, PROT_READ | PROT_WRITE,
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
PATCH v4 8/12 selftests/mm: Skip gup_longterm tests on weird filesystems
In reply to Brendan JackmanSome filesystems don't support ftruncate()ing unlinked files. They return ENOENT. In that case, skip the test.
--- tools/testing/selftests/mm/gup_longterm.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
tools/testing/selftests/mm/gup_longterm.c +9 -1
@@ -96,7 +96,15 @@ static void do_test(int fd, size_t size, enum test_type type, bool shared)int ret;if (ftruncate (fd, size)) { -ksft_test_result_fail ("ftruncate() failed (%s)\n" ,strerror (errno)); +if (errno ==ENOENT ) { +/* +* This can happen if the file has been unlinked and the +* filesystem doesn't support truncating unlinked files. +*/ +ksft_test_result_skip ("ftruncate() failed with ENOENT\n" ); + }else { +ksft_test_result_fail ("ftruncate() failed (%s)\n" ,strerror (errno)); + }return ; }
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
PATCH v4 9/12 selftests/mm: Drop unnecessary sudo usage
In reply to Brendan JackmanThis script must be run as root anyway (see all the writing to privileged files in /proc etc).
Remove the unnecessary use of sudo to avoid breaking on single-user systems that don't have sudo. This also avoids confusing readers.
--- tools/testing/selftests/mm/run_vmtests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/mm/run_vmtests.sh +1 -1
@@ -386,7 +386,7 @@ CATEGORY="madv_populate" run_test ./madv_populate if [ -x ./memfd_secret ] then -(echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope 2>&1) | tap_prefix +(echo 0 > /proc/sys/kernel/yama/ptrace_scope 2>&1) | tap_prefix CATEGORY="memfd_secret" run_test ./memfd_secret fi
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
PATCH v4 10/12 selftests/mm: Ensure uffd-wp-mremap gets pages of each size
In reply to Brendan JackmanThis test allocates a page of every available size and doesn't have any SKIP logic if the allocation fails. So, ensure it's available and skip the test if we can't do so.
--- tools/testing/selftests/mm/run_vmtests.sh | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
tools/testing/selftests/mm/run_vmtests.sh +22 -1
@@ -309,9 +309,30 @@ CATEGORY="userfaultfd" run_test ${uffd_stress_bin} hugetlb "$half_ufd_size_MB" 3 CATEGORY="userfaultfd" run_test ${uffd_stress_bin} hugetlb-private "$half_ufd_size_MB" 32 CATEGORY="userfaultfd" run_test ${uffd_stress_bin} shmem 20 16 CATEGORY="userfaultfd" run_test ${uffd_stress_bin} shmem-private 20 16 -CATEGORY="userfaultfd" run_test ./uffd-wp-mremap +# uffd-wp-mremap requires at least one page of each size. +have_all_size_hugepgs=true +declare -A nr_size_hugepgs +for f in /sys/kernel/mm/hugepages/**/nr_hugepages; do + old=$(cat $f) + nr_size_hugepgs["$f"]="$old" + if [ "$old" == 0 ]; then + echo 1 > "$f" + fi + if [ $(cat "$f") == 0 ]; then + have_all_size_hugepgs=false + break + fi +done +if $have_all_size_hugepgs; then + CATEGORY="userfaultfd" run_test ./uffd-wp-mremap +else + echo "# SKIP ./uffd-wp-mremap" +fi #cleanup +for f in "${!nr_size_hugepgs[@]}"; do + echo "${nr_size_hugepgs["$f"]}" > "$f" +done echo "$nr_hugepgs" > /proc/sys/vm/nr_hugepages CATEGORY="compaction" run_test ./compaction_test
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
PATCH v4 11/12 selftests/mm: Skip mlock tests if nobody user can't read it
In reply to Brendan JackmanIf running from a directory that can't be read by unprivileged users, executing on-fault-test via the nobody user will fail.
The kselftest build does give the file the correct permissions, but after being installed it might be in a directory without global execute permissions.
Since the script can't safely fix that, just skip if it happens. Note that the stderr of the ls command is unfiltered meaning the user sees a "permission denied" error that can help inform them why the test was skipped.
--- tools/testing/selftests/mm/run_vmtests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/mm/run_vmtests.sh +1 -1
@@ -337,7 +337,7 @@ echo "$nr_hugepgs" > /proc/sys/vm/nr_hugepages CATEGORY="compaction" run_test ./compaction_test -if command -v sudo &> /dev/null; +if command -v sudo &> /dev/null && sudo -u nobody ls ./on-fault-limit >/dev/null; then CATEGORY="mlock" run_test sudo -u nobody ./on-fault-limit else
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
PATCH v4 12/12 selftests/mm/mlock: Print error on failure
In reply to Brendan JackmanIt's not really possible to start diagnosing this without knowing the actual error.
Also update the mlock2 helper to behave like libc would by setting errno and returning -1.
--- tools/testing/selftests/mm/mlock-random-test.c | 4 ++-- tools/testing/selftests/mm/mlock2.h | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-)
tools/testing/selftests/mm/mlock-random-test.c +2 -2
@@ -161,9 +161,9 @@ static void test_mlock_within_limit(char *p, int alloc_size) MLOCK_ONFAULT);if (ret) -ksft_exit_fail_msg ("%s() failure at |%p(%d)| mlock:|%p(%d)|\n" , +ksft_exit_fail_msg ("%s() failure (%s) at |%p(%d)| mlock:|%p(%d)|\n" , is_mlock ?"mlock" :"mlock2" , - p, alloc_size, +strerror (errno), p, alloc_size, p + start_offset, lock_size); }
tools/testing/selftests/mm/mlock2.h +7 -1
@@ -6,7 +6,13 @@static int mlock2_ (void *start,size_t len,int flags) { -return syscall (__NR_mlock2, start, len, flags); +int ret =syscall (__NR_mlock2, start, len, flags); + +if (ret) { + errno = ret; +return -1 ; + } +return 0 ; }static FILE *seek_to_smaps_entry (unsigned long addr)
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog