mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiangtian Feng <jiangtianfeng@linux.alibaba.com>
To: catalin.marinas@arm.com, will@kernel.org,
	akpm@linux-foundation.org, rafael@kernel.org
Cc: mark.rutland@arm.com, james.morse@arm.com, robin.murphy@arm.com,
	nikumbh.adi@gmail.com, tony.luck@intel.com, guohanjun@huawei.com,
	mchehab@kernel.org, lenb@kernel.org, xueshuai@linux.alibaba.com,
	tongtiangen@huawei.com, tianruidong@linux.alibaba.com,
	tongweilin@linux.alibaba.com, baolin.wang@linux.alibaba.com,
	ashok.raj@oss.qualcomm.com, jonathan.cameron@oss.qualcomm.com,
	david@kernel.org, liam@infradead.org, vbabka@kernel.org,
	rppt@kernel.org, mhocko@suse.com, ljs@kernel.org,
	surenb@google.com, shivankg@amd.com, wangkefeng.wang@huawei.com,
	xiangzao@linux.alibaba.com, ying.huang@linux.alibaba.com,
	linmiaohe@huawei.com, nao.horiguchi@gmail.com, ziy@nvidia.com,
	tujinjiang@huawei.com, mgorman@techsingularity.net,
	kaitao.cheng@linux.dev, chengkaitao@kylinos.cn,
	muchun.song@linux.dev, nico.pache@linux.dev,
	ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org,
	lance.yang@linux.dev, usama.arif@linux.dev, kas@kernel.org,
	kees@kernel.org, andreyknvl@gmail.com, dvyukov@google.com,
	glider@google.com, ryabinin.a.a@gmail.com,
	vincenzo.frascino@arm.com, tglx@kernel.org, mingo@redhat.com,
	bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com,
	maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com,
	chleroy@kernel.org, ritesh.list@gmail.com, sshegde@linux.ibm.com,
	aneesh.kumar@kernel.org, naveen.n.rao@linux.ibm.com,
	linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org,
	linux-mm@kvack.org, linux-hardening@vger.kernel.org,
	kasan-dev@googlegroups.com, linuxppc-dev@lists.ozlabs.org,
	x86@kernel.org, linux-kernel@vger.kernel.org,
	Jiangtian Feng <jiangtianfeng@linux.alibaba.com>
Subject: [PATCH v16 0/9] arm64: add ARCH_HAS_COPY_MC support
Date: Sat,  5 Dec 2026 09:24:25 +0800	[thread overview]
Message-ID: <20261205012435.1406255-1-jiangtianfeng@linux.alibaba.com> (raw)

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

             reply	other threads:[~2026-12-05  1:25 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  1:24 Jiangtian Feng [this message]
2026-12-05  1:24 ` [PATCH v16 1/9] uaccess: add generic fallback version of copy_mc_to_user() Jiangtian Feng
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-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-05  1:24 ` [PATCH v16 4/9] arm64: enable recover from synchronous external abort in kernel context Jiangtian Feng
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-05  1:24 ` [PATCH v16 7/9] arm64: introduce copy_mc_to_kernel() implementation Jiangtian Feng
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-05  1:24 ` [PATCH v16 9/9] lib/tests: memcpy_kunit: add memcpy_mc() and memcpy_mc_large() test Jiangtian Feng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261205012435.1406255-1-jiangtianfeng@linux.alibaba.com \
    --to=jiangtianfeng@linux.alibaba.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@gmail.com \
    --cc=aneesh.kumar@kernel.org \
    --cc=ashok.raj@oss.qualcomm.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=bp@alien8.de \
    --cc=catalin.marinas@arm.com \
    --cc=chengkaitao@kylinos.cn \
    --cc=chleroy@kernel.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=guohanjun@huawei.com \
    --cc=hpa@zytor.com \
    --cc=james.morse@arm.com \
    --cc=jonathan.cameron@oss.qualcomm.com \
    --cc=kaitao.cheng@linux.dev \
    --cc=kas@kernel.org \
    --cc=kasan-dev@googlegroups.com \
    --cc=kees@kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=lenb@kernel.org \
    --cc=liam@infradead.org \
    --cc=linmiaohe@huawei.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=ljs@kernel.org \
    --cc=maddy@linux.ibm.com \
    --cc=mark.rutland@arm.com \
    --cc=mchehab@kernel.org \
    --cc=mgorman@techsingularity.net \
    --cc=mhocko@suse.com \
    --cc=mingo@redhat.com \
    --cc=mpe@ellerman.id.au \
    --cc=muchun.song@linux.dev \
    --cc=nao.horiguchi@gmail.com \
    --cc=naveen.n.rao@linux.ibm.com \
    --cc=nico.pache@linux.dev \
    --cc=nikumbh.adi@gmail.com \
    --cc=npiggin@gmail.com \
    --cc=rafael@kernel.org \
    --cc=ritesh.list@gmail.com \
    --cc=robin.murphy@arm.com \
    --cc=rppt@kernel.org \
    --cc=ryabinin.a.a@gmail.com \
    --cc=ryan.roberts@arm.com \
    --cc=shivankg@amd.com \
    --cc=sshegde@linux.ibm.com \
    --cc=surenb@google.com \
    --cc=tglx@kernel.org \
    --cc=tianruidong@linux.alibaba.com \
    --cc=tongtiangen@huawei.com \
    --cc=tongweilin@linux.alibaba.com \
    --cc=tony.luck@intel.com \
    --cc=tujinjiang@huawei.com \
    --cc=usama.arif@linux.dev \
    --cc=vbabka@kernel.org \
    --cc=vincenzo.frascino@arm.com \
    --cc=wangkefeng.wang@huawei.com \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    --cc=xiangzao@linux.alibaba.com \
    --cc=xueshuai@linux.alibaba.com \
    --cc=ying.huang@linux.alibaba.com \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®