kernel-selftest: fix ptest hangs and several failing selftests

meta-oe-image-ptest-kernel-selftest on qemux86-64 was killed by
ptest-runner after 34 of 427 tests. Fix the hangs, and a set of
failures found while running the rest of the suite:

- Add coreutils to RDEPENDS: the kselftest runner only enforces
  per-test timeouts when timeout(1) is available, and busybox has
  no timeout applet by default.
- Skip ftrace:ftracetest-ktap: it has no per-test timeout, and
  instances/instance-event.tc can leave a task stuck in D state in
  trace_array_get() on linux-yocto 7.2.4, hanging the whole suite.
- Add e2fsprogs-mke2fs to RDEPENDS, mount_setattr_test needs mkfs.ext4.
- selftests/filelock: zero-initialize struct flock in ofdlocks, which
  memcmp()s structures with uninitialized padding, and fix its test
  plan count (it announces 4 tests but reports 5).
- selftests/cgroup: keep the anon page touches in test_memcontrol
  from being removed as dead stores by GCC 16 at -O2.
- selftests/filesystems: chown the idmapped_tmpfile layer directory
  into the idmapped range so the mapped caller is not refused.
- Backport "selftests: proc: include fcntl.h in proc-pidns" to fix
  the proc selftests build.

Each fix was verified on qemux86-64 by running the affected tests.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
This commit is contained in:
Khem Raj
2026-09-12 16:52:17 -07:00
co-authored by Claude Opus 5
parent 510601e794
commit 11a9324c84
7 changed files with 201 additions and 2 deletions
@@ -19,6 +19,11 @@ MM_PATCH = "file://0001-selftests-mm-pass-down-full-CC-and-CFLAGS-to-check_c.pat
SRC_URI += "file://run-ptest \
file://COPYING \
file://0001-selftests-timers-Fix-clock_adjtime-for-newer-32-bit-.patch \
file://0001-selftests-filelock-zero-initialize-struct-flock-in-o.patch \
file://0001-selftests-filelock-fix-the-test-plan-count-in-ofdloc.patch \
file://0001-selftests-cgroup-memcontrol-keep-anon-page-touches-f.patch \
file://0001-selftests-filesystems-idmapped_tmpfile-chown-the-lay.patch \
file://0001-selftests-proc-include-fcntl.h-in-proc-pidns.patch \
${@bb.utils.contains('PACKAGECONFIG', 'mm', '${MM_PATCH}', '', d)} \
"
@@ -219,7 +224,10 @@ PACKAGE_ARCH = "${MACHINE_ARCH}"
INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
FILES:${PN} += "/usr/kernel-selftest"
RDEPENDS:${PN} += "python3 perl perl-module-io-handle bash libcap libgcc"
# coreutils provides timeout(1) with --foreground, which the kselftest runner
# needs to enforce per-test timeouts; busybox has no timeout applet by default.
# mount_setattr_test creates an ext4 image with mkfs.ext4.
RDEPENDS:${PN} += "python3 perl perl-module-io-handle bash libcap libgcc coreutils e2fsprogs-mke2fs"
INSANE_SKIP:${PN} += "libdir"
@@ -0,0 +1,41 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Khem Raj <khem.raj@oss.qualcomm.com>
Date: Sat, 12 Sep 2026 00:00:00 -0700
Subject: [PATCH] selftests/cgroup: memcontrol: keep anon page touches from
being optimized away
alloc_and_populate_anon() writes one byte per page so that the memory
is faulted in and charged to the cgroup. alloc_anon() inlines it and
frees the buffer right away without reading it, so GCC 16 at -O2 treats
the page writes as dead stores and drops them, leaving an empty loop.
The memory is then never charged and the tests expecting reclaim or
OOM fail:
not ok 3 test_memcg_min
not ok 4 test_memcg_low
not ok 7 test_memcg_max
not ok 9 test_memcg_oom_events
not ok 12 test_memcg_oom_group_leaf_events
not ok 13 test_memcg_oom_group_parent_events
not ok 14 test_memcg_oom_group_score_events
Write through a volatile pointer so the stores are kept.
Upstream-Status: Pending
Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
---
tools/testing/selftests/cgroup/test_memcontrol.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c
--- a/tools/testing/selftests/cgroup/test_memcontrol.c
+++ b/tools/testing/selftests/cgroup/test_memcontrol.c
@@ -67,7 +67,7 @@
}
for (ptr = buf; ptr < buf + size; ptr += page_size)
- *ptr = 0;
+ *(volatile char *)ptr = 0;
return buf;
}
@@ -0,0 +1,34 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Khem Raj <khem.raj@oss.qualcomm.com>
Date: Sat, 12 Sep 2026 00:00:00 -0700
Subject: [PATCH] selftests/filelock: fix the test plan count in ofdlocks
ofdlocks reports five results with ksft_test_result() but announces
only four with ksft_set_plan(4). Once all subtests pass the harness
flags the mismatch and the test fails anyway:
# Planned tests != run tests (4 != 5)
# Totals: pass:5 fail:0 xfail:0 xpass:0 skip:0 error:0
not ok 1 selftests: filelock: ofdlocks # exit=1
Set the plan to five.
Fixes: 33d5b13098fb ("kselftest/filelock: report each test in oftlocks separately")
Upstream-Status: Pending
Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
---
tools/testing/selftests/filelock/ofdlocks.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/filelock/ofdlocks.c b/tools/testing/selftests/filelock/ofdlocks.c
--- a/tools/testing/selftests/filelock/ofdlocks.c
+++ b/tools/testing/selftests/filelock/ofdlocks.c
@@ -40,7 +40,7 @@
int fd2 = open("/tmp/aa", O_RDONLY);
ksft_print_header();
- ksft_set_plan(4);
+ ksft_set_plan(5);
unlink("/tmp/aa");
assert(fd != -1);
@@ -0,0 +1,34 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Khem Raj <khem.raj@oss.qualcomm.com>
Date: Sat, 12 Sep 2026 00:00:00 -0700
Subject: [PATCH] selftests/filelock: zero-initialize struct flock in ofdlocks
ofdlocks compares two struct flock results with memcmp(). struct flock
has padding on 64-bit targets (after l_whence and after l_pid), and
F_OFD_GETLK copies the whole structure back to user space as it was
passed in, so the padding of fl and fl2 is whatever was on the stack.
Depending on compiler and stack contents the test then fails with:
not ok 4 F_UNLCK with len==0 returned the same
Zero-initialize both structures so memcmp() only compares the fields
filled in by the kernel.
Upstream-Status: Pending
Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
---
tools/testing/selftests/filelock/ofdlocks.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/filelock/ofdlocks.c b/tools/testing/selftests/filelock/ofdlocks.c
--- a/tools/testing/selftests/filelock/ofdlocks.c
+++ b/tools/testing/selftests/filelock/ofdlocks.c
@@ -35,7 +35,7 @@
int main(void)
{
int rc;
- struct flock fl, fl2;
+ struct flock fl = {0}, fl2 = {0};
int fd = open("/tmp/aa", O_RDWR | O_CREAT | O_EXCL, 0600);
int fd2 = open("/tmp/aa", O_RDONLY);
@@ -0,0 +1,39 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Khem Raj <khem.raj@oss.qualcomm.com>
Date: Sat, 12 Sep 2026 00:00:00 -0700
Subject: [PATCH] selftests/filesystems: idmapped_tmpfile: chown the layer
directory into the idmapped range
mapped_caller_creates_and_links fails with EACCES:
idmapped_tmpfile.c:145:mapped_caller_creates_and_links:Expected fd (-1) >= 0 (0)
The fixture creates /tmp/d as root, i.e. owned by on-disk id 0. The
idmapped mount maps caller ids [0, 10000) onto on-disk ids
[10000, 20000), so the directory owner has no mapping through the mount
and inode_permission() refuses MAY_WRITE with -EACCES because of
HAS_UNMAPPED_ID(), before the world-writable mode is even looked at.
Chown the directory to MAP_HOST so it is representable through the
idmapped mount. The unmapped caller test still reaches the
fsuidgid_has_mapping() check in vfs_tmpfile() and gets -EOVERFLOW.
Fixes: d943e68edc5c ("selftests/filesystems: test O_TMPFILE creation on idmapped mounts")
Upstream-Status: Pending
Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
---
tools/testing/selftests/filesystems/idmapped_tmpfile.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/testing/selftests/filesystems/idmapped_tmpfile.c b/tools/testing/selftests/filesystems/idmapped_tmpfile.c
--- a/tools/testing/selftests/filesystems/idmapped_tmpfile.c
+++ b/tools/testing/selftests/filesystems/idmapped_tmpfile.c
@@ -91,6 +91,8 @@
ASSERT_EQ(mkdir(self->dir, 0777), 0);
/* World-writable so an unmapped caller still passes permission(). */
ASSERT_EQ(chmod(self->dir, 0777), 0);
+ /* Owned by an id the idmapped mount can represent, else MAY_WRITE is refused. */
+ ASSERT_EQ(chown(self->dir, MAP_HOST, MAP_HOST), 0);
}
FIXTURE_TEARDOWN(idmapped_tmpfile)
@@ -0,0 +1,40 @@
From 879b3353d04d043a9e01525c520d9b81339421b2 Mon Sep 17 00:00:00 2001
From: Amin Vakil <info@aminvakil.com>
Date: Thu, 18 Jun 2026 18:44:44 +0330
Subject: [PATCH] selftests: proc: include fcntl.h in proc-pidns
proc-pidns.c uses open() and O_* flags, but does not include
<fcntl.h>. This breaks the proc selftests build with errors such as:
error: implicit declaration of function 'open'
error: 'O_WRONLY' undeclared
error: 'O_CREAT' undeclared
error: 'O_RDONLY' undeclared
Include <fcntl.h> to provide the declaration and flag definitions.
Fixes: 5554d820f71c ("selftests/proc: add tests for new pidns APIs")
Tested with:
make -C tools/testing/selftests TARGETS=proc
Signed-off-by: Amin Vakil <info@aminvakil.com>
Link: https://patch.msgid.link/20260618151444.124739-1-info@aminvakil.com
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Upstream-Status: Backport [https://git.kernel.org/torvalds/c/879b3353d04d]
Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
---
tools/testing/selftests/proc/proc-pidns.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/testing/selftests/proc/proc-pidns.c b/tools/testing/selftests/proc/proc-pidns.c
index 25b9a2933c45697..6f7c10fe97b304c 100644
--- a/tools/testing/selftests/proc/proc-pidns.c
+++ b/tools/testing/selftests/proc/proc-pidns.c
@@ -6,6 +6,7 @@
#include <assert.h>
#include <errno.h>
+#include <fcntl.h>
#include <sched.h>
#include <stdbool.h>
#include <stdlib.h>
@@ -1,5 +1,8 @@
#!/bin/sh
/usr/kernel-selftest/run_kselftest.sh -s
# ftrace:ftracetest-ktap has no per-test timeout and its
# instances/instance-event.tc can leave a task stuck in D state in
# trace_array_get() (seen on linux-yocto 7.2.4), hanging the suite. Skip it.
/usr/kernel-selftest/run_kselftest.sh -s -S ftrace:ftracetest-ktap
if [ $? == 0 ]; then
echo "PASS: kernel-selftest"
else