[RFC PATCH 0/6] fix nommu mmap and add nommu kselftests
Hajime Tazaki <[email protected]>
| Newsgroups | org.kvack.linux-mm |
|---|---|
| Message-ID | <[email protected]> |
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. 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. 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 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). Additionally, the lack of test cases for nommu environment will (or already) become serious issues to maintain the codebase in the future. 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