* [PATCH v2 1/9] selftests/mm: Report errno when things fail in gup_longterm
2025-02-21 18:25 [PATCH v2 0/9] selftests/mm: Some cleanups from trying to run them Brendan Jackman
@ 2025-02-21 18:25 ` Brendan Jackman
2025-02-21 18:25 ` [PATCH v2 2/9] selftests/mm: Fix assumption that sudo is present Brendan Jackman
` (7 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Brendan Jackman @ 2025-02-21 18:25 UTC (permalink / raw)
To: Lorenzo Stoakes, Andrew Morton, Shuah Khan
Cc: Dev Jain, linux-mm, linux-kselftest, linux-kernel, Brendan Jackman
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.
Signed-off-by: Brendan Jackman <jackmanb@google.com>
---
tools/testing/selftests/mm/gup_longterm.c | 37 ++++++++++++++++++-------------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/tools/testing/selftests/mm/gup_longterm.c b/tools/testing/selftests/mm/gup_longterm.c
index 9423ad439a6140163bdef2974615bb86406a8c14..879e9e4e8cce8127656fabe098abf7db5f6c5e23 100644
--- a/tools/testing/selftests/mm/gup_longterm.c
+++ b/tools/testing/selftests/mm/gup_longterm.c
@@ -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(errno));
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(errno));
} 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;
}
--
2.48.1.601.g30ceb7b040-goog
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v2 2/9] selftests/mm: Fix assumption that sudo is present
2025-02-21 18:25 [PATCH v2 0/9] selftests/mm: Some cleanups from trying to run them Brendan Jackman
2025-02-21 18:25 ` [PATCH v2 1/9] selftests/mm: Report errno when things fail in gup_longterm Brendan Jackman
@ 2025-02-21 18:25 ` Brendan Jackman
2025-02-21 18:25 ` [PATCH v2 3/9] selftests/mm: Skip uffd-stress if userfaultfd not available Brendan Jackman
` (6 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Brendan Jackman @ 2025-02-21 18:25 UTC (permalink / raw)
To: Lorenzo Stoakes, Andrew Morton, Shuah Khan
Cc: Dev Jain, linux-mm, linux-kselftest, linux-kernel, Brendan Jackman
If we are root, sudo isn't needed. If we are not root, we need sudo, so
skip the test if it isn't present.
We already do this for on-fault-limit, but this uses separate
infrastructure since that is specifically for sudo-ing to the nobody
user.
Note this ptrace_skip configuration still fails if that file doesn't
exist, but in that case the test is still fine, so this just prints an
error but doesn't break anything. I suspect that's probably deliberate.
Signed-off-by: Brendan Jackman <jackmanb@google.com>
---
tools/testing/selftests/mm/run_vmtests.sh | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh
index da7e266681031d2772fb0c4139648904a18e0bf9..9c963f50927ab2b10c3f942cedd087087d4d0def 100755
--- a/tools/testing/selftests/mm/run_vmtests.sh
+++ b/tools/testing/selftests/mm/run_vmtests.sh
@@ -89,6 +89,17 @@ RUN_ALL=false
RUN_DESTRUCTIVE=false
TAP_PREFIX="# "
+# We can do stuff as root either if we are already root, or if sudo exists.
+if [ "$(id -u)" == 0 ]; then
+ HAVE_SUDO_ROOT=true
+ SUDO_ROOT=
+elif command -v sudo >/dev/null 2>&1; then
+ HAVE_SUDO_ROOT=true
+ SUDO_ROOT=sudo
+else
+ HAVE_SUDO_ROOT=false
+fi
+
while getopts "aht:n" OPT; do
case ${OPT} in
"a") RUN_ALL=true ;;
@@ -384,10 +395,13 @@ CATEGORY="madv_guard" run_test ./guard-pages
# MADV_POPULATE_READ and MADV_POPULATE_WRITE tests
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
-CATEGORY="memfd_secret" run_test ./memfd_secret
+if [ -x ./memfd_secret ]; then
+ if $HAVE_SUDO_ROOT; then
+ (echo 0 | $SUDO_ROOT tee /proc/sys/kernel/yama/ptrace_scope 2>&1) | tap_prefix
+ CATEGORY="memfd_secret" run_test ./memfd_secret
+ else
+ echo "# SKIP ./memfd_secret"
+ fi
fi
# KSM KSM_MERGE_TIME_HUGE_PAGES test with size of 100
--
2.48.1.601.g30ceb7b040-goog
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v2 3/9] selftests/mm: Skip uffd-stress if userfaultfd not available
2025-02-21 18:25 [PATCH v2 0/9] selftests/mm: Some cleanups from trying to run them Brendan Jackman
2025-02-21 18:25 ` [PATCH v2 1/9] selftests/mm: Report errno when things fail in gup_longterm Brendan Jackman
2025-02-21 18:25 ` [PATCH v2 2/9] selftests/mm: Fix assumption that sudo is present Brendan Jackman
@ 2025-02-21 18:25 ` Brendan Jackman
2025-02-21 18:25 ` [PATCH v2 4/9] selftests/mm: Skip uffd-wp-mremap " Brendan Jackman
` (5 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Brendan Jackman @ 2025-02-21 18:25 UTC (permalink / raw)
To: Lorenzo Stoakes, Andrew Morton, Shuah Khan
Cc: Dev Jain, linux-mm, linux-kselftest, linux-kernel, Brendan Jackman
It'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.
Signed-off-by: Brendan Jackman <jackmanb@google.com>
---
tools/testing/selftests/mm/uffd-stress.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c
index a4b83280998ab7ce8d31e91d8f9fbb47ef11d742..ed68436fac62c76e2ca7060c661487f2f8a6ab45 100644
--- a/tools/testing/selftests/mm/uffd-stress.c
+++ b/tools/testing/selftests/mm/uffd-stress.c
@@ -411,8 +411,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);
--
2.48.1.601.g30ceb7b040-goog
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v2 4/9] selftests/mm: Skip uffd-wp-mremap if userfaultfd not available
2025-02-21 18:25 [PATCH v2 0/9] selftests/mm: Some cleanups from trying to run them Brendan Jackman
` (2 preceding siblings ...)
2025-02-21 18:25 ` [PATCH v2 3/9] selftests/mm: Skip uffd-stress if userfaultfd not available Brendan Jackman
@ 2025-02-21 18:25 ` Brendan Jackman
2025-02-21 18:25 ` [PATCH v2 5/9] selftests/mm/uffd: Rename nr_cpus -> nr_threads Brendan Jackman
` (4 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Brendan Jackman @ 2025-02-21 18:25 UTC (permalink / raw)
To: Lorenzo Stoakes, Andrew Morton, Shuah Khan
Cc: Dev Jain, linux-mm, linux-kselftest, linux-kernel, Brendan Jackman
It'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
Signed-off-by: Brendan Jackman <jackmanb@google.com>
---
tools/testing/selftests/mm/uffd-wp-mremap.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/uffd-wp-mremap.c b/tools/testing/selftests/mm/uffd-wp-mremap.c
index 2c4f984bd73caa17e12b9f4a5bb71e7fdf5d8554..c2ba7d46c7b4581a3c32a6b6acd148e3e89c2172 100644
--- a/tools/testing/selftests/mm/uffd-wp-mremap.c
+++ b/tools/testing/selftests/mm/uffd-wp-mremap.c
@@ -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)) {
--
2.48.1.601.g30ceb7b040-goog
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v2 5/9] selftests/mm/uffd: Rename nr_cpus -> nr_threads
2025-02-21 18:25 [PATCH v2 0/9] selftests/mm: Some cleanups from trying to run them Brendan Jackman
` (3 preceding siblings ...)
2025-02-21 18:25 ` [PATCH v2 4/9] selftests/mm: Skip uffd-wp-mremap " Brendan Jackman
@ 2025-02-21 18:25 ` Brendan Jackman
2025-02-21 18:25 ` [PATCH v2 6/9] selftests/mm: Print some details when uffd-stress gets bad params Brendan Jackman
` (3 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Brendan Jackman @ 2025-02-21 18:25 UTC (permalink / raw)
To: Lorenzo Stoakes, Andrew Morton, Shuah Khan
Cc: Dev Jain, linux-mm, linux-kselftest, linux-kernel, Brendan Jackman
A later commit will bound this variable so it no longer necessarily
matches the number of CPUs. Rename it appropriately.
Signed-off-by: Brendan Jackman <jackmanb@google.com>
---
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(-)
diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c
index 717539eddf98754250e70e564cd9a59f398bd7ea..a72a2ed5e89480ed06c81b034967ed5ae5f8cad5 100644
--- a/tools/testing/selftests/mm/uffd-common.c
+++ b/tools/testing/selftests/mm/uffd-common.c
@@ -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_threads, 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_threads * 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_threads * 2);
if (!pipefd)
err("pipefd");
- for (cpu = 0; cpu < nr_cpus; cpu++)
+ for (cpu = 0; cpu < nr_threads; cpu++)
if (pipe2(&pipefd[cpu * 2], O_CLOEXEC | O_NONBLOCK))
err("pipe");
diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h
index a70ae10b5f6206daecc8e19ed3e3bbb388e265aa..604e3572fe17280ae346b031e2e867e039578f95 100644
--- a/tools/testing/selftests/mm/uffd-common.h
+++ b/tools/testing/selftests/mm/uffd-common.h
@@ -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_threads, 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;
diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c
index ed68436fac62c76e2ca7060c661487f2f8a6ab45..ec842bbb9f18e291fa51de0ed8d1fbf9aaf14372 100644
--- a/tools/testing/selftests/mm/uffd-stress.c
+++ b/tools/testing/selftests/mm/uffd-stress.c
@@ -179,12 +179,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_threads];
+ pthread_t uffd_threads[nr_threads];
+ pthread_t background_threads[nr_threads];
finished = 0;
- for (cpu = 0; cpu < nr_cpus; cpu++) {
+ for (cpu = 0; cpu < nr_threads; cpu++) {
if (pthread_create(&locking_threads[cpu], &attr,
locking_thread, (void *)cpu))
return 1;
@@ -202,7 +202,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_threads; cpu++)
if (pthread_join(background_threads[cpu], NULL))
return 1;
@@ -218,11 +218,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_threads; cpu++)
if (pthread_join(locking_threads[cpu], NULL))
return 1;
- for (cpu = 0; cpu < nr_cpus; cpu++) {
+ for (cpu = 0; cpu < nr_threads; cpu++) {
char c;
if (bounces & BOUNCE_POLL) {
if (write(pipefd[cpu*2+1], &c, 1) != 1)
@@ -245,11 +245,11 @@ static int userfaultfd_stress(void)
{
void *area;
unsigned long nr;
- struct uffd_args args[nr_cpus];
+ struct uffd_args args[nr_threads];
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_threads);
if (features & UFFD_FEATURE_WP_UNPOPULATED && test_type == TEST_ANON)
flags = UFFD_FEATURE_WP_UNPOPULATED;
@@ -324,7 +324,7 @@ static int userfaultfd_stress(void)
*/
uffd_test_ops->release_pages(area_dst);
- uffd_stats_reset(args, nr_cpus);
+ uffd_stats_reset(args, nr_threads);
/* bounce pass */
if (stress(args)) {
@@ -358,7 +358,7 @@ static int userfaultfd_stress(void)
swap(area_src_alias, area_dst_alias);
- uffd_stats_report(args, nr_cpus);
+ uffd_stats_report(args, nr_threads);
}
uffd_test_ctx_clear();
@@ -452,9 +452,9 @@ int main(int argc, char **argv)
return KSFT_SKIP;
}
- nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
+ nr_threads = sysconf(_SC_NPROCESSORS_ONLN);
- nr_pages_per_cpu = bytes / page_size / nr_cpus;
+ nr_pages_per_cpu = bytes / page_size / nr_threads;
if (!nr_pages_per_cpu) {
_err("invalid MiB");
usage();
@@ -465,7 +465,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_threads;
printf("nr_pages: %lu, nr_pages_per_cpu: %lu\n",
nr_pages, nr_pages_per_cpu);
diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c
index 9ff71fa1f9bf09b3ae599250663a25bbe2c13b8a..2f84fae5642c6f91b75fbf5f5d59ae64a1c15f92 100644
--- a/tools/testing/selftests/mm/uffd-unit-tests.c
+++ b/tools/testing/selftests/mm/uffd-unit-tests.c
@@ -197,7 +197,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_threads = 1;
/* Initialize test arguments */
args->mem_type = mem_type;
--
2.48.1.601.g30ceb7b040-goog
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v2 6/9] selftests/mm: Print some details when uffd-stress gets bad params
2025-02-21 18:25 [PATCH v2 0/9] selftests/mm: Some cleanups from trying to run them Brendan Jackman
` (4 preceding siblings ...)
2025-02-21 18:25 ` [PATCH v2 5/9] selftests/mm/uffd: Rename nr_cpus -> nr_threads Brendan Jackman
@ 2025-02-21 18:25 ` Brendan Jackman
2025-02-28 12:47 ` Brendan Jackman
2025-02-21 18:25 ` [PATCH v2 7/9] selftests/mm: Don't fail uffd-stress if too many CPUs Brendan Jackman
` (2 subsequent siblings)
8 siblings, 1 reply; 13+ messages in thread
From: Brendan Jackman @ 2025-02-21 18:25 UTC (permalink / raw)
To: Lorenzo Stoakes, Andrew Morton, Shuah Khan
Cc: Dev Jain, linux-mm, linux-kselftest, linux-kernel, Brendan Jackman
So this can be debugged more easily.
Signed-off-by: Brendan Jackman <jackmanb@google.com>
---
tools/testing/selftests/mm/uffd-stress.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c
index ec842bbb9f18e291fa51de0ed8d1fbf9aaf14372..be0c93f24fccd618f52d54ff36d9a5540f420e46 100644
--- a/tools/testing/selftests/mm/uffd-stress.c
+++ b/tools/testing/selftests/mm/uffd-stress.c
@@ -456,7 +456,8 @@ int main(int argc, char **argv)
nr_pages_per_cpu = bytes / page_size / nr_threads;
if (!nr_pages_per_cpu) {
- _err("invalid MiB");
+ _err("pages_per_cpu = 0, cannot test (%lu / %lu / %lu)",
+ nr_pages_per_cpu, bytes, page_size, nr_threads);
usage();
}
--
2.48.1.601.g30ceb7b040-goog
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v2 6/9] selftests/mm: Print some details when uffd-stress gets bad params
2025-02-21 18:25 ` [PATCH v2 6/9] selftests/mm: Print some details when uffd-stress gets bad params Brendan Jackman
@ 2025-02-28 12:47 ` Brendan Jackman
0 siblings, 0 replies; 13+ messages in thread
From: Brendan Jackman @ 2025-02-28 12:47 UTC (permalink / raw)
To: Lorenzo Stoakes, Andrew Morton, Shuah Khan
Cc: Dev Jain, linux-mm, linux-kselftest, linux-kernel
On Fri, 21 Feb 2025 at 19:26, Brendan Jackman <jackmanb@google.com> wrote:
> nr_pages_per_cpu = bytes / page_size / nr_threads;
> if (!nr_pages_per_cpu) {
> - _err("invalid MiB");
> + _err("pages_per_cpu = 0, cannot test (%lu / %lu / %lu)",
> + nr_pages_per_cpu, bytes, page_size, nr_threads);
Ugh, this is garbage, wrong number of args for the format string.
I think I originally had %d instead of 0, then changed and didn't
notice I broke it because it doesn't actually cause the overall
kselftests build to fail. I'll need to find a way to update my scripts
to detect that.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 7/9] selftests/mm: Don't fail uffd-stress if too many CPUs
2025-02-21 18:25 [PATCH v2 0/9] selftests/mm: Some cleanups from trying to run them Brendan Jackman
` (5 preceding siblings ...)
2025-02-21 18:25 ` [PATCH v2 6/9] selftests/mm: Print some details when uffd-stress gets bad params Brendan Jackman
@ 2025-02-21 18:25 ` Brendan Jackman
2025-02-21 18:25 ` [PATCH v2 8/9] selftests/mm: Skip map_populate on weird filesystems Brendan Jackman
2025-02-21 18:25 ` [PATCH v2 9/9] selftests/mm: Skip gup_longerm tests " Brendan Jackman
8 siblings, 0 replies; 13+ messages in thread
From: Brendan Jackman @ 2025-02-21 18:25 UTC (permalink / raw)
To: Lorenzo Stoakes, Andrew Morton, Shuah Khan
Cc: Dev Jain, linux-mm, linux-kselftest, linux-kernel,
Brendan Jackman, Mateusz Guzik
This 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.
Suggested-by: Mateusz Guzik <mjguzik@gmail.com>
Signed-off-by: Brendan Jackman <jackmanb@google.com>
---
tools/testing/selftests/mm/uffd-stress.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c
index be0c93f24fccd618f52d54ff36d9a5540f420e46..cfadac801ed43e8b6dc331b343b6dc4030048f9b 100644
--- a/tools/testing/selftests/mm/uffd-stress.c
+++ b/tools/testing/selftests/mm/uffd-stress.c
@@ -434,6 +434,7 @@ static void sigalrm(int sig)
int main(int argc, char **argv)
{
+ unsigned long nr_cpus;
size_t bytes;
if (argc < 4)
@@ -452,7 +453,15 @@ int main(int argc, char **argv)
return KSFT_SKIP;
}
- nr_threads = 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_threads = 32;
+ } else {
+ nr_cpus = nr_threads;
+ }
nr_pages_per_cpu = bytes / page_size / nr_threads;
if (!nr_pages_per_cpu) {
--
2.48.1.601.g30ceb7b040-goog
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v2 8/9] selftests/mm: Skip map_populate on weird filesystems
2025-02-21 18:25 [PATCH v2 0/9] selftests/mm: Some cleanups from trying to run them Brendan Jackman
` (6 preceding siblings ...)
2025-02-21 18:25 ` [PATCH v2 7/9] selftests/mm: Don't fail uffd-stress if too many CPUs Brendan Jackman
@ 2025-02-21 18:25 ` Brendan Jackman
2025-02-24 10:25 ` Brendan Jackman
2025-02-21 18:25 ` [PATCH v2 9/9] selftests/mm: Skip gup_longerm tests " Brendan Jackman
8 siblings, 1 reply; 13+ messages in thread
From: Brendan Jackman @ 2025-02-21 18:25 UTC (permalink / raw)
To: Lorenzo Stoakes, Andrew Morton, Shuah Khan
Cc: Dev Jain, linux-mm, linux-kselftest, linux-kernel, Brendan Jackman
It 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.
Signed-off-by: Brendan Jackman <jackmanb@google.com>
---
tools/testing/selftests/mm/map_populate.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/tools/testing/selftests/mm/map_populate.c b/tools/testing/selftests/mm/map_populate.c
index 5c8a53869b1bd287b09a250edf628a66c25c2439..cdd88531dd9fe98f2d25edf4878659767c919e8e 100644
--- a/tools/testing/selftests/mm/map_populate.c
+++ b/tools/testing/selftests/mm/map_populate.c
@@ -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?");
+ }
BUG_ON(ret, "ftruncate()");
smap = mmap(0, MMAP_SZ, PROT_READ | PROT_WRITE,
--
2.48.1.601.g30ceb7b040-goog
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v2 8/9] selftests/mm: Skip map_populate on weird filesystems
2025-02-21 18:25 ` [PATCH v2 8/9] selftests/mm: Skip map_populate on weird filesystems Brendan Jackman
@ 2025-02-24 10:25 ` Brendan Jackman
2025-02-27 12:58 ` Brendan Jackman
0 siblings, 1 reply; 13+ messages in thread
From: Brendan Jackman @ 2025-02-24 10:25 UTC (permalink / raw)
To: Lorenzo Stoakes, Andrew Morton, Shuah Khan
Cc: Dev Jain, linux-mm, linux-kselftest, linux-kernel
On Fri, 21 Feb 2025 at 19:26, Brendan Jackman <jackmanb@google.com> wrote:
>
> It seems that 9pfs does not allow truncating unlinked files, Mark Brown
> has noted that NFS may also behave this way.
I have not investigated at all but I _think_ over the weekend I saw
ftruncate() failure on a QEMU guest where /tmp was tmpfs.
Most likely explanation is user probably error (like /tmp wasn't
actually tmpfs or the tmpfile() did not actually come from /tmp). But
still, maybe just waving my hands and going "buggy filesystem, ignore"
wasn't so smart. I should actually understand the problem before
switching off tests.
So, I think this and the other "ignore on weird filesystem" patch 9/9
should be ignored for the moment.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 8/9] selftests/mm: Skip map_populate on weird filesystems
2025-02-24 10:25 ` Brendan Jackman
@ 2025-02-27 12:58 ` Brendan Jackman
0 siblings, 0 replies; 13+ messages in thread
From: Brendan Jackman @ 2025-02-27 12:58 UTC (permalink / raw)
To: Lorenzo Stoakes, Andrew Morton, Shuah Khan
Cc: Dev Jain, linux-mm, linux-kselftest, linux-kernel
On Mon, 24 Feb 2025 at 11:25, Brendan Jackman <jackmanb@google.com> wrote:
>
> On Fri, 21 Feb 2025 at 19:26, Brendan Jackman <jackmanb@google.com> wrote:
> >
> > It seems that 9pfs does not allow truncating unlinked files, Mark Brown
> > has noted that NFS may also behave this way.
>
> I have not investigated at all but I _think_ over the weekend I saw
> ftruncate() failure on a QEMU guest where /tmp was tmpfs.
>
> Most likely explanation is user probably error (like /tmp wasn't
> actually tmpfs or the tmpfile() did not actually come from /tmp).
OK I double checked. It was in fact a 9p filesystem, turns out
virtme-ng uses that unconditionally for its --rwdir/--rodir mounts
even if the root is virtiofsd, and the tests operate on files in the
CWD as well as in /tmp.
I am still pondering ways to tackle this kinda problem more
systematically but for now I think just skipping these tests is fine.
> + ksft_exit_skip("ftruncate(fileno(tmpfile())) gave ENOENT, weird filesystem?");
This is missing a newline though, ditto in the subsequent patch. I
will wait and see if any reviews come in before I send a fixup.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 9/9] selftests/mm: Skip gup_longerm tests on weird filesystems
2025-02-21 18:25 [PATCH v2 0/9] selftests/mm: Some cleanups from trying to run them Brendan Jackman
` (7 preceding siblings ...)
2025-02-21 18:25 ` [PATCH v2 8/9] selftests/mm: Skip map_populate on weird filesystems Brendan Jackman
@ 2025-02-21 18:25 ` Brendan Jackman
8 siblings, 0 replies; 13+ messages in thread
From: Brendan Jackman @ 2025-02-21 18:25 UTC (permalink / raw)
To: Lorenzo Stoakes, Andrew Morton, Shuah Khan
Cc: Dev Jain, linux-mm, linux-kselftest, linux-kernel, Brendan Jackman
Some filesystems don't support funtract()ing unlinked files. They return
ENOENT. In that case, skip the test.
Signed-off-by: Brendan Jackman <jackmanb@google.com>
---
tools/testing/selftests/mm/gup_longterm.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/gup_longterm.c b/tools/testing/selftests/mm/gup_longterm.c
index 879e9e4e8cce8127656fabe098abf7db5f6c5e23..d2c33dd9da9cd43cc6666e5d9ffd3ff9e62dbb27 100644
--- a/tools/testing/selftests/mm/gup_longterm.c
+++ b/tools/testing/selftests/mm/gup_longterm.c
@@ -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");
+ } else {
+ ksft_test_result_fail("ftruncate() failed (%s)\n", strerror(errno));
+ }
return;
}
--
2.48.1.601.g30ceb7b040-goog
^ permalink raw reply [flat|nested] 13+ messages in thread