Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp36352852rwd; Mon, 10 Jul 2023 23:06:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlGZe/5SSiCFa86cQi+G3LTh+pTjoobkWKUJDBEFQYM9jU/0lb9J88iXLf614RugabKeYE6Y X-Received: by 2002:a05:6a20:12c8:b0:f0:50c4:4c43 with SMTP id v8-20020a056a2012c800b000f050c44c43mr20738824pzg.5.1689055583275; Mon, 10 Jul 2023 23:06:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689055583; cv=none; d=google.com; s=arc-20160816; b=1CLiYCVcqkx5JlFmbl38GJvHJteODmeceuHaHS22It7KTPpaDEZ1rWb84v7PTodmoQ gp2EueGBJt1wN9J7qnVFCjBya6cfxTN67qUTauA+as92Ou8tbHFeaVQRT15J2jvyLzc0 an9D0HQglUTbNhsxB7jYOUFI/CZ4bwCz2WXcBrrNOy/JINKYOAP24WTyL2nmdF96rn55 q87TnKFIm4Xdc8OpuGka7uIRL2YOdaqW1DAxtLG6Z5ivEn9uJDbwcVTeXMDQB12ja3in zQp1k4XhrznoMDaFCbErpMHJ7QhB/72wQIhntox904cnLUgFuaTetm7CklLfAAhUwzkf Qyow== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a21-20020a63e855000000b00557848bf4d7si854598pgk.798.2023.07.10.23.06.10; Mon, 10 Jul 2023 23:06:23 -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 S230397AbjGKFub (ORCPT + 99 others); Tue, 11 Jul 2023 01:50:31 -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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 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 -- 2.33.0