|
| 1 | +.. SPDX-License-Identifier: GPL-2.0-only |
| 2 | +
|
| 3 | +=========================================== |
| 4 | +Experimental per-process page sizes on arm64 |
| 5 | +=========================================== |
| 6 | + |
| 7 | +The mixed-page implementation lets an address space use a different user |
| 8 | +translation granule from the kernel's native physical page size. The kernel |
| 9 | +page size remains fixed for the boot. An address space's user granule remains |
| 10 | +fixed for its lifetime; exec can create a new address space with another |
| 11 | +supported granule. See :doc:`../../mm/user_page_size` for the generic launch |
| 12 | +policy and architecture integration contract. |
| 13 | + |
| 14 | +This is an experimental feature and ABI. It is built into the kernel but |
| 15 | +stays off unless the kernel is booted with ``user4k=on``. The launch |
| 16 | +commands use private prctl numbers, not assigned upstream UAPI. The |
| 17 | +implementation and tests do not establish complete application, device or |
| 18 | +hardware qualification. |
| 19 | + |
| 20 | +Configuration and supported combinations |
| 21 | +======================================== |
| 22 | + |
| 23 | +``CONFIG_ARM64_USER4K_EXPERIMENTAL`` requires 48-bit VA and PA and a native |
| 24 | +16K or 64K page size. The option is on by default and selects the generic |
| 25 | +``MM_SUBPAGE`` backing and ``ARCH_HAS_USER_PAGE_SIZE`` exec policy support. |
| 26 | +LPA2 and ``NO_PAGE_MAPCOUNT`` configurations are excluded by Kconfig. |
| 27 | + |
| 28 | +The exposed combinations are: |
| 29 | + |
| 30 | +=================== ================== ============================ |
| 31 | +Native kernel size AArch64 default AArch64 alternatives |
| 32 | +=================== ================== ============================ |
| 33 | +4K 4K None in this implementation |
| 34 | +16K 16K 4K, when supported by the CPUs |
| 35 | +64K 64K 4K and 16K, subject to support |
| 36 | +=================== ================== ============================ |
| 37 | + |
| 38 | +Capability detection uses the sanitized system-wide granule intersection, |
| 39 | +and only runs with ``user4k=on``. AArch32 executables select 4K when that |
| 40 | +capability is available and retain the native granule otherwise, regardless |
| 41 | +of launch preferences. The latter case still enforces native |
| 42 | +mapping/protection alignment. AArch32 mmap2 file offsets retain their 4K |
| 43 | +ABI unit in either case. |
| 44 | + |
| 45 | +An AArch32 executable running under an arm64 kernel is distinct from an |
| 46 | +``arch/arm`` kernel. The latter retains its existing native ABI; this series |
| 47 | +does not yet provide its alternative-granule backend. Exploiting extra |
| 48 | +translation capabilities available only within an asymmetric AArch32 CPU |
| 49 | +domain also remains unimplemented. |
| 50 | + |
| 51 | +Larger-than-native process granules are not exposed. Internal 64K-on-16K |
| 52 | +fixtures exercise allocation, mappings and argument staging, but those |
| 53 | +fixtures do not enable a public 64K process ABI on a 16K kernel. |
| 54 | + |
| 55 | +Enabling at boot |
| 56 | +================ |
| 57 | + |
| 58 | +Building the option in does not enable it. Add ``user4k=on`` to the kernel |
| 59 | +command line to enable it for that boot; ``user4k=off`` or no parameter |
| 60 | +leaves it off. The value is parsed with ``kstrtobool()``, so ``1``/``0`` |
| 61 | +and ``y``/``n`` also work, and it cannot be changed after boot. |
| 62 | + |
| 63 | +While it is off: |
| 64 | + |
| 65 | +* ``PR_AURORA_SET_EXEC_PAGE_SIZE`` and ``PR_AURORA_SET_DEFAULT_PAGE_SIZE`` |
| 66 | + fail with ``EINVAL`` for every non-native size; a native or zero size |
| 67 | + still succeeds. The GET commands report the native default (zero). |
| 68 | +* Every exec, including AArch32 executables, gets the native granule. |
| 69 | +* The CPUs report no alternative user granule: the boot log has no |
| 70 | + ``4K userspace translation granule`` capability line. |
| 71 | +* The 4K ownership record is not reserved in ``page_ext``. With it on, |
| 72 | + the record takes 32 bytes for every native page of RAM (about 0.2% with |
| 73 | + 16K pages). ``page_ext`` itself is still allocated if another user, such |
| 74 | + as page_owner, needs it. |
| 75 | + |
| 76 | +The shared MM code paths that serve every process are compiled in either |
| 77 | +way and do not change with the parameter. |
| 78 | + |
| 79 | +With ``user4k=on`` the CPU capability line appears on CPUs that support |
| 80 | +the 4K translation granule, and the launcher below can select 4K pages. |
| 81 | + |
| 82 | +Selecting an executable's page size |
| 83 | +=================================== |
| 84 | + |
| 85 | +The kernel must be booted with ``user4k=on``. Build the development |
| 86 | +launcher with:: |
| 87 | + |
| 88 | + make -C tools/aurora-userpages |
| 89 | + |
| 90 | +For example:: |
| 91 | + |
| 92 | + tools/aurora-userpages/userpages 4k COMMAND [ARGUMENTS...] |
| 93 | + tools/aurora-userpages/userpages --once native COMMAND [ARGUMENTS...] |
| 94 | + tools/aurora-userpages/userpages --status |
| 95 | + |
| 96 | +The ordinary selection establishes an inherited per-thread exec preference. |
| 97 | +``--once`` overrides it for one successful exec. A failed exec retains the |
| 98 | +pending request; changing a preference never changes existing mappings. |
| 99 | +Fork copies the preferences and mappings. Threads sharing an mm have the |
| 100 | +same current granule but may establish different preferences for later exec. |
| 101 | +``native`` clears an inherited alternative preference; a one-shot native |
| 102 | +request can override that preference without clearing it. |
| 103 | + |
| 104 | +The final ELF loader resolves the granule before committing the new image. |
| 105 | +If arguments were staged with another granule, their bytes are transferred |
| 106 | +into a new private mm. Temporary argument mappings are bounded by both the |
| 107 | +user leaf and native page size. Logical argument-size limits continue to |
| 108 | +use the process granule. The interpreter and executable share one mm and |
| 109 | +therefore one final granule. ELF segment alignment alone does not opt a |
| 110 | +program into an alternative ABI. |
| 111 | + |
| 112 | +``AT_PAGESZ`` reports the process granule. User virtual address alignment, |
| 113 | +protection boundaries and mapping lengths use that granule. Native physical |
| 114 | +allocation, PFN arithmetic and file-cache indices continue to use the kernel |
| 115 | +page size. Application execution does not require any of the KUnit options |
| 116 | +or the ``arm64.user4k_test=1`` diagnostic boot parameter. |
| 117 | + |
| 118 | +Memory and table ownership |
| 119 | +========================== |
| 120 | + |
| 121 | +Keep the following units separate: |
| 122 | + |
| 123 | +* ``PAGE_SIZE`` and physical PFNs describe native physical pages. |
| 124 | +* ``mm_page_size(mm)`` describes the user mapping/protection unit. |
| 125 | +* A folio owns one or more native pages and carries their physical charge. |
| 126 | + |
| 127 | +Smaller anonymous mappings retain explicit subpage ownership. A reference to |
| 128 | +the containing folio alone does not retain an individual reusable slot. |
| 129 | +The slot's byte offset must survive fault, COW, reverse mapping, migration, |
| 130 | +swap and pinning operations. Newly exposed bytes are zeroed, and changing |
| 131 | +one mapping's protection must not widen that change to adjacent slots. |
| 132 | + |
| 133 | +File offsets use a native cache index plus an explicit byte offset. VMA |
| 134 | +split/merge, truncation and reverse mapping must preserve both components. |
| 135 | +Physical allocation charges count the actual backing once, independently |
| 136 | +of how many user mappings expose it. |
| 137 | + |
| 138 | +Lower page tables can share a native allocation. Table tokens preserve the |
| 139 | +fragment address, while locking and lifetime use the native table owner. |
| 140 | +Unissued cached fragments retain owner references. Issued fragments are not |
| 141 | +reused within a live owner. Deferred reclamation must preserve the fragment |
| 142 | +token through TLB invalidation and the required RCU grace period, including |
| 143 | +allocation-failure fallback paths. |
| 144 | + |
| 145 | +Translation context and invalidation |
| 146 | +=================================== |
| 147 | + |
| 148 | +The arm64 backend supplies per-mm page-table geometry. TTBR1 retains native |
| 149 | +kernel tables, while TTBR0 uses the selected user geometry. A granule change |
| 150 | +installs and synchronizes a reserved TTBR0 before changing TG0, then |
| 151 | +synchronizes the new geometry before installing the user root. Software PAN |
| 152 | +also selects the user TG0 even when restoration of TTBR0 is deferred until |
| 153 | +uaccess or return to userspace. |
| 154 | + |
| 155 | +The existing mm ASID is retained. Selecting another granule does not add |
| 156 | +an unconditional context-switch TLB flush. User invalidation operands and |
| 157 | +range strides use the target mm's geometry; kernel and stage-2 operations |
| 158 | +retain their own native geometry. Transition/idmap paths restore native |
| 159 | +TG0 and then the active mm's user geometry when returning. |
| 160 | + |
| 161 | +The current configuration retains the existing 48-bit user address size. |
| 162 | +Independent TG0/TG1 fields do not make all other translation controls |
| 163 | +independent; the LPA2 exclusion must not be removed merely by changing TG0. |
| 164 | + |
| 165 | +Sharing, pinning and interface limits |
| 166 | +==================================== |
| 167 | + |
| 168 | +Mixed-granule sharing is permitted. Shared mappings refer to one coherent |
| 169 | +backing object, with permissions belonging to each virtual mapping. Shared |
| 170 | +futex identity includes the object and byte offset. Private copying is not |
| 171 | +an implementation of shared-memory semantics. |
| 172 | + |
| 173 | +Some interfaces have additional layout or ownership requirements. For |
| 174 | +example, a perf ring's first mapper fixes its userspace granule; a mapper |
| 175 | +using another granule is rejected. This does not prohibit mixed-granule |
| 176 | +memfd or System V shared-memory aliases. |
| 177 | + |
| 178 | +A legacy page-array pin cannot express every smaller-granule byte range. |
| 179 | +Converted consumers use typed fragment references carrying backing, offset, |
| 180 | +length and ownership. Unconverted paths must not silently round a pin or DMA |
| 181 | +mapping into neighboring slots. Mock IOMMU/VFIO tests validate the recorded |
| 182 | +translations and ownership paths, not physical-device DMA on arbitrary |
| 183 | +hardware. |
| 184 | + |
| 185 | +Alternative-granule THP/KSM and hugetlb support, remaining legacy pin |
| 186 | +consumers, larger-than-native process activation and broader device |
| 187 | +integration still need work. Userfaultfd feature bits and per-range ioctl |
| 188 | +masks must be consulted; success for a shmem operation does not imply |
| 189 | +support for the corresponding hugetlb operation. Sparse individual fills |
| 190 | +can retain an entire native folio; packing behavior is not a throughput |
| 191 | +or memory-efficiency guarantee for every workload. |
| 192 | + |
| 193 | +Test coverage |
| 194 | +============= |
| 195 | + |
| 196 | +The arm64 selftests are in ``tools/testing/selftests/arm64/user4k``. The |
| 197 | +fixtures that select another page size need a guest booted with |
| 198 | +``user4k=on``. The ``page-contract`` executable checks the exposed |
| 199 | +userspace contract. Extended |
| 200 | +fixtures cover exec policy, AArch32, shared mappings, accounting, reclaim, |
| 201 | +I/O and device-facing interfaces. Several are disposable-guest PID1 programs |
| 202 | +with companion executables or storage requirements; they are not ordinary |
| 203 | +host test commands. |
| 204 | + |
| 205 | +``CONFIG_ARM64_USER4K_KUNIT_TEST`` and the data/TLB suites exercise internal |
| 206 | +geometry and ownership. Boot them with ``user4k=on``, for example |
| 207 | +``kunit.py run --kernel_args user4k=on``. The ``arm64-user4k-policy`` suite |
| 208 | +also runs without it and checks that the feature stays closed while off. |
| 209 | +Some fixtures additionally require ``arm64.user4k_test=1`` and |
| 210 | +some hardware translation tests are disabled under KASAN. Check individual |
| 211 | +KTAP results and skips rather than treating boot success as a suite pass. |
| 212 | +Private IOMMUFD/VFIO test-device options are separate and should remain off |
| 213 | +in application kernels. |
| 214 | + |
| 215 | +The NUMA COW batching case runs only at boot, before userspace can change |
| 216 | +its policy prerequisite. Its results remain visible in KUnit debugfs, but |
| 217 | +it has no runtime rerun control. Other suites retain their rerun controls. |
| 218 | + |
| 219 | +Validation must distinguish native/default operation, each exposed |
| 220 | +alternative, and AArch32 fallback with 4K support unavailable. Native ARM32 |
| 221 | +short-descriptor and LPAE controls check that generic changes preserve the |
| 222 | +existing ABI; they do not validate a mixed-page ARM32 backend. Internal |
| 223 | +larger-leaf tests likewise do not qualify a public process mode. |
0 commit comments