Skip to content

selftests/arm64: check that a uffd-wp window's populated neighbours read zero - #2869

Merged
RyanTheTide merged 1 commit into
aurora-silicon:integration/aurorafrom
jgoyvaerts:m4pro/mm-subpage-uffd-wp-zero
Nov 22, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:integration/aurorafrom
jgoyvaerts:m4pro/mm-subpage-uffd-wp-zero

Conversation

@jgoyvaerts

Copy link
Copy Markdown

Follow-up to #2225, from RyanTheTide's merge-train review (nits 2 and 3).

Nit 3 (this commit). marker_window() in tools/testing/selftests/arm64/user4k/uffd-wp-init.c checked that one write into a window write-protected before its first touch maps the whole native page in order, and that the neighbours keep their uffd-wp bit. It never read the neighbours, so a populate path that left stale data in their slots would still pass. It now checks !a[2 * ps] && !a[3 * ps] right after the first write. The loop after it still expects pages 2 and 3 to carry the uffd-wp bit, so it also shows that a read leaves the bit alone. Selftest only, no kernel change.

Nit 2 (user-visible effects the #2225 commit message listed only in part). After one write into a WP-before-touch window, the populated neighbours are present pages. Besides RSS and PAGE_IS_PRESENT, they also count in mincore() and in /proc/pid/smaps Rss. CRIU-style dumpers that use PAGEMAP_SCAN dump them as present but unwritten zero pages. none neighbours on this path already behave the same way, so nothing new for them. That commit is merged, so the note goes here instead of into its message.

Tested (qemu, 16K kernel, user4k=on)

Kernel: integration/aurora 110861f4333e (this branch's base, which has #2225), arm64_user4k.config + USERFAULTFD, NET, UNIX, CGROUPS, MEMCG, FAULT_INJECTION, FAILSLAB, FAULT_INJECTION_DEBUG_FS. The static uffd-wp-init binary from this commit is /init; KVM, -cpu max -smp 4 -m 2048, a 512M swap disk.

  • UFFD CONTRACT PASS, 29/29 (16K worker 13/13 + status, 4K worker 14/14 + status), including ok - uffd ABI 4K unpopulated WP first write: one native page, neighbours WP.
  • To show that the new line runs on this path, I inverted it (CHECK(a[2 * ps] || a[3 * ps])) in a throwaway build. It fails at that line: not ok - uffd line=470, UFFD CONTRACT FAIL.

checkpatch: 0 errors, 0 warnings. The binary builds with -Wall -Wextra and no warnings.

Assisted-by: LLM (Claude:Opus 5.5)

…ead zero

marker_window() checks that one write into a window write-protected
before its first touch maps the whole native page at once, and that the
neighbours keep their uffd-wp bit. It never read the neighbours, so a
populate path that left stale data in their slots would pass.

Check that pages 2 and 3 read zero after the first write. The loop after
it still expects their WP bit, so it also shows that a read does not
clear it.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
@RyanTheTide

Copy link
Copy Markdown

Review at a5343b2.

Thanks, this closes the gap in marker_window(): before, the case never read the neighbours the write populated. The check sits in the right place (after the first write, before a[0] is written), and the loop after it confirms that the read leaves bits 2 and 3 set. It cannot run past the window: worker() calls marker_window() only when ps < native, so pages 2 and 3 are always inside the native page (16K/4K, 64K/4K, 64K/16K). The negative run in the PR body shows the line runs.

One optional suggestion. Feel free to skip it.

  1. tools/testing/selftests/arm64/user4k/uffd-wp-init.c:470: the check reads one byte of two neighbours. With a 64K native page that is 2 of 15 neighbours, and stale data from a recycled slice can have a zero first byte. A whole-page check of every neighbour would catch more. The existing loop at :464 already visits each page, so it could do the work, e.g.
    for (size_t i = 0; i < native; i += ps)
            for (size_t j = 0; i != ps && j < ps; j++)
                    CHECK(!a[i + j]);
    placed before a[0] = 0xa5. Reading page 0 is fine there: the later loop still expects its bit to clear on the write.

Looks good to me otherwise.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formal §1–§6 pre-PR checklist review at live head a5343b255ee7d0fc55359f666b986eb45855be0e (CI green: host-tests).

Test Validity & Checklist Summary

  • Bounds & ordering: worker() calls marker_window(ps, native) only when ps < native (uffd-wp-init.c:825), so on arm64 (16K/4K, 64K/4K, 64K/16K) native >= 4 * ps always holds and a[2 * ps] / a[3 * ps] are strictly in-bounds. Because a escapes to ioctl/physical/pagemap before and after line 470, the compiler cannot elide the loads. The subsequent loop at lines 473–476 re-checks ((pagemap(a + i, ps) >> 57) & 1) == (i > ps), verifying both that the populated neighbours read zero and that reading them preserves their uffd-wp bits.
  • §1 No model gating: Pass (arch-generic arm64 selftest, no model/board gating).
  • §2 Production-ready: Pass (selftest-only change, no hacks/delays/parameters).
  • §3 Safety: Pass (userspace selftest only).
  • §4 Clean-room & attribution: Pass. Single human commit (Jonathan Goyvaerts), valid Signed-off-by, zero AI trailers in commit.
  • §5 Evidence: Pass for a userspace selftest-only PR — executed on QEMU KVM arm64 16K (user4k=on) at base 110861f4333e (29/29 UFFD CONTRACT PASS), plus negative-mutation proof (CHECK(a[2 * ps] || a[3 * ps]) failing at line 470).
  • §6 Naming: Pass.

Optional non-blocking suggestion

  • Line 470 checks only byte 0 of neighbour pages 2 and 3 (leaving page 0 before a[0] = 0xa5, pages 4..15 on 64K native, and non-zero bytes at offset > 0 unchecked). Scanning all bytes of all i != ps neighbour pages before a[0] = 0xa5 would make the check stricter, though this PR strictly improves coverage as-is.

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide
RyanTheTide merged commit 3883172 into aurora-silicon:integration/aurora Nov 22, 2026
1 check passed
@jgoyvaerts

Copy link
Copy Markdown
Author

Ran on hardware: J616s (M4 Pro, 16K kernel, user4k=on), our combined m4.179 kernel, which carries this commit on top of #2225's pair. uffd-wp-init built from that tree (static; byte-identical to the binary from the qemu run), run as PID 1 in its own PID and mount namespace: 29/29 ok, UFFD CONTRACT PASS, including the new !a[2 * ps] && !a[3 * ps] check. No kernel warnings.

Assisted-by: LLM (Claude:Opus 5.5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants