Skip to content

mm, arm64: add per-process userspace page-size support - #170

Closed
DjDeveloperr wants to merge 63 commits into
aurora-wipfrom
mm-mixed-userspace-abi
Closed

DjDeveloperr wants to merge 63 commits into
aurora-wipfrom
mm-mixed-userspace-abi

Conversation

@DjDeveloperr

Copy link
Copy Markdown
Contributor

This patch series introduces generic MM support for per-process mapping size, with an arm64 backend that supports 4 KiB userspace on 16/64 KiB kernels, and 16 KiB userspace on 64 KiB kernels.

Aim is to reduce fragmentation in the arm ecosystem and keep legacy apps supported. Native performance stays unaffected.

It keeps native kernel allocation sizes while carrying subpage offsets and ownership through mapping, sharing, reclaim, swap, exec, and converted I/O interfaces.

It has so far been tested on many different configurations of QEMU with mix-and-matched kernel and userspace page sizes, for both ARM64 and ARM32.

This has also been tested on Apple Silicon devices with a 16 KiB kernel build and proven to be stable and supports running 4 KiB applications (such as x86 apps translated by FEX) natively without workarounds like muvm - which tend to be inefficient and unstable.

bonzini and others added 15 commits October 6, 2026 18:15
Right now, users of .pfn_mkwrite() have no way to create a PTE
that has gone through maybe_mkwrite().  Because vma_set_page_prot()
will have cleared the writable PTE bit, users of fixup_user_fault()
will see a read-only PTE and have no clue that the page needs
a *second* fault to reach its final status.

Handling this in fixup_user_fault() is problematic: the information
about the presence of *_mkwrite is only recorded in vma->vm_page_prot,
which is an opaque pgprot_t, therefore only follow_pfnmap_start()
knows how to retrieve it.

There are actually some preexisting functions that suggest how this
is supposed to be handled, namely vmf_insert_page_mkwrite() and
vmf_insert_pfn_pmd().  Fixing the drivers requires similar variants
of vm_insert_pfn(), namely vmf_insert_pfn_mkwrite() for the common
case where vma->vm_page_prot is okay, and vmf_insert_pfn_prot_mkwrite()
when really all parameters are needed.  This makes it possible
to fix drivers that use .pfn_mkwrite together with
vmf_insert_pfn() and vmf_insert_pfn_prot().

Since vmf_insert_pfn_prot_mkwrite() is the most general variant
and all the others are just special cases, turn them into inline
functions in the header.

Fixes: 28e3918 ("drm/gem-shmem: Track folio accessed/dirty status in mmap")
Cc: [email protected]
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit c1fd108)
Signed-off-by: Diljit Singh <[email protected]>
This ensures that KVM or VFIO correctly see a writable PTE when
they request one.  Otherwise, a guest write to an unpopulated
PTE from a mapping backed by a DRM GEM BO triggers a VM exit
with EFAULT.

The code actually is simpler, because the same logic already
applied to the hugepage mapping case using vmf_insert_pfn_pmd().

Reported-by: Sergio Lopez <[email protected]>
Link: https://lore.kernel.org/kvm/[email protected]/
Tested-by: Sergio Lopez <[email protected]>
Reviewed-by: Boris Brezillon <[email protected]>
Fixes: 28e3918 ("drm/gem-shmem: Track folio accessed/dirty status in mmap")
Cc: [email protected]
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit c2b3c97)
Signed-off-by: Diljit Singh <[email protected]>
All callers of follow_pfnmap_start() except s390_pci_mmio_write()
are following it, if they are doing a write, with a check that
args.writable is true; for s390_pci_mmio_write() that's a bug.
Also, most of them return -EFAULT if it is not.  Pull the check
directly into follow_pfnmap_start() through another input parameter
args.write_fault, to eliminate the need to do it in the caller.

This also fixes an issue where follow_pfnmap_start() would return
0 for a PFN that is mapped read-only, and the caller would not
attempt to call fixup_user_fault() on it; this can happen with
vm_ops that set .pfn_mkwrite(), for example.  Instead, now the
caller (for example hva_to_pfn_remapped()) sees an error,
does attempt to fix it, and only returns -EFAULT if the
fixup was fruitless.

Reported-by: Sergio Lopez <[email protected]>
Fixes: 28e3918 ("drm/gem-shmem: Track folio accessed/dirty status in mmap")
Link: https://lore.kernel.org/kvm/CAAiTLFU1ALsDoJoKW3d9bUvv990AozAoX=bEHmfnG54qyBAHFg@mail.gmail.com/
Cc: [email protected]
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit 2e835aa)
Signed-off-by: Diljit Singh <[email protected]>
Separate target-mm virtual geometry from native physical pages across
faults, COW, reclaim, swap, GUP, VMAs and accounting. Supply explicit
fragment interfaces and keep native defaults until the optional backend
is enabled later in the series.

Signed-off-by: Diljit Singh <[email protected]>
Implement reference-counted user slots within native folios, including
zeroing, mapping and pin ownership, migration and deferred lifetime.
The backend remains disabled until its architecture integration.

Signed-off-by: Diljit Singh <[email protected]>
Resolve the per-thread exec preference before exposing the new address
space. Transfer staged arguments across granules, bound temporary copies
by their native mappings, and use the selected ABI for ELF and core dumps.

Signed-off-by: Diljit Singh <[email protected]>
Carry the backing offset and retained fragment reference through bio,
splice and io_uring paths so a smaller user mapping is not treated as an
entire native physical page.

Signed-off-by: Diljit Singh <[email protected]>
Preserve fragment ownership and byte ranges in socket, TLS, BPF and
vhost consumers of user memory.

Signed-off-by: Diljit Singh <[email protected]>
Convert IOMMUFD, VFIO and GEM/DMA-BUF paths to preserve the backing
offset, mapping span and ownership of smaller user pages.

Signed-off-by: Diljit Singh <[email protected]>
Keep kernel mappings at their native granule while selecting TTBR0
geometry per address space. Add capability checks, table-fragment lifetime,
TLB invalidation and exec selection for 4K on 16K/64K and 16K on 64K.
The backend remains opt-in; private launch commands are experimental.

Signed-off-by: Diljit Singh <[email protected]>
Add internal MM, table, subpage and recorded VFIO tests with separate
opt-in controls. Translation fixtures require a disposable guest and
recorded device mappings do not establish physical DMA qualification.

Signed-off-by: Diljit Singh <[email protected]>
Cover exec policy, AArch32 fallback, mappings, sharing, reclaim,
accounting and converted I/O interfaces. Keep extended PID1 fixtures
separate from the ordinary page-contract executable.

Signed-off-by: Diljit Singh <[email protected]>
Document native backing versus per-process mappings, architecture
responsibilities, supported combinations and remaining limitations.
Provide a launcher for inherited and one-shot exec preferences.

Signed-off-by: Diljit Singh <[email protected]>
Preserve Apple's TSO capabilities and memory-model prctls alongside
per-process page-size controls. Retain the offset-aware PFN/GEM helpers
when reconciling the prerequisite backports with aurora-wip.

Both 16K and 64K kernels build and pass guest exec-policy checks with
memory-model controls enabled. Actual Apple TSO hardware behavior is
not qualified by these guest tests.

Signed-off-by: Diljit Singh <[email protected]>
Linear subpage owners retain an anon-vma root even without an rmap
sidecar. Their last slot reference can be released by skb completion
in softirq after the originating mm has exited. Route both kinds of
root through the existing unbound cleanup work so the final anon-vma
put and its sleeping synchronization run in process context. Preserve
the physical unbinding and folio reference ordering.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
RyanTheTide and others added 14 commits October 8, 2026 19:34
mm: defer linear subpage anon-vma destruction from atomic context
Closing a subpage pool after each COW fault leaves every remaining slot
unavailable for later faults. On a 16K kernel with a 4K process ABI, a
64MiB densely modified fork child therefore uses 256MiB of backing.

Retain bounded, address-group pools for eligible faults in each mm.
Keep charge domains and memory policy explicit, preserve independent
fork ownership, and close pools after exit_mmap while referenced owners
remain alive. Copy into a reserved slot under the folio lock, decide
first rmap/LRU publication after relocking, and fall back to private
backing if nonlinear rmap metadata cannot be allocated.

Distribute concurrent faults across 16 address-group pools, skip busy
backing on the normal path, and use exact per-offset free counts to
avoid repeatedly scanning incompatible partial owners. Speculative
allocation and charge do not invoke OOM; under pressure, retry reusable
backing before ordinary allocation. Existing policy-sensitive, locked,
droppable and multi-node faults keep private backing.

Add a user4k selftest covering concurrent, sparse, phased and random COW,
mlock and lazy-free transitions, and a descendant that retains data
after the pool-owning mm exits. Each case checks untouched bytes and
parent isolation. Physical density and reclaim were tested separately
on Neo hardware; the selftest does not infer them from logical RSS.

Assisted-by: LLM
Signed-off-by: Diljit Singh <[email protected]>
A missing 4K PTE in a partially populated native 16K window currently gets
a fresh private folio. Existing neighbors are skipped and the unused
quarters are stranded when its pool closes. Repeated per-quarter hole
refills can leave 16 MiB of logical data backed by 64 MiB of native pages.

Reserve the missing-quarter mask from one compatible shared owner, keeping
whole-window private allocation for initial dense faults. Initialize and
hold the selected folio through reverse-map setup and PTE publication.
Revalidate the missing mask under the PTE lock, release surplus or losing
reservations, and retain the private fallback for metadata allocation
failure. Existing pool charge, NUMA, locking and droppable exclusions apply.

Add density, neighbor-prefault, concurrent refill, owner-exit, and controlled
reclaim selftests. On native 16K Neo hardware with the 4K userspace ABI, the
16 MiB refill fixture finishes at 16.09 MiB instead of 64 MiB, with byte-exact
contents. Initial dense backing stays at 16 MiB. Native/4K ABI, fork/exec,
mprotect, existing concurrent COW and GPU quarter-refault controls pass.
Controlled reclaim swaps all 4096 test leaves after original-owner exit,
then passes byte-exact readback. Subnautica menu/world backing snapshots
show lower native backing overhead; this is not an FPS qualification.

Assisted-by: LLM
Signed-off-by: Diljit Singh <[email protected]>
A workload writing the same logical quarter in each native window used
16 MiB of backing for 4 MiB of changed data because COW only reused a
matching physical quarter. Allow eligible pooled single-slot copies to
use any free quarter, retaining exact-offset private fallbacks and dense
anonymous batching.

Prepare nonlinear reverse mappings before taking PTE locks, including
anonymous hole and swap-in publication. Restore swapoff from a locked
swap-PTE snapshot and recheck it before installation. Use actual source
and destination slot offsets for file and anonymous copies.

On Neo, the same-quarter case now uses 4.09375 MiB with byte-exact parent
isolation. Hardware checks cover same-native-folio COW, typed GUP and
shifted mremap, complete owned-cgroup reclaim/readback, selected-page
swapoff, native/4K ABI, hole refill, GPU quarter refault and normal game
correctness. Maintained regression binaries match those tested exactly.
Ongoing game memory pressure and other first-write allocation paths are
separate unresolved issues; this change makes no FPS claim.

Assisted-by: LLM
Signed-off-by: Diljit Singh <[email protected]>
Short anonymous windows and untouched private-file writes allocated a
fresh 16 KiB folio for individual 4 KiB destinations. They consumed
64 MiB of backing for 16 MiB of written data on a 16 KiB kernel.

Reserve clipped anonymous batches from one shared owner using a matching
free-slot count throughout lookup, waiting and supply. Keep slots indexed
by their logical mask while zeroing and publishing their actual physical
quarters. Preserve full native-window batching and private fallbacks.

Pool private-file first writes only for known filemap and shmem callbacks.
Release destination locks before invoking the source callback, serialize
publication and nonlinear rmap preparation, and mark shared folios uptodate
atomically. Retry publication metadata OOM once with private backing,
without internally retrying callbacks that dropped the VMA lock.

Hardware first-write cases now use 16.06-16.19 MiB for 16 MiB of data.
Clipped-neighbor prefaulting, full contents, source isolation, repeated
eight-writer first faults, COW/GUP/mremap and actual reclaim/readback pass.
Dense allocation remains 16 MiB; sparse wide-VMA prefaulting is unchanged.
Maintained regression binaries match the hardware-tested artifacts.

Assisted-by: LLM
Signed-off-by: Diljit Singh <[email protected]>
A fork that must copy pinned 4 KiB leaves previously allocated one native
16 KiB folio per leaf. Reserve copies from the child mm's subpage pools,
while retaining the source mm for the existing fork allocation charge.
Preflight non-linear rmap before taking the page-table locks and copy from
the actual source offset after revalidating the parent PTE.

Add a bounded real io_uring buffer-pin regression that verifies distinct
parent/child native owners, full two-way byte isolation and packed density.
On Neo, a 1 MiB copy fell from 4 MiB to 1 MiB of native backing. A held
non-root cgroup check verified every payload native PFN retained the
correct charge. Retained MM, actual reclaim/readback and GPU controls pass.

Assisted-by: LLM
Signed-off-by: Diljit Singh <[email protected]>
Concurrent small-table allocators can all miss the fragment cache before
allocating a native owner. Recheck the cache after construction and consume
its reserved fragment if another allocator supplied it. Destroy the unused
fresh owner instead of returning one table and stranding its other slots.

Add bounded serial and concurrent backing fixtures with separate logical
VmPTE and physical-charge checkpoints. On Neo the same concurrent fixture
fell from 5632 to 4192 KiB physical pagetables for approximately 4160 KiB
logical tables. All contents, retained MM, reclaim/readback and GPU controls
pass. Issued-fragment retention after unmap is a separate unresolved case.

Assisted-by: LLM
Signed-off-by: Diljit Singh <[email protected]>
Keep an independent per-mm, per-level pool of native table owners so holes
left by unmap can satisfy subsequent small-table allocations. Retain issued
references until RCU retirement, clear dirty slots only when reused, and
release empty owners. Pool references outlive mm teardown for callbacks.

On Neo, serial refill physical tables fall from 7,421,952 to 4,276,224 bytes;
concurrent refill falls from 6,275,072 to 4,276,224. Contents, teardown,
pinned-copy charges, repeated MM, actual swap readback and GPU controls pass.
Host allocator checks cover native 4K/16K/64K primitives; maintained KUnit
code compiles but was not enabled in the hardware kernel. Seven-round
operation timing has overlapping ranges and about 1% higher medians; no
zero-overhead claim. Live-table compaction remains separate.

Assisted-by: LLM
Signed-off-by: Diljit Singh <[email protected]>
Index per-mm subpage pools by charge domain, node and VA shard instead of
keeping only the first domain. Retain discoverable pools while their native
owners survive, so A-to-B-to-A moves can reuse each domain's free quarters.
Pin charge identities and registry lifetime, retire empty pools safely, and
retry lookup when allocation races with retirement. Preserve private fallback
and existing allocation policy restrictions.

Add a bounded fixture for bulk moves, alternating single-slot tails and
concurrent moves followed by steady allocation. On Neo, the previously 4 MiB
backing for a 1 MiB steady allocation becomes approximately 1 MiB; alternating
eight 4K leaves per domain fit two 16K owners. Actual kpagecgroup charges,
old/new PFN stability, disjoint quarters and complete bytes pass. The corrected
race oracle measures added owners rather than counting reused live backing
again. Retained MM, pin, real swap readback and GPU controls also pass.

Assisted-by: LLM
Signed-off-by: Diljit Singh <[email protected]>
When a retained reference prevents discarding a clean lazyfree slot,
try_to_unmap_subpage() restores the PTE but then marks the native folio
swap-backed. The extra reference alone does not cancel MADV_FREE, so this
can prevent reclaim without swap and cause unnecessary swap traffic.

Leave the classification unchanged after restoring a clean PTE. Dirty
entries still cancel lazyfree and follow the existing swap-backed path.
Extend the lazyfree KUnit case to retain a reader after whole-folio advice,
check the clean classification, then release the reader and reclaim.

The expanded test passes on 16K and 64K KASAN guests without warnings.

Signed-off-by: Diljit Singh <[email protected]>
The IOMMUFD harness selects IOMMU_PT even when IOMMU_SUPPORT is disabled,
excluding the page allocation implementation its selected code requires.
The boolean VFIO harness selectors can also force VFIO built-in while
IOMMUFD is modular, bypassing VFIO's own tristate constraint.

Require IOMMU_SUPPORT for the IOMMUFD harness. Require non-modular IOMMUFD
for both VFIO selectors, including the ioctl selector that selects the
accounting harness. Built-in and disabled IOMMUFD configurations remain
available for VFIO testing.

Six before/after configuration checks cover the invalid combinations and
the retained valid selections. Integrated 16K/64K KASAN images build.

Signed-off-by: Diljit Singh <[email protected]>
contpte_try_unfold_partial() checks its exclusive endpoint with
contpte_align_down(). That helper derives granule geometry from the PTE's
backing metadata, but ptep + nr can already lie beyond that backing.

Use the mm's contiguous-group size to test alignment at both ends. This
preserves partial-group unfolding while avoiding a metadata lookup for a
pointer that need not identify an allocated page-table entry.

16K/64K KASAN images build and their existing native/4K contiguous-PTE
functional tests pass without warnings. The endpoint defect is established
by source inspection; no runtime reproduction is claimed.

Signed-off-by: Diljit Singh <[email protected]>
perf_get_pgtable_size() starts with an mm-aware PGD lookup but continues
with native table offsets and leaf sizes. A smaller userspace granule can
therefore select an unrelated entry or report the native page size.

Add mm-aware lockless offset and leaf-size helpers with native fallbacks.
Use the target mm throughout perf's walk, including runtime folding and
contiguous mappings, while preserving the existing interrupt exclusion
and descriptor-snapshot semantics.

Expose the walker only for KUnit testing and cover ordinary mapped and
unmapped addresses across table levels. Extend contiguous-PTE fixtures to
check perf's reported size and cover 16K userspace on a 64K kernel.

The tests pass in 16K/64K KASAN guests for native, 4K and supported 16K
userspace granules. An x86_64 perf-object build checks the native fallbacks.
Hardware PMU event delivery was not tested.

Signed-off-by: Diljit Singh <[email protected]>
The smaller-page orig_page_is_identical() path compares bytes directly,
bypassing the architecture checks used by pages_identical(). On arm64,
byte equality does not make distinct tagged ranges interchangeable.

Add memcmp_pages_range() with a generic mapped-byte implementation and
an arm64 implementation retaining the existing MTE policy. Distinct
tagged ranges remain non-identical, including different offsets within
one page. Keep full-page comparison as the zero-offset full-length case,
and use the range API for the smaller-page uprobe comparison.

Add direct tests for offset ranges, bytes outside the compared range,
unequal contents, empty ranges and tagged-range identity. These and the
existing ownership tests pass in 16K/64K KASAN guests. The generic util and
uprobe objects also compile for x86. Actual uprobe removal with private
tag state was not runtime reproduced.

Signed-off-by: Diljit Singh <[email protected]>
Supply the native page offset when bounding the reverse-map walk. For a
smaller-granule MM, return the matching leaf found by the walk instead of
the initial address, which can refer to an unmapped leading fragment.
Keep the byte address within a covering leaf for native and coarser MMs.

Extend the existing boundary case with a nonzero file offset and an absent
leading fragment. Reverse-map tests pass in 16K/64K KASAN guests; native
x86 objects build with CONFIG_MEMORY_FAILURE enabled.

Signed-off-by: Diljit Singh <[email protected]>
Match the native MADV_FREE handling of hardware-poison and software poison
markers. Clearing these non-swap entries must not change swap accounting.

Extend the existing userfaultfd marker case to check MADV_FREE recovery
and neighboring data. The suite passes for native/4K processes on 16K and
native/4K/16K processes on 64K KASAN kernels. Hardware memory errors were
not injected.

Signed-off-by: Diljit Singh <[email protected]>
A pin worker can exit on an error before cleanup calls kthread_stop().
Create it stopped, acquire a task reference, register cleanup, and then
wake it. Release the reference after kthread_stop(), including the cleanup
registration failure path.

The existing retained-pin test passes on 16K and 64K KASAN kernels.
No additional test fixture is introduced.

Signed-off-by: Diljit Singh <[email protected]>
Add an explicit physical offset to the PFN range mapping path. Carry it
through the existing page-table batching and error cleanup, record it in
COW mapping offsets, and track the complete covering native-page range.
The existing remap_pfn_range() interface selects offset zero.

Use the offset-aware range interface in the system dma-buf heap. Shorten
the first scatterlist extent by the starting offset and reset that offset
when advancing to the next extent. Physical identity remains independent
of the target virtual address.

Extend the existing PFN mapping test with noncongruent physical/virtual
offsets. 16K/64K KASAN builds and tests pass. Locally adapted existing
dma-buf heap tests also verify offset aliases across backing segments for
native/4K/16K processes, including coherent writes. Native x86 PFN tracking
and system-heap objects build. Physical DMA hardware remains unqualified.

Signed-off-by: Diljit Singh <[email protected]>
Round resource coverage in the target MM's granule and combine the resource
start with the VMA's complete byte offset. Validate lengths and offset
arithmetic before publishing mappings. Native-page rounding is unchanged.

Carry the resulting physical offset through both vm_iomap_memory() and
mmap_prepare actions. Keep the native architecture PFN conversion and
protection hooks, include the offset in their range, and preserve COW
physical identity. The action field is absent without CONFIG_MM_SUBPAGE.

Extend the existing PFN mapping test across native, 4K and supported 16K
process geometries. Direct and descriptor I/O mappings check noncongruent
offsets and reject insufficient resource ranges. 16K/64K KASAN builds and
tests pass; native x86 mapping/action objects compile. Physical MMIO device
access is not qualified by these RAM-backed fixtures.

Signed-off-by: Diljit Singh <[email protected]>
Provide a zero-offset wrapper for remap_pfn_range_offset() without an MMU.
It retains the existing identity-mapping checks and rejects offsets that
this configuration cannot represent. MMU kernels keep the range mapper.

ARM MPS2 no-MMU builds of mm/nommu.o and the system heap pass; their symbols
contain no unresolved offset-remap reference. Native x86 mapping and action
objects also build. No no-MMU runtime test was performed.

Signed-off-by: Diljit Singh <[email protected]>
Shared shmem backing and neighboring retained slots can already expose the
folio while a fill operation updates it. Holding the folio lock and PTL
does not exclude other atomic changes to the folio flags word.

Use folio_mark_uptodate() for both published-backing paths, preserving the
write barrier while avoiding a non-atomic flags update. Keep private
allocation initialization unchanged.

16K/64K KASAN builds and the existing userfaultfd contract suite pass for
native/4K and supported 16K processes. No new fixture was added and the
specific flag-word race was not forced at runtime.

Signed-off-by: Diljit Singh <[email protected]>
Argument staging can use a smaller userspace granule, where legacy
page-array GUP cannot represent the backing. Read the requested virtual
bytes through access_remote_vm(), retaining the existing native-page
buffer and caller iteration units. Keep the no-MMU page-array path.

Cache the first copied virtual position instead of a backing-page pointer.
Refill on a backward access outside the cached tail and invalidate before
a potentially partial copy. Multiple fragments may contribute to one
cached native-sized virtual range.

Local extensions of existing exec tests verify argument bytes and cache
rewinds on 16K/64K KASAN kernels for all supported process granules. Native
x86 and ARM no-MMU TOMOYO objects compile. The temporary test hooks are not
submitted; full policy enforcement was not exercised.

Signed-off-by: Diljit Singh <[email protected]>
would_dump() can refine the staging MM's namespace for the interpreter
before final ELF geometry selection. A replacement MM allocated from the
current credentials must not discard that earlier policy decision.

Transfer a namespace reference from the old MM after preparation succeeds,
before publishing the replacement. Failed preparation leaves the old MM
and namespace untouched.

Local extensions of existing exec tests verify retention of a distinct
namespace during granule changes on 16K/64K KASAN kernels. Native x86 and
ARM no-MMU exec objects build. No privileged-exec experiment was performed.

Signed-off-by: Diljit Singh <[email protected]>
Fragment pinning emits records in mm_user_fragment_size() intervals.
Count the same intervals when reserving vectors, including unaligned
segments and saturation at the caller's limit. Fixed 4K counting
otherwise overestimates 16K userspace buffers on a 64K kernel, affecting
allocation and direct-I/O path selection.

Local extensions of the existing BIO tests cover native and smaller
granules on 16K/64K KASAN kernels. The native x86 BIO object builds.

Signed-off-by: Diljit Singh <[email protected]>
Pass FOLL_NOFAULT when the iterator forbids faulting, matching ordinary
iterator extraction. Filesystems set this flag while holding locks
that must not be reacquired through a user-buffer fault.

Keep existing partial-progress and cleanup behavior. Local extensions
of the existing BIO tests check missing and resident mappings with
nofault set on 16K/64K KASAN kernels. Filesystem-specific locking paths
have not been exercised.

Signed-off-by: Diljit Singh <[email protected]>
A queued TCP skb can carry retained subpage references in its ubuf_info.
A subsequent MSG_ZEROCOPY send cannot extend that owner as a message
completion record. Allocate a fresh record for stream sockets and let
the existing incompatible-owner handling select another skb, as it
already does when a completion record reaches its size limit.

Keep the datagram behavior unchanged. Mixed-granule pipe producers and
native TCP consumers passed both send orders on IPv4/IPv6 loopback in
16K/64K KASAN guests, including completion notifications.

Signed-off-by: Diljit Singh <[email protected]>
Splicing a retained subpage into a queued MSG_ZEROCOPY skb needs its own
fragment owner. Report this conflict as EEXIST and retry on a new TCP
segment, matching the reverse zerocopy transition. Preserve the iterator
position and the existing owner's completion references.

IPv4/IPv6 loopback checks cover both operation orders, exact bytes and
completion notifications on 16K/64K KASAN guests. Existing SKB clone,
trim and retained-reference tests also pass. No NIC throughput claim is
made by these checks.

Signed-off-by: Diljit Singh <[email protected]>
The splice fixture assumes a 16K native pipe page, a corked payload that
fits below TCP's MSS, and a process page smaller than a UDP datagram.
Those assumptions fail on a 64K kernel even for native processes.

Discover the native pipe allocation unit, size the test mapping to hold
it, and bound corked TCP and UDP payloads by their protocol limits.
Retain the data, ownership, teardown and capacity assertions. The same
existing fixture now passes its 148 checks on both 16K and 64K kernels.

Signed-off-by: Diljit Singh <[email protected]>
The migration guard accidentally encloses the VMA split and brk tests,
but their registrations are unconditional. Keep those definitions
available without migration and guard the reclaim cases which explicitly
exercise migration. Guard the userfaultfd MOVE/migration fixture and its
registration too; a migration-disabled build exposed its unguarded
reference to the migration allocator.

The existing KUnit object builds on 16K and 64K configurations with
migration both enabled and disabled. No new tests are added.

Signed-off-by: Diljit Singh <[email protected]>
- Track fragment-backed registrations in a refcounted account for each
  user/MM counter pair. Charge each backing folio once and release its
  charge with the final retained fragment, including cloned buffers.
- Keep the account alive independently of the originating ring. Roll back
  only the references acquired by failed preparation.
- Serialize account updates locally; cache the registry lookup per ring.
  Preserve existing ring-context member offsets and keep native backing
  owners in their separate accounting path.
- Validate with 16K/64K KASAN and lockdep builds, 110 guest lifecycle checks,
  and an x86 io_uring build. Warmed emulated registration measurements do
  not reproduce the earlier native timing discrepancy; hardware overhead
  and total metadata costs remain unqualified.

Signed-off-by: Diljit Singh <[email protected]>
- Take the pool lock when cancelling lazyfree so discard eligibility
  cannot combine an earlier lazyfree state with a later reference count.
- Keep cancellation ordered before releasing the caller's retained
  reference. Existing callers acquire the helper outside the pool lock.
- Validate with 16K/64K KASAN and lockdep builds and existing lazyfree and
  ownership suites; no concurrent-race or hardware reproduction claimed.

Signed-off-by: Diljit Singh <[email protected]>
- Keep retained fragments in KUnit-managed storage with a release action
  so a fatal assertion cannot strand the backing reference.
- Use the already-retained folio when exercising reclaim; transient
  migration PTEs must not turn a successful GET into a failed lookup.
- Keep the existing eleven test modes. Both 16K/64K lazyfree runs pass;
  no concurrent memory-offline experiment was performed.

Signed-off-by: Diljit Singh <[email protected]>
Pin alternative-granule local ranges with the fragment API and derive the
Xen frame from the retained backing offset. Keep native fast GUP and the
existing hypercall batch size. Cache the fragment array with each batch,
selecting its use from the calling MM on every ioctl.

Track write intent per local pin so a later source-only segment cannot
suppress dirty release for an earlier destination. Release adjacent pins
with the same intent together, including on preparation failures.

Signed-off-by: Diljit Singh <[email protected]>
- Replace poisoned anonymous subpage PTEs with hardware-poison entries
  under the existing folio/PTE locks and MMU notifier scope.
- Complete invalidation before dropping mapping ownership, preserving
  exact slot references retained by pins or asynchronous users.
- Reject poisoned pool supply and skip poisoned owners during allocation;
  unused neighboring slots share the same native hardware-error granule.
- Preserve the existing swap-cache containment path when TTU_HWPOISON is
  cleared by unmap_poisoned_folio().

Signed-off-by: Diljit Singh <[email protected]>
- HMM results represent whole native pages without fragment offsets or
  per-leaf permissions. Reject non-native MMs before walking or changing
  the output PFN array.
- Device VMA migration collects, owns and restores native pages. Reject
  non-native MMs before rounding endpoints or modifying mappings/arrays.
- Return -EOPNOTSUPP as a non-retry error. Native MMs keep the existing
  paths; enabling alternatives requires converting the complete API and
  its consumers together.

Signed-off-by: Diljit Singh <[email protected]>
The published COW pool work added a pressure retry scan and folio-locked
eligibility rechecks after the original poison-containment fix was prepared.
Checking hwpoison only in find_available leaves those paths inconsistent:
the pressure path can report unusable poisoned backing as retryable.

Put the exclusion in the shared eligibility predicate, before the non-COW
early return, so ordinary allocation, pressure retry and locked revalidation
all use the same condition. Keep the fresh-supply rejection.

Assisted-by: LLM
Signed-off-by: Diljit Singh <[email protected]>
The remote fragment-pin/COW test reaches mm_subpage_cow_folio_matches()
without an RCU read lock. With lockdep enabled, folio_memcg() warns in
obj_cgroup_memcg() because the charge's memcg can be reparented.

Hold RCU across the comparison as required by folio_memcg(). The pool's
retained memcg reference does not protect a different memcg obtained from
the folio. No returned memcg pointer escapes the read-side section.

Fixes: 5469651 ("mm: reuse backing folios for small-granule anonymous COW")
Assisted-by: LLM
Signed-off-by: Diljit Singh <[email protected]>
COW backing can now use a physical quarter unrelated to the fault's
virtual quarter. Update the zero, fork, file and fragment-permission
fixtures to validate the actual PTE and slot rather than requiring the
old fixed-offset allocation policy.

Read zeroed bytes and write child-private bytes at the actual slot offset.
Keep the checks for untouched neighboring PTEs, copied data, parent and
file-cache isolation, mapping ownership and access permissions.

Assisted-by: LLM
Signed-off-by: Diljit Singh <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor

All 48 commits of this series are already in integration/aurora (7.3) with identical patch-ids, carried in by the unified 7.3 userpages merge 8009d9f2cd2d (for example 7880a2d3f47b). The aurora-wip base is retired now that 7.3 is the base. Closing as superseded, the branch is left as it is. Thanks!

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

@mkurz Yes, I learned about those efforts after I had already done work on this - they came out with the talk and patches few days later. I decided to see this to the end anyway - and it works very well - we're going to be shipping this as an experimental feature default off. It is not based on Google's effort at all. I believe this is more generic and upstreamable.

@mkurz

mkurz commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

👍

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.

4 participants