From patchwork Sat Jul 8 08:57:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 117421 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp3807230vqx; Sat, 8 Jul 2023 02:26:24 -0700 (PDT) X-Google-Smtp-Source: APBJJlE40mcTEYkKGmpeQ66sbrUkKBOJji7cqFTQcswdStXYy55bihUh2xfNaXWAm3AgsaoSAmGz X-Received: by 2002:a92:c68b:0:b0:345:d741:33d with SMTP id o11-20020a92c68b000000b00345d741033dmr7417210ilg.20.1688808384593; Sat, 08 Jul 2023 02:26:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688808384; cv=none; d=google.com; s=arc-20160816; b=o9FmM07dAIWdsWo+86t4wOvWouYJv2pOBsYbi5vu5JSbP1Gv+unht7m1M3aJxUobN8 3opaBeNMjdg4wxiGRldOI2xKpw5T76ltEDEw46tPfENnZ9cu2VDP/Y769QNfBbXd+2hI DahTsEQdG6zyLRtClwqosr5CJwbu2URbJ7DfvUcZ2NZ1TyS3x2qH/atzAIahcGVDqnxq zeGREyGCXSyNMog6TmT1MzzhfvvSTFExiW9jWaNiRX0tTwND32Dni5msDIENp2QIVoAc UWKFYHsEUFsKcif7hMzIhzDfVLfcPHSBfEFoslmeaP023pMIoVPrhABhd2ijO2dobUHG 5yfg== 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=4zvreph+WtV4FNPz7Sph1CKBbIMj5dh6CNbYbbIKYXM=; fh=4o7DIXI/66oHEW09L3854GeQKXh9nrvBy5ZxENMFBvA=; b=pq2mFokjpa4GbEua/fpNjT43GB+lgLCkHvkkRKVKHA4vb8oV57sx1j8ZGjejTXikJW dggJk5RmmBTE78C7DCHsDNTdteC8QsyAo2j3aCuGUsMa6AXK0POi39dRPzpbWhZOielX KSFFxCwaAyg4J6ODDbsQ6WgwA8go+PU/DLmIj+vEAzXT2stfxI6qAjhSq1xwyl+nGbc3 tXMSEE1GPgnX3aX8nJB+CFH3EynPDoegas8/UthEIKJ1PCF0kgZXdIM3Rq+/QYZ+QBbi iwQ3DijEkjvwL/yCqh+4Wl29atHP+yN2vxvlEtbUnR/5LH5huecC/jyvo4NPcSD8nEET M1nw== 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 r17-20020a170902c61100b001b89f814e78si4927840plr.559.2023.07.08.02.26.11; Sat, 08 Jul 2023 02:26:24 -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 S231316AbjGHI5w (ORCPT + 99 others); Sat, 8 Jul 2023 04:57:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbjGHI5g (ORCPT ); Sat, 8 Jul 2023 04:57:36 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1968A2114 for ; Sat, 8 Jul 2023 01:57:35 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Qykbc53xHztQnv; Sat, 8 Jul 2023 16:54:36 +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; Sat, 8 Jul 2023 16:57:31 +0800 From: Miaohe Lin To: , CC: , , Subject: [PATCH 7/8] mm: memory-failure: fetch compound head after extra page refcnt is held Date: Sat, 8 Jul 2023 16:57:43 +0800 Message-ID: <20230708085744.3599311-8-linmiaohe@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230708085744.3599311-1-linmiaohe@huawei.com> References: <20230708085744.3599311-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770843940848204430?= X-GMAIL-MSGID: =?utf-8?q?1770843940848204430?= 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 0f93175ed862..76d88d27cdbe 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2179,8 +2179,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: @@ -2219,6 +2217,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