From patchwork Wed Jun 26 08:53:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13712427 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 5D0D9C27C4F for ; Wed, 26 Jun 2024 08:54:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 40E726B008A; Wed, 26 Jun 2024 04:54:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 398436B008C; Wed, 26 Jun 2024 04:54:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 237DC6B0092; Wed, 26 Jun 2024 04:54:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 065596B008A for ; Wed, 26 Jun 2024 04:54:44 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 936ED160BFD for ; Wed, 26 Jun 2024 08:54:43 +0000 (UTC) X-FDA: 82272429246.01.A133D13 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf15.hostedemail.com (Postfix) with ESMTP id 72287A001C; Wed, 26 Jun 2024 08:54:40 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719392066; 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=D55No0sOA7xeG1UPfcnEqQYDbF60ezPO2crDG8379Dk=; b=hDY4tH51To8PnSyAsEhV2BUTHlMPLM+Wq2bG9dk0lZg9/SgQdMqOXi6kHeY2GWxneZbHsi iMkQXwwSeIiGdCL+/cdxPh9jGVMNFX8QRH8zB4ZKrSqU3CCeQ55bIf/R1KDH+GSU8URY35 C5hB5aX7CheiRRyhCi5fgOkSdMk5Dwg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719392066; a=rsa-sha256; cv=none; b=Y8q+kpQmLqJceGmPHYcSiY6YEWahczcPJq6Dql+k2Abui3wtBBmk0tHU29hQ8VM8ddngz5 /2E5NvcIuoFz0Q6ZHMzMypg+dPBPBBnM70E1U0kmUsCSxaJgCnGoyNnWIGTj8gtE8qxyD9 O2S4t327F6Lho2IAkYqPLXH7iBN3s4Q= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4W8Fnj5tCyz1HDZP; Wed, 26 Jun 2024 16:52:25 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 26FB214037E; Wed, 26 Jun 2024 16:54:36 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemf100008.china.huawei.com (7.185.36.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 26 Jun 2024 16:54:35 +0800 From: Kefeng Wang To: , CC: Tony Luck , Miaohe Lin , , Matthew Wilcox , David Hildenbrand , Muchun Song , Benjamin LaHaise , , Jiaqi Yan , Hugh Dickins , Vishal Moola , Alistair Popple , Jane Chu , Oscar Salvador , Lance Yang , Kefeng Wang Subject: [PATCH v5 1/6] mm: move memory_failure_queue() into copy_mc_[user]_highpage() Date: Wed, 26 Jun 2024 16:53:23 +0800 Message-ID: <20240626085328.608006-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240626085328.608006-1-wangkefeng.wang@huawei.com> References: <20240626085328.608006-1-wangkefeng.wang@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 dggpemf100008.china.huawei.com (7.185.36.138) X-Rspamd-Queue-Id: 72287A001C X-Stat-Signature: e71om4ga4u3yctkgxehtx7epduy5xcs9 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1719392080-963881 X-HE-Meta: U2FsdGVkX191LNXiLVgfdE1UYsUUPkQHzOt96tlIWCE0cJ2HDFBPOkm/+1h8BaZ6F35nmYB0PtvRnXsNEbnS3+75EPFjGXgHsMhxVOr1WAlGWom9YygSJNXbm60FbpruXwOkiCyI2XOXMJ6/6ZvKIuaTpwhI6Du2slknCutPwdRrXLFAH9497FOQbDeG4vWF+E4PSLKBf3F17+2AXcaZCUhA0fhtMRHXWpMSnVqWIzj5nJmBzOnJaaICZLGm8KQ/BqqC9KcIKmBlAE7UThvPqmGBUoKqBtb8DeWEl+UlXwy0HUr8YiIHjEbHjM0y7FXhWKJDwy8qQl2U1oZ3OqPTXHa3WJwtCXSXpHxpCmjDPv7XmcgD9S76Jq4FIv01S+yf4ikk91iYRqfGGBHH9CrEzFkymBFajrV9UGyLmN+6ITIov48ULRDxgwxbkyx8L4Jf089/P+9mMQbg279wYs5uuVrxHLNT0YJLIEQhNfePBH1R3WxEzmvLtGF0xZmDCcTLomysw9LGutQxHCgV6VxFtHZkXboI13N5lGW85PYX0JdxuOVUStDppNdSIbg4fBaUmkJ6hHClav047binzmSqdkJ3XIBT8E+Ui+Q6TVSI92A9OYvHPXgPbqL0LoBmLYd7SkwuHN09Oz9gtxBAuaICBZLFLLHbLu2dtH53Y91/iLUkLcMuGvjue4ATy0IgiIvDgPKeDC45TQmvXMJpXsfbSHtJ6+BuAPp5Pc08OLyHqdN1CfMZuAQuOrbj0z0E+Elh/4NnDRjtP9FlN1S7x5Mik4dFpy2YFEa+IhdzmgoX5N9R+DR3Bt7+ys0mGcdZQdrZV6yWuyom2V5QISlF27D9EVik8lgf4ED46svDZBFU5FuCG4aY4lTwTxo456mG8K8TmJ33ENn/vwOKNSgWM+PJebNpcMCiT2EVsJOUit5mmdSsgck/9VNihSgu2RtfgkffgS9oaRIld2C88fQ1mg3 LmTTtRJq TXZLPwMJWxtYReGxgeWRzovHQBjLeVWYrJGdDCkpz+mMj3NVldx7EPtLBhpiZjHaJGuEb210EQ/OM9omTcNXZB94HwWCuzanX08FDzUZAX0b9sUOtPJH+ljE6AxSM6Xy9XqkhMGIH16bNRxevt5waaq5gwXwzrCXK3ArjubdmXobrcGm90rwGHPbP+yHsN3jEdZLkOOzOhFkjlfVab6E2l8UvCf0/vKLtUiJsScbPQSp0VcbC6NuEFs7dYw5upLr1Hz1XP1AB/XJqNM2gcWRTXLAPHa/aX0fjNA75 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: There is a memory_failure_queue() call after copy_mc_[user]_highpage(), see callers, eg, CoW/KSM page copy, it is used to mark the source page as h/w poisoned and unmap it from other tasks, and the upcomming poison recover from migrate folio will do the similar thing, so let's move the memory_failure_queue() into the copy_mc_[user]_highpage() instead of adding it into each user, this should also enhance the handling of poisoned page in khugepaged. Reviewed-by: Jane Chu Reviewed-by: Miaohe Lin Signed-off-by: Kefeng Wang --- include/linux/highmem.h | 6 ++++++ mm/ksm.c | 1 - mm/memory.c | 12 +++--------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/include/linux/highmem.h b/include/linux/highmem.h index fa6891e06316..930a591b9b61 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -352,6 +352,9 @@ static inline int copy_mc_user_highpage(struct page *to, struct page *from, kunmap_local(vto); kunmap_local(vfrom); + if (ret) + memory_failure_queue(page_to_pfn(from), 0); + return ret; } @@ -368,6 +371,9 @@ static inline int copy_mc_highpage(struct page *to, struct page *from) kunmap_local(vto); kunmap_local(vfrom); + if (ret) + memory_failure_queue(page_to_pfn(from), 0); + return ret; } #else diff --git a/mm/ksm.c b/mm/ksm.c index b9a46365b830..df6bae3a5a2c 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2998,7 +2998,6 @@ struct folio *ksm_might_need_to_copy(struct folio *folio, if (copy_mc_user_highpage(folio_page(new_folio, 0), page, addr, vma)) { folio_put(new_folio); - memory_failure_queue(folio_pfn(folio), 0); return ERR_PTR(-EHWPOISON); } folio_set_dirty(new_folio); diff --git a/mm/memory.c b/mm/memory.c index d4f0e3df68bc..0a769f34bbb2 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3022,10 +3022,8 @@ static inline int __wp_page_copy_user(struct page *dst, struct page *src, unsigned long addr = vmf->address; if (likely(src)) { - if (copy_mc_user_highpage(dst, src, addr, vma)) { - memory_failure_queue(page_to_pfn(src), 0); + if (copy_mc_user_highpage(dst, src, addr, vma)) return -EHWPOISON; - } return 0; } @@ -6492,10 +6490,8 @@ static int copy_user_gigantic_page(struct folio *dst, struct folio *src, cond_resched(); if (copy_mc_user_highpage(dst_page, src_page, - addr + i*PAGE_SIZE, vma)) { - memory_failure_queue(page_to_pfn(src_page), 0); + addr + i*PAGE_SIZE, vma)) return -EHWPOISON; - } } return 0; } @@ -6512,10 +6508,8 @@ static int copy_subpage(unsigned long addr, int idx, void *arg) struct page *dst = folio_page(copy_arg->dst, idx); struct page *src = folio_page(copy_arg->src, idx); - if (copy_mc_user_highpage(dst, src, addr, copy_arg->vma)) { - memory_failure_queue(page_to_pfn(src), 0); + if (copy_mc_user_highpage(dst, src, addr, copy_arg->vma)) return -EHWPOISON; - } return 0; } From patchwork Wed Jun 26 08:53:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13712426 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 3E368C30659 for ; Wed, 26 Jun 2024 08:54:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D10106B0089; Wed, 26 Jun 2024 04:54:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CC02F6B008A; Wed, 26 Jun 2024 04:54:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B86D46B008C; Wed, 26 Jun 2024 04:54:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 805856B008A for ; Wed, 26 Jun 2024 04:54:43 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3E99C160A4B for ; Wed, 26 Jun 2024 08:54:43 +0000 (UTC) X-FDA: 82272429246.21.F869781 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf25.hostedemail.com (Postfix) with ESMTP id 90E9CA001C; Wed, 26 Jun 2024 08:54:40 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719392063; 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=MWVDevXksDIwh0FjeHi66IxAYHx+RIoPPrdEHW5AufM=; b=TMmqvHDzqqfqZhYQG3m8NKcBtWBitH0sv4sWgjjempb8v+jJWyZkijp8z2XtRSEPSQOhfg URZgx0+VGcyc7Zn0opzpMxEgYVofOGW73Hml7KZN7Fsqkljazql9gIE21TZwaTmZNw3NBa qRegHmNeRPJE64xH2k4+tXNmX5emKc0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719392063; a=rsa-sha256; cv=none; b=5ohyFlUmKhMWOREfyk09huSBjZtl1jbWGGceqlANW2MLNTyk9/bmjsH8A+B1d66B1u5pze OEiSK7WxWfw43Uj15Apruc3TNAg0tObtUK4u+e/hqmAnpPM8c1Dg7Dx9K7bfCvjWPE3+zE XCoSX4FreqUJ5Z/NOvPoaQqA3Cxa86M= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4W8FpR0GbvzddvZ; Wed, 26 Jun 2024 16:53:03 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id DF18E1402D0; Wed, 26 Jun 2024 16:54:36 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemf100008.china.huawei.com (7.185.36.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 26 Jun 2024 16:54:36 +0800 From: Kefeng Wang To: , CC: Tony Luck , Miaohe Lin , , Matthew Wilcox , David Hildenbrand , Muchun Song , Benjamin LaHaise , , Jiaqi Yan , Hugh Dickins , Vishal Moola , Alistair Popple , Jane Chu , Oscar Salvador , Lance Yang , Kefeng Wang Subject: [PATCH v5 2/6] mm: add folio_mc_copy() Date: Wed, 26 Jun 2024 16:53:24 +0800 Message-ID: <20240626085328.608006-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240626085328.608006-1-wangkefeng.wang@huawei.com> References: <20240626085328.608006-1-wangkefeng.wang@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 dggpemf100008.china.huawei.com (7.185.36.138) X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 90E9CA001C X-Stat-Signature: zbc4xgw4w31x1epuhzrt7swawx8obeie X-Rspam-User: X-HE-Tag: 1719392080-264884 X-HE-Meta: U2FsdGVkX193zDLaoHWmxlqflEadULVX+dPr7effLT5pkaV5nzMcDkGvho0mu9AekKkoB7KCH5Rv/TTNUfkS6y0L7uEAYj+14O3h/5Q7YK+4hsq9ThnkrDsGsLBatBOVuoYCfJrCKSLBu4yM06Q92e0dcEaWdYt3tfRbPd9Y11ZLc8tZd+WQH9Y8/LzzPhTN5iddtAszItQ/Pk4/CNNV7NbNQD92PsED6vHnVsyWc2E2IYJrI6IVyvL657JX8vn18T/aUxKbSCtH7+dRNbkBwtg8IaMvBtMYvpMWXYM+hvsDphgA5YlMjRyWI42Rml7fzHggcrXmKNh10wofPX8qBE3u0P3ZAhWGqYttkpMKiEKI3SGRH32MMm8K5VqFx5k+qZJjBC05Kgp51+TqeK5OUDRQKBabH35Oi03vfCNVw9EjE38o11MPhl/NgIpHSYhOrcsbunfCj52JN1iVJG1cPICZtdvD493oosyU4P+hTvPBw5eEoiMIFPjxRjU0d/Ddf4sCC12hg7LP3HdLqcu7Lc3iCOjj+mJaOUylA9HEvEnojslJ2cw156hP0X7hqt+hkTST+OQUQKzY1GbJu/URICECwU3AcN73hQT80wSovCjSvidhqDlM+R/09aPYF4MxCZyYtFx9HEEG6NtnRgpoi3vf8Fbk9pgRbBKFJp+DM4CzREqtv4hDztvcOyvkXGambk/qbJQ3kSlegVdkbH/A9FzihcJ1fvWUSRkOJbnkNj6RIaD026saSIf9JQ6kSzU3OfLs4whq6M1wv6RRX3l2hVA8kzFC7OBkjTkm/h5x4TXu01WXDube0qCW6cV7ABVGNJL4Ox9T2N+1mGnixnY840EK6SVZOxU863XIXUOKLvkvzF5OB+ouoRgHhuf1CbebtJQYyvNpkPU2APNXDwVA3bJp4cQk4UuLl9g0cywHVDNmfyvUwaGSkK3uB1EtTACe0WnkFQcZG+8OjxQR3D7 /2RmyDPz n2qp4ktBCQlCihpCC//CWxxm71XZj56gOL7U8R5yLBOKdG4aNc1oFt3pnVWtt9FkjNOciclTQNtd7ag7AGx94L6YdNUwSrGgcdNQCMNOxVfvtjiXfxwi1SDARi3UGaEBiVYmRF/WlBb44gxPMu95YlbUjgg/VW70Zzq7eykdnCY2jAEYbEausaBFtmVebLqMuRL3aOdnsGPXkpCYFBE/Lh4IpUh+ctZg6w7537mvj4E5ainQaxWcI1dM1oibi374Ku/PrnLihHH0Lh+Qmp8U8dSM8oS16/T3QUc9T 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: Add a #MC variant of folio_copy() which uses copy_mc_highpage() to support #MC handled during folio copy, it will be used in folio migration soon. Reviewed-by: Jane Chu Reviewed-by: Miaohe Lin Signed-off-by: Kefeng Wang --- include/linux/mm.h | 1 + mm/util.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index fc07b5c6fa6b..60f42daf3be8 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1301,6 +1301,7 @@ void put_pages_list(struct list_head *pages); void split_page(struct page *page, unsigned int order); void folio_copy(struct folio *dst, struct folio *src); +int folio_mc_copy(struct folio *dst, struct folio *src); unsigned long nr_free_buffer_pages(void); diff --git a/mm/util.c b/mm/util.c index 1796bf46db17..10f215985fe5 100644 --- a/mm/util.c +++ b/mm/util.c @@ -831,6 +831,23 @@ void folio_copy(struct folio *dst, struct folio *src) } EXPORT_SYMBOL(folio_copy); +int folio_mc_copy(struct folio *dst, struct folio *src) +{ + long nr = folio_nr_pages(src); + long i = 0; + + for (;;) { + if (copy_mc_highpage(folio_page(dst, i), folio_page(src, i))) + return -EHWPOISON; + if (++i == nr) + break; + cond_resched(); + } + + return 0; +} +EXPORT_SYMBOL(folio_mc_copy); + int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; int sysctl_overcommit_ratio __read_mostly = 50; unsigned long sysctl_overcommit_kbytes __read_mostly; From patchwork Wed Jun 26 08:53:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13712428 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 7366DC30659 for ; Wed, 26 Jun 2024 08:54:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 08E7E6B008C; Wed, 26 Jun 2024 04:54:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EE2E66B0093; Wed, 26 Jun 2024 04:54:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE96A6B0092; Wed, 26 Jun 2024 04:54:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A4B3A6B008C for ; Wed, 26 Jun 2024 04:54:44 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5D5181A0C89 for ; Wed, 26 Jun 2024 08:54:44 +0000 (UTC) X-FDA: 82272429288.19.917900E Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf08.hostedemail.com (Postfix) with ESMTP id 5B679160022; Wed, 26 Jun 2024 08:54:40 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719392074; 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=TkSSK5PIGWIBqJEjoJP7tskJQuPJTT6Bph3CaZdqLz8=; b=Y+OJBLeTSz1QUdjfWhtWHVSpWNkRdT47EhL/p13KBLpHFx6G5fBlISmHnZt0tBDHnR1BfX B4KWPAq9PN/Ph8cAh+ajvlRt50fwilYSjewW7SIYz3U26KjOqPxXnYRUFcMMepvoTdE6/i druV1GpFoS8F98T/Mv2vwmw2vRMLLTE= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719392074; a=rsa-sha256; cv=none; b=dBA3UMT41RHZ9CESTPNzxHW9uD2C4Zj98oDvLCaAVcbaZfFJbxa0Ou45RKkbWiknM1lVgY LxGxrWccNNmolaEnm2or9fuzuV6kblz97HCPSWOCvUhbNuLJ9mwWO6z9nnz7zADWNqOL3c Q9CRpZP/WlQQE9FwVLEdcIyLVwgmzu8= Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4W8Fm12WLvzMqtD; Wed, 26 Jun 2024 16:50:57 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id AE9FC18009B; Wed, 26 Jun 2024 16:54:37 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemf100008.china.huawei.com (7.185.36.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 26 Jun 2024 16:54:36 +0800 From: Kefeng Wang To: , CC: Tony Luck , Miaohe Lin , , Matthew Wilcox , David Hildenbrand , Muchun Song , Benjamin LaHaise , , Jiaqi Yan , Hugh Dickins , Vishal Moola , Alistair Popple , Jane Chu , Oscar Salvador , Lance Yang , Kefeng Wang Subject: [PATCH v5 3/6] mm: migrate: split folio_migrate_mapping() Date: Wed, 26 Jun 2024 16:53:25 +0800 Message-ID: <20240626085328.608006-4-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240626085328.608006-1-wangkefeng.wang@huawei.com> References: <20240626085328.608006-1-wangkefeng.wang@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 dggpemf100008.china.huawei.com (7.185.36.138) X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 5B679160022 X-Stat-Signature: 95mcqmgdguoco6pwyz5n3ddetmtwj1sq X-HE-Tag: 1719392080-203933 X-HE-Meta: U2FsdGVkX1/rwQnBI3yO1feOj7Bd0Y4+/1+g7jbzfCeMq2U5UbnuuGFuFGjWwxcuNXKbwpz3xsEELy7t3hb2a7pfBTtQ/GYb91LxMw52+Kthq1+P3D3WE00vnK76tIsX7jCyNaepuCVe/1jKfR8AVXn6E1JGNrRxkHcuuhjiPzlJE2XW5Sl6nTKmPa+KDr6bRo1+/DHN49Cb+Fo7iDuomqvZCfj2UwtOBpjFZGBAvGpdhzofnB9MofnMnXhMOpEH1y0tl0+1gG7UIUuTwndjOg8t9quIPTKy3oJtGDHP99VA4gQOpGAibALkx2W5Xk0d/9Uq2ZVBroTHPYWZLatw0hrELds+TfIHhCa21IhzPTVHhln8rah9ujgL1ZmzDGDqGFs6A9VU7XBsLxlnQFKb/dYX3GcfXr0yPzzXAl8ZKSdi2yWrfxyWEzJDWtkSIoRq44aesf+xAguIbI3D+mG5mqGa2gC5aDerYOTqkZo/KqIbIFcelUnRzVXij8J7Ql0PA+Ri8C5K0iDkfU2rzOn1cIjqXc/4uSmmVlR35WI+u1rqUx5w3BcxdWCjDbzk7Flcx7NZqVxzonCcdIeDPhID4rPKnsXX0CZo6N9wsvAi1P/ZsxX1ZGngTrDE8ob1tAHVweagQSONGxU6iRWztkzoUTuNs3t7x150hP9+mzudXH03iPco8ibgX+K8Hg0qdG7B4UUkVVSBTGYb88E1CJ/NQZ6ZuaZ9l3vv/WgOHCfEx3V9ZRBmSJrfapiWNEJiE082qOJQVE60IrlFHmoqRKoC1E/F5ro1y+eLJhCFJzd0689CQXDw52m7YGuIvUahJxVUCuaQ6iGhPTm1mWZW8EtUE49AmXWh8ilsuxt4YewnC/VuwJJ3jtx10fz7BT8TiAuUdtdPEJCADg3VhfY6+UQaglRCnmPM+OPOaR+BE17VZ/QeIA0jQTFqfd5ZWGP6Dik9DOj9GG1FxftYPpZgMi/ +oSkSHAS BOIjZQdzQJ5hDWNuG9/SsCimbncuUa0nKL1m9oImmI6dRsQWe+3zCtf1Mq89H/+g3VmhiD8MJiCzAkbYs462rSkj4NnYkvLsE+pdmjcIF1riIUynESD0LvncVr5HS9ZpA/5yz9V0ionsdS4OzkCOIEwVplig5LeeMZEIt+gm9AgZkFYj4VsUBoE49qvKgB5cSr6KOUsB5VwkW54OT1qLt7JGglfTbvO14r8A8RAokKmWVhVyAzw6mJ1jOXVuiIEaflfzUpR6xo8sdM98= 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: The folio refcount check is moved out for both !mapping and mapping folio, also update comment from page to folio for folio_migrate_mapping(). No functional change intended. Signed-off-by: Kefeng Wang --- mm/migrate.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index c1ac9edf8e52..e97fbaed564d 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -393,29 +393,24 @@ static int folio_expected_refs(struct address_space *mapping, } /* - * Replace the page in the mapping. + * Replace the folio in the mapping. * * The number of remaining references must be: - * 1 for anonymous pages without a mapping - * 2 for pages with a mapping - * 3 for pages with a mapping and PagePrivate/PagePrivate2 set. + * 1 for anonymous folios without a mapping + * 2 for folios with a mapping + * 3 for folios with a mapping and PagePrivate/PagePrivate2 set. */ -int folio_migrate_mapping(struct address_space *mapping, - struct folio *newfolio, struct folio *folio, int extra_count) +static int __folio_migrate_mapping(struct address_space *mapping, + struct folio *newfolio, struct folio *folio, int expected_count) { XA_STATE(xas, &mapping->i_pages, folio_index(folio)); struct zone *oldzone, *newzone; int dirty; - int expected_count = folio_expected_refs(mapping, folio) + extra_count; long nr = folio_nr_pages(folio); long entries, i; if (!mapping) { - /* Anonymous page without mapping */ - if (folio_ref_count(folio) != expected_count) - return -EAGAIN; - - /* No turning back from here */ + /* Anonymous folio without mapping, no turning back from here */ newfolio->index = folio->index; newfolio->mapping = folio->mapping; if (folio_test_swapbacked(folio)) @@ -452,7 +447,7 @@ int folio_migrate_mapping(struct address_space *mapping, entries = 1; } - /* Move dirty while page refs frozen and newpage not yet exposed */ + /* Move dirty while folio refs frozen and newfolio not yet exposed */ dirty = folio_test_dirty(folio); if (dirty) { folio_clear_dirty(folio); @@ -466,7 +461,7 @@ int folio_migrate_mapping(struct address_space *mapping, } /* - * Drop cache reference from old page by unfreezing + * Drop cache reference from old folio by unfreezing * to one less reference. * We know this isn't the last reference. */ @@ -477,11 +472,11 @@ int folio_migrate_mapping(struct address_space *mapping, /* * If moved to a different zone then also account - * the page for that zone. Other VM counters will be + * the folio for that zone. Other VM counters will be * taken care of when we establish references to the - * new page and drop references to the old page. + * new folio and drop references to the old folio. * - * Note that anonymous pages are accounted for + * Note that anonymous folios are accounted for * via NR_FILE_PAGES and NR_ANON_MAPPED if they * are mapped to swap space. */ @@ -521,6 +516,17 @@ int folio_migrate_mapping(struct address_space *mapping, return MIGRATEPAGE_SUCCESS; } + +int folio_migrate_mapping(struct address_space *mapping, + struct folio *newfolio, struct folio *folio, int extra_count) +{ + int expected_count = folio_expected_refs(mapping, folio) + extra_count; + + if (folio_ref_count(folio) != expected_count) + return -EAGAIN; + + return __folio_migrate_mapping(mapping, newfolio, folio, expected_count); +} EXPORT_SYMBOL(folio_migrate_mapping); /* From patchwork Wed Jun 26 08:53:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13712429 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 9C50AC27C4F for ; Wed, 26 Jun 2024 08:54:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C4D906B0092; Wed, 26 Jun 2024 04:54:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BB0206B0093; Wed, 26 Jun 2024 04:54:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 967716B0095; Wed, 26 Jun 2024 04:54:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5F6326B0092 for ; Wed, 26 Jun 2024 04:54:45 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 0CCA9C0C88 for ; Wed, 26 Jun 2024 08:54:45 +0000 (UTC) X-FDA: 82272429330.05.8115466 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf08.hostedemail.com (Postfix) with ESMTP id 19217160023; Wed, 26 Jun 2024 08:54:41 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719392071; 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=pLdchAKMVOnnow5g3bHuaFejgGWqLsRQABjHVMysOR4=; b=jUcw9GQSm168qguJwqdj39RUEsvgNJa1FPCnpYGPPoXZ5uVrP0ANsljGzH7Yq+d/p5ns2n oV/V5EVkSIX9S93jS/u9jL63E7AZAi0LAAkKaM3szQnh5nD1suo1avnoeS8P1+F1B4akx9 D1HkaxETejsZyOruBXJbW+fRt+k6mdE= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719392071; a=rsa-sha256; cv=none; b=gpAffjIDbWZKgmRRUFQnkuFnVxUfofwJUJR8fAVqKnEn3rvLoyXQ7lw3DxWK5Lv2qocYv6 k7miVGkEYI1WAUSZ+ShUaIJA63WxblYo3OnVEZG4mqz0Wm3LS5fy+/SdsmKpMKQDkBWdI9 HaFR9n8twI7XLvDyCXsPfxDIcPLDPH0= Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4W8FpS46mszddwR; Wed, 26 Jun 2024 16:53:04 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 702C414011D; Wed, 26 Jun 2024 16:54:38 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemf100008.china.huawei.com (7.185.36.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 26 Jun 2024 16:54:37 +0800 From: Kefeng Wang To: , CC: Tony Luck , Miaohe Lin , , Matthew Wilcox , David Hildenbrand , Muchun Song , Benjamin LaHaise , , Jiaqi Yan , Hugh Dickins , Vishal Moola , Alistair Popple , Jane Chu , Oscar Salvador , Lance Yang , Kefeng Wang Subject: [PATCH v5 4/6] mm: migrate: support poisoned recover from migrate folio Date: Wed, 26 Jun 2024 16:53:26 +0800 Message-ID: <20240626085328.608006-5-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240626085328.608006-1-wangkefeng.wang@huawei.com> References: <20240626085328.608006-1-wangkefeng.wang@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 dggpemf100008.china.huawei.com (7.185.36.138) X-Stat-Signature: 4apmgdzu5m6ebouecu7gc5gr4ejxfdpb X-Rspam-User: X-Rspamd-Queue-Id: 19217160023 X-Rspamd-Server: rspam02 X-HE-Tag: 1719392081-364570 X-HE-Meta: U2FsdGVkX19BKlxqF3jpkCCbqUiBLcQv6BIWY6yVEwllMzwmdq/Jr+oERZeZqAY38EWag51JFPTZuCi3OaPpZwAXt0DCVDgZVqYP+I30OBGSy9IUOwDNxl0DXGYNFoWtplIBTJ7tT7mhu+M7LL6nNDEXhUO57Cp5WYgSmynG8mAblGbTii4jaerxmMeZzKtl/CS47wVxTn+fSn4Z8SpDoYcjk/KGfPJV1YH7HYkfY2hfke4egR3hK2y2qM1FI1bAZ9iLsoGhO10cM//N91UzWpbPzoQ7/d1FLMci7aRdKtnzJP4IeuPpJIq7o4RhhvjDFzeqzmWCmu4dPnud8YAJuOD6aqAnd/cmSyuiBCKaBfJAOlq0HSHor5Wyep5fNgSrbeZxY0a9xdUK+sgo8hKTqQUN55iMdWCxiLzEWUhcd1YghLILcHMux8G/IG9yY7BfV2Ssz/qcpPsF1WwmveJEG/VKZe7Y83ZGBAobw68nYGFhJzHskflWbtg+ks/zEhkjkS3zDdRFV/EPXXQvLfuKJWRTg8fgOo2wIKAPNx4EjhEQvZ99tsiew7jLONO7mmcqEgCNE0Kg+JHcj7cA2jEGho9pJfog7qyi+EwkcxAiD/dc4Q9OJlVpI2bOQAPhzDC5o9MPOpk5fcn0dZV3YgbFtFmSO+A519yDazMpZYliAqrWQG+wa0cYt99cKnjkRMiEG4HWHTNq136o1Mkmd8mTZ6XntXuSa+MNU4vQwuFdiX9zAapqrdt2oH/D0uBzPpZRR+4dLeBUgjSMMlzQS2Wjtn7/pEbRGJMN4zHz4ydAKo4FiA26cC5/JWNywTKrKeGL3pLbvcZB4VAcyB27aaOGUDZQ8PAmJCZ1iPgv0XpSPmU20BXfrcoQmqKQUvceZuy9IoXuWfn5VSKFBgJs0dpg8Yj5X3TVUxLQdK6n0K3/MvzMPT2I5l8Yy/v9GAn2q/lkRH9C1nqlPW8lH3Gs/fo CPGD4W6r nSTGLJtPSErDCkv5s1gfRgOkKDHYzbcvJKLqnoSui0hYxMSJqPyX6YG+4RQ5RLxCxEqIhAEdG1Xu7f+PnZMs8Qmo9N9NDlvzuJY8oQUPSyiZA4nBG90HKLOjn5lQccVOUy4KBaxWC8pk88Y/px0qd6qxOIEvEW2z6PwVSmCDH6FCrhLm7vLd8COInIGWFRCBlk/qa5cj6HTBq0EECsaHcrIcm0EBIVOcUH5Js 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: The folio migration is widely used in kernel, memory compaction, memory hotplug, soft offline page, numa balance, memory demote/promotion, etc, but once access a poisoned source folio when migrating, the kerenl will panic. There is a mechanism in the kernel to recover from uncorrectable memory errors, ARCH_HAS_COPY_MC, which is already used in other core-mm paths, eg, CoW, khugepaged, coredump, ksm copy, see copy_mc_to_{user,kernel}, copy_mc_{user_}highpage callers. In order to support poisoned folio copy recover from migrate folio, we chose to make folio migration tolerant of memory failures and return error for folio migration, because folio migration is no guarantee of success, this could avoid the similar panic shown below. CPU: 1 PID: 88343 Comm: test_softofflin Kdump: loaded Not tainted 6.6.0 pc : copy_page+0x10/0xc0 lr : copy_highpage+0x38/0x50 ... Call trace: copy_page+0x10/0xc0 folio_copy+0x78/0x90 migrate_folio_extra+0x54/0xa0 move_to_new_folio+0xd8/0x1f0 migrate_folio_move+0xb8/0x300 migrate_pages_batch+0x528/0x788 migrate_pages_sync+0x8c/0x258 migrate_pages+0x440/0x528 soft_offline_in_use_page+0x2ec/0x3c0 soft_offline_page+0x238/0x310 soft_offline_page_store+0x6c/0xc0 dev_attr_store+0x20/0x40 sysfs_kf_write+0x4c/0x68 kernfs_fop_write_iter+0x130/0x1c8 new_sync_write+0xa4/0x138 vfs_write+0x238/0x2d8 ksys_write+0x74/0x110 Note, folio copy is moved in the begin of the __migrate_folio(), which could simplify the error handling since there is no turning back if folio_migrate_mapping() return success, the downside is the folio copied even though folio_migrate_mapping() return fail, an optimization is to check whether source folio does not have extra refs before we do folio copy. Signed-off-by: Kefeng Wang --- mm/migrate.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index e97fbaed564d..f9d700d82ea9 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -668,16 +668,24 @@ static int __migrate_folio(struct address_space *mapping, struct folio *dst, struct folio *src, void *src_private, enum migrate_mode mode) { - int rc; + int rc, expected_count = folio_expected_refs(mapping, src); + + /* Check whether src does not have extra refs before we do more work */ + if (folio_ref_count(src) != expected_count) + return -EAGAIN; + + rc = folio_mc_copy(dst, src); + if (unlikely(rc)) + return rc; - rc = folio_migrate_mapping(mapping, dst, src, 0); + rc = __folio_migrate_mapping(mapping, dst, src, expected_count); if (rc != MIGRATEPAGE_SUCCESS) return rc; if (src_private) folio_attach_private(dst, folio_detach_private(src)); - folio_migrate_copy(dst, src); + folio_migrate_flags(dst, src); return MIGRATEPAGE_SUCCESS; } From patchwork Wed Jun 26 08:53:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13712430 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 B4C6FC30653 for ; Wed, 26 Jun 2024 08:54:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4857C6B0093; Wed, 26 Jun 2024 04:54:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 412E16B0096; Wed, 26 Jun 2024 04:54:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 176636B0098; Wed, 26 Jun 2024 04:54:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C5EF76B0095 for ; Wed, 26 Jun 2024 04:54:45 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 827B2C0C8D for ; Wed, 26 Jun 2024 08:54:45 +0000 (UTC) X-FDA: 82272429330.07.66554B0 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf18.hostedemail.com (Postfix) with ESMTP id 9745D1C000D; Wed, 26 Jun 2024 08:54:42 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719392062; 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=55a+RYVMO2xObEKXg6OIQKt+jLPX8WHUckSNrVuuSxU=; b=0Ai6vr8ma2rIGKw73jMiPQff9H/mG7hhaPiUbQ9FtbmE7x+pu7uloLmLEJXSbrzylUv4jw KlU0Ie30leUKv4KJSGTGE/oSSWe+lGzo2bfxaI46M5lUBjlihyJfbpb6rGlp2CvJsCyKzr pwKYVOsM2PEQLFds7ZDj/RrmROen0bc= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719392062; a=rsa-sha256; cv=none; b=HzdznB91YwK5D2cvRZWJRfqFILnBcKwOuXDIIeQvRda2QuPJaMgvi3IrR1hdNQ1FoM4oAP ca1ZYY7/yVsXWU6fgsqqR+QOoyvirw6kebJYc5EieQV6CdprMSh0ZW7aoAdJaqECokP+r5 rFWGSibwYzZbnb1d/2Uc44SuxIoQf5E= Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4W8Fm32Bt4z1ytgJ; Wed, 26 Jun 2024 16:50:59 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 3ADFA1A016C; Wed, 26 Jun 2024 16:54:39 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemf100008.china.huawei.com (7.185.36.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 26 Jun 2024 16:54:38 +0800 From: Kefeng Wang To: , CC: Tony Luck , Miaohe Lin , , Matthew Wilcox , David Hildenbrand , Muchun Song , Benjamin LaHaise , , Jiaqi Yan , Hugh Dickins , Vishal Moola , Alistair Popple , Jane Chu , Oscar Salvador , Lance Yang , Kefeng Wang Subject: [PATCH v5 5/6] fs: hugetlbfs: support poisoned recover from hugetlbfs_migrate_folio() Date: Wed, 26 Jun 2024 16:53:27 +0800 Message-ID: <20240626085328.608006-6-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240626085328.608006-1-wangkefeng.wang@huawei.com> References: <20240626085328.608006-1-wangkefeng.wang@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 dggpemf100008.china.huawei.com (7.185.36.138) X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9745D1C000D X-Stat-Signature: woomsod3zdpee7g3somjjpit3bteynsq X-Rspam-User: X-HE-Tag: 1719392082-143514 X-HE-Meta: U2FsdGVkX19BNhuE2hg1meNBad8gCZ/3c/rrU4BToUL5SxMQs+UuSYBSaa8qGYTRwb9ZdAjwHhM3VnlzK/020L0v3t7mTCzQK0sz9dO+QZ9eVxzW3xYaQy+dJsNiB6PHR9Cw7Lt41KMi+CJqTliaZBkjOkllbRKTC9WGzC9GDkmRL8MWchQ6HxGUn30OmsGpgZmGMm9dwsEWsJxAda40HFCYS78q+JS/YqEE8hSB6F5pGDgnQvn+wRmFNCS7sTD89jumOpmeToG3R3OWsC/zzI9TlhI4QDyJKQLDe9lkpMn5LQ6ZgbT6ues1Hw+QfAdxw7GtXSZUgpUZkE26Cs/hyQOTDes2r/baAcH/A9vyPlk/FpU1Tl067NbYTWnuIKRGZr3alOu3u8pQs0o/5+UUkzdgYWWFnTa0MypKYxdxeaosjBU5+l9mzxClq8EPkwurMawLANPb3GCqYXLWQAXkUwufgWu8TQprfl350HRwGKgb76yB+9lJt5gez8hbTvQgya+Wrnr8HeuXLTUiXRhk/p7jQw9Fuf0eb3D7neZ0lHTbgxt1PDGhJopKiYSfESjRu5+seeSgCCX07kBVzxdX9K9DJabmLdEbgBByTjjhHcHUZhXSCTsekD4wIbJx1wJvUSE3Nrnpx6KMHcDLRB8AHSEl4+r4Wt3naH00bm6buSChceJRYjpHpy4ropcLtYHSVIaW+GXOtnWhH7a7eFosJ/j2+qSYRkvvd3YoezYcdkgNFJUglmwNK1JE1cTLNE22TeQ359Mo2cVs0hLxU3g6c9Lf7kTenmhmC2Zyxa0zo5VDYgOdoZDwPpQC9916nH0FAddu414gM8W7rrTMZZcBV8mMA6R9HcSRwsvJUYtceNX9nRe8t+OsqvTVkDvuYT8OCGwAJ6J4llRFcupvb+BhLtmRX3KBqSOD8wnD58PWxkQznRzzE4oC8AFj30YFIIYCeYT/gTfaXiaEEnqTh7G k5OwHVNN 9ib91BEHshnSycfJLanA5Kk2VKJYhwVzY8rxloLfId0IM8NRoRf5Uux+uk2U3rF1ZK8wvT+nofr7zLRFCwREmV+Te9MaqHf8rD6haNcZ2/v0h8kc9hWnBOdaS742ZGWSxEI8gsmR50wXmqBFv9fyMTlBzRCbqx+C6xzNLS0piGSmaNYSQ99TC3KwZUYTCA8lNKyM2j/2D9kRu5WDmI/ok4mwMTNC8/C7sUEAcZ5RViD7KmQOIatDaLwKTYe3B4S5tfYte8cv+tXaXNKk= 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: This is similar to __migrate_folio(), use folio_mc_copy() in HugeTLB folio migration to avoid panic when copy from poisoned folio. Signed-off-by: Kefeng Wang --- fs/hugetlbfs/inode.c | 2 +- mm/migrate.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 9456e1d55540..ecad73a4f713 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -1128,7 +1128,7 @@ static int hugetlbfs_migrate_folio(struct address_space *mapping, hugetlb_set_folio_subpool(src, NULL); } - folio_migrate_copy(dst, src); + folio_migrate_flags(dst, src); return MIGRATEPAGE_SUCCESS; } diff --git a/mm/migrate.c b/mm/migrate.c index f9d700d82ea9..ad78b053815a 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -537,10 +537,16 @@ int migrate_huge_page_move_mapping(struct address_space *mapping, struct folio *dst, struct folio *src) { XA_STATE(xas, &mapping->i_pages, folio_index(src)); - int expected_count; + int rc, expected_count = folio_expected_refs(mapping, src); + + if (folio_ref_count(src) != expected_count) + return -EAGAIN; + + rc = folio_mc_copy(dst, src); + if (unlikely(rc)) + return rc; xas_lock_irq(&xas); - expected_count = folio_expected_refs(mapping, src); if (!folio_ref_freeze(src, expected_count)) { xas_unlock_irq(&xas); return -EAGAIN; From patchwork Wed Jun 26 08:53:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13712431 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 428A1C27C4F for ; Wed, 26 Jun 2024 08:54:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 990CA6B0095; Wed, 26 Jun 2024 04:54:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A2D36B0098; Wed, 26 Jun 2024 04:54:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 63A826B0095; Wed, 26 Jun 2024 04:54:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 186546B0099 for ; Wed, 26 Jun 2024 04:54:46 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CA2771C1C11 for ; Wed, 26 Jun 2024 08:54:45 +0000 (UTC) X-FDA: 82272429330.18.3F71D8E Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf23.hostedemail.com (Postfix) with ESMTP id 313E414000B; Wed, 26 Jun 2024 08:54:42 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719392075; 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=sh/rLJatyLcvr58SzlyCdL8mOi1a46w/NsBvf6k1hqw=; b=sysLQFJxI1bmUSb35vhmr0kx2EHfJZHebrMy6fCXEeWVCNMwW7NxlzURCo+BWirqrVJEPk GsU037BVElw6VXcaNy3poboEneNA0G/YN+SE3I3hSCRPbOqbFgQHIKNS3adRSmEe/SxGCS dryS0JhDp1kG3g7Z9HXxP4pbErIQZJE= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719392075; a=rsa-sha256; cv=none; b=CLyNdEk2AWSKdbAX99Ri0Bvb3KF8JyMo4kGkV2idLXls+hlF8OSvjn7K9XHfJ512QQFnGn idBxNe5IR4a7BKMCfwqVHmZLwpzcM4ydgJ1QwLiEUch5Hg15blizltwYaxn/Imma+AEus+ etUx08a3Kx4DKG6eXQ0BK7TtVA86SOs= Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4W8FpV0zlvzddvV; Wed, 26 Jun 2024 16:53:06 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 0453514011B; Wed, 26 Jun 2024 16:54:40 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemf100008.china.huawei.com (7.185.36.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 26 Jun 2024 16:54:39 +0800 From: Kefeng Wang To: , CC: Tony Luck , Miaohe Lin , , Matthew Wilcox , David Hildenbrand , Muchun Song , Benjamin LaHaise , , Jiaqi Yan , Hugh Dickins , Vishal Moola , Alistair Popple , Jane Chu , Oscar Salvador , Lance Yang , Kefeng Wang Subject: [PATCH v5 6/6] mm: migrate: remove folio_migrate_copy() Date: Wed, 26 Jun 2024 16:53:28 +0800 Message-ID: <20240626085328.608006-7-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240626085328.608006-1-wangkefeng.wang@huawei.com> References: <20240626085328.608006-1-wangkefeng.wang@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 dggpemf100008.china.huawei.com (7.185.36.138) X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 313E414000B X-Stat-Signature: 4mnrg188huyxo8fzjxp91m3zuwwsduu5 X-Rspam-User: X-HE-Tag: 1719392082-41563 X-HE-Meta: U2FsdGVkX19dWLhFiTyVrBB96C1LVcy52MVEXg6ZvMIYpv/alen6vAXvA8IccfAr3so5bE/QMD6N1RAwaDV2i8Fzvc/HyVl9//DVtO1nmNcjoL3vi+LG+dxnFKbFnTYW7eZxDJIezptbuIpuM43lygESCf6F6Q4YH4RA+kImO8W5b3f27Kv6Az2xPIztcIybfolaCHrDDk+StZPfUL/Zq+w/CE6QwYcmx+Tp4II7koXFTPrfo44xA13BSrZQl9m3pqEeFoorJRt9cB6D7TDz/KQm7+7KleisQjWoO8NObOe3H9oce32I3GTc8q4uUKDIr7grDhgEVNxRcV0ua02Rep6HmoJIMNXs90rWqDzXMaNIrDxMtUq8Zrs7zBrXlfyio8J7p7nNmxr8q1rNfqoOoUDP2CceluYB1Tf1l5L72i/rFSG2jTI6phHZrBPV2EKl8MJknnaFtI0qL+klwMN1x7iJDJbDWlK+8qtQFEr9vxsCa2Fn44wxFo0OhCo3bKf7/GozjK6sUgwtFGrDJ/S2R7Au7pQ4XoZKapH8GJDvP0CyE+U9ReIU7nPkmFHHJX+MOosGr3FXrJCJK1OJzSWKdFs2NzgDHu7Kt988zbHBDqrFZq9JRfaDXtUciv6AZ1beRBuIa3RkL6g0Siof50m7+jWpQe4aVFfmStvH+CmaRZyHLlFlcgszepW7BgjQewF1CtqlnBSjf0eIV+ZC+RsLFLwIaim4NMX+6tNMmSSLRJzv3+3pWqzjM8dkw861zSu28uwuih+OKl+5qHshOamx4JZHy7MQkg8wPUZTO4hRT7dYYU/kSpZXDdDWR1XifS0Qtl5itEaA+9hTYVIWkkciXMhgFt5b5RXZGUQwUHlBo9sAIYY62j5TKcl07Eg14LDE9u8zLQL6jRIFmaGSP8R6e2orF3/dCMWM39y/Ror1LYTtX/utB8ssgGtHmyoJpY03X9oNbrnXlcdulI/Ggds 975RK1RZ XPClbfWU8l8k/0EQdelsucFHqcIkJFal9hbvw/QRcbr0kA9tX5o5eIFCCIQrTGFR2bq87EaXXuie9+TdYXjV1p2101rv+L6pSUiZyICs+CHiYcvu7nmwaR5+ibdI+JSvuJVo9CLRNRLsgQN2EhJ2N+5SqSTudmqYJzo5J74DQrj4HtPf/mfMLChqbvtos/rMlAeOTpwZpmIgyYUBi82pPvE7PJvCTp0t2jFLJwOP6F3OVWBg5JAgZhG0kuN0f8xby1YyM3CLKrrEFImPYr+AM01BJX/+VagPRtAyR 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: The folio_migrate_copy() is just a wrapper of folio_copy() and folio_migrate_flags(), it is simple and only aio use it for now, unfold it and remove folio_migrate_copy(). Reviewed-by: Jane Chu Signed-off-by: Kefeng Wang --- fs/aio.c | 3 ++- include/linux/migrate.h | 1 - mm/migrate.c | 7 ------- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index ed730b5f4c54..6066f64967b3 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -455,7 +455,8 @@ static int aio_migrate_folio(struct address_space *mapping, struct folio *dst, * events from being lost. */ spin_lock_irqsave(&ctx->completion_lock, flags); - folio_migrate_copy(dst, src); + folio_copy(dst, src); + folio_migrate_flags(dst, src); BUG_ON(ctx->ring_folios[idx] != src); ctx->ring_folios[idx] = dst; spin_unlock_irqrestore(&ctx->completion_lock, flags); diff --git a/include/linux/migrate.h b/include/linux/migrate.h index af2579ae93f2..644be30b69c8 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -76,7 +76,6 @@ int migrate_huge_page_move_mapping(struct address_space *mapping, void migration_entry_wait_on_locked(swp_entry_t entry, spinlock_t *ptl) __releases(ptl); void folio_migrate_flags(struct folio *newfolio, struct folio *folio); -void folio_migrate_copy(struct folio *newfolio, struct folio *folio); int folio_migrate_mapping(struct address_space *mapping, struct folio *newfolio, struct folio *folio, int extra_count); diff --git a/mm/migrate.c b/mm/migrate.c index ad78b053815a..906f6a2e4f38 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -659,13 +659,6 @@ void folio_migrate_flags(struct folio *newfolio, struct folio *folio) } EXPORT_SYMBOL(folio_migrate_flags); -void folio_migrate_copy(struct folio *newfolio, struct folio *folio) -{ - folio_copy(newfolio, folio); - folio_migrate_flags(newfolio, folio); -} -EXPORT_SYMBOL(folio_migrate_copy); - /************************************************************ * Migration functions ***********************************************************/