Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1450816pxp; Thu, 17 Mar 2022 09:26:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz79yx0QDFSTiaN4FfXOkvcEySr9GlZkysCWACB9YQ/sDbWuZPui9oSRiDwTSqkGGVc5LXX X-Received: by 2002:a17:903:2341:b0:150:2371:ee59 with SMTP id c1-20020a170903234100b001502371ee59mr5554898plh.57.1647534382826; Thu, 17 Mar 2022 09:26:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647534382; cv=none; d=google.com; s=arc-20160816; b=Rly2EBZkrw+JuDDV8ev0Rp9SHdAKsNmP4h/LctlGaYKH0jVZSWUysIR/PJCuY1aW84 vTAgL/EUdUTHXDHXH7+XXDVq5mrqOI58r9jr9HUCPpMOu4oh45TBZD9Sojc2pL4Gp9ah C8UqsnATf6Svp3NYcx7XvDnCgSVGb6PcGsVlMYu0NHbyK2m/G0VscihhdCMQofEa+oGE X6TZ5/Wheillna5xsIW6nv/3OoaBSz7RZtRXbs0Y3ddU/K0g+AYt0ns1xzaQDbEhyLCp pqEv+bsZQBLMKed6/fOu1uzQlgXq0R7Grrdi9PZj4oMkwJQgtCZLjZ19ZTZJ+2z2Yc6G Rb2A== 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=DHODRIz3hrckIzJZTeHbCHaq9PVlF2hnRi8NtUKdhrY=; b=HreR3vZNmRpBq1gaviq2dspRMb/8HlziTltJx21uzbYwWuElpALFoNlwyJlKUjNkUu 4P+LQ/rytBbBk/eTESk53Bxr/2uW1CMCR/hrWA8on7lqK07gtfNM1hW7aakYmdtWEsXr v6najMP5tXu8mrV1T3oAa5RQHeJ1NTUBshzm5fV7xafwiS0/rMPcMKtB4G9O8KTtTSv/ kdhJEpeSFgUb7mTQv0x9Y3faqRl7q5d+KjAtl34vFZCoR5vG2EgfVU34bAi9gzlGGEt7 dQPctPXJmww0wCGY+n8V60fT9XUFR1zZll3fJyMwG+WkAacFReB5UzXXyEy7F2Mwfhtr 1ZcA== 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 h15-20020a170902f54f00b001539db53169si5277976plf.344.2022.03.17.09.26.06; Thu, 17 Mar 2022 09:26:22 -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 S235371AbiCQOnm (ORCPT + 99 others); Thu, 17 Mar 2022 10:43:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235417AbiCQOnL (ORCPT ); Thu, 17 Mar 2022 10:43:11 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1588200946 for ; Thu, 17 Mar 2022 07:41:54 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KK8vC6qVqzfZFk; Thu, 17 Mar 2022 22:40:23 +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; Thu, 17 Mar 2022 22:41:52 +0800 From: Miaohe Lin To: CC: , , , , , , , Subject: [PATCH v2 09/11] mm/migration: fix potential page refcounts leak in migrate_pages Date: Fri, 18 Mar 2022 19:17:07 +0800 Message-ID: <20220318111709.60311-10-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220318111709.60311-1-linmiaohe@huawei.com> References: <20220318111709.60311-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.124.27] 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=-1.0 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_12_24, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 In -ENOMEM case, there might be some subpages of fail-to-migrate THPs left in thp_split_pages list. We should move them back to migration list so that they could be put back to the right list by the caller otherwise the page refcnt will be leaked here. Also adjust nr_failed and nr_thp_failed accordingly to make vm events account more accurate. Fixes: b5bade978e9b ("mm: migrate: fix the return value of migrate_pages()") Signed-off-by: Miaohe Lin Reviewed-by: Zi Yan Reviewed-by: "Huang, Ying" Reviewed-by: Baolin Wang --- mm/migrate.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/migrate.c b/mm/migrate.c index 63a87ef0996f..97dfd1f4870d 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1438,6 +1438,14 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, } nr_failed_pages += nr_subpages; + /* + * There might be some subpages of fail-to-migrate THPs + * left in thp_split_pages list. Move them back to migration + * list so that they could be put back to the right list by + * the caller otherwise the page refcnt will be leaked. + */ + list_splice_init(&thp_split_pages, from); + nr_thp_failed += thp_retry; goto out; case -EAGAIN: if (is_thp) -- 2.23.0