Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v16 0/9] arm64: add ARCH_HAS_COPY_MC support
@ 2026-12-05  1:24 Jiangtian Feng
  2026-12-05  1:24 ` [PATCH v16 1/9] uaccess: add generic fallback version of copy_mc_to_user() Jiangtian Feng
                   ` (8 more replies)
  0 siblings, 9 replies; 18+ messages in thread
From: Jiangtian Feng @ 2026-12-05  1:24 UTC (permalink / raw)
  To: catalin.marinas, will, akpm, rafael
  Cc: mark.rutland, james.morse, robin.murphy, nikumbh.adi, tony.luck,
	guohanjun, mchehab, lenb, xueshuai, tongtiangen, tianruidong,
	tongweilin, baolin.wang, ashok.raj, jonathan.cameron, david, liam,
	vbabka, rppt, mhocko, ljs, surenb, shivankg, wangkefeng.wang,
	xiangzao, ying.huang, linmiaohe, nao.horiguchi, ziy, tujinjiang,
	mgorman, kaitao.cheng, chengkaitao, muchun.song, nico.pache,
	ryan.roberts, dev.jain, baohua, lance.yang, usama.arif, kas, kees,
	andreyknvl, dvyukov, glider, ryabinin.a.a, vincenzo.frascino,
	tglx, mingo, bp, dave.hansen, hpa, maddy, mpe, npiggin, chleroy,
	ritesh.list, sshegde, aneesh.kumar, naveen.n.rao,
	linux-arm-kernel, linux-acpi, linux-mm, linux-hardening,
	kasan-dev, linuxppc-dev, x86, linux-kernel, Jiangtian Feng

History and handoff
===================

This series continues Tong Tiangen's work and is based on Ruidong Tian's
v15:

  https://lore.kernel.org/all/20260618092124.3901230-1-tianruidong@linux.alibaba.com/

Weilin Tong subsequently announced his takeover here:

  https://lore.kernel.org/all/20261111111033.627610-1-tongweilin@linux.alibaba.com/

With Weilin's agreement, I am preparing this version. Original authorship
and prior review history are preserved. Substantial rewrites are submitted
for fresh review.

Base: Linux v7.4-rc5
  fe6ff8d5d675c01793b9f051d16055dd4aa75244

Relevant v15 review history
===========================

The related MM fallback discussion covers the missing arm64 recovery path,
the need to avoid unnecessary server panics and Weilin's subsequent takeover:

  https://lore.kernel.org/all/20261110112641.1196786-1-xiangzao@linux.alibaba.com/

Ashok's cover reply noted the incorrect 0/8 patch count, corrected here:

  https://lore.kernel.org/all/akZWyYnAdnvlkZbi@hu-ashoraj-lv.qualcomm.com/

Ashok's Reviewed-by for patch 5/9 was explicitly conditional on a
tree-wide caller audit. That audit now covers all target-tree highpage
callers, and the khugepaged positive-residual checks are converted to
nonzero-error checks. The resulting Reviewed-by is included in patch 5:

  https://lore.kernel.org/all/akZ3t68so_q68OHx@hu-ashoraj-lv.qualcomm.com/

Ashok's patch 6/9 review raised the ACPI_APEI_SEA Kconfig gate, MOPS
changelog/macro/build handling, MTE failure state, and poison queue/offline
questions. The v16 changes below address the code and documentation points;
the related hardware and fault-injection boundaries remain in NOT_RUN:

  https://lore.kernel.org/all/akZ0Gax5zZ23PIv2@hu-ashoraj-lv.qualcomm.com/

Problem and field motivation
============================

Uncorrectable memory errors are a recurring operational concern on large
ARM64 systems. When such an error is consumed while the kernel reads memory
for a copy operation, an otherwise recoverable user or MM consumer can turn
into a fatal host event. Existing COW, KSM, khugepaged, migration, coredump,
uaccess and DAX/PMEM users already have error paths for these failures, but
arm64 needs the corresponding machine-check-safe copy primitives to return
through those paths instead of panicking.

This is also a long-standing downstream requirement. The public openEuler
OLK-5.10 branch has carried an arm64 copy_mc_to_kernel() implementation
since November 2022, and the public Anolis devel-5.10 branch has carried
copy_mc_[user]_highpage() support since 2023:

  https://gitee.com/openeuler/kernel/commit/ee7b5d7559e6f2ca633f8ab6fbd23c06991595ad
  https://gitee.com/anolis/cloud-kernel/commit/6d9fac4c059045e1ae70b9a5628038fdf3acb4de

These downstream references demonstrate established demand; they are not
evidence of upstream acceptance or proof of this version's correctness.

Solution and scope
==================

The series provides machine-check-safe user, kernel and page-copy paths.
Only explicitly marked accesses and exact EL1 data SEAs with SET=0 are
eligible for recovery. SET=0 means UER on RAS systems and is RES0 on
non-RAS systems. UC, UEO and other encodings are rejected. Instruction
aborts, table-walk and parity/ECC errors, S1PTW and faults without a
suitable exception-table handler retain the existing failure path.
Ordinary translation faults must not be swallowed by the new MC SEA fixup.

The buffer-copy interfaces retain the bytes-not-copied return convention.
The highpage interfaces use zero on success and -EFAULT on failure. All
highpage callers on the target tree were audited and treat any nonzero
return as failure without consuming a residual byte count. On arm64, every
data or tag-copy failure also queues the actual source PFN with flags=0;
a hugetlb tag failure uses the failing subpage. GHES may queue the same PFN,
so duplicate events are possible. Supported RAM callers rely on MM's
already-poisoned handling to avoid a second substantive isolation, not on
strict FIFO exactly-once or a final-recovery guarantee.

The GHES changes preserve the original exception context through deferred
processing. Kernel context is captured before the arch fixup decision:
recovered copies return an error, while rejected fixups retain the fatal
SEA path. USER and KVM/NA duplicate anti-storm behavior is retained, but a
duplicate KERNEL record still reaches the strict arch SEA/extable gate.

Non-APEI recovery is outside this version's scope. Adi's related proposal
is tracked here and is expected to be coordinated as a follow-up unless
maintainers request a unified scope:

  https://lore.kernel.org/all/20261028045028.72644-1-nikumbh.adi@gmail.com/

Shivank's batch-copy v4 is a separate series. This arm64 version does not
include its raw-range batching. I have proposed an explicit
ARCH_HAS_COPY_MC_BATCH opt-in so that adding arm64 ARCH_HAS_COPY_MC cannot
silently bypass the architecture's per-page MTE/KASAN/cache and failure
handling. The coordination discussion is here:

  https://lore.kernel.org/all/20261204034522.302814-1-jiangtianfeng@linux.alibaba.com/

Changes in v16
==============

- Rebase to v7.4-rc5 and correct the cover patch count.
- Adapt the generic copy_mc_to_user() fallback to the current uaccess
  layout without changing the existing x86/powerpc implementations.
- Adapt GHES exception-context propagation to queue aggregation, including
  the memory-failure flags and the synchronous !queued SIGBUS path. Keep
  USER/KVM duplicate anti-storm handling while allowing duplicate KERNEL
  records to reach the arch fixup gate.
- Merge the access error-zero extable types and keep ordinary-fault and
  TTBR0/PAN handling for the new kernel SEA type unchanged.
- Restrict kernel recovery to exact EL1 data FSC_EXTABT without S1PTW and
  with SET=0. Reject UC, UEO and other encodings; UEO support requires a
  separate RAS-version-aware change with fault-injection coverage.
- Handle MOPS EX_TYPE_UACCESS_CPY with direction-aware SEA fixups. In
  addition to the user side, accept copy_to_user's kernel source read to
  match the scalar path, while copy_from_user's kernel destination remains
  rejected. MOPS faults bypass the single-byte try-harder path to avoid
  repeating a zero-progress SEA. Ordinary zero-progress MOPS faults may
  therefore return the full residual instead of retrying one byte; scalar
  faults retain the existing behavior.
- Keep EX_TYPE_KACCESS_SEA source-only and reject MOPS destination writes.
- Keep the highpage 0/-EFAULT contract, audit all target-tree callers and
  convert the khugepaged positive-byte checks to nonzero error checks.
- Select ARCH_HAS_COPY_MC from ACPI_APEI_SEA, address the MOPS macro/fixup
  review and adapt the MTE declarations to v7.4-rc5. Failed destination
  pages remain unpublished and are freed through the existing MM paths.
  Match normal copy_highpage() for already-tagged migration destinations,
  and queue the actual failing source page or hugetlb subpage on error.
- Preserve the buffer residual-byte contract and unsigned-long types. Use
  the forward copy template so every completed store advances the current
  destination, including a correct MOPS Option A conversion on the error
  path. Leave the normal optimized memcpy implementation unchanged.
- Guard the KASAN memcpy_mc wrapper with CONFIG_ARCH_HAS_COPY_MC to avoid an
  undefined __memcpy_mc reference when COPY_MC is disabled.
- Add the copy_page/copy_mc_page and memcpy_mc/memcpy_mc_large KUnit cases
  with their architecture guards.

Validation
==========

- Relevant GHES, fault/extable, uaccess, copy-page, normal memcpy and MC
  objects build with W=1 in the default ARM64 configuration.
- Complete ARM64 Image build with Buildroot GCC 13.3.0 and binutils
  2.43.1: 43,010,560 bytes, SHA-256
  cfad340658f5e55a65b446ab76ff3c24505bcdad3aaac72227a8bd8fa77a39cd.
- A synthetic toolchain without MOPS assembler support builds the relevant
  fault/extable, uaccess, copy-page and MC objects with W=1. This tests the
  non-MOPS build path; it is not a claim about a particular old compiler.
- The final tree links vmlinux successfully with CONFIG_ARCH_HAS_COPY_MC=n
  and CONFIG_KASAN_GENERIC=y, without the earlier undefined __memcpy_mc
  reference. A matching KASAN=y/KASAN_GENERIC=y configuration also builds
  mm/kasan/shadow.o with W=1; this is a compile check, not KASAN runtime
  validation.
- Disassembly of memcpy_mc confirms that normal stores advance the current
  destination and the exception exit returns end - current_dst. MOPS
  main/epilogue faults perform the Option A conversion first. The normal
  memcpy source is byte-identical to the v7.4-rc5 base.
- The target-tree highpage caller audit covers MM COW/large folio, KSM,
  khugepaged and the arm64 internal caller; all use nonzero-error handling.
- Independent review of the residual state machine found that the original
  direction-selecting CPY operations could choose backward even without
  overlap. The final forward-only CPYFP/CPYFM/CPYFE revision was separately
  reviewed with no remaining High/Medium code issue.
- Independent review of the final SEA/uaccess changes found no
  High/Medium/Low code issue in the SET gate, direction matrix,
  source-only KACCESS handling or MOPS no-retry paths.
- Built-in KUnit on QEMU virt/Cortex-A57 ran ten cases with
  "pass:10 fail:0 skip:0 total:10", including copy_mc_page_test,
  memcpy_mc_test and the non-skipped slow memcpy_mc_large_test. The kernel
  mounted the Buildroot rootfs and reached login. QEMU was stopped by the
  collection timeout after these results.

NOT_RUN
=======

- Real UCE/SEA/GHES/EINJ injection, poison-page isolation and panic-boundary
  testing, including SET/WnR variants and duplicate error records.
- MOPS and MTE hardware execution, including MOPS prologue/main/epilogue
  fault injection and MTE failure-state validation.
- Partial-progress residual and the remaining negative-fault matrix across
  source alignments, copy-template paths, TTW/S1PTW/instruction/parity errors
  and incorrect uaccess directions. A separate test-only validation branch
  exercised a synthetic scalar zero-progress SEA with residual=8; that test
  code is not part of this submission.
- Runtime MM, uaccess, DAX/PMEM and coredump consumer tests.
- Actual source-PFN queue/refcount behavior, firmware-first queue-versus-final
  offline timing and dev_pagemap handling.
- A complete no-MOPS Image: available assemblers reject unrelated LSUI
  instructions elsewhere in the kernel. Relevant no-MOPS objects were built.

The clean-memory KUnit and static/build results do not establish any of
these fault-path behaviors.

Tool assistance
===============

Qoder, an AI coding assistant, assisted with source and review-history
comparison, rebase/conflict analysis, the SEA/MOPS/residual fixes, build and
disassembly review, and drafting this cover. The submitter is responsible
for reviewing the final content, validating the changes and responding to
review feedback.

Ruidong Tian (5):
  ACPI: APEI: GHES: use exception context to gate SIGBUS on poison
    consumption
  arm64: extable: merge UACCESS_ERR_ZERO and KACCESS_ERR_ZERO into
    ACCESS_ERR_ZERO
  arm64: enable recover from synchronous external abort in kernel
    context
  lib/test: memcpy_kunit: add copy_page() and copy_mc_page() tests
  lib/tests: memcpy_kunit: add memcpy_mc() and memcpy_mc_large() test

Tong Tiangen (4):
  uaccess: add generic fallback version of copy_mc_to_user()
  mm/hwpoison: return -EFAULT when copy fail in
    copy_mc_[user]_highpage()
  arm64: support copy_mc_[user]_highpage()
  arm64: introduce copy_mc_to_kernel() implementation

 arch/arm64/Kconfig                   |   1 +
 arch/arm64/include/asm/asm-extable.h |  21 ++--
 arch/arm64/include/asm/asm-uaccess.h |   4 +
 arch/arm64/include/asm/extable.h     |   1 +
 arch/arm64/include/asm/mte.h         |   9 ++
 arch/arm64/include/asm/page.h        |  12 ++
 arch/arm64/include/asm/string.h      |   9 ++
 arch/arm64/include/asm/uaccess.h     |  17 +++
 arch/arm64/kernel/acpi.c             |   2 +-
 arch/arm64/lib/Makefile              |   2 +
 arch/arm64/lib/copy_from_user.S      |   6 +-
 arch/arm64/lib/copy_mc_page.S        |  43 +++++++
 arch/arm64/lib/copy_page.S           |  67 ++--------
 arch/arm64/lib/copy_page_template.S  |  70 ++++++++++
 arch/arm64/lib/copy_to_user.S        |  16 ++-
 arch/arm64/lib/memcpy_mc.S           |  84 ++++++++++++++
 arch/arm64/lib/mte.S                 |  29 +++++
 arch/arm64/mm/copypage.c             |  85 ++++++++++++++
 arch/arm64/mm/extable.c              |  54 ++++++--
 arch/arm64/mm/fault.c                |  38 ++++--
 arch/powerpc/include/asm/uaccess.h   |   1 +
 arch/x86/include/asm/uaccess.h       |   1 +
 drivers/acpi/apei/ghes.c             |  48 ++++-----
 include/acpi/ghes.h                  |  15 ++-
 include/linux/highmem.h              |  16 ++-
 include/linux/uaccess.h              |   8 ++
 lib/tests/memcpy_kunit.c             | 186 ++++++++++++++++++++++++++-
 mm/kasan/shadow.c                    |  12 ++
 mm/khugepaged.c                      |   4 +-
 29 files changed, 740 insertions(+), 121 deletions(-)
 create mode 100644 arch/arm64/lib/copy_mc_page.S
 create mode 100644 arch/arm64/lib/copy_page_template.S
 create mode 100644 arch/arm64/lib/memcpy_mc.S

base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
-- 
2.47.3


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2026-12-06  1:27 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05  1:24 [PATCH v16 0/9] arm64: add ARCH_HAS_COPY_MC support Jiangtian Feng
2026-12-05  1:24 ` [PATCH v16 1/9] uaccess: add generic fallback version of copy_mc_to_user() Jiangtian Feng
2026-12-06  1:26   ` sashiko-bot
2026-12-05  1:24 ` [PATCH v16 2/9] ACPI: APEI: GHES: use exception context to gate SIGBUS on poison consumption Jiangtian Feng
2026-12-06  1:26   ` sashiko-bot
2026-12-05  1:24 ` [PATCH v16 3/9] arm64: extable: merge UACCESS_ERR_ZERO and KACCESS_ERR_ZERO into ACCESS_ERR_ZERO Jiangtian Feng
2026-12-06  1:26   ` sashiko-bot
2026-12-05  1:24 ` [PATCH v16 4/9] arm64: enable recover from synchronous external abort in kernel context Jiangtian Feng
2026-12-06  1:26   ` sashiko-bot
2026-12-05  1:24 ` [PATCH v16 5/9] mm/hwpoison: return -EFAULT when copy fail in copy_mc_[user]_highpage() Jiangtian Feng
2026-12-05  1:24 ` [PATCH v16 6/9] arm64: support copy_mc_[user]_highpage() Jiangtian Feng
2026-12-06  1:26   ` sashiko-bot
2026-12-05  1:24 ` [PATCH v16 7/9] arm64: introduce copy_mc_to_kernel() implementation Jiangtian Feng
2026-12-06  1:26   ` sashiko-bot
2026-12-05  1:24 ` [PATCH v16 8/9] lib/test: memcpy_kunit: add copy_page() and copy_mc_page() tests Jiangtian Feng
2026-12-06  1:26   ` sashiko-bot
2026-12-05  1:24 ` [PATCH v16 9/9] lib/tests: memcpy_kunit: add memcpy_mc() and memcpy_mc_large() test Jiangtian Feng
2026-12-06  1:26   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox