From mboxrd@z Thu Jan 1 00:00:00 1970 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 58D5DC433F5 for ; Fri, 29 Apr 2022 08:49:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 70E3D6B0071; Fri, 29 Apr 2022 04:49:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6BE076B0073; Fri, 29 Apr 2022 04:49:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5863D6B0074; Fri, 29 Apr 2022 04:49:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 467406B0071 for ; Fri, 29 Apr 2022 04:49:22 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 1C50B815D4 for ; Fri, 29 Apr 2022 08:49:22 +0000 (UTC) X-FDA: 79409292564.19.D203F1B Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf31.hostedemail.com (Postfix) with ESMTP id 65D732004C for ; Fri, 29 Apr 2022 08:49:10 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KqR1B6MCBzGpJJ; Fri, 29 Apr 2022 16:46:38 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 29 Apr 2022 16:49:16 +0800 Subject: Re: [RFC PATCH v1 2/4] mm,hwpoison,hugetlb,memory_hotplug: hotremove memory section with hwpoisoned hugepage To: Naoya Horiguchi CC: Andrew Morton , David Hildenbrand , Mike Kravetz , Yang Shi , Oscar Salvador , Muchun Song , Naoya Horiguchi , , Linux-MM References: <20220427042841.678351-1-naoya.horiguchi@linux.dev> <20220427042841.678351-3-naoya.horiguchi@linux.dev> From: Miaohe Lin Message-ID: <9bdddf53-b01a-9665-04c3-0146efc1404d@huawei.com> Date: Fri, 29 Apr 2022 16:49:16 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20220427042841.678351-3-naoya.horiguchi@linux.dev> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 65D732004C X-Stat-Signature: 43w9gwxn9gwkhu8fzjcdxnssuqbs9qx5 Authentication-Results: imf31.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf31.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspam-User: X-HE-Tag: 1651222150-159793 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: On 2022/4/27 12:28, Naoya Horiguchi wrote: > From: Naoya Horiguchi > > HWPoisoned page is not supposed to prevent memory hotremove, but > currently this does not properly work for hwpoisoned hugepages and the > kernel tries to migrate them, which could cause consuming corrupted > data. > > Move dissolve_free_huge_pages() before scan_movable_pages(). This is > because the result of the movable check depends on the result of the > dissolve. Now delayed dissolve is available, so hwpoisoned hugepages > can be turned into 4kB hwpoison page which memory hotplug can handle. > > And clear HPageMigratable pseudo flag for hwpoisoned hugepages. This is > also important because dissolve_free_huge_page() can fail. So it's > still necessary to prevent do_migrate_pages() from trying to migrate > hwpoison hugepages. > > Reported-by: Miaohe Lin > Signed-off-by: Naoya Horiguchi > --- > mm/hugetlb.c | 11 +++++++++++ > mm/memory-failure.c | 2 ++ > mm/memory_hotplug.c | 23 +++++++++++------------ > 3 files changed, 24 insertions(+), 12 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 6867ea8345d1..95b1db852ca9 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -2159,6 +2159,17 @@ int dissolve_free_huge_pages(unsigned long start_pfn, unsigned long end_pfn) > > for (pfn = start_pfn; pfn < end_pfn; pfn += 1 << minimum_order) { > page = pfn_to_page(pfn); > + > + if (PageHuge(page) && PageHWPoison(page)) { > + /* > + * Release the last refcount from hwpoison to turn into > + * a free hugepage. > + */ > + if (page_count(page) == 1) > + put_page(page); > + page = hugetlb_page_hwpoison(page); > + } > + This patch looks good to me. Thanks! One question: Can this hugepage be put into buddy system? In free_huge_page, if h->surplus_huge_pages_node[nid] > 0, hugepage might be put into buddy via update_and_free_page. So it's not PageHuge anymore and won't be dissolved. If this happens, the "raw error page" is still missed and might be accessed later. Or am I miss something? Thanks! > rc = dissolve_free_huge_page(page); > if (rc) > break; > diff --git a/mm/memory-failure.c b/mm/memory-failure.c > index 73948a00ad4a..4a2e22bf0983 100644 > --- a/mm/memory-failure.c > +++ b/mm/memory-failure.c > @@ -1607,6 +1607,8 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb > return res == MF_RECOVERED ? 0 : -EBUSY; > } > > + ClearHPageMigratable(head); > + > page_flags = head->flags; > > /* > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index 416b38ca8def..4bc0590f4334 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -1864,6 +1864,17 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages, > > cond_resched(); > > + /* > + * Dissolve free hugepages in the memory block before doing > + * offlining actually in order to make hugetlbfs's object > + * counting consistent. > + */ > + ret = dissolve_free_huge_pages(start_pfn, end_pfn); > + if (ret) { > + reason = "failure to dissolve huge pages"; > + goto failed_removal_isolated; > + } > + > ret = scan_movable_pages(pfn, end_pfn, &pfn); > if (!ret) { > /* > @@ -1879,19 +1890,7 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages, > goto failed_removal_isolated; > } > > - /* > - * Dissolve free hugepages in the memory block before doing > - * offlining actually in order to make hugetlbfs's object > - * counting consistent. > - */ > - ret = dissolve_free_huge_pages(start_pfn, end_pfn); > - if (ret) { > - reason = "failure to dissolve huge pages"; > - goto failed_removal_isolated; > - } > - > ret = test_pages_isolated(start_pfn, end_pfn, MEMORY_OFFLINE); > - > } while (ret); > > /* Mark all sections offline and remove free pages from the buddy. */ >