Re: [RFC PATCH 0/6] fix nommu mmap and add nommu kselftests

"Lorenzo Stoakes (ARM)" <[email protected]>
Newsgroups org.kvack.linux-mm
Message-ID <an74JAGcEuHXxr5G@lucifer>
Note on procedure - please do just cc- everybody on everything. It's a
total pain to pull down series

On Thu, Aug 13, 2026 at 03:33:55PM +0900, Hajime Tazaki wrote:
> This patchset fixes several issues on nommu mmap, munmap, and mremap
> syscalls and add test cases on kselftests framework, which currently not
> runnable on nommu platform.
>
> Fixes for nommu is to correctly handle error cases when vma shrink
> happens, and add calling .mmap_prepare callback on private mapping
> requests to fix the issue which we cannot MAP_PRIVATE /dev/zero file.
>
> One thing that I'd like to broadly ask you (thus this marks as RFC) is:
> this fix contains a dirty check of /dev/zero using device type number.
> Since mmap_zero_prepare() should be called before actual mapping, but
> some of the .mmap_prepare handler should be called _after_
> determine_vm_flags() as the .mmap_prepare handler checks the shared
> flags, we cannot use vma_is_anonymous() in determine_vm_flags() to
> check the file is /dev/zero or not.  So we introduced
> is_file_anonymous() for that purpose, which I'd like to ask your inputs.

Yeah I have plans for /dev/zero which will make it truly anon soon enough
:)

And I definitely do not want a predicate that tests for just this edge
case.

>
> And we add test cases to introduce kselftest for 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.

Let's fix things only where it's not too invasive.

>
> 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 can be simply avoided, at a glance, by globally
> replacing the symbol `fork` with `vfork`, which is available on nommu
> targets.  Especially the test harness helper (kselftest_harness.h) uses
> fork(2).  But the issue is not simple: for instance, in vfork(2) case

No please don't do this, nommu is the odd one out and the tests should be
targeted at the normal case.

vfork() has entirely different semantics than fork() and we need to assert
fork() behaviour, not vfork() behaviour.

(Honestly it's completely bizarre that we support a version of linux that
can't fork() in 2026)

> parent process has to wait until children has done jobs, parent and
> children share the memory and children may corrupt parent memory which
> is never happened with fork(2) syscall.  `timeout` command used in
> `runner.sh` never works for nommu platform as it uses fork(2).

Yup again this speaks to the surreal craziness of linux supporting nommu at
all :)

>
> Additionally, the lack of test cases for nommu environment will (or
> already) become serious issues to maintain the codebase in the future.

But this has to be weighed against the maintenance headache of supporting
nommu stuff.

It's not right for it to force everybody writing tests to have to think
about it.

And already in the thread there's been discussion about a serious bug in
5.10 that nobody reported for _years_.

So testing stuff sure - but right now people (apart from you of course!)
aren't even doing boot testing against mainline AFAICT, let alone running
self-tests.

So I want the minimal changes that are not invasive and limited to nommu
only as much as possible, please.

> The test cases is implemented based on the document
> (Documentation/admin-guide/mm/nommu-mmap.rst).  The test programs is
> implemented with the assist of LLM.
>
> So, for the first step, nommu targets only support low-level API of
> kselftests (kselftest.h), and not supporting the harness tests since it
> uses fork(2) syscall.  This partially address the second issue; in the
> future we can refactor the harness test framework to be able to run with
> vfork(2) syscall but this is not the part of this patchset.
>
> Hajime Tazaki (6):
>   mm: nommu: fix do_mremap() to correctly update internal states
>   mm: nommu: use vma_is_anonymous() to check if vmas are anonymous
>   mm: nommu: fix an issue on map request to /dev/zero
>   selftests: fix build errors on alpine linux
>   selftests: run tests on nommu architecture
>   selftests/mm: add nommu mmap and mremap behavior tests
>
>  Documentation/dev-tools/kselftest.rst         |  12 +
>  drivers/char/mem.c                            |   5 +-
>  mm/filemap.c                                  |   6 +-
>  mm/nommu.c                                    | 235 ++++++-
>  tools/testing/selftests/kselftest.h           |  43 ++
>  tools/testing/selftests/kselftest/runner.sh   |   9 +-
>  tools/testing/selftests/kselftest_harness.h   |   4 +
>  tools/testing/selftests/lib.mk                |  10 +-
>  tools/testing/selftests/mm/Makefile           |   3 +
>  tools/testing/selftests/mm/hugetlb_dio.c      |   8 +-
>  tools/testing/selftests/mm/mdwe_test.c        |   4 +-
>  tools/testing/selftests/mm/nommu_mmap_test.c  | 294 +++++++++
>  .../testing/selftests/mm/nommu_mremap_test.c  | 583 ++++++++++++++++++
>  13 files changed, 1174 insertions(+), 42 deletions(-)
>  create mode 100644 tools/testing/selftests/mm/nommu_mmap_test.c
>  create mode 100644 tools/testing/selftests/mm/nommu_mremap_test.c
>
> --
> 2.43.0
>
>

--
Cheers, Lorenzo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.