From nobody Mon Jun 22 16:52:13 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B612C433FE for ; Sat, 19 Mar 2022 08:38:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242522AbiCSIji (ORCPT ); Sat, 19 Mar 2022 04:39:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232549AbiCSIjg (ORCPT ); Sat, 19 Mar 2022 04:39:36 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1A452BE2D0 for ; Sat, 19 Mar 2022 01:38:14 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KLDmK5VnlzcZyB; Sat, 19 Mar 2022 16:38:09 +0800 (CST) Received: from huawei.com (10.175.124.27) 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.2308.21; Sat, 19 Mar 2022 16:38:12 +0800 From: Miaohe Lin To: , , , , CC: , , Subject: [PATCH v4 1/2] mm/memory-failure.c: avoid calling invalidate_inode_page() with unexpected pages Date: Sun, 20 Mar 2022 13:13:33 +0800 Message-ID: <20220320051334.44502-2-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220320051334.44502-1-linmiaohe@huawei.com> References: <20220320051334.44502-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" invalidate_inode_page() can invalidate the pages in the swap cache because the check of page->mapping !=3D mapping is removed via Matthew's patch titl= ed "mm/truncate: Inline invalidate_complete_page() into its one caller". But invalidate_inode_page() is not expected to deal with the pages in the swap cache. Also non-lru movable page can reach here too. They're not page cache pages. Skip these pages by checking PageSwapCache and PageLRU to fix this unexpected issue. Signed-off-by: Miaohe Lin --- mm/memory-failure.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 5444a8ef4867..ecf45961f3b6 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2178,7 +2178,7 @@ static int __soft_offline_page(struct page *page) return 0; } =20 - if (!PageHuge(page)) + if (!PageHuge(page) && PageLRU(page) && !PageSwapCache(page)) /* * Try to invalidate first. This should work for * non dirty unmapped page cache pages. --=20 2.23.0 From nobody Mon Jun 22 16:52:13 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACCF4C4332F for ; Sat, 19 Mar 2022 08:38:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242529AbiCSIjl (ORCPT ); Sat, 19 Mar 2022 04:39:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242519AbiCSIji (ORCPT ); Sat, 19 Mar 2022 04:39:38 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 172832BE2D3 for ; Sat, 19 Mar 2022 01:38:15 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4KLDmL57mMz1GCSK; Sat, 19 Mar 2022 16:38:10 +0800 (CST) Received: from huawei.com (10.175.124.27) 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.2308.21; Sat, 19 Mar 2022 16:38:13 +0800 From: Miaohe Lin To: , , , , CC: , , Subject: [PATCH v4 2/2] mm/memory-failure.c: make non-LRU movable pages unhandlable Date: Sun, 20 Mar 2022 13:13:34 +0800 Message-ID: <20220320051334.44502-3-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220320051334.44502-1-linmiaohe@huawei.com> References: <20220320051334.44502-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We can not really handle non-LRU movable pages in memory failure. Typically they are balloon, zsmalloc, etc. Assuming we run into a base (4K) non-LRU movable page, we could reach as far as identify_page_state(), it should not fall into any category except me_unknown. For the non-LRU compound movable pages, they could be taken for transhuge pages but it's unexpected to split non-LRU movable pages using split_huge_page_to_list in memory_failure. So we could just simply make non-LRU movable pages unhandlable to avoid these possible nasty cases. Suggested-by: Yang Shi Signed-off-by: Miaohe Lin Reviewed-by: Yang Shi Acked-by: Naoya Horiguchi --- mm/memory-failure.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index ecf45961f3b6..837ceae90d64 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1176,12 +1176,16 @@ void ClearPageHWPoisonTakenOff(struct page *page) * does not return true for hugetlb or device memory pages, so it's assumed * to be called only in the context where we never have such pages. */ -static inline bool HWPoisonHandlable(struct page *page) +static inline bool HWPoisonHandlable(struct page *page, unsigned long flag= s) { - return PageLRU(page) || __PageMovable(page) || is_free_buddy_page(page); + /* Soft offline could migrate non-LRU movable pages. */ + if ((flags & MF_SOFT_OFFLINE) && __PageMovable(page)) + return true; + + return PageLRU(page) || is_free_buddy_page(page); } =20 -static int __get_hwpoison_page(struct page *page) +static int __get_hwpoison_page(struct page *page, unsigned long flags) { struct page *head =3D compound_head(page); int ret =3D 0; @@ -1196,7 +1200,7 @@ static int __get_hwpoison_page(struct page *page) * for any unsupported type of page in order to reduce the risk of * unexpected races caused by taking a page refcount. */ - if (!HWPoisonHandlable(head)) + if (!HWPoisonHandlable(head, flags)) return -EBUSY; =20 if (get_page_unless_zero(head)) { @@ -1221,7 +1225,7 @@ static int get_any_page(struct page *p, unsigned long= flags) =20 try_again: if (!count_increased) { - ret =3D __get_hwpoison_page(p); + ret =3D __get_hwpoison_page(p, flags); if (!ret) { if (page_count(p)) { /* We raced with an allocation, retry. */ @@ -1249,7 +1253,7 @@ static int get_any_page(struct page *p, unsigned long= flags) } } =20 - if (PageHuge(p) || HWPoisonHandlable(p)) { + if (PageHuge(p) || HWPoisonHandlable(p, flags)) { ret =3D 1; } else { /* @@ -2296,7 +2300,7 @@ int soft_offline_page(unsigned long pfn, int flags) =20 retry: get_online_mems(); - ret =3D get_hwpoison_page(page, flags); + ret =3D get_hwpoison_page(page, flags | MF_SOFT_OFFLINE); put_online_mems(); =20 if (ret > 0) { --=20 2.23.0