Skip to content

Commit 8009d9f

Browse files
committed
Merge branch 'unified-7.3/bits/220-userpages' into unified-7.3/canonical
Topic head 5f92b85, 119 commits not already in the tree. Top commit: arm64: user4k: set Linux 7.3 VMA state in the KUnit fixtures Conflict resolved in drivers/gpu/drm/drm_gem_shmem_helper.c as in the 210/220 test merge 5bc189ffceb3: the shared drm_gem_shmem_object_offset() line once, and in drm_gem_shmem_mmap() 220's byte-range validation before 210's revocation check, which is aurora-wip's order. Re-recorded after the 220 review fixes (#136): same rule, with 220's validation now covering a partial native-page PRIME offset.
2 parents ea36d42 + 5f92b85 commit 8009d9f

313 files changed

Lines changed: 58820 additions & 1734 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/admin-guide/kernel-parameters.txt‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8322,6 +8322,17 @@ Kernel parameters
83228322
not on uas)
83238323
Example: quirks=0419:aaf5:rl,0421:0433:rc
83248324

8325+
user4k= [ARM64,EARLY]
8326+
Format: <bool>
8327+
Enable the experimental per-process user page sizes
8328+
(4K userspace pages on a 16K or 64K kernel) built
8329+
with CONFIG_ARM64_USER4K_EXPERIMENTAL.
8330+
Default: off. While off, the private page-size
8331+
prctls refuse every non-native size with EINVAL,
8332+
every exec uses the native page size and the 4K
8333+
ownership record is not reserved in page_ext.
8334+
See Documentation/arch/arm64/user4k.rst.
8335+
83258336
user_debug= [KNL,ARM]
83268337
Format: <int>
83278338
See arch/arm/Kconfig.debug help text.

‎Documentation/arch/arm64/index.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ ARM64 Architecture
3232
sve
3333
tagged-address-abi
3434
tagged-pointers
35+
user4k
3536

3637
features
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
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.

‎Documentation/mm/index.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ see the :doc:`admin guide <../admin-guide/mm/index>`.
2626
physical_memory
2727
page_tables
2828
process_addrs
29+
user_page_size
2930
bootmem
3031
page_allocation
3132
vmalloc
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
.. SPDX-License-Identifier: GPL-2.0-only
2+
3+
==============================
4+
Per-process user mapping sizes
5+
==============================
6+
7+
The experimental mixed-page implementation separates the user mapping
8+
size of an address space from the kernel's native allocation size.
9+
``PAGE_SIZE`` still describes native physical pages. ``mm_page_size(mm)``
10+
describes the minimum user mapping and protection unit of that address
11+
space. A process retains one mapping size for the lifetime of its ``mm``.
12+
Exec may create a new ``mm`` with a different size; changing a launch
13+
preference never changes an existing mapping.
14+
15+
The generic interfaces described here are internal development interfaces.
16+
The experimental launch commands still use private prctl numbers; these
17+
are not assigned upstream UAPI. The arm64 backend's supported modes and
18+
current restrictions are documented in
19+
:doc:`../arch/arm64/user4k`.
20+
21+
Exec policy and inheritance
22+
===========================
23+
24+
``ARCH_HAS_USER_PAGE_SIZE`` enables two per-thread policy fields in
25+
``task_struct``:
26+
27+
``exec_page_shift``
28+
A one-shot request for the next exec. Zero means no one-shot request.
29+
30+
``default_exec_page_shift``
31+
An inherited preference used when no one-shot request overrides it.
32+
Zero means the architecture's ordinary executable policy.
33+
34+
Fork and thread creation copy both fields. Subsequent changes affect only
35+
the calling thread, including when it shares an ``mm`` with other threads.
36+
An exec by a non-leader uses the execing thread's policy. The fields do not
37+
belong in ``mm_struct``: threads sharing one address space may launch new
38+
images with different preferences.
39+
40+
Generic prctl handling validates reserved arguments before calling the
41+
architecture validator. A rejected request leaves both fields unchanged.
42+
Setting a native one-shot request while an inherited alternative is active
43+
stores ``PAGE_SHIFT`` explicitly, so the next exec can override that
44+
alternative. Clearing the inherited preference does not consume a pending
45+
one-shot request.
46+
47+
Exec stages arguments in a private ``mm``. Its initial allocation receives
48+
the one-shot shift, if any; the final executable loader resolves the
49+
inherited preference and any executable-specific policy. An ELF interpreter
50+
must be loaded using the same final mapping size as its executable.
51+
Failure before committing the new image retains both preferences.
52+
``setup_new_exec()`` consumes the one-shot field after the new image is
53+
committed, while retaining the inherited preference.
54+
55+
Architecture responsibilities
56+
=============================
57+
58+
An architecture selecting ``ARCH_HAS_USER_PAGE_SIZE`` must implement:
59+
60+
* ``arch_exec_page_size_shift(size)``: return zero for a native request, a
61+
validated alternative shift, or a negative errno. Validation includes
62+
the supported hardware, the kernel configuration and any boot-time
63+
switch, not just whether the requested byte size is a power of two.
64+
* ``arch_mm_init_exec(mm, shift)``: initialize the private address space's
65+
geometry before allocating its page-table root. Zero denotes native
66+
geometry. The hook receives the request explicitly and does not read
67+
a separate architecture thread-policy field.
68+
* ``arch_mm_alt_granule_enabled()``, optionally: report whether this boot
69+
may create alternative-granule address spaces. It must be fixed before
70+
memory management initialization. When it is false the ``MM_SUBPAGE``
71+
page_ext record is not reserved. arm64 returns true only when booted
72+
with ``user4k=on``.
73+
* Binary-loader integration that resolves the final executable policy
74+
before exposing the address space. ``bprm_set_page_shift()`` transfers
75+
staged argument bytes when the final choice changes the initial granule.
76+
* Page-table allocation, walking, invalidation, context switching and MM
77+
operations for every size the architecture exposes.
78+
79+
The architecture retains control over executable compatibility policy.
80+
For example, the arm64 AArch32 loader prefers 4K where the backend supports
81+
it and retains the native ABI when that capability is absent. This is
82+
separate from running an AArch32 kernel: ``arch/arm`` needs its own backend
83+
integration before it can advertise alternative mapping sizes. The generic
84+
exec policy alone does not provide that backend or expose new sizes there.
85+
86+
Architectures without this capability retain native mappings and reject
87+
the experimental launch-policy commands. ``ARCH_HAS_MM_PGTABLE`` describes
88+
per-mm page-table accessors; it does not by itself promise an executable
89+
userspace ABI.

‎arch/arm64/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ config FIX_EARLYCON_MEM
362362

363363
config PGTABLE_LEVELS
364364
int
365+
default 4 if ARM64_USER4K_EXPERIMENTAL
365366
default 2 if ARM64_16K_PAGES && ARM64_VA_BITS_36
366367
default 2 if ARM64_64K_PAGES && ARM64_VA_BITS_42
367368
default 3 if ARM64_64K_PAGES && (ARM64_VA_BITS_48 || ARM64_VA_BITS_52)

0 commit comments

Comments
 (0)