Re: [PATCH v4 0/3] selftests/mm: skip tests when FOLL_FORCE writes are denied
From: David Hildenbrand (Arm)
Date: Tue Dec 01 2026 - 11:27:44 EST
On 12/1/26 17:25, Nikolai Dokutovich wrote:
> A write through /proc/self/mem into a mapping that is not writable is
> performed by the kernel as a forced write. Since commit
> 41e8149c8892 ("proc: add config & param to block forcing mem writes")
> such a write is refused unless the writing task is tracing the target
> task, the kernel was built with CONFIG_PROC_MEM_ALWAYS_FORCE, or it was
> booted with proc_mem.force_override=always. Commit
> 599bbba5a36f ("proc: make PROC_MEM_FORCE_PTRACE the Kconfig default") made
> the refusal the default.
>
> Commit a3907a3169d0 ("selftests/mm: specify requirement for
> PROC_MEM_ALWAYS_FORCE=y") set CONFIG_PROC_MEM_ALWAYS_FORCE=y in mm/config.
> That fragment is merged into the kernel configuration only when it is
> requested, so a test binary run against a distribution kernel is not
> covered, and mkdirty and the ksm PROT_NONE test then report failures
> instead of skipping:
>
> not ok 1 write() failed
> not ok 5 ptrace write failed
>
> The first patch adds a probe to vm_util that reports whether such a write
> is permitted. The permission belongs to the kernel and the calling task,
> not to the mapping, so the probe takes no protection argument: it maps one
> read-only page and writes a byte through /proc/self/mem. A refused forced
> write copies zero bytes and mem_rw() reports that as -EIO, but any other
> zero-byte remote access reports the same, so -EIO can indicate a refusal
> without proving one. Only the two decisive results are cached; anything
> else is inconclusive, returns allowed and is not cached, so the test below
> still runs and can fail.
>
> This is deliberately not a check of errno on the tests' own write: that
> was raised in the April discussion of the mm/config fix, and checking the
> result of the operation under test cannot tell a policy refusal from a
> failure of the operation itself. The probe isolates the question, and
> the test then either runs unchanged or is skipped at its entry.
>
> Tested with this series on x86_64 against a kernel built from this base
> whose .config has
> CONFIG_PROC_MEM_FORCE_PTRACE=y, CONFIG_CHECKPOINT_RESTORE=n,
> CONFIG_USERFAULTFD=n, CONFIG_KSM=y:
>
> default boot
> mkdirty pass:3 skip:3 (2 probe skips, 1 no uffd)
> ksm_functional_tests pass:8 skip:2 (test_prot_none, 1 no uffd)
>
> boot with proc_mem.force_override=always
> mkdirty pass:5 skip:1 (no uffd)
> ksm_functional_tests pass:9 skip:1 (no uffd)
>
> When the probe causes a skip, the test reports "FOLL_FORCE write got EIO
> (CONFIG_PROC_MEM_ALWAYS_FORCE)", and no other test changes its result. The
> name is a hint rather than a diagnosis: a kernel booted with
> proc_mem.force_override=never denies the write even when
> CONFIG_PROC_MEM_ALWAYS_FORCE is set.
>
> Changes in v4:
> - Extend the skip message to point at CONFIG_PROC_MEM_ALWAYS_FORCE, as Xu
> Xin suggested.
>
You sent out a v4 way to fast and created a mess.
--
Cheers,
David