From patchwork Mon Dec 9 02:42:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tong Tiangen X-Patchwork-Id: 13898750 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40FD5E7717F for ; Mon, 9 Dec 2024 02:43:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2EEE66B03A5; Sun, 8 Dec 2024 21:43:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B5466B03A6; Sun, 8 Dec 2024 21:43:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E35E96B03A7; Sun, 8 Dec 2024 21:43:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BC4636B03A5 for ; Sun, 8 Dec 2024 21:43:31 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 77DBA1C77B7 for ; Mon, 9 Dec 2024 02:43:31 +0000 (UTC) X-FDA: 82873873824.06.B07DEC4 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf18.hostedemail.com (Postfix) with ESMTP id DD0591C0004 for ; Mon, 9 Dec 2024 02:43:19 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf18.hostedemail.com: domain of tongtiangen@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=tongtiangen@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733712190; a=rsa-sha256; cv=none; b=7eyoONlqcXXQ6hmH8fsRrV2399e02wOw5uprUZ4QUITHNYit4ClYJ3beh2y3nN7yiE8d5a qvtbSzxxMpZIlH4wUicSByqlzi+N6nfbL9HHFeJYpp6MgPEvnXnBBAsfxLdSz8b19AOoG7 sLFo7+2MTbhQqOMQR79d4h9sgtQB0hQ= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf18.hostedemail.com: domain of tongtiangen@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=tongtiangen@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733712190; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LlnRR/ekzvfKFU0JIU5g10P2k1CrW7ToDOkJBkyI4mw=; b=LpCEclZL9+vnfGoQ1yUnjMigaJsgKkU+vHQ6slb6RFLM9pd2ZAQZeybv5mFclBvdutvBjw ceoZxGQwvOvrd9KpoeD6TPdsfeMoGv9kTCmQmNXoBBHYQNKsMVVX1X1C7DaORUGpm1czYG Cu3owyk4SgbRJxf+oKAEwoE4irfL6jA= Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Y65jL32dzzRj4G; Mon, 9 Dec 2024 10:41:42 +0800 (CST) Received: from kwepemk500005.china.huawei.com (unknown [7.202.194.90]) by mail.maildlp.com (Postfix) with ESMTPS id F0128180102; Mon, 9 Dec 2024 10:43:24 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by kwepemk500005.china.huawei.com (7.202.194.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 9 Dec 2024 10:43:22 +0800 From: Tong Tiangen To: Mark Rutland , Jonathan Cameron , Mauro Carvalho Chehab , Catalin Marinas , Will Deacon , Andrew Morton , James Morse , Robin Murphy , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Michael Ellerman , Nicholas Piggin , Andrey Ryabinin , Alexander Potapenko , Christophe Leroy , Aneesh Kumar K.V , "Naveen N. Rao" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , , "H. Peter Anvin" , Madhavan Srinivasan CC: , , , , , Tong Tiangen , , Guohanjun Subject: [PATCH v13 3/5] mm/hwpoison: return -EFAULT when copy fail in copy_mc_[user]_highpage() Date: Mon, 9 Dec 2024 10:42:55 +0800 Message-ID: <20241209024257.3618492-4-tongtiangen@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241209024257.3618492-1-tongtiangen@huawei.com> References: <20241209024257.3618492-1-tongtiangen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemk500005.china.huawei.com (7.202.194.90) X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: DD0591C0004 X-Stat-Signature: rkb8pn1iqx4tzcbnexardx1twzjxaxm3 X-Rspam-User: X-HE-Tag: 1733712199-475187 X-HE-Meta: U2FsdGVkX1/ML1m/Clvqv+bHTTGyIjJnASdi9DMt5BP5vgc31oux3d4Xn59ooV5KUQwwOgJvVOgLIdBNKSxwcqc3JNAAuHTCCUFdU709iR0UE3fS+78/BsQwzd57oQvvaQG++Br2wFM8yWibcEe5TB73Bp4lm76mKpSdGgCm2jqesXt9X4/a12vVMDZfLUVUNJPVhPlYjdd+9B8GvakXuot8C2nULlli0zenhrUJdjhnigzu6REFr+X6tWrwdZr9Azq9OJnD96I8FPcpOm/hwthGUi9JIhGJnc5n8iBZ36J50njz9Xzp5YZJFzTrvwKRpKg5L8aeNxg+msTjX7i1VTwgphm4A6hOjNY4TO/lcXPpL4imZA/yZ2mS3TEOVMN9aHiEtFzDl04wVlzzd5skmc25VDfIX9s5Rm4LYj7OmyetrIXHN/7eqPSVIlJ1ALnmi5KfHl6Vi5ACQxGAzmRCR+Wni/wdXQPEJL6fiAF7zCABB0xPiJNUsN+ASROT8nrmqb4JpqI3ckK1E8SmJvXm+ULqRa+BbtCNsX7vB61i6WsEVo3P1O/2AybG0DMF8mYvem+OadjUGxhnyhfrX0NG8SpjeO2wyGYlE+5Ief+3rtlGpU6uHasPnuX5HimvAskhoCC/dwVqDJPRg9V7QwD4QzueD00f4Uw+BkNLwwaSym0/D6G07qTUMSfKdv/hqPDOlBrg9laYCAWeTRQ/DxSOpohEr/GIteF6z44hkYfY23xCxesVWEcDokrTguBYgkurjKRSAfV82Je/rowoQgV9Dc+AmrkD8AQ1loKKNS6/30w7V/fOdiqnSr689jfEQYYehvv2XW0dVRSDIiO9tDlfm7LLfduQcd4RpdxEK+2xxzWQNkwJHeLjCQK2OXClIo3Ss57E1/+hi0kNxLCNwPSH6G3IS0LXDRnd6W3whwGyYotQ6Jon0TZ0EIkuch9AXacEI/3bkdG3gkE7/FMsFfV r+cVp6Zk raFeE6VESWx3RALLANKa2vb7+1sI4FL6V0FYynPqsWnUb5dO8UFDtPxITEFemEH9tmItULZd74ZgcC/bKmlPWWCAaY+3TGTEhMY3Sp8V4F3Nja7rbpCWwUWZYrtvxLsaWZllH5ykVG+0/9/8I5iQTz4RJYRwyGa3VYBeYka/r5z/ETWqxKDAU5AhZ9T8BdWwmXimXLMo8CC/i8/fNwmoHvlwoxJGDYxkbL2/aVFY7ITmlDCEH3cC2sLU3nLSHSAJcZr9h1UvtjfIHjjR2+TjhcLRqH9URZxsydtqbg9W2aPDERVU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 --- 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 6e452bd8e7e3..0eb4b9b06837 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -329,8 +329,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) @@ -349,7 +349,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) @@ -368,7 +368,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 6f8d46d107b4..c3cdc0155dcd 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -820,7 +820,7 @@ static int __collapse_huge_page_copy(pte_t *pte, struct folio *folio, 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; } @@ -2081,7 +2081,7 @@ static int 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; }