From mboxrd@z Thu Jan 1 00:00:00 1970 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 BC6A0C433EF for ; Wed, 16 Feb 2022 09:15:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F90C6B0088; Wed, 16 Feb 2022 04:15:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4BBDA6B0082; Wed, 16 Feb 2022 04:15:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 205E36B0083; Wed, 16 Feb 2022 04:15:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0036.hostedemail.com [216.40.44.36]) by kanga.kvack.org (Postfix) with ESMTP id DDB606B0082 for ; Wed, 16 Feb 2022 04:15:19 -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 A235690931 for ; Wed, 16 Feb 2022 09:15:19 +0000 (UTC) X-FDA: 79148084358.22.6087654 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf12.hostedemail.com (Postfix) with ESMTP id CFD4B40009 for ; Wed, 16 Feb 2022 09:15:17 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4JzByP2Vqdz1FCsp; Wed, 16 Feb 2022 17:10:53 +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; Wed, 16 Feb 2022 17:15:14 +0800 From: Miaohe Lin To: , CC: , , Subject: [PATCH v2 4/8] mm/memory-failure.c: fix race with changing page more robustly Date: Wed, 16 Feb 2022 17:14:27 +0800 Message-ID: <20220216091431.39406-5-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220216091431.39406-1-linmiaohe@huawei.com> References: <20220216091431.39406-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Type: text/plain 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 X-Rspamd-Queue-Id: CFD4B40009 X-Rspam-User: Authentication-Results: imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Stat-Signature: 4rp5td1e6g1aebmdsen4z4fitjuo3p69 X-Rspamd-Server: rspam03 X-HE-Tag: 1645002917-308845 Content-Transfer-Encoding: quoted-printable 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: We're only intended to deal with the non-Compound page after we split thp in memory_failure. However, the page could have changed compound pages du= e to race window. If this happens, we could try again to hopefully handle t= he page next round. Also remove unneeded orig_head. It's always equal to the hpage. So we can use hpage directly and remove this redundant one. Signed-off-by: Miaohe Lin --- mm/memory-failure.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 7e205d91b2d7..d66f642888be 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1690,7 +1690,6 @@ int memory_failure(unsigned long pfn, int flags) { struct page *p; struct page *hpage; - struct page *orig_head; struct dev_pagemap *pgmap; int res =3D 0; unsigned long page_flags; @@ -1736,7 +1735,7 @@ int memory_failure(unsigned long pfn, int flags) goto unlock_mutex; } =20 - orig_head =3D hpage =3D compound_head(p); + hpage =3D compound_head(p); num_poisoned_pages_inc(); =20 /* @@ -1817,13 +1816,18 @@ int memory_failure(unsigned long pfn, int flags) lock_page(p); =20 /* - * The page could have changed compound pages during the locking. - * If this happens just bail out. + * We're only intended to deal with the non-Compound page here. + * However, the page could have changed compound pages due to + * race window. If this happens, we could try again to hopefully + * handle the page next round. */ - if (PageCompound(p) && compound_head(p) !=3D orig_head) { - action_result(pfn, MF_MSG_DIFFERENT_COMPOUND, MF_IGNORED); - res =3D -EBUSY; - goto unlock_page; + if (PageCompound(p)) { + if (TestClearPageHWPoison(p)) + num_poisoned_pages_dec(); + unlock_page(p); + put_page(p); + flags &=3D ~MF_COUNT_INCREASED; + goto try_again; } =20 /* --=20 2.23.0