* [PATCH RESEND 0/3] selftests: target selection fixes for cross and LLVM builds
@ 2026-11-05 12:56 Sasha Levin
2026-11-05 12:56 ` [PATCH RESEND 1/3] selftests/prctl: skip the anonymous VMA naming test when unsupported Sasha Levin
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Sasha Levin @ 2026-11-05 12:56 UTC (permalink / raw)
To: Andrew Morton, Shuah Khan
Cc: Ivan Orlov, David Woodhouse, Nageswara R Sastry, kexec,
Willy Tarreau, Thomas Weißschuh, Wake Liu, linux-kselftest,
linux-kernel
A few suites select their tests from the build host instead of the
target, or depend on the host C library in ways that break cross
builds:
- set-anon-vma-name-test fails instead of skipping on kernels built
without CONFIG_ANON_VMA_NAME.
- kexec only recognizes the ppc64le spelling of PowerPC and decides
about the x86-64 jump test from the build host.
- size links a custom _start against the static C library, which
fails on ARM with clang and on LoongArch; it now uses nolibc.
The patches are independent of each other and apply on
mm-nonmm-unstable.
Since the original posting:
- "selftests/prctl: build generated tests for the target architecture"
is dropped. "selftests/prctl: select the tests by ARCH alone" in
mm-nonmm-unstable replaces it.
- "selftests/thermal: allow cross builds of the Intel tests" is dropped,
it went in through the thermal tree as ff4194e54f84.
- The size patch has Thomas's Reviewed-by.
Original posting:
https://lore.kernel.org/r/20261014200127.1363472-1-sashal@kernel.org
Sasha Levin (3):
selftests/prctl: skip the anonymous VMA naming test when unsupported
selftests/kexec: select tests using the target compiler
selftests/size: use nolibc startup and syscall wrappers
tools/testing/selftests/kexec/Makefile | 26 ++++++++-------
.../selftests/prctl/set-anon-vma-name-test.c | 3 ++
tools/testing/selftests/size/Makefile | 9 ++++-
tools/testing/selftests/size/get_size.c | 33 +++++--------------
4 files changed, 34 insertions(+), 37 deletions(-)
base-commit: 72afe7762a29508ae89831540347c1be3b7ba621
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH RESEND 1/3] selftests/prctl: skip the anonymous VMA naming test when unsupported
2026-11-05 12:56 [PATCH RESEND 0/3] selftests: target selection fixes for cross and LLVM builds Sasha Levin
@ 2026-11-05 12:56 ` Sasha Levin
2026-11-05 12:57 ` [PATCH RESEND 2/3] selftests/kexec: select tests using the target compiler Sasha Levin
2026-11-05 12:57 ` [PATCH RESEND 3/3] selftests/size: use nolibc startup and syscall wrappers Sasha Levin
2 siblings, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2026-11-05 12:56 UTC (permalink / raw)
To: Andrew Morton, Shuah Khan; +Cc: Ivan Orlov, linux-kselftest, linux-kernel
PR_SET_VMA_ANON_NAME is only implemented when CONFIG_ANON_VMA_NAME is
enabled. Without it, set_anon_vma_name() returns -EINVAL for every
request, so set-anon-vma-name-test reports a failure on kernels that
simply do not provide the feature:
# renaming: Expected rename_vma(...) (-22) >= 0
not ok 1 vma.renaming
Probe the interface in the fixture setup by clearing the name of the
anonymous mapping, which succeeds whenever the feature is available,
and skip the test when the kernel rejects the request with EINVAL.
Fixes: 5290586186d2 ("selftests: prctl: Add new prctl test for PR_SET_VMA action")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
tools/testing/selftests/prctl/set-anon-vma-name-test.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tools/testing/selftests/prctl/set-anon-vma-name-test.c b/tools/testing/selftests/prctl/set-anon-vma-name-test.c
index 5f9589534da8e..d3854ccb2a7a3 100644
--- a/tools/testing/selftests/prctl/set-anon-vma-name-test.c
+++ b/tools/testing/selftests/prctl/set-anon-vma-name-test.c
@@ -93,6 +93,9 @@ FIXTURE_SETUP(vma) {
MAP_PRIVATE, self->fd_not_anon, 0);
ASSERT_NE(self->ptr_not_anon, MAP_FAILED);
close(self->fd_not_anon);
+
+ if (rename_vma((unsigned long)self->ptr_anon, AREA_SIZE, NULL) == -EINVAL)
+ SKIP(return, "PR_SET_VMA_ANON_NAME is not supported");
}
FIXTURE_TEARDOWN(vma) {
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH RESEND 2/3] selftests/kexec: select tests using the target compiler
2026-11-05 12:56 [PATCH RESEND 0/3] selftests: target selection fixes for cross and LLVM builds Sasha Levin
2026-11-05 12:56 ` [PATCH RESEND 1/3] selftests/prctl: skip the anonymous VMA naming test when unsupported Sasha Levin
@ 2026-11-05 12:57 ` Sasha Levin
2026-11-05 12:57 ` [PATCH RESEND 3/3] selftests/size: use nolibc startup and syscall wrappers Sasha Levin
2 siblings, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2026-11-05 12:57 UTC (permalink / raw)
To: Andrew Morton, Shuah Khan
Cc: David Woodhouse, Nageswara R Sastry, kexec, linux-kselftest,
linux-kernel
The kexec Makefile recognizes PowerPC only through the ppc64le spelling
of ARCH, so the canonical ARCH=powerpc used for cross builds omits the
tests. The x86 jump test is selected with IS_64_BIT from
scripts/Makefile.arch, which describes the build host rather than the
compiler being used. On other architectures the Makefile includes no
lib.mk rules at all, so installation and runlist generation fail with
missing targets.
Select x86 and PowerPC from the target ARCH when it is given and from
the host's SUBARCH otherwise, without assigning ARCH, so that lib.mk
keeps choosing the compiler's native clang target. Ask the selected
compiler, including USERCFLAGS, whether it targets a 64-bit x86 ABI
and whether it targets little-endian 64-bit PowerPC. lib.mk expands the
generated program list before it appends USERCFLAGS to CFLAGS, so the
flags are passed explicitly to keep both probes consistent. If the
compiler cannot be run, select the jump test so that the build fails
instead of silently dropping it. Include lib.mk unconditionally so that
unsupported targets build, install and emit an empty runlist.
Fixes: 65e38e32a959 ("selftests/kexec: Enable secureboot tests for PowerPC")
Fixes: 7615b94b6371 ("selftests/kexec: Add x86_64 selftest for kexec-jump and exception handling")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
tools/testing/selftests/kexec/Makefile | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/tools/testing/selftests/kexec/Makefile b/tools/testing/selftests/kexec/Makefile
index 874cfdd3b75b3..97d5dd10208a1 100644
--- a/tools/testing/selftests/kexec/Makefile
+++ b/tools/testing/selftests/kexec/Makefile
@@ -1,20 +1,22 @@
# SPDX-License-Identifier: GPL-2.0-only
# Makefile for kexec tests
-ARCH ?= $(shell uname -m 2>/dev/null || echo not)
-ARCH_PROCESSED := $(shell echo $(ARCH) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
+top_srcdir = ../../../..
+include $(top_srcdir)/scripts/subarch.include
+ARCH_PROCESSED := $(shell echo $(or $(ARCH),$(SUBARCH)) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
-ifeq ($(ARCH_PROCESSED),$(filter $(ARCH_PROCESSED),x86 ppc64le))
-TEST_PROGS := test_kexec_load.sh test_kexec_file_load.sh
-TEST_FILES := kexec_common_lib.sh
+PROBE_CC = $(filter-out -fuse-ld=%,$(CC)) $(CFLAGS) $(USERCFLAGS) -E -P -x c -
+CC_IS_64BIT = $(shell echo __SIZEOF_LONG__ | $(PROBE_CC) || echo 8)
+PPC64LE = $(shell printf '\043if defined(__powerpc64__) && __BYTE_ORDER__ == \
+ __ORDER_LITTLE_ENDIAN__\n1\n\043endif\n' | $(PROBE_CC))
-include ../../../scripts/Makefile.arch
-
-ifeq ($(IS_64_BIT)$(ARCH_PROCESSED),1x86)
-TEST_PROGS += test_kexec_jump.sh
-TEST_GEN_PROGS := test_kexec_jump
+ifeq ($(ARCH_PROCESSED),x86)
+TEST_PROGS = test_kexec_load.sh test_kexec_file_load.sh \
+ $(if $(filter 8,$(CC_IS_64BIT)),test_kexec_jump.sh)
+TEST_GEN_PROGS = $(if $(filter 8,$(CC_IS_64BIT)),test_kexec_jump)
+else ifneq (,$(filter powerpc ppc64le,$(ARCH_PROCESSED)))
+TEST_PROGS = $(if $(filter 1,$(PPC64LE)),test_kexec_load.sh test_kexec_file_load.sh)
endif
+TEST_FILES = $(if $(TEST_PROGS),kexec_common_lib.sh)
include ../lib.mk
-
-endif
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH RESEND 3/3] selftests/size: use nolibc startup and syscall wrappers
2026-11-05 12:56 [PATCH RESEND 0/3] selftests: target selection fixes for cross and LLVM builds Sasha Levin
2026-11-05 12:56 ` [PATCH RESEND 1/3] selftests/prctl: skip the anonymous VMA naming test when unsupported Sasha Levin
2026-11-05 12:57 ` [PATCH RESEND 2/3] selftests/kexec: select tests using the target compiler Sasha Levin
@ 2026-11-05 12:57 ` Sasha Levin
2 siblings, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2026-11-05 12:57 UTC (permalink / raw)
To: Andrew Morton, Shuah Khan
Cc: Willy Tarreau, Thomas Weißschuh, Wake Liu, linux-kselftest,
linux-kernel, stable
get_size provides its own _start and is linked statically against the C
library with -nostartfiles. That combination assumes startup and TLS
details that vary between architectures and C library versions: errno
lives in thread-local storage that is never set up, and the static link
expects symbols from the skipped startup files. CI builds have failed
with undefined _init/_fini on ARM with clang and an undefined _DYNAMIC
on LoongArch.
Build the test with the in-tree nolibc instead. nolibc provides the
startup code, so the test returns from main(), and it provides the
write() and syscall() wrappers without the TLS errno problem. A failing
sysinfo() is now reported as a TAP failure instead of crashing the
test. Keep the static link and the existing TAP output.
Since the test no longer uses the system C library headers, the kernel
UAPI headers have to be installed before it is built. Add the headers
target as an order-only prerequisite, as nolibc-test does, so that a
standalone build installs them. Link libgcc only when the selected
compiler is GCC, which needs it for division helpers on ARM, and detect
that from the compiler rather than from LLVM so that CC=clang builds do
not try to link a libgcc that clang does not provide.
nolibc does not support arc, csky, microblaze, nios2 or xtensa, so the
test can no longer be built for those architectures. This conversion
also makes the separate i386 vDSO workaround proposed for get_size
unnecessary.
Link: https://lore.kernel.org/r/20260929043637.1917707-1-wakel@google.com
Fixes: 3ce51050fadd ("selftest: size: Add size test for Linux kernel")
Cc: stable@vger.kernel.org # 6.18.x
Reviewed-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
tools/testing/selftests/size/Makefile | 9 ++++++-
tools/testing/selftests/size/get_size.c | 33 +++++++------------------
2 files changed, 17 insertions(+), 25 deletions(-)
diff --git a/tools/testing/selftests/size/Makefile b/tools/testing/selftests/size/Makefile
index b87facc00a6e9..884b42d7fd0e2 100644
--- a/tools/testing/selftests/size/Makefile
+++ b/tools/testing/selftests/size/Makefile
@@ -1,6 +1,13 @@
# SPDX-License-Identifier: GPL-2.0-only
-CFLAGS := -static -ffreestanding -nostartfiles -s
+CFLAGS = -Os -static -nostdlib -nostdinc -ffreestanding -fno-stack-protector -s
+CFLAGS += -isystem $(top_srcdir)/tools/include/nolibc $(KHDR_INCLUDES)
TEST_GEN_PROGS := get_size
include ../lib.mk
+
+CC_IS_GCC := $(shell printf '\043if defined(__GNUC__) && !defined(__clang__)\nGCC\n\043endif\n' | \
+ $(CC) $(CFLAGS) -E -P -x c - 2>/dev/null)
+LDLIBS += $(if $(filter GCC,$(CC_IS_GCC)),-lgcc)
+
+$(OUTPUT)/get_size: | headers
diff --git a/tools/testing/selftests/size/get_size.c b/tools/testing/selftests/size/get_size.c
index 2980b1a63366b..ada6a271711a7 100644
--- a/tools/testing/selftests/size/get_size.c
+++ b/tools/testing/selftests/size/get_size.c
@@ -11,26 +11,12 @@
* own execution. It also attempts to have as few dependencies
* on kernel features as possible.
*
- * It should be statically linked, with startup libs avoided. It uses
- * no library calls except the syscall() function for the following 3
- * syscalls:
- * sysinfo(), write(), and _exit()
- *
- * For output, it avoids printf (which in some C libraries
- * has large external dependencies) by implementing it's own
- * number output and print routines, and using __builtin_strlen()
- *
- * The test may crash if any of the above syscalls fails because in some
- * libc implementations (e.g. the GNU C Library) errno is saved in
- * thread-local storage, which does not get initialized due to avoiding
- * startup libs.
+ * It is statically linked with nolibc startup and syscall wrappers.
+ * For output, it avoids printf by implementing its own print routines.
*/
-#include <sys/sysinfo.h>
-#include <unistd.h>
-#include <sys/syscall.h>
-
-#define STDOUT_FILENO 1
+#include <nolibc.h>
+#include <linux/sysinfo.h>
static int print(const char *s)
{
@@ -39,7 +25,7 @@ static int print(const char *s)
while (s[len] != '\0')
len++;
- return syscall(SYS_write, STDOUT_FILENO, s, len);
+ return write(STDOUT_FILENO, s, len);
}
static inline char *num_to_str(unsigned long num, char *buf, int len)
@@ -80,8 +66,7 @@ static int print_k_value(const char *s, unsigned long num, unsigned long units)
return ccode;
}
-/* this program has no main(), as startup libraries are not used */
-void _start(void)
+int main(void)
{
int ccode;
struct sysinfo info;
@@ -91,12 +76,12 @@ void _start(void)
print("TAP version 13\n");
print("# Testing system size.\n");
- ccode = syscall(SYS_sysinfo, &info);
+ ccode = syscall(__NR_sysinfo, &info);
if (ccode < 0) {
print("not ok 1");
print(test_name);
print(" ---\n reason: \"could not get sysinfo\"\n ...\n");
- syscall(SYS_exit, ccode);
+ return 1;
}
print("ok 1");
print(test_name);
@@ -112,5 +97,5 @@ void _start(void)
print(" ...\n");
print("1..1\n");
- syscall(SYS_exit, 0);
+ return 0;
}
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-05 12:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-05 12:56 [PATCH RESEND 0/3] selftests: target selection fixes for cross and LLVM builds Sasha Levin
2026-11-05 12:56 ` [PATCH RESEND 1/3] selftests/prctl: skip the anonymous VMA naming test when unsupported Sasha Levin
2026-11-05 12:57 ` [PATCH RESEND 2/3] selftests/kexec: select tests using the target compiler Sasha Levin
2026-11-05 12:57 ` [PATCH RESEND 3/3] selftests/size: use nolibc startup and syscall wrappers Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®