Repository navigation
mm: populate a subpage window's uffd-wp markers with the faulting page - #2225
RyanTheTide merged 2 commits into
Conversation
|
Base control for the full Setup: arm64_user4k.config + Results:
Signature: the test kthread loops forever on a level-2 write translation fault at Why this change isn't involved:
So the stall is pre-existing and independent of #2225/#2226.
|
DjDeveloperr
left a comment
There was a problem hiding this comment.
Reviewed as core mm. The change is right and contained:
- It only reaches
do_anonymous_subpage(). With noVM_UFFD_WPthe mask and the PTEs written are identical to base: every non-target slot incurrent_maskis thenpte_none, so the new marker test is false. Native-16K processes and non-uffd users see no change. - The PTL-held recompute (mm/memory.c:6944) and the per-neighbour marker test in the set loop (6972-6973) both read under the PTL, so they agree. A racing population only shrinks
current_mask, and the dense-path abort is skipped for armed VMAs, so nothing is lost. - arm64
pte_mkuffd()write-protects, so a populated neighbour behaves like the marker it replaced: a WP fault in sync mode, a bit clear in async mode, and the marker comes back on a zap.
The stall control you posted settles #2114's question: base stalls 4/4, and the mm hunk here is byte-identical to 695bc5e. By construction this cannot reach a test that registers no userfaultfd.
Before merge, please post the negative run for the new case. Same uffd-wp-init binary, 4K worker mode, on a 16K kernel without 834e0e6 (0abc2f3 or a fleet kernel without the fix). I expect marker_window to fail at physical(a, ps) on page 0 with the earlier cases passing, then 29/29 on this head.
Two small things, neither blocking:
- Match the marker exactly (
softleaf_to_marker(...) == PTE_MARKER_UFFD_WP) rather than "has the UFFD_WP bit".handle_pte_marker()ranks GUARD and POISONED above UFFD_WP, and this path would turn such a slot into a zero page. Nothing creates the combination today, so this is hardening. - One sentence in the commit message: neighbours are now present (RSS,
PAGE_IS_PRESENT), and aUFFDIO_COPYinto one in a WP-only VMA returns-EEXISTwhere upstream would accept it. Both are already true fornoneneighbours on this path.
Optional for the test: after the first write, write a[0] and check that its bit 57 clears, pages 2 and 3 keep theirs, and physical() is unchanged.
|
Thanks, the change reads right as core mm: it only reaches One request before merge: could you add the uffd-wp case as a test that fails on a kernel without this fix (a subpage window registered for write-protect, first touch on one subpage, then check that the other subpages still report the marker)? A selftest under |
In an mm whose user page size is smaller than the native page, a write fault on unpopulated anonymous memory fills the whole native window from one fresh native page, each 4K page at its own offset. That keeps the window physically in VA order, and costs one native page for four user pages. A uffd-wp marker (UFFD_FEATURE_WP_UNPOPULATED) is unpopulated memory too, but anon_subpage_missing_mask() counted only none PTEs as missing. In a VMA write-protected before its first touch, every neighbour holds a marker, so each first write took a native page of its own for one 4K page: four times the memory, and no window was ever one native page in order. A device that maps native pages (a GPU with 16K pages taking user memory through GEM_USERPTR) can then use none of it. Count a uffd-wp marker in a uffd-wp VMA as missing, and give the neighbour it stood for the uffd-wp bit, as the faulting page already gets it from its own marker: the populated neighbours stay write protected and unwritten for PAGEMAP_SCAN. Markers in a VMA that is no longer registered are left as they were. Only a marker that is exactly PTE_MARKER_UFFD_WP counts: handle_pte_marker() ranks poison and guard above uffd-wp, so a slot carrying either keeps faulting as before. The populated neighbours are present: they count in RSS and report PAGE_IS_PRESENT, and a UFFDIO_COPY into one in a WP-only VMA returns -EEXIST where it would have filled the marker. Both were already true for none neighbours on this path. Measured with a probe in a 4K process on an M4 Pro (16K kernel): 8 MiB of anonymous memory, write-protected through userfaultfd with WP_ASYNC | WP_UNPOPULATED before its first touch, then written once per 4K page. Before, 0 of 512 16K blocks were one native page in order; memory registered after its first touch, or never registered, gave 512 of 512. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Add a uffd-wp-init case that write-protects a native-aligned window with WP_ASYNC | WP_UNPOPULATED before any touch, then writes one byte to its second user page. pagemap must then show every user page of the window present in one native page in VA order, with the uffd-wp bit kept on the neighbours and cleared on the written page. A second write, to the first user page, must then clear only that page's bit and leave the window's physical layout unchanged. markers() never reached this path: its window is not native-aligned, and its first touch is a read that maps the zero page, so its write is a copy-on-write fault. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
c139961 to
7655e71
Compare
|
Updated to 7655e71 (force-pushed, same two commits, base 0abc2f3). Negative run: the same static
The exact output is in the PR body. @RyanTheTide, this covers your request: the case is in 1. Exact marker match: new 2. Commit message: added a paragraph. The populated neighbours are present (RSS, Optional test extension: done (uffd-wp-init.c:470). After the first write, No regressions: base and head give identical results in the same qemu setup:
checkpatch reports 0 errors and 0 warnings on both commits, and |
|
Thanks, the before/after is exactly what we asked for: the 4K worker fails |
7655e71 to
6643e60
Compare
|
Commit messages only, for the pre-PR checklist: the commits no longer carry Assisted-by: LLM (Claude:Opus 5.5) |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Re-review of head 6643e60c5bfd85ff319f17dfa06d3d7371b94d1c against the pre-PR checklist (following our earlier comment on c139961).
Resolution of earlier items
- Exact marker match:
pte_is_only_uffd_wp_marker()(mm/memory.c:6842) checkssoftleaf_is_marker(entry) && softleaf_to_marker(entry) == PTE_MARKER_UFFD_WPin bothanon_subpage_missing_mask()(pre-PTL snapshot and PTL-held recompute) and the per-neighbour set loop (mm/memory.c:6980-6982). Guard/poison markers are preserved, andsoftleaf_from_pte()returns none for present/none PTEs. - Commit message:
6ac4b1169a2fnow documents RSS /PAGE_IS_PRESENTandUFFDIO_COPY-EEXISTsemantics on populated neighbours. - Selftest & negative control:
marker_window()(tools/testing/selftests/arm64/user4k/uffd-wp-init.c:443-479) now also checks the second write toa[0]clears only page 0's bit 57 ((i > ps)) while keeping the native physical layout intact. The posted KVM arm64 16K-kerneluser4k=onrun reproduces the exact expected failure on base0abc2f385e54(line=120 errno=17,UFFD CONTRACT FAIL) and passes 29/29 (UFFD CONTRACT PASS) on this tree (7655e71689->6643e60c5b, commit messages only), with identical KUnitarm64-user4k*and user4k selftest regression results, backed by the J616s 512/512 +PAGEMAP_SCANbare-metal probe.
Checklist & CI
- 0 blockers. CI (
host-tests) is green. - §1–§4 & §6: Core
mm/change with no model gating or hacks; both commits carry human author/committer and humanSigned-off-by:only, with PR-body disclosure present.
Assisted-by: LLM (Gemini 4 Neon)
|
Merge-train adversarial review (MERGETRAIN-LINUX2) at 6643e60: NO BLOCKERS. With Dj's approval at this head, that makes the joint verdict MERGE. Before the merge we will boot it on our Macs, as one test kernel of integration 24dc422 plus #2222 and #2225: M1 Pro, M2, J616s, Neo and the J615. Results will follow here. Full review#2225 mm: populate a subpage window's uffd-wp markers with the faulting page @6643e60cVERDICT: NO BLOCKERS Commits: 6ac4b11 (mm), 6643e60 (selftest). Line numbers are in mm/memory.c at 6643e60. What I checked and found to hold:
Blockers: none. Nits:
Missing rows:
Commit hygiene: both commits are by Jonathan Goyvaerts with a human Signed-off-by, and there are no agent trailers in the commits (they were removed in the message-only push, and the tree is identical to 7655e71 according to the thread). Provenance: there are no Apple-internal names. |
|
Hardware rows (MERGETRAIN-LINUX2), test kernel 7.3.0-aurora-mt3 = integration/aurora 24dc422 + #2222 c2e95d3 + #2225 6643e60, on the default fleet cmdline. Each Mac got 3 one-shot warm boots and went back to its default:
Evidence: traces/kernel/20261122-mt3-fleetboot (lab store). |
71abea7
into
aurora-silicon:integration/aurora
In an mm whose user page size is smaller than the native page (
CONFIG_MM_SUBPAGE: 4K processes on a 16K kernel, such as everything running under FEX), a write fault on unpopulated anonymous memory fills the whole native window from one fresh native page. Each 4K page lands at its own offset, so the window is physically in VA order.A uffd-wp marker (
UFFD_FEATURE_WP_UNPOPULATED) is unpopulated memory too, butanon_subpage_missing_mask()counted only none PTEs as missing.This change counts a uffd-wp marker in a uffd-wp VMA as missing, and gives the neighbour it stood for the uffd-wp bit, as the faulting page already gets from its own marker. The populated neighbours stay write-protected and unwritten for PAGEMAP_SCAN. Markers in a VMA that is no longer registered are left as they were. Only a marker that is exactly
PTE_MARKER_UFFD_WPcounts:handle_pte_marker()ranks poison and guard above uffd-wp, so a slot that carries either keeps faulting as before.The populated neighbours are present: they count in RSS and report
PAGE_IS_PRESENT, and aUFFDIO_COPYinto one in a WP-only VMA returns-EEXISTwhere upstream would have filled the marker. Both are already true fornoneneighbours on this path.The second commit adds a case to
tools/testing/selftests/arm64/user4k/uffd-wp-init.c. The existingmarkers()case reads before it writes, so its first touch maps the zero page and never reaches this path. The new case covers a native-aligned window, write-protected withWP_ASYNC | WP_UNPOPULATEDbefore any touch, then written once in its second 4K page:Before/after (qemu, 16K kernel,
user4k=on)The same static
uffd-wp-initbinary as/init, on the same kernel config (arm64_user4k.config+USERFAULTFD,NET,UNIX,MEMCG,FAILSLAB), KVM,-cpu max -smp 4.not ok - uffd line=120UFFD CONTRACT FAILUFFD CONTRACT PASS, 29/29On base, line 120 is the present-bit check in
physical(), reached fromstart = physical(a, ps)on page 0 ofmarker_window: page 0 is still a marker. Base output, 4K worker:Head output, 4K worker:
Regression check, same qemu setup, base vs head
All of these give identical results on base and head:
arm64-user4k*(user4k=on, noarm64.user4k_test=1): 226 tests, 116 passed, 109 skipped, 1 failed. The failure isuser4k_move_migration_race_test, the pre-existing one already reported (drm/asahi: GEM_USERPTR in 4K (user4k) processes #2114). The IOMMUFD cases that stall need the opt-in, so they were not run (pre-existing, see the comment above).lazyfree-fixture-init: 8/8 in each granule.anon-hole-refill --native-16k8/8,anon-hole-refill-race3/3 (with swap),clipped-firstwrite --native-16kPASS,first-write --native-16k4 pass and 2 skip (regular-file arms skip on tmpfs), andcow-pool7 pass and 2 skip (memlock limit).anon-hole-refill-reclaimskips (needs--external-reclaim).uffd-move-init: 12 ok on both, then the samenot ok - MOVE line=180 errno=16(EBUSY) in both granules on base too. This is a qemu environment or pre-existing issue, not this change.mm/memory.obuilds with W=1 and no warnings. checkpatch reports 0 errors and 0 warnings on both commits.Tested on the J616s (M4 Pro, 16K kernel), earlier revision
WP_ASYNC | WP_UNPOPULATEDbefore its first touch, then written once per 4K page. Before, 0 of 512 16K blocks were one native page in order; after, 512 of 512. Memory registered after its first touch, or never registered, gave 512 of 512 either way. PAGEMAP_SCAN's written/unwritten report stayed exact, native and 4K.Not done
Assisted-by: LLM (Claude:Opus 5.5)