From patchwork Tue Mar 22 21:44:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12789199 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 D2D0BC43217 for ; Tue, 22 Mar 2022 21:44:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C0256B010A; Tue, 22 Mar 2022 17:44:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6479D6B010B; Tue, 22 Mar 2022 17:44:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 538AC6B010C; Tue, 22 Mar 2022 17:44:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 449736B010A for ; Tue, 22 Mar 2022 17:44:25 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 21FA3813A4 for ; Tue, 22 Mar 2022 21:44:25 +0000 (UTC) X-FDA: 79273351290.04.ADF7F1F Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf22.hostedemail.com (Postfix) with ESMTP id 7F156C0030 for ; Tue, 22 Mar 2022 21:44:24 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7A944B81D77; Tue, 22 Mar 2022 21:44:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F3C2C340F4; Tue, 22 Mar 2022 21:44:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1647985462; bh=5knbsc9OlMkSq/1JDIMEwr7Iq1plkwPjCJe2HFT5o5s=; h=Date:To:From:In-Reply-To:Subject:From; b=MeK1pPSadAhOJHBjCXNBdOmV+lXNgwsEfcOI13rfFlmV9IErLT7PNfJfGbBAVpHrZ cbcxiG7B3uFjJbh0Uxn7g6odnIgKVY30iMto9aENL2BdtTrO8t+2c/pyvwk6/apStt gnte1kXO3Hf7vQjMK2HKUtlR4E2cXLaOvsipj5hk= Date: Tue, 22 Mar 2022 14:44:21 -0700 To: naoya.horiguchi@nec.com,linmiaohe@huawei.com,akpm@linux-foundation.org,patches@lists.linux.dev,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220322143803.04a5e59a07e48284f196a2f9@linux-foundation.org> Subject: [patch 115/227] mm/memory-failure.c: fix race with changing page more robustly Message-Id: <20220322214422.0F3C2C340F4@smtp.kernel.org> X-Rspam-User: Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=MeK1pPSa; spf=pass (imf22.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 7F156C0030 X-Stat-Signature: wb8wwpa74hixdijie8zg53h1qrfpkpjk X-HE-Tag: 1647985464-759643 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: Miaohe Lin Subject: mm/memory-failure.c: fix race with changing page more robustly 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 due to race window. If this happens, we could retry once to hopefully handle the 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. Link: https://lkml.kernel.org/r/20220218090118.1105-5-linmiaohe@huawei.com Signed-off-by: Miaohe Lin Acked-by: Naoya Horiguchi Signed-off-by: Andrew Morton --- mm/memory-failure.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) --- a/mm/memory-failure.c~mm-memory-failurec-fix-race-with-changing-page-more-robustly +++ a/mm/memory-failure.c @@ -1686,7 +1686,6 @@ int memory_failure(unsigned long pfn, in { struct page *p; struct page *hpage; - struct page *orig_head; struct dev_pagemap *pgmap; int res = 0; unsigned long page_flags; @@ -1732,7 +1731,7 @@ try_again: goto unlock_mutex; } - orig_head = hpage = compound_head(p); + hpage = compound_head(p); num_poisoned_pages_inc(); /* @@ -1813,10 +1812,21 @@ try_again: lock_page(p); /* - * 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) != orig_head) { + if (PageCompound(p)) { + if (retry) { + if (TestClearPageHWPoison(p)) + num_poisoned_pages_dec(); + unlock_page(p); + put_page(p); + flags &= ~MF_COUNT_INCREASED; + retry = false; + goto try_again; + } action_result(pfn, MF_MSG_DIFFERENT_COMPOUND, MF_IGNORED); res = -EBUSY; goto unlock_page;