From patchwork Tue Jul 11 05:50:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 118265 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp266496vqm; Mon, 10 Jul 2023 22:59:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlEqI+5IE1QUiMDeRZywcXNJwKnm2cvbFzc4cbOU//a406dsX/LMxEtB/gDLOcYVaUlbfaGU X-Received: by 2002:a17:902:c410:b0:1b8:ad90:7af8 with SMTP id k16-20020a170902c41000b001b8ad907af8mr28242617plk.17.1689055198906; Mon, 10 Jul 2023 22:59:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689055198; cv=none; d=google.com; s=arc-20160816; b=wPYyCR84D8OwNBfHb2dCrY/fvU89qAnlqYmomxqG/ySotO8xA7oTJ6z4jBDE9RaAWR d6EgDlg8kJskyoL9OI8EM3t8j7PPVGPICwH3Ya5mq9BqOGSGjx/ZWhOZnKoyGf8nrvq+ T9kVjAR5XzavF2BRYRDo1An3nR/WeSP+asGUOw6EVsttYoC9E2KqkEkEn+DF1Zt0Ih8r 0ncLIUr6viNsV9laAmuGLxGybk560cES9yTBp5tMxzQGjss/EFxn207lRaYvcFidiRxd EiT1/kqGe3s/QJgI4XK0wzj89BeH5LIecnNhW8pZFHnqs6xcCYNGa2r0rR/blgiFubOO WVxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=IV0T4/Lz70cuW+hklOvSGRAWozfHSplI/Flw5cVKpWk=; fh=4o7DIXI/66oHEW09L3854GeQKXh9nrvBy5ZxENMFBvA=; b=VzBXrpLZfksc8PeY/r7kkdtQUQ0qUPVMKsfeijiYvWzB81YdeWODaFFQfbI/S+Wzzx 7nscn1tuAUh5La7mVPDS+l3sNOnalB7xiTkepODDi3KAuBdo6ySJ17Ll5lHwx21Oj4WI GO2PQxWOrfwke3CwHUTBReV3a1Xv0fPTAIEM9qhX+bWZrpsunpdOgzlGivVVJjDHnlWE r0mHXHdVLENky4VbS5ldR7/HsVcKUTBqYPviSwN8gBCZwr6Xw9FOE8MlSBTM8wRYy0FY t5nQxYDeZBXs0hwJn5dI3luzx5mjMlvcxfVN7NjKuYUKOpcvC+Z7jzDulKchIRCGzVvf Rn/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z8-20020a170902d54800b001b3bd85f54bsi1026851plf.35.2023.07.10.22.59.45; Mon, 10 Jul 2023 22:59:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231179AbjGKFuc (ORCPT + 99 others); Tue, 11 Jul 2023 01:50:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230035AbjGKFuJ (ORCPT ); Tue, 11 Jul 2023 01:50:09 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EAA81BB for ; Mon, 10 Jul 2023 22:50:06 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4R0VJd66LkzPk1v; Tue, 11 Jul 2023 13:47:45 +0800 (CST) Received: from huawei.com (10.174.151.185) 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.2507.27; Tue, 11 Jul 2023 13:50:04 +0800 From: Miaohe Lin To: , CC: , , Subject: [PATCH v2 7/8] mm: memory-failure: fetch compound head after extra page refcnt is held Date: Tue, 11 Jul 2023 13:50:15 +0800 Message-ID: <20230711055016.2286677-8-linmiaohe@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230711055016.2286677-1-linmiaohe@huawei.com> References: <20230711055016.2286677-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771102744053758688 X-GMAIL-MSGID: 1771102744053758688 Page might become thp, huge page or being splited after compound head is fetched but before page refcnt is bumped. So hpage might be a tail page leading to VM_BUG_ON_PAGE(PageTail(page)) in PageTransHuge(). Fixes: 415c64c1453a ("mm/memory-failure: split thp earlier in memory error handling") Signed-off-by: Miaohe Lin Acked-by: Naoya Horiguchi --- mm/memory-failure.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index db4c530944d6..af34fd4669d3 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2186,8 +2186,6 @@ int memory_failure(unsigned long pfn, int flags) goto unlock_mutex; } - hpage = compound_head(p); - /* * We need/can do nothing about count=0 pages. * 1) it's a free page, and therefore in safe hand: @@ -2226,6 +2224,7 @@ int memory_failure(unsigned long pfn, int flags) } } + hpage = compound_head(p); if (PageTransHuge(hpage)) { /* * The flag must be set after the refcount is bumped