From patchwork Wed Apr 27 04:28:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12828277 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 C728FC433F5 for ; Wed, 27 Apr 2022 04:28:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F23C6B0075; Wed, 27 Apr 2022 00:28:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A2066B0078; Wed, 27 Apr 2022 00:28:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41CCD6B007B; Wed, 27 Apr 2022 00:28:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 304426B0075 for ; Wed, 27 Apr 2022 00:28:59 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 0F9EB81751 for ; Wed, 27 Apr 2022 04:28:59 +0000 (UTC) X-FDA: 79401378798.06.2F889AF Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf11.hostedemail.com (Postfix) with ESMTP id B30314004A for ; Wed, 27 Apr 2022 04:28:55 +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=1651033737; 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=vhFv468URMziQMW888ZYB3zUqaYOfFeInA7ZUvxhWkc=; b=FIkAxocmKdaKVf5IxSOBZWld4OyWK+kxFY3MwdXcu6ZQBpNw203KwgWMbt+dNNyuZSUFkx fZ6F9Iu6x7FM54n99F6JvN0fC8yTDgxwtGGhEV1XNgxY77wfRgdSMRbaIIPisBRPaGfuFf z0TkMtNqa1+2tjPtjsnsUwno22b75aY= 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 1/4] mm, hwpoison, hugetlb: introduce SUBPAGE_INDEX_HWPOISON to save raw error page Date: Wed, 27 Apr 2022 13:28:38 +0900 Message-Id: <20220427042841.678351-2-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 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: B30314004A X-Stat-Signature: 8bmsmatns7trmnt864uzcg9z84hc7fqj X-Rspam-User: Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=FIkAxocm; spf=pass (imf11.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-HE-Tag: 1651033735-245883 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 When handling memory error on a hugetlb page, the error handler tries to dissolve and turn it into 4kB pages. If it's successfully dissolved, PageHWPoison flag is moved to the raw error page, so but that's all right. However, dissolve sometimes fails, then the error page is left as hwpoisoned hugepage. It's useful if we can retry to dissolve it to save healthy pages, but that's not possible now because the information about where the raw error page is lost. Use the private field of a tail page to keep that information. The code path of shrinking hugepage pool used this info to try delayed dissolve. Signed-off-by: Naoya Horiguchi --- include/linux/hugetlb.h | 24 ++++++++++++++++++++++++ mm/hugetlb.c | 9 +++++++++ mm/memory-failure.c | 2 ++ 3 files changed, 35 insertions(+) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index ac2a1d758a80..689e69cb556b 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -42,6 +42,9 @@ enum { SUBPAGE_INDEX_CGROUP, /* reuse page->private */ SUBPAGE_INDEX_CGROUP_RSVD, /* reuse page->private */ __MAX_CGROUP_SUBPAGE_INDEX = SUBPAGE_INDEX_CGROUP_RSVD, +#endif +#ifdef CONFIG_CGROUP_HUGETLB + SUBPAGE_INDEX_HWPOISON, #endif __NR_USED_SUBPAGE, }; @@ -784,6 +787,27 @@ extern int dissolve_free_huge_page(struct page *page); extern int dissolve_free_huge_pages(unsigned long start_pfn, unsigned long end_pfn); +#ifdef CONFIG_MEMORY_FAILURE +/* + * pointer to raw error page is located in hpage[SUBPAGE_INDEX_HWPOISON].private + */ +static inline struct page *hugetlb_page_hwpoison(struct page *hpage) +{ + return (void *)page_private(hpage + SUBPAGE_INDEX_HWPOISON); +} + +static inline void hugetlb_set_page_hwpoison(struct page *hpage, + struct page *page) +{ + set_page_private(hpage + SUBPAGE_INDEX_HWPOISON, (unsigned long)page); +} +#else +static inline struct page *hugetlb_page_hwpoison(struct page *hpage) +{ + return NULL; +} +#endif + #ifdef CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION #ifndef arch_hugetlb_migration_supported static inline bool arch_hugetlb_migration_supported(struct hstate *h) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index f8e048b939c7..6867ea8345d1 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1547,6 +1547,15 @@ static void __update_and_free_page(struct hstate *h, struct page *page) return; } + if (unlikely(PageHWPoison(page))) { + struct page *raw_error = hugetlb_page_hwpoison(page); + + if (raw_error && raw_error != page) { + SetPageHWPoison(raw_error); + ClearPageHWPoison(page); + } + } + for (i = 0; i < pages_per_huge_page(h); i++, subpage = mem_map_next(subpage, page, i)) { subpage->flags &= ~(1 << PG_locked | 1 << PG_error | diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 3e36fc19c4d1..73948a00ad4a 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1535,6 +1535,8 @@ int __get_huge_page_for_hwpoison(unsigned long pfn, int flags) goto out; } + hugetlb_set_page_hwpoison(head, page); + return ret; out: if (count_increased) 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. */ From patchwork Wed Apr 27 04:28:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12828279 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 DD987C433F5 for ; Wed, 27 Apr 2022 04:29:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 72E566B007B; Wed, 27 Apr 2022 00:29:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B42C6B007D; Wed, 27 Apr 2022 00:29:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 52E316B007E; Wed, 27 Apr 2022 00:29:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 3E74E6B007B for ; Wed, 27 Apr 2022 00:29:07 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 1B4C11216BB for ; Wed, 27 Apr 2022 04:29:07 +0000 (UTC) X-FDA: 79401379134.18.57BEFF2 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf14.hostedemail.com (Postfix) with ESMTP id 8856110004D for ; Wed, 27 Apr 2022 04:29:05 +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=1651033745; 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=7e1Yfv3+WJ1fxThypP2QZLDZeirFxR4HqHmaF3bZjlA=; b=aUCORwS68E5McyVQBtJuE1xfpGbKspsKYsA73An8M7dgGg2jXwmKaxOfBHK+vTh+Ybuqhm RbYaDMhrg8Ct30WsJQL40gpZQwRucwVZpbA7tc/YJM5KcxB8RJas6h7m2r4YWw5haVrxkp PhWnKc6fmlZthsdkoh80jU3Mjzcbvys= 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 3/4] mm, hwpoison: add parameter unpoison to get_hwpoison_huge_page() Date: Wed, 27 Apr 2022 13:28:40 +0900 Message-Id: <20220427042841.678351-4-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 X-Stat-Signature: qhhpb1t894qx53ta1w78pbwwo7mbxo3x Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=aUCORwS6; spf=pass (imf14.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 8856110004D X-HE-Tag: 1651033745-28892 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 Now hwpoisoned hugepage is expected to be !HPageMigratable, so grabbing hugepage for unpoison should negate the check from that for poisoning. This patch implements it by logical XOR. Signed-off-by: Naoya Horiguchi --- include/linux/hugetlb.h | 5 +++-- mm/hugetlb.c | 4 ++-- mm/memory-failure.c | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 689e69cb556b..99b7ded651f6 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -171,7 +171,7 @@ bool hugetlb_reserve_pages(struct inode *inode, long from, long to, long hugetlb_unreserve_pages(struct inode *inode, long start, long end, long freed); bool isolate_huge_page(struct page *page, struct list_head *list); -int get_hwpoison_huge_page(struct page *page, bool *hugetlb); +int get_hwpoison_huge_page(struct page *page, bool *hugetlb, bool unpoison); int get_huge_page_for_hwpoison(unsigned long pfn, int flags); void putback_active_hugepage(struct page *page); void move_hugetlb_state(struct page *oldpage, struct page *newpage, int reason); @@ -377,7 +377,8 @@ static inline bool isolate_huge_page(struct page *page, struct list_head *list) return false; } -static inline int get_hwpoison_huge_page(struct page *page, bool *hugetlb) +static inline int get_hwpoison_huge_page(struct page *page, bool *hugetlb, + bool unpoison) { return 0; } diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 95b1db852ca9..0fbdfa753b54 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6788,7 +6788,7 @@ bool isolate_huge_page(struct page *page, struct list_head *list) return ret; } -int get_hwpoison_huge_page(struct page *page, bool *hugetlb) +int get_hwpoison_huge_page(struct page *page, bool *hugetlb, bool unpoison) { int ret = 0; @@ -6798,7 +6798,7 @@ int get_hwpoison_huge_page(struct page *page, bool *hugetlb) *hugetlb = true; if (HPageFreed(page)) ret = 0; - else if (HPageMigratable(page)) + else if (!unpoison != !HPageMigratable(page)) ret = get_page_unless_zero(page); else ret = -EBUSY; diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 4a2e22bf0983..b5ee3cbc7fbc 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1190,7 +1190,7 @@ static int __get_hwpoison_page(struct page *page, unsigned long flags) int ret = 0; bool hugetlb = false; - ret = get_hwpoison_huge_page(head, &hugetlb); + ret = get_hwpoison_huge_page(head, &hugetlb, false); if (hugetlb) return ret; @@ -1283,7 +1283,7 @@ static int __get_unpoison_page(struct page *page) int ret = 0; bool hugetlb = false; - ret = get_hwpoison_huge_page(head, &hugetlb); + ret = get_hwpoison_huge_page(head, &hugetlb, true); if (hugetlb) return ret; From patchwork Wed Apr 27 04:28:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12828280 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 E44BAC433EF for ; Wed, 27 Apr 2022 04:29:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7EDF16B007D; Wed, 27 Apr 2022 00:29:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 79D776B007E; Wed, 27 Apr 2022 00:29:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 666336B0080; Wed, 27 Apr 2022 00:29:11 -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 56B006B007D for ; Wed, 27 Apr 2022 00:29:11 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 32E6761A05 for ; Wed, 27 Apr 2022 04:29:11 +0000 (UTC) X-FDA: 79401379302.14.9AE907A Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf03.hostedemail.com (Postfix) with ESMTP id 2131C20032 for ; Wed, 27 Apr 2022 04:29:06 +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=1651033749; 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=eItuMRrHX4Os0FsD9ZvtHrWEjjS1bDgCgiQWK4LzGH8=; b=Q/L/bZLR2KByUYsk0eKAUGr4PH3NUZja3XUO0pphORYpe2Rj7I0j0E8fs/cZgyDX/WahYp 09fcfU+W8FupvA87f9W0dG+wtisEPzXqeStjOqyflUdvzWcdv0AuLrYisdZAoSasUl0Jor l4AoypbWmeThkIg4PlM2aCefocljWNw= 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 4/4] mm, memory_hotplug: fix inconsistent num_poisoned_pages on memory hotremove Date: Wed, 27 Apr 2022 13:28:41 +0900 Message-Id: <20220427042841.678351-5-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 X-Stat-Signature: h5dw8mgc537c9qzhyssiegkoty6omgxt Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="Q/L/bZLR"; spf=pass (imf03.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 2131C20032 X-HE-Tag: 1651033746-534842 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 When offlining memory section with hwpoisoned pages, the hwpoisons are canceled. But num_poisoned_pages is not updated for that event, so the counter becomes inconsistent. Add num_poisoned_pages_dec() in __offline_isolated_pages(). PageHWPoison can be set on a tail page of some high order buddy page, so we need check PageHWPoison on each subpage. Signed-off-by: Naoya Horiguchi --- mm/page_alloc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 6e5b4488a0c5..dcd962855617 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -9487,12 +9487,15 @@ void __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) zone = page_zone(pfn_to_page(pfn)); spin_lock_irqsave(&zone->lock, flags); while (pfn < end_pfn) { + int i; + page = pfn_to_page(pfn); /* * The HWPoisoned page may be not in buddy system, and * page_count() is not 0. */ if (unlikely(!PageBuddy(page) && PageHWPoison(page))) { + num_poisoned_pages_dec(); pfn++; continue; } @@ -9510,6 +9513,9 @@ void __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) BUG_ON(page_count(page)); BUG_ON(!PageBuddy(page)); order = buddy_order(page); + for (i = 0; i < 1 << order; i++) + if (PageHWPoison(page + i)) + num_poisoned_pages_dec(); del_page_from_free_list(page, zone, order); pfn += (1 << order); }