From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.30.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796433904; b=5PHa2orfNkFukHM0U0Xfi+M47XbY5UX7gAGOPHtdeh2FIVw7bg77G/byJjSJi2qI03rb PQO6xeWHGaJjEZdnxWdrUdWa5c5+fSJKxPWAWaZWbasrGioPmyNAF4G1u8wWo2r5stQmN NsEPOrBz7+vO6zlFJI+vZYKQQ3RlnVG4a4Upu0gkCWN2T7tXiQjsQZO+SH4/AI/vajqrB dMF1G/AbYEoz4MArT8luX2dUqj1RLBOlXeL/5wFBjJf1C5URSoDo/8NMmPUhtCgV7Oq42 aT7Wa2UAyfmgMLYD+jXoFwswMfTLgCIfSDRhaZ4T7supJktWNCIZ72SDONdR3pZUBYQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796433904; h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:From:To:Cc: Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=nGl0foJMYEA3fSKFoG4zr5PLx2WnfYAuhkHP87TWBl0=; b=Cj9rk/n9a6b/BGE2mgWNzePmBb5tk7lyarPGeMXEZababD4Gci61CYyOfvnGLfjTDv8z cId0zoiA6tkI72T+m54ZAmEq5kTNZm7CA/YTTIJzAMlJzREjvUlzJYvvisCYbh4XoSiWb Rffa3okkrDRMP1QWBZh1ZaezLFYQknmfj/4u5XUHJ8vTEHWPCjqmlyIcPVl/qJkyHCqqu cgeCJfCRsBT2TiTYQAoVunbxwDIV5XcHvfUuoYw35OFAaOWQZ5C9U062j48A2yeSJOCNk PV4iJOFepWYZDoG6DDKiFlPyjUrv4Z4Yq25T6Gcy7XXK9Pj8Epo7dhKpJSNFxVMdZDw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=iRyVqOez; arc=none smtp.remote-ip=115.124.30.131 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD41D606A32D; Sat, 5 Dec 2026 01:25:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CD41D606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=iRyVqOez DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1796433895; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=nGl0foJMYEA3fSKFoG4zr5PLx2WnfYAuhkHP87TWBl0=; b=iRyVqOez5HhWUtwkyRgOMXZud5D+cBej//ZyShGNop/0lp2TRZzJQ9jaPuc5B6F5G6D2XkOerneMKdjrDKQ8elAQOMknLM8BImtYbsnzznKHBwMg9GSJTIJegyOkHkwLwaqiVeihLOFJm76jCYXbW2uLfE90YfUVVXfWa9Vlmxs= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R691e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033065142238;MF=jiangtianfeng@linux.alibaba.com;NM=1;PH=DS;RN=73;SR=0;TI=SMTPD_---0XGISExb_1796433877; Received: from h68d07384.sqa.eu95.tbsite.net(mailfrom:jiangtianfeng@linux.alibaba.com fp:SMTPD_---0XGISExb_1796433877 cluster:ay36) by smtp.aliyun-inc.com; Sat, 05 Dec 2026 09:24:51 +0800 From: Jiangtian Feng 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 Subject: [PATCH v16 0/9] arm64: add ARCH_HAS_COPY_MC support Date: Sat, 5 Dec 2026 09:24:25 +0800 Message-ID: <20261205012435.1406255-1-jiangtianfeng@linux.alibaba.com> X-Mailer: git-send-email 2.47.3 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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