From patchwork Wed Apr 27 04:28:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12828278 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 2E6A8C433EF for ; Wed, 27 Apr 2022 04:29:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7EF236B0078; Wed, 27 Apr 2022 00:29:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7772C6B007B; Wed, 27 Apr 2022 00:29:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 619026B007D; Wed, 27 Apr 2022 00:29:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 52C236B0078 for ; Wed, 27 Apr 2022 00:29:03 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2EF2123A9E for ; Wed, 27 Apr 2022 04:29:03 +0000 (UTC) X-FDA: 79401378966.07.9450D27 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf06.hostedemail.com (Postfix) with ESMTP id 4E0CC18004B for ; Wed, 27 Apr 2022 04:29:01 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1651033741; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4aX7odo5pcxf80dhjL+1ki2q7oMjNnbh5/VzkH5pVqg=; b=EKimL9Toxeqt4HnHJHW5pRSliyYwJNFr9WPy84AXTdu3zPV6CCK1gzxtzJ+LCRxxYt2BYh gBkQNKGYCvwoIb+XERgEhAUCTZaC2S9/q/TpjM5aTQQhpyvlef1g3TGgjrTU99sAcs+N71 F52kfL5TtQhvSQrQwaNLhxnNHymIzlA= From: Naoya Horiguchi To: linux-mm@kvack.org Cc: Andrew Morton , Miaohe Lin , David Hildenbrand , Mike Kravetz , Yang Shi , Oscar Salvador , Muchun Song , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 2/4] mm,hwpoison,hugetlb,memory_hotplug: hotremove memory section with hwpoisoned hugepage Date: Wed, 27 Apr 2022 13:28:39 +0900 Message-Id: <20220427042841.678351-3-naoya.horiguchi@linux.dev> In-Reply-To: <20220427042841.678351-1-naoya.horiguchi@linux.dev> References: <20220427042841.678351-1-naoya.horiguchi@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=EKimL9To; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf06.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 4E0CC18004B X-Rspam-User: X-Stat-Signature: kgjow16qqrxi7u1nhan5o639puyqrii1 X-HE-Tag: 1651033741-424452 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: 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); + } + 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. */