From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.30.110 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796433922; b=VUgD140T1SdFnGBLr9jR436ddbtJ384l/MXwxSzKBq76vj1MQMlacV/CKCeXi0CdXMWx qLvpMoqBvRNAvrUyDSfDmp6/lZ6iK8R01UTb94ylwpGkjJsmGtjBg5WKPbihC1Ojc1hAx BU/J0PkpUU7gO54fMUaWn0poJuzNe21iT3kDSrBSSKlSe6F7qRuS8wISwWA6uwwbt7lXm t1boQLLeung1/PIvyUIDNxuqIXBQ1/DvtepOREAQE41lO3sj1z8E1raL2UoytfMp2h8PI Q36YzGeSU3mIyRn3oSfyRezjAqEEima2imirQ33YNaz8830/8EaUjPB1y34tLdjnlag== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796433922; h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=yksKetz9UJ/JYQ7oC44ZrBlW6uSJOhuicMHvW8xDMLQ=; b=u27HrG4RTjAIRSlEUifSgO5JmGmYJVIzLZSzSqjjTxBcNwwc2w4QOJvwOfF0QJtaWHuH 1V7UdQ2CK3dz2gqhR7odYYbjAPMDoH2vG7NEiEjsk5zSYT9x/DMctlOmzjx7t51UpxFLJ 5r0gYkxllUbQV4Q5agfXBc1lcrLnEQU/7bHFp2mSJiFk03I1GmtepAd7DtDMOhrnz26Ec 4l4bHKx7pKmG3ePyO2YoTU99gKbi7o4umDxlK1SXLXAI6g61ecsTHWBt/h18kePxmrJzv jaM8rO2iRLm0t77n7TvmMMCYo70St1GjNEQxd94uyIH6iRAdtfc95P/a1lPGHD7CjqA== 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=Lp9MlGC4; arc=none smtp.remote-ip=115.124.30.110 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) (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 C53C2606A33D; Sat, 5 Dec 2026 01:25:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C53C2606A33D 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=Lp9MlGC4 DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1796433918; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=yksKetz9UJ/JYQ7oC44ZrBlW6uSJOhuicMHvW8xDMLQ=; b=Lp9MlGC409fBYagZrk+AFLEkqU/6pBA9S09BN8NWFQgvyuskTeoxfAvKONkS2insYSZbk/XcBTSPSfHemIzbbyN4AC5v+7ypZiuZkOhZZLl8vPY5DpMLot/yxDCpsSwz6xhMNN3ppLZJiTX51pevfjH8LbnK9frx+3+v3PGlsWI= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033071064103;MF=jiangtianfeng@linux.alibaba.com;NM=1;PH=DS;RN=75;SR=0;TI=SMTPD_---0XGISF8V_1796433912; Received: from h68d07384.sqa.eu95.tbsite.net(mailfrom:jiangtianfeng@linux.alibaba.com fp:SMTPD_---0XGISF8V_1796433912 cluster:ay36) by smtp.aliyun-inc.com; Sat, 05 Dec 2026 09:25:14 +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, Jonathan Cameron , Mauro Carvalho Chehab , Jiangtian Feng Subject: [PATCH v16 5/9] mm/hwpoison: return -EFAULT when copy fail in copy_mc_[user]_highpage() Date: Sat, 5 Dec 2026 09:24:30 +0800 Message-ID: <20261205012435.1406255-6-jiangtianfeng@linux.alibaba.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261205012435.1406255-1-jiangtianfeng@linux.alibaba.com> References: <20261205012435.1406255-1-jiangtianfeng@linux.alibaba.com> 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 From: Tong Tiangen Currently, copy_mc_[user]_highpage() returns zero on success, or in case of failures, the number of bytes that weren't copied. While tracking the number of not copied works fine for x86 and PPC, There are some difficulties in doing the same thing on ARM64 because there is no available caller-saved register in copy_page()(lib/copy_page.S) to save "bytes not copied", and the following copy_mc_page() will also encounter the same problem. Consider the caller of copy_mc_[user]_highpage() cannot do any processing on the remaining data(The page has hardware errors), they only check if copy was succeeded or not, make the interface more generic by using an error code when copy fails (-EFAULT) or return zero on success. Signed-off-by: Tong Tiangen Reviewed-by: Jonathan Cameron Reviewed-by: Mauro Carvalho Chehab Reviewed-by: Shuai Xue Reviewed-by: Ashok Raj Signed-off-by: Jiangtian Feng --- include/linux/highmem.h | 8 ++++---- mm/khugepaged.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/highmem.h b/include/linux/highmem.h index d7aac9de1c8a..685c62c10408 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -428,8 +428,8 @@ static inline void copy_highpage(struct page *to, struct page *from) /* * If architecture supports machine check exception handling, define the * #MC versions of copy_user_highpage and copy_highpage. They copy a memory - * page with #MC in source page (@from) handled, and return the number - * of bytes not copied if there was a #MC, otherwise 0 for success. + * page with #MC in source page (@from) handled, and return -EFAULT if there + * was a #MC, otherwise 0 for success. */ static inline int copy_mc_user_highpage(struct page *to, struct page *from, unsigned long vaddr, struct vm_area_struct *vma) @@ -448,7 +448,7 @@ static inline int copy_mc_user_highpage(struct page *to, struct page *from, if (ret) memory_failure_queue(page_to_pfn(from), 0); - return ret; + return ret ? -EFAULT : 0; } static inline int copy_mc_highpage(struct page *to, struct page *from) @@ -467,7 +467,7 @@ static inline int copy_mc_highpage(struct page *to, struct page *from) if (ret) memory_failure_queue(page_to_pfn(from), 0); - return ret; + return ret ? -EFAULT : 0; } #else static inline int copy_mc_user_highpage(struct page *to, struct page *from, diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 964f78c3856b..4ceb440e242c 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -874,7 +874,7 @@ static enum scan_result __collapse_huge_page_copy(pte_t *pte, struct folio *foli continue; } src_page = pte_page(pteval); - if (copy_mc_user_highpage(page, src_page, src_addr, vma) > 0) { + if (copy_mc_user_highpage(page, src_page, src_addr, vma)) { result = SCAN_COPY_MC; break; } @@ -2515,7 +2515,7 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr, } for (i = 0; i < nr_pages; i++) { - if (copy_mc_highpage(dst, folio_page(folio, i)) > 0) { + if (copy_mc_highpage(dst, folio_page(folio, i))) { result = SCAN_COPY_MC; goto rollback; } -- 2.47.3