diff --git a/Documentation/arch/arm64/user4k.rst b/Documentation/arch/arm64/user4k.rst index 15da1cdae5894..c8269fa39a1d1 100644 --- a/Documentation/arch/arm64/user4k.rst +++ b/Documentation/arch/arm64/user4k.rst @@ -73,8 +73,23 @@ While it is off: 16K pages). ``page_ext`` itself is still allocated if another user, such as page_owner, needs it. -The shared MM code paths that serve every process are compiled in either -way and do not change with the parameter. +The shared MM code that serves every process is compiled in either way, and +the parameter does not switch it back to the upstream code. A kernel built +with this option therefore differs from upstream even while the feature is +off. The differences that callers can see are: + +* ``vm_insert_pages()`` returns ``EFAULT`` for a start address that is not + aligned to the address space's page size. +* The ``fault_around_bytes`` debugfs file accepts values down to 4K, so + writing ``0`` reads back 4096 rather than the native page size. +* ``generic_access_phys()`` handles at most one user page per call. + ``access_process_vm()`` and other callers that loop still move the same + total. +* ``locked_vm`` is counted in 4K units for every process. Limit checks and + ``VmLck`` give the same results as before for native address spaces. + +Other changes, such as the 64K zero page and ``pgtable_t`` holding a +``pte_t`` pointer, keep native results the same. While it is on, the CPU capability line appears on CPUs that support the 4K translation granule, and the launcher below can select 4K pages. diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug index f08f789e501db..9b8a5b45a4ebb 100644 --- a/arch/arm64/Kconfig.debug +++ b/arch/arm64/Kconfig.debug @@ -42,7 +42,9 @@ config ARM64_USER4K_EXPERIMENTAL prctls refuse every non-native size with EINVAL, every exec gets the native granule, the CPUs report no alternative user granule and the per-page 4K ownership record in page_ext is not - reserved. The shared MM code paths remain compiled in either way. + reserved. The shared MM code paths remain compiled in either way, so + a few behaviours differ from upstream even while it is off; see + Documentation/arch/arm64/user4k.rst. While it is on, an experimental prctl selects a supported granule for the next exec. Ordinary address spaces and kernel tables retain @@ -50,6 +52,7 @@ config ARM64_USER4K_EXPERIMENTAL and device mappings still require integration and validation. The private prctl numbers are not upstream assignments or a stable ABI promise. Programs that do not use the prctl keep the native granule. + KSM does not merge the memory of programs that use another granule. config ARM64_CPUINFO_KUNIT_TEST bool "KUnit tests for the /proc/cpuinfo model name" if !KUNIT_ALL_TESTS diff --git a/fs/splice.c b/fs/splice.c index 4b707ce00e86d..9ec2998b94ab7 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -219,22 +219,35 @@ static const struct pipe_buf_operations subpage_pipe_buf_ops = { static int subpage_pipe_buf_retain(struct pipe_buffer *buf) { struct subpage_pipe_refs *refs; + struct mm_subpage *first; unsigned int pos, count = 0; if (!buf->len || buf->ops != &nosteal_pipe_buf_ops || !folio_test_anon(page_folio(buf->page))) return 0; + /* + * Look up the first quarter before allocating. It has no owner on a + * native anonymous page, and none at all while user4k is off, so the + * common splice keeps its native reference without an allocation. + */ + pos = round_down(buf->offset, MM_SUBPAGE_SIZE); + first = mm_subpage_get_from_phys(page_to_phys(buf->page) + pos); + if (!first) + return 0; refs = kmalloc(struct_size(refs, fragments, PAGE_SIZE / MM_SUBPAGE_SIZE), GFP_KERNEL); - if (!refs) + if (!refs) { + mm_subpage_put(first); return -ENOMEM; - for (pos = round_down(buf->offset, MM_SUBPAGE_SIZE); - pos < buf->offset + buf->len; pos += MM_SUBPAGE_SIZE) { - struct mm_subpage *slot = mm_subpage_get_from_phys(page_to_phys(buf->page) + pos); + } + for (; pos < buf->offset + buf->len; pos += MM_SUBPAGE_SIZE) { + struct mm_subpage *slot = first; + if (count) + slot = mm_subpage_get_from_phys(page_to_phys(buf->page) + pos); if (!slot) { release_user_fragments(refs->fragments, count, false); kfree(refs); - return count ? -EFAULT : 0; + return -EFAULT; } refs->fragments[count++] = (struct user_page_fragment) { .folio = page_folio(buf->page),