support kselftest on nommu platform
Subsystems (5)
v5 cover support kselftest on nommu platform
This patchset adds an ability to execute kselftest on nommu platforms.
Currently there are several issues if we wish to run kselftests on nommu targets:
- it cannot compile/build test binaries because the current files mainly assume to build with glibc,
- some of the tests are not able to run on nommu targets as there are no fork(2) syscall.
The first issue can be avoided if we can build static PIE binaries (if targets support it), but in our case (build on ubuntu/glibc and run on alpine/musl-libc), it fails to invoke due to lack of the GNU ifunc mechanism. Thus, we need to cross-compile with musl toolchain, which needs to be solved the first issue.
The second issue is the lack of fork(2) syscall on those platforms. Especially the test harness helper (kselftest_harness.h) uses the syscall, which cannot be simply with vfork(2). timeout command used in runner.sh never works for nommu platform as it uses fork(2).
nommu component in the mm subsystem has several known issues and having test cases should help this situation, thus this patchset is very first step toward enriching test environment which has not been well tested for a while. The test cases is implemented based on the document (Documentation/admin-guide/mm/nommu-mmap.rst).
Initial shape for this patches is implemented as an opt-in TARGET, not built/invoked automatically if users don't specify this nommu target.
--
- v4:
https://lore.kernel.org/all/[email protected]/
- v3:
https://lore.kernel.org/linux-mm/[email protected]/
- v2:
https://lore.kernel.org/linux-mm/[email protected]/
- rfc:
https://lore.kernel.org/linux-mm/[email protected]/
Hajime Tazaki (2):
selftests: run tests on nommu architecture selftests/nommu: add nommu mmap and mremap behavior tests
Documentation/dev-tools/kselftest.rst | 18 + tools/testing/selftests/kselftest/runner.sh | 11 +- tools/testing/selftests/nommu/Makefile | 7 + tools/testing/selftests/nommu/nommu.h | 33 ++ .../testing/selftests/nommu/nommu_mmap_test.c | 264 +++++++++++++ .../selftests/nommu/nommu_mremap_test.c | 356 ++++++++++++++++++ 6 files changed, 688 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/nommu/Makefile create mode 100644 tools/testing/selftests/nommu/nommu.h create mode 100644 tools/testing/selftests/nommu/nommu_mmap_test.c create mode 100644 tools/testing/selftests/nommu/nommu_mremap_test.c
base-commit: e8d0f6a1b2a447d02845984fa6288787543cb03c
Signature · 1 line
2.52.0
PATCH v5 1/2 selftests: run tests on nommu architecture
Architectures lacking MMU don't support fork(2) syscall and only vfork(2) is available with limitations. Thus, we cannot run kselftest on nommu architecture as is.
This commit addresses this issue with the following changes:
- Detect NOMMU at runtime from the MmapCopy field in /proc/meminfo and avoid timeout, which requires fork(2).
- Document how to build and run the NOMMU tests, including the procfs prerequisite for runtime detection.
Build and run the tests with:
$ make ARCH=um O=build kselftest-all TARGETS=nommu $ make ARCH=um O=build kselftest-install TARGETS=nommu $ ./build/kselftest/kselftest_install/run_kselftest.sh -p -c nommu
--
v4 => v5
- remove build-time selection and detect NOMMU at runtime
v3 => v4
- fix typos in commit message
v2 => v3
- remove unnecessary modification
- new target is moved from TARGETS=mm/nommu to TARGETS=nommu
- rename CONFIG_NOMMU to NOMMU to avoid confusion to kernel config
rfc => v2
- reformat ktap header, reported by Sashiko review
- https://lore.kernel.org/linux-mm/[email protected]/
rfc: https://lore.kernel.org/linux-mm/[email protected]/
--- Documentation/dev-tools/kselftest.rst | 18 ++++++++++++++++++ tools/testing/selftests/kselftest/runner.sh | 11 ++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-)
Documentation/dev-tools/kselftest.rst +18 -0
@@ -230,6 +230,24 @@ section:: .. _tar's auto-compress: https://www.gnu.org/software/tar/manual/html_node/gzip.html#auto_002dcompress +Build and test on nommu target +============================== + +The nommu selftests detect NOMMU at runtime by checking for the ``MmapCopy`` +entry in ``/proc/meminfo``. Ensure procfs is mounted at ``/proc`` before +building and running the tests. + +:: + + $ make ARCH=um O=build kselftest-all TARGETS=nommu # <= build-only + $ make ARCH=um O=build kselftest-install TARGETS=nommu + $ ./build/kselftest/kselftest_install/run_kselftest.sh -p -c nommu + +The C tests report a skip if ``/proc/meminfo`` is unavailable. On a NOMMU +system, the runner needs that file to avoid wrapping the tests in ``timeout`` +before they can report a skip. Mounting procfs is therefore a prerequisite +for running this target through the kselftest runner. + Contributing new tests ======================
tools/testing/selftests/kselftest/runner.sh +10 -1
@@ -36,10 +36,19 @@ tap_prefix() fi } +is_nommu() +{ + grep -q '^MmapCopy:' /proc/meminfo 2>/dev/null +} + tap_timeout() { + # nommu doesn't support timeout command (missing fork(2)) + if is_nommu; then + echo "timeout isn't supported for NOMMU" + $1 # Make sure tests will time out if utility is available. - if [ -x /usr/bin/timeout ] ; then + elif [ -x /usr/bin/timeout ]; then /usr/bin/timeout --foreground "$kselftest_timeout" \ /usr/bin/timeout "$kselftest_timeout" $1 else
Signature · 1 line
2.52.0
Re: [PATCH v5 1/2] selftests: run tests on nommu architecture
Quoted 17 lines · Hajime Tazaki
Architectures lacking MMU don't support fork(2) syscall and only vfork(2) is available with limitations. Thus, we cannot run kselftest on nommu architecture as is.
This commit addresses this issue with the following changes:
- Detect NOMMU at runtime from the MmapCopy field in
/proc/meminfoand avoid timeout, which requires fork(2).
- Document how to build and run the NOMMU tests, including the procfs prerequisite for runtime detection.Build and run the tests with:
$ make ARCH=um O=build kselftest-all TARGETS=nommu $ make ARCH=um O=build kselftest-install TARGETS=nommu $ ./build/kselftest/kselftest_install/run_kselftest.sh -p -c nommu
Quoted 16 lines
Cc Shuah Khan <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Kees Cook <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Will Drewry <[email protected]>Cc Mark Brown <[email protected]>Cc Brendan Jackman <[email protected]>Cc Hangbin Liu <[email protected]>Cc "Ricardo B. Marliere" <[email protected]>Signed-off-by Hajime Tazaki <[email protected]>
Signature · 3 lines
Cheers, David
PATCH v5 2/2 selftests/nommu: add nommu mmap and mremap behavior tests
In reply to Hajime TazakiIntroduce a kselftest utility to validate memory mapping capabilities under nommu kernels, aligned with Documentation/admin-guide/mm/nommu-mmap.rst.
The test implements basic checks into a generic architecture-agnostic test matrix applicable across nommu targets. It evaluates:
1. MAP_FIXED allocation rejections.
2. Standard MAP_PRIVATE and MAP_ANONYMOUS allocation resilience.
3. Regular file mappings via standard filesystem storage.
4. Block device subsystem mappings (gracefully skipping if node is missing).
5. Shared vs Private backing discrepancies under nommu conditions.
6. mremap limits, ensuring non-expandable restrictions behave properly.
--
v4 => v5
- remove #ifdef NOMMU and use a global variable detected from /proc/meminfo
v3 => v4
- clean up messages
v2 => v3
- remove unnecessary modifications
- address Sashiko review
rfc => v2
- prepare a different TARGETS for tests (mm/nommu)
- drop shrink fix tests
- drop mmap /dev/zero tests
- https://lore.kernel.org/linux-mm/[email protected]/
rfc:
- https://lore.kernel.org/linux-mm/[email protected]/
--- tools/testing/selftests/nommu/Makefile | 7 + tools/testing/selftests/nommu/nommu.h | 33 ++ .../testing/selftests/nommu/nommu_mmap_test.c | 264 +++++++++++++ .../selftests/nommu/nommu_mremap_test.c | 356 ++++++++++++++++++ 4 files changed, 660 insertions(+) create mode 100644 tools/testing/selftests/nommu/Makefile create mode 100644 tools/testing/selftests/nommu/nommu.h create mode 100644 tools/testing/selftests/nommu/nommu_mmap_test.c create mode 100644 tools/testing/selftests/nommu/nommu_mremap_test.c
tools/testing/selftests/nommu/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 +# Makefile for nommu selftests + +TEST_GEN_PROGS += nommu_mmap_test +TEST_GEN_PROGS += nommu_mremap_test + +include ../lib.mk
tools/testing/selftests/nommu/nommu.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef NOMMU_H +#define NOMMU_H + +#include <stdio.h> +#include <string.h> + +/* Returns 1 for NOMMU, 0 for MMU, and -1 if /proc/meminfo is unavailable. */ +static inline int ksft_is_nommu (void ) +{ +FILE *fp; +char line[256 ]; +int nommu =0 ; + + fp =fopen ("/proc/meminfo" ,"r" ); +if (!fp) +return -1 ; + +while (fgets (line,sizeof (line), fp)) { +if (strncmp (line,"MmapCopy:" ,sizeof ("MmapCopy:" ) -1 ) ==0 ) { + nommu =1 ; +break ; + } + } + +if (ferror (fp)) + nommu =-1 ; +fclose (fp); + +return nommu; +} + +#endif
tools/testing/selftests/nommu/nommu_mmap_test.c new file +264 -0
264 lines not on this page · raw message
tools/testing/selftests/nommu/nommu_mremap_test.c new file +356 -0
356 lines not on this page · raw message
Signature · 1 line
2.52.0
Andrew Morton
maintainerQuoted 21 lines · On Tue, 6 Oct 2026 17:56:40 +0900 Hajime Tazaki <[email protected]> wrote:
This patchset adds an ability to execute kselftest on nommu platforms.
Currently there are several issues if we wish to run kselftests on nommu targets:
- it cannot compile/build test binaries because the current files mainly assume to build with glibc,
- some of the tests are not able to run on nommu targets as there are no fork(2) syscall.The first issue can be avoided if we can build static PIE binaries (if targets support it), but in our case (build on ubuntu/glibc and run on alpine/musl-libc), it fails to invoke due to lack of the GNU ifunc mechanism. Thus, we need to cross-compile with musl toolchain, which needs to be solved the first issue.
The second issue is the lack of fork(2) syscall on those platforms. Especially the test harness helper (
kselftest_harness.h) uses the syscall, which cannot be simply with vfork(2).timeoutcommand used inrunner.shnever works for nommu platform as it uses fork(2).
Quoted 8 lines
nommu component in the mm subsystem has several known issues and having test cases should help this situation, thus this patchset is very first step toward enriching test environment which has not been well tested for a while. The test cases is implemented based on the document (
Documentation/admin-guide/mm/nommu-mmap.rst).Initial shape for this patches is implemented as an opt-in TARGET, not built/invoked automatically if users don't specify this nommu target.
Thanks, I've updated mm.git's mm-unstable branch with this version.
Then I moved the series down into the tail of the mm-unstable branch, in preparation for excluding it from the 7.3-rcX queue.
It's changing a lot and it isn't converging quickly and review hasn't happened and everyone's traveling so I'll likely hold this series over for 7.4-rcX.
Hang in there - it's great that you're caring for nommu!
Quoted 1 line
--
That should be --- (in the patches too).
<grabs the v4->v5 logging from the individual patches>
Quoted 3 lines
v4 => v5
- remove build-time selection and detect NOMMU at runtime
- remove #ifdef NOMMU and use a global variable detected from/proc/meminfo
Here's how v5 altered mm.git:
Documentation/dev-tools/kselftest.rst | 18 +- tools/testing/selftests/kselftest/runner.sh | 9 - tools/testing/selftests/nommu/Makefile | 1 tools/testing/selftests/nommu/local.mk | 7 tools/testing/selftests/nommu/nommu.h | 33 ++++ tools/testing/selftests/nommu/nommu_mmap_test.c | 91 ++++++------ tools/testing/selftests/nommu/nommu_mremap_test.c | 72 ++++----- 7 files changed, 129 insertions(+), 102 deletions(-)
Documentation/dev-tools/kselftest.rst renamed from Documentation/dev-tools/kselftest.rst~b +11 -7
@@ -233,16 +233,20 @@ section:: Build and test on nommu target ============================== -If you (cross-)build kselftests for nommu targets, or run tests on nommu targets, use -``NOMMU=1`` as a make variable/environment setting to tell build system to do the additional -checks. These nommu targets may differ in several ways, such as not supporting fork(2) or -using musl or another libc. Set this variable to apply the necessary build and test adjustments. +The nommu selftests detect NOMMU at runtime by checking for the ``MmapCopy`` +entry in ``/proc/meminfo``. Ensure procfs is mounted at ``/proc`` before +building and running the tests. :: - $ make ARCH=um NOMMU=1 O=build kselftest-all TARGETS=nommu # <= build-only - $ make ARCH=um NOMMU=1 O=build kselftest-install TARGETS=nommu - $ NOMMU=1 ./build/kselftest/kselftest_install/run_kselftest.sh -p -c nommu + $ make ARCH=um O=build kselftest-all TARGETS=nommu # <= build-only + $ make ARCH=um O=build kselftest-install TARGETS=nommu + $ ./build/kselftest/kselftest_install/run_kselftest.sh -p -c nommu + +The C tests report a skip if ``/proc/meminfo`` is unavailable. On a NOMMU +system, the runner needs that file to avoid wrapping the tests in ``timeout`` +before they can report a skip. Mounting procfs is therefore a prerequisite +for running this target through the kselftest runner. Contributing new tests ======================
tools/testing/selftests/kselftest/runner.sh renamed from tools/testing/selftests/kselftest/runner.sh~b +7 -2
@@ -36,14 +36,19 @@ tap_prefix() fi } +is_nommu() +{ + grep -q '^MmapCopy:' /proc/meminfo 2>/dev/null +} + tap_timeout() { # nommu doesn't support timeout command (missing fork(2)) - if [ "$NOMMU" = "1" ] ; then + if is_nommu; then echo "timeout isn't supported for NOMMU" $1 # Make sure tests will time out if utility is available. - elif [ -x /usr/bin/timeout ] ; then + elif [ -x /usr/bin/timeout ]; then /usr/bin/timeout --foreground "$kselftest_timeout" \ /usr/bin/timeout "$kselftest_timeout" $1 else
tools/testing/selftests/nommu/local.mk deleted +0 -7
@@ -1,7 +0,0 @@ -# detect if users request NOMMU build or not -# User can set NOMMU to 1 to build/test for NOMMU platforms -NOMMU ?= 0 -ifeq ($(NOMMU),1) -CFLAGS += -DNOMMU -export NOMMU -endif
tools/testing/selftests/nommu/Makefile renamed from tools/testing/selftests/nommu/Makefile~b +0 -1
@@ -5,4 +5,3 @@ TEST_GEN_PROGS += nommu_mmap_test TEST_GEN_PROGS += nommu_mremap_test include ../lib.mk -include local.mk
tools/testing/selftests/nommu/nommu.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef NOMMU_H +#define NOMMU_H + +#include <stdio.h> +#include <string.h> + +/* Returns 1 for NOMMU, 0 for MMU, and -1 if /proc/meminfo is unavailable. */ +static inline int ksft_is_nommu (void ) +{ +FILE *fp; +char line[256 ]; +int nommu =0 ; + + fp =fopen ("/proc/meminfo" ,"r" ); +if (!fp) +return -1 ; + +while (fgets (line,sizeof (line), fp)) { +if (strncmp (line,"MmapCopy:" ,sizeof ("MmapCopy:" ) -1 ) ==0 ) { + nommu =1 ; +break ; + } + } + +if (ferror (fp)) + nommu =-1 ; +fclose (fp); + +return nommu; +} + +#endif
tools/testing/selftests/nommu/nommu_mmap_test.c renamed from tools/testing/selftests/nommu/nommu_mmap_test.c~b +47 -44
193 lines not on this page · raw message
tools/testing/selftests/nommu/nommu_mremap_test.c renamed from tools/testing/selftests/nommu/nommu_mremap_test.c~b +31 -41
175 lines not on this page · raw message
_