From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 96CDB606A31F for ; Sun, 6 Dec 2026 01:26:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FKTR40f7 Received: by kanga.kvack.org (Postfix) id CDE0A6B05B6; Sat, 5 Dec 2026 20:26:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C8E1D6B05B7; Sat, 5 Dec 2026 20:26:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B562A6B05B8; Sat, 5 Dec 2026 20:26:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2D61C6B05B6 for ; Sat, 5 Dec 2026 20:26:31 -0500 (EST) Received: from smtpin15.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8B6D01C4116 for ; Sun, 6 Dec 2026 01:26:30 +0000 (UTC) X-FDA: 85511818140.15.150ADB0 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf01.hostedemail.com (Postfix) with ESMTP id EB62540007 for ; Sun, 6 Dec 2026 01:26:28 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=fail ("headers rsa verify failed") header.d=kernel.org header.s=k20260515 header.b=FKTR40f7; spf=pass (imf01.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796520389; b=HJ203zlNhepX07eg2hX2UGwIb8HAe83CWmxtd1driguIaIIJjyHQl/dg+N+DXIqZfgTcN6 pMPdajTurdLyXJ5yxB1hOA0Lu0vk+OBARQoCbaA+7Hg1zN3TvT+l1CCEwxQ6vuqN31mCc9 1WuJE6B92zN8v9Y+ayaozvJ7c0OOZ7Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796520389; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Yo/AAq08qtUICyIidrJZsuSACALwL36hFOFSIgwlDKY=; b=KCGCL0lCHkc1fuJNyBlJqJjXIc/I7gv6Maabwduo8+ILqRGzHdgGrplAvxFaul9bqvA1Xe 1+wWwJ8EZGoBh67LP9woBj94sVosdXB5BqTByoMBYme7f3gLBg/kSGka0y74v0vBIKEATS 8xPyNterHswL2lA8Gi04tt/Bwf60MgI= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=fail ("headers rsa verify failed") header.d=kernel.org header.s=k20260515 header.b=FKTR40f7; spf=pass (imf01.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 89BF5602A8; Sun, 6 Dec 2026 01:26:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 081C01F0092B; Sun, 6 Dec 2026 01:26:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796520388; bh=Yo/AAq08qtUICyIidrJZsuSACALwL36hFOFSIgwlDKY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=FKTR40f7O7vznMaOPqJ85r0rimpNrCCzIZ/5P/AdE1O8wiGjUYl0dCguBjPNftk69 Xm1FCsP7QIvz6GjWl9wfNxZYMS+87vxsy4FhPXZPJeM2dhPWs46b9tWORLoc3ZrE5C 5veS43zKUj7gIh/JYL8cP3VRGILPHCIZzKyhQUcIQwh725jKkfyZzMM6nIVN6tFbV5 E+Pi+VkNV9tXLQIxqglLkQBBhonqJxy0oFWUWxv/qAnmrFbj3OE/EM3ip0SCBafNzg /CdRCAEgQzDIccB52na0kTsw0DRV1ouWm1CZSUT8j3mAWmOyCHp2jABOaxWcWhbFzO RHw28tSip3nlA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v16 6/9] arm64: support copy_mc_[user]_highpage() Reply-To: sashiko-reviews@lists.linux.dev To: "Jiangtian Feng" , 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, gli@kvack.org, der@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-mm@kvack.org, kasan-dev@googlegroups.com, x86@kernel.org In-Reply-To: <20261205012435.1406255-7-jiangtianfeng@linux.alibaba.com> References: <20261205012435.1406255-1-jiangtianfeng@linux.alibaba.com> <20261205012435.1406255-7-jiangtianfeng@linux.alibaba.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 01:26:25 +0000 X-Stat-Signature: gqdrj6gyhp78iyggs4oaf4e7ioynd6ro X-Rspam-User: X-Spam-Status: No, score=-8.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Rspamd-Queue-Id: EB62540007 X-Rspamd-Server: rspam01 X-HE-Tag: 1796520388-943037 X-HE-Meta: U2FsdGVkX19pGb6OMougM8UwHE+c0WN/TXORkOhAOyWqqajMnt8aT3UwhkpFhN5iCyFHWiVSezfYk0q6dE6lcWkaRo7UFIxMVBIGB+XSx5mfS4dPSF08ZC/p6rdAmZBtlJesY8hOHe4vbgwjznhkdwjIVYoI/StIo9qWqRBiLuJ2W+dsKtXoWTOoeQmsIl2jb/gzlUEYC+X2JhLEwvevn/F7IPfp/wxRGG/dfFFfHsoifI3S7cdDyqS1QzJzSqx1tR3qTpXzIcMNjZycoqeu97svaN6GTpDjWOzGi1ccvGKkCpKF2d6hgzVsB92lFVa5F2UNjfEhsm5bxA5K1R5vmQusTFgUt5MWSvoYo5FJYw3cP2us9gyIjxe6FoVPee5duDrfSBOeBYy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GGycR9dvsDQIDM6d3AvY6N3Lgb+uvjboX8LV1B7UKbbUk6EWTO+ZyCC2h+uKrGdU83H5TxTIBLcS4ULfUA0qYnv7FoycOSWbdoNvpZVy/ATkXLuptbFM8002LBKWMeBcyq84Mn7qRggxEh+hDcnaLgP3xPKoPQ4DKjoXZlEx8/AhDXPIHReOVUzYEHHo2gx6pxRU5aJodO4A3ORjYoZ6g/hbfTQR52D0Dc4VaFHKOUmokLcpEYzSB8VbDHKdL5VeHkFtdo2AbK2c9we5q/BXmSzieEcEu7ysVvGXD8JuYu2v/dkm3D3iz7m1ehaZ2yf6eIaFmWZNAqlfmHSKeckPifqBRZxM9lR4GsXVmsGy52ZueHZjO8FwSeXi7XTcieZ77zu6v7tM0FCNmsKfsU3Qmwt9CoWL4bOVnmAV+MjsNMs143jVlhOPyS+gVJ2VFat1DAidEy3uEIYx6z1xUTMOaRkyXg== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [High] arm64: missing copy_mc_to_user() causes usercopy_abort() BUG() on FS-DAX - [Medium] arm64: missing copy_mc_to_user() defeats DAX HARDENED_USERCOPY bypass - [Medium] arm64: missing KASAN tag reset for hugetlb tail pages in copy_mc_highpage() - [Low] arm64: unconfirmed ESR_ELx.WnR semantics for SEA on MOPS cpy and MTE ldgm - [Low] arm64: copy_mc_highpage() duplicates KASAN and MTE logic of copy_highpage() - [Low] arm64: unnecessary __pi_copy_mc_page symbol alias in copy_mc_page.S -- commit 94594e11edb86f9c462d47449731063afc1c8dca Author: Tong Tiangen arm64: support copy_mc_[user]_highpage() This commit adds machine-check safe page copying helpers copy_mc_page(), copy_mc_highpage(), and copy_mc_user_highpage() on arm64, along with MTE tag copying in mte_copy_mc_page_tags(), and selects ARCH_HAS_COPY_MC when ACPI_APEI_SEA is enabled. > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig > index 9b08b2457a555..0c017bdc77594 100644 > --- a/arch/arm64/Kconfig > +++ b/arch/arm64/Kconfig > @@ -21,6 +21,7 @@ config ARM64 > select ARCH_HAS_CACHE_LINE_SIZE > select ARCH_HAS_CC_PLATFORM > select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION > + select ARCH_HAS_COPY_MC if ACPI_APEI_SEA > select ARCH_HAS_CURRENT_STACK_POINTER > select ARCH_HAS_DEBUG_VIRTUAL > select ARCH_HAS_DEBUG_VM_PGTABLE [Severity: High] Can selecting ARCH_HAS_COPY_MC without defining an arm64 copy_mc_to_user() trigger usercopy_abort() BUG() on FS-DAX reads? With CONFIG_ARCH_HAS_COPY_MC enabled, _copy_mc_to_iter() switches from _copy_to_iter() (which calls raw_copy_to_user()) to copy_to_user_iter_mc(). Without an arm64 copy_mc_to_user(), that calls the generic fallback copy_mc_to_user() -> copy_to_user() -> __check_object_size() -> check_heap_object(). When a user mmap()s an FS-DAX file with a PMD fault, dax_folio_init() creates a PageCompound() folio of PMD_SIZE. A subsequent read() spanning past that folio boundary on a linear-mapped pmem range tracked in memblock.memory (where arch_add_memory() cleared MEMBLOCK_NOMAP so virt_addr_valid() is true) passes the full extent length to dax_copy_to_iter(), tripping usercopy_abort() -> BUG() under CONFIG_HARDENED_USERCOPY while holding inode->i_rwsem and dax_read_lock(). [Severity: Medium] Does falling back to generic copy_mc_to_user() also defeat the HARDENED_USERCOPY bypass on the DAX read hot path? dax_copy_to_iter() uses _copy_mc_to_iter() on DAXDEV_NOMC devices, and copy_to_user_iter_mc() already performs access_ok() and instrument_copy_to_user(). Routing through the generic copy_mc_to_user() -> copy_to_user() adds __check_object_size() (with a memblock_is_map_memory= () lookup) and repeats might_fault(), access_ok(), and instrument_copy_to_user= () on every read segment. Since __arch_copy_to_user() already carries KERNEL_SEA() fixups, defining an arm64 copy_mc_to_user() around raw_copy_to_user() would preserve SEA recove= ry without the extra overhead or the usercopy_abort() BUG() above. [ ... ] > diff --git a/arch/arm64/lib/copy_mc_page.S b/arch/arm64/lib/copy_mc_page.S > new file mode 100644 > index 0000000000000..542a083e2fd88 > --- /dev/null > +++ b/arch/arm64/lib/copy_mc_page.S [ ... ] > + .macro cpy1 dst, src, count > + .arch_extension mops > + KERNEL_SEA(9998f, cpypwn [\dst]!, [\src]!, \count!) > + KERNEL_SEA(9998f, cpymwn [\dst]!, [\src]!, \count!) > + KERNEL_SEA(9998f, cpyewn [\dst]!, [\src]!, \count!) > + .endm [Severity: Low] This question rests on an arm64 architectural detail that the review could not confirm from the kernel source: when an EL1 synchronous external abort (ESR_ELx_FSC_EXTABT, S1PTW=3D0, SET=3D0) occurs on a destination write of FEAT_MOPS cpypwn/cpymwn/cpyewn, can hardware report ESR_ELx.WnR as 0? Similarly, in mte_copy_mc_page_tags() (arch/arm64/lib/mte.S), can an SEA on ldgm ever report ESR_ELx.WnR as 1? fixup_exception_me() accepts EX_TYPE_KACCESS_SEA solely when ESR_ELx_WNR is 0. If a destination-write SEA on cpy* reported WnR as 0, copy_mc_page() would return -EFAULT, causing copy_mc_highpage() to poison-queue the healthy source page while callers free the corrupted destination page instead of panicking. If an SEA on ldgm reported WnR as 1, fixup_exception_me() would reject the fixup and do_sea() would panic instead of recovering. > + > +SYM_FUNC_START(__pi_copy_mc_page) > +#include "copy_page_template.S" > + > + mov x0, #0 > + ret > + > +9998: mov x0, #-EFAULT > + ret > + > +SYM_FUNC_END(__pi_copy_mc_page) > +SYM_FUNC_ALIAS(copy_mc_page, __pi_copy_mc_page) > +EXPORT_SYMBOL(copy_mc_page) [Severity: Low] Is the __pi_copy_mc_page name and alias needed here? Unlike __pi_copy_page, __pi_copy_mc_page has no PI or KVM nVHE callers, and its EL1 KERNEL_SEA() __ex_table fixups are not usable in early boot or KVM nVHE context. Other extable-using routines in arch/arm64/lib/ (such as copy_from_user.S, copy_to_user.S, and mte.S) define their public symbol directly with SYM_FUNC_START(). [ ... ] > diff --git a/arch/arm64/mm/copypage.c b/arch/arm64/mm/copypage.c > index cd5912ba617b7..611024fca6d45 100644 > --- a/arch/arm64/mm/copypage.c > +++ b/arch/arm64/mm/copypage.c > @@ -72,3 +72,88 @@ void copy_user_highpage(struct page *to, struct page *= from, > flush_dcache_page(to); > } > EXPORT_SYMBOL_GPL(copy_user_highpage); > + > +#ifdef CONFIG_ARCH_HAS_COPY_MC > +/* > + * Return -EFAULT if anything goes wrong while copying page or mte. > + */ > +int copy_mc_highpage(struct page *to, struct page *from) [Severity: Low] This isn't a bug, but copy_mc_highpage() duplicates the KASAN tag reset and hugetlb/base-page MTE tag-copying logic from copy_highpage() directly above it. Factoring the shared body into a static __always_inline helper taking a compile-time constant bool mc would avoid future divergence without adding overhead to copy_highpage(). [ ... ] > + if (kasan_hw_tags_enabled()) > + page_kasan_tag_reset(to); > + > + if (!system_supports_mte()) > + return 0; > + > + if (folio_test_hugetlb(src)) { > + if (!folio_test_hugetlb_mte_tagged(src) || > + from !=3D folio_page(src, 0)) > + return 0; > + > + folio_try_hugetlb_mte_tagging(dst); > + > + /* > + * Populate tags for all subpages. > + * > + * Don't assume the first page is head page since > + * huge page copy may start from any subpage. > + */ > + nr_pages =3D folio_nr_pages(src); > + for (i =3D 0; i < nr_pages; i++) { > + kfrom =3D page_address(folio_page(src, i)); > + kto =3D page_address(folio_page(dst, i)); > + ret =3D mte_copy_mc_page_tags(kto, kfrom); > + if (ret) { > + memory_failure_queue(page_to_pfn(folio_page(src, i)), 0); > + return -EFAULT; > + } > + } > + folio_set_hugetlb_mte_tagged(dst); [Severity: Medium] Can overwriting hardware MTE tags on hugetlb tail pages without resetting their KASAN tags trigger spurious KASAN tag check faults under CONFIG_KASAN_HW_TAGS? copy_mc_highpage() only resets the KASAN tag on subpage 0, while mte_copy_mc_page_tags() overwrites hardware MTE tags across all subpages dst[0..nr_pages-1]. When a hugetlb folio is allocated via GFP_HIGHUSER (for example gigantic pages with default movable_gigantic_pages=3D0, or any hugepage when CONFIG_MIGRATION=3Dn), __GFP_SKIP_KASAN is omitted and every subpage gets a random non-match-all KASAN tag. On the normal path, the next subpage copy accesses dst[1] via page_address() with the stale KASAN tag against the overwritten user MTE tags. On the new SEA error path, returning -EFAULT mid-loop leaves dst[1..i-1] mismatched, and free_huge_folio() -> arch_clear_hugetlb_flags() returns the folio to the hugetlb pool without resetting per-subpage KASAN tags, causing tag check faults on later reuse. Calling page_kasan_tag_reset(folio_page(dst, i)) before mte_copy_mc_page_tags() when kasan_hw_tags_enabled() would prevent this. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205012435.1406= 255-1-jiangtianfeng@linux.alibaba.com?part=3D6