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)) {