From patchwork Mon Feb 28 14:02:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12763346 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 0BF78C433FE for ; Mon, 28 Feb 2022 14:03:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ACED08D0007; Mon, 28 Feb 2022 09:03:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A08D78D0001; Mon, 28 Feb 2022 09:03:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F6458D0007; Mon, 28 Feb 2022 09:03:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0108.hostedemail.com [216.40.44.108]) by kanga.kvack.org (Postfix) with ESMTP id 7906B8D0001 for ; Mon, 28 Feb 2022 09:03:38 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id D55FB9BE36 for ; Mon, 28 Feb 2022 14:03:36 +0000 (UTC) X-FDA: 79192356432.23.919EF84 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf31.hostedemail.com (Postfix) with ESMTP id DDE902001D for ; Mon, 28 Feb 2022 14:03:35 +0000 (UTC) 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 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 X-Rspamd-Server: rspam10 X-Rspam-User: X-Stat-Signature: fb41846j6dc8xrbxtndk3cd7twdrbt4m Authentication-Results: imf31.hostedemail.com; dkim=none; spf=pass (imf31.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspamd-Queue-Id: DDE902001D X-HE-Tag: 1646057015-958245 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: 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) } 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) != head) { + action_result(pfn, MF_MSG_DIFFERENT_COMPOUND, MF_IGNORED); + res = -EBUSY; + goto out; + } + page_flags = head->flags; if (hwpoison_filter(p)) { From patchwork Mon Feb 28 14:02:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12763345 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 C3A06C433EF for ; Mon, 28 Feb 2022 14:03:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3CC988D0006; Mon, 28 Feb 2022 09:03:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 28F9F8D0001; Mon, 28 Feb 2022 09:03:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A43D8D0006; Mon, 28 Feb 2022 09:03:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0080.hostedemail.com [216.40.44.80]) by kanga.kvack.org (Postfix) with ESMTP id 0121E8D0001 for ; Mon, 28 Feb 2022 09:03:37 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B98979ACBF for ; Mon, 28 Feb 2022 14:03:36 +0000 (UTC) X-FDA: 79192356432.22.26713B7 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf31.hostedemail.com (Postfix) with ESMTP id DB2C620012 for ; Mon, 28 Feb 2022 14:03:35 +0000 (UTC) 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 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 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: DB2C620012 X-Stat-Signature: yor4pcmuwm7mcsxn48cus5ebhad6rtc7 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.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspam-User: X-HE-Tag: 1646057015-797666 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: 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, struct page *p) static int me_swapcache_dirty(struct page_state *ps, struct page *p) { int ret; - bool extra_pins = false; ClearPageDirty(p); /* Trigger EIO in shmem: */ @@ -993,10 +992,7 @@ static int me_swapcache_dirty(struct page_state *ps, struct page *p) ret = delete_from_lru_cache(p) ? MF_FAILED : MF_DELAYED; unlock_page(p); - if (ret == MF_DELAYED) - extra_pins = true; - - if (has_extra_refcount(ps, p, extra_pins)) + if (has_extra_refcount(ps, p, true)) ret = MF_FAILED; return ret; From patchwork Mon Feb 28 14:02:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12763343 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 3317DC4332F for ; Mon, 28 Feb 2022 14:03:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 91F648D0003; Mon, 28 Feb 2022 09:03:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A9058D0005; Mon, 28 Feb 2022 09:03:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 747878D0003; Mon, 28 Feb 2022 09:03:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0048.hostedemail.com [216.40.44.48]) by kanga.kvack.org (Postfix) with ESMTP id 665F08D0001 for ; Mon, 28 Feb 2022 09:03:37 -0500 (EST) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 1E5D38249980 for ; Mon, 28 Feb 2022 14:03:37 +0000 (UTC) X-FDA: 79192356474.31.708BD55 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf25.hostedemail.com (Postfix) with ESMTP id 64837A001D for ; Mon, 28 Feb 2022 14:03:36 +0000 (UTC) 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 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 X-Rspamd-Queue-Id: 64837A001D X-Stat-Signature: eqbfgct9gn79tz9rap4mhuh6ohmzeond Authentication-Results: imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1646057016-690081 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: 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 != 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; } - if (!PageHuge(page)) + if (!PageHuge(page) && PageLRU(page) && !PageSwapCache(page)) /* * Try to invalidate first. This should work for * non dirty unmapped page cache pages. From patchwork Mon Feb 28 14:02:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12763342 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 D07B1C433F5 for ; Mon, 28 Feb 2022 14:03:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3EF458D0002; Mon, 28 Feb 2022 09:03:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 39E7C8D0001; Mon, 28 Feb 2022 09:03:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 28EDA8D0002; Mon, 28 Feb 2022 09:03:37 -0500 (EST) 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 1B22A8D0001 for ; Mon, 28 Feb 2022 09:03:37 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C61C1614CC for ; Mon, 28 Feb 2022 14:03:36 +0000 (UTC) X-FDA: 79192356432.14.3D08BEC Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf12.hostedemail.com (Postfix) with ESMTP id BD3AB40005 for ; Mon, 28 Feb 2022 14:03:35 +0000 (UTC) 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 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 X-Rspamd-Queue-Id: BD3AB40005 X-Stat-Signature: rorjn76jn99ubxx6knq1g8f4sfcb8bmb X-Rspam-User: Authentication-Results: imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspamd-Server: rspam07 X-HE-Tag: 1646057015-885239 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: 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) } 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 = -EBUSY; + goto unlock_mutex; + } /* * The flag must be set after the refcount is bumped * otherwise it may race with THP split.