From nobody Tue Jun 23 19:24:50 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 87DD7C433EF for ; Mon, 28 Feb 2022 14:03:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236881AbiB1OER (ORCPT ); Mon, 28 Feb 2022 09:04:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230338AbiB1OEN (ORCPT ); Mon, 28 Feb 2022 09:04:13 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF40533A0B for ; Mon, 28 Feb 2022 06:03:33 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4K6hs42mnPzccx1; Mon, 28 Feb 2022 22:02:16 +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; Mon, 28 Feb 2022 22:03:31 +0800 From: Miaohe Lin To: , CC: , , Subject: [PATCH 1/4] mm/memory-failure.c: fix race with changing page compound again Date: Mon, 28 Feb 2022 22:02:42 +0800 Message-ID: <20220228140245.24552-2-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220228140245.24552-1-linmiaohe@huawei.com> References: <20220228140245.24552-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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" There is a race window where we got the compound_head, the hugetlb page could be freed to buddy, or even changed to another compound page just before we try to get hwpoison page. If this happens, just bail out. Signed-off-by: Miaohe Lin --- mm/memory-failure.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 5444a8ef4867..0d7c58340a98 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1534,6 +1534,17 @@ static int memory_failure_hugetlb(unsigned long pfn,= int flags) } =20 lock_page(head); + + /** + * The page could have changed compound pages due to race window. + * If this happens just bail out. + */ + if (!PageHuge(p) || compound_head(p) !=3D head) { + action_result(pfn, MF_MSG_DIFFERENT_COMPOUND, MF_IGNORED); + res =3D -EBUSY; + goto out; + } + page_flags =3D head->flags; =20 if (hwpoison_filter(p)) { --=20 2.23.0 From nobody Tue Jun 23 19:24:50 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 BB499C433F5 for ; Mon, 28 Feb 2022 14:03:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236897AbiB1OEV (ORCPT ); Mon, 28 Feb 2022 09:04:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233491AbiB1OEO (ORCPT ); Mon, 28 Feb 2022 09:04:14 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC8BB4968D for ; Mon, 28 Feb 2022 06:03:34 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4K6hnB6ZcNz1GBw2; Mon, 28 Feb 2022 21:58:54 +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; Mon, 28 Feb 2022 22:03:31 +0800 From: Miaohe Lin To: , CC: , , Subject: [PATCH 2/4] mm/memory-failure.c: fix wrong user reference report Date: Mon, 28 Feb 2022 22:02:43 +0800 Message-ID: <20220228140245.24552-3-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220228140245.24552-1-linmiaohe@huawei.com> References: <20220228140245.24552-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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" The dirty swapcache page is still residing in the swap cache after it's hwpoisoned. So there is always one extra refcount for swap cache. Signed-off-by: Miaohe Lin --- mm/memory-failure.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 0d7c58340a98..5f9503573263 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -984,7 +984,6 @@ static int me_pagecache_dirty(struct page_state *ps, st= ruct page *p) static int me_swapcache_dirty(struct page_state *ps, struct page *p) { int ret; - bool extra_pins =3D false; =20 ClearPageDirty(p); /* Trigger EIO in shmem: */ @@ -993,10 +992,7 @@ static int me_swapcache_dirty(struct page_state *ps, s= truct page *p) ret =3D delete_from_lru_cache(p) ? MF_FAILED : MF_DELAYED; unlock_page(p); =20 - if (ret =3D=3D MF_DELAYED) - extra_pins =3D true; - - if (has_extra_refcount(ps, p, extra_pins)) + if (has_extra_refcount(ps, p, true)) ret =3D MF_FAILED; =20 return ret; --=20 2.23.0 From nobody Tue Jun 23 19:24:50 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 9DE45C433EF for ; Mon, 28 Feb 2022 14:03:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236905AbiB1OEY (ORCPT ); Mon, 28 Feb 2022 09:04:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235976AbiB1OEO (ORCPT ); Mon, 28 Feb 2022 09:04:14 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2A2C49F17 for ; Mon, 28 Feb 2022 06:03:34 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4K6hrS6W3TzBrJV; Mon, 28 Feb 2022 22:01:44 +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; Mon, 28 Feb 2022 22:03:32 +0800 From: Miaohe Lin To: , CC: , , Subject: [PATCH 3/4] mm/memory-failure.c: avoid calling invalidate_inode_page() with unexpected pages Date: Mon, 28 Feb 2022 22:02:44 +0800 Message-ID: <20220228140245.24552-4-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220228140245.24552-1-linmiaohe@huawei.com> References: <20220228140245.24552-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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" Since commit 042c4f32323b ("mm/truncate: Inline invalidate_complete_page() into its one caller"), invalidate_inode_page() can invalidate the pages in the swap cache because the check of page->mapping !=3D mapping is removed. But invalidate_inode_page() is not expected to deal with the pages in 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. 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 5f9503573263..23bfd809dc8c 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2185,7 +2185,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 Tue Jun 23 19:24:50 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 0E1A0C433EF for ; Mon, 28 Feb 2022 14:03:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236912AbiB1OE1 (ORCPT ); Mon, 28 Feb 2022 09:04:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232334AbiB1OEO (ORCPT ); Mon, 28 Feb 2022 09:04:14 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B3FB49F31 for ; Mon, 28 Feb 2022 06:03:35 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4K6hs526PWzdfkJ; Mon, 28 Feb 2022 22:02:17 +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; Mon, 28 Feb 2022 22:03:32 +0800 From: Miaohe Lin To: , CC: , , Subject: [PATCH 4/4] mm/memory-failure.c: fix potential VM_BUG_ON_PAGE in split_huge_page_to_list Date: Mon, 28 Feb 2022 22:02:45 +0800 Message-ID: <20220228140245.24552-5-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220228140245.24552-1-linmiaohe@huawei.com> References: <20220228140245.24552-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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" The huge zero page could reach here and if we ever try to split it, the VM_BUG_ON_PAGE will be triggered in split_huge_page_to_list(). Also the non-lru compound movable pages could be taken for transhuge pages. Skip these pages by checking PageLRU because huge zero page isn't lru page as non-lru compound movable pages. Signed-off-by: Miaohe Lin --- mm/memory-failure.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 23bfd809dc8c..ac6492e36978 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1792,6 +1792,20 @@ int memory_failure(unsigned long pfn, int flags) } =20 if (PageTransHuge(hpage)) { + /* + * The non-lru compound movable pages could be taken for + * transhuge pages. Also huge zero page could reach here + * and if we ever try to split it, the VM_BUG_ON_PAGE will + * be triggered in split_huge_page_to_list(). Skip these + * pages by checking PageLRU because huge zero page isn't + * lru page as non-lru compound movable pages. + */ + if (!PageLRU(hpage)) { + put_page(p); + action_result(pfn, MF_MSG_UNSPLIT_THP, MF_IGNORED); + res =3D -EBUSY; + goto unlock_mutex; + } /* * The flag must be set after the refcount is bumped * otherwise it may race with THP split. --=20 2.23.0