Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2057072pxp; Fri, 18 Mar 2022 02:04:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6hUY1nlQq6I5KU2YBjQYr4CAkdM1Cbi6r8G+KPfRvK2qNGVRXJbghqkK+4Lzy9hDk9/dV X-Received: by 2002:a63:7502:0:b0:37f:f089:7d56 with SMTP id q2-20020a637502000000b0037ff0897d56mr7015501pgc.531.1647594247974; Fri, 18 Mar 2022 02:04:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647594247; cv=none; d=google.com; s=arc-20160816; b=eEQSwNeVqQyRh0iOX9kF6imqeTGG5qv95zohwfufrlCFXAEEd39RouzjA4HLA01thF O424wjKiQS7+dm5hPGr2m6TkxUq+1FOR2oW8YY9yHvqHj6bSrvLIEWWsKmpfp8+e2+CI ZIDSV2e1ZA4617aOabFMFOwmpZVUh8djYkEfg1iVVds54a2tx7rKmvhkGFp3DGtTqYhG a/zuPpTeSyYYOmQYJT+VSl6MZ/fWU91j9MD0HjLL/hQS24CN77Ki7kMp2kxoC370ibD5 R2MT54JTyT3nfoWpA0sElVDjxhUf+ciHCNGc3JYWHJAgyWhnTR+3IqtT+77krspOr6rD 2ZuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=ZaoXM2KrrC0pdZgojdsNFensGJayQcP3+uetOkOzI2U=; b=zenbkiBZYhCNgoKJEAgfDjBdadbmYHpeimY1FWw1oOFtT2a1yv0QjniTyxxmMDpOJj vz9mGDVH2EBmSZbeumQRJjzVQjcuCweGGe67BOG1Ze6Dp5ve31vR2fZyPUKlw2goRMbH F9ctyhnoZ+24E6Y0s/z6zBETegET7evcwSlxNGJ8Jq46HkKOmsslprfXGfTzuxtZ86p2 VejcbJcVISedlqbtRbtonTcl9lPMYP0XNVVzc6OKTfjlHs3S2SScVRwaqfztT5hELToN J15gILWrVPJCcBCrYGAR+rA2glEGEq9nrIVUUlzTH469Zfjux0j5fHTYfieCrhHwV+P2 UWzg== 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 d3-20020a170902c18300b00153f4626e44si1520788pld.397.2022.03.18.02.03.54; Fri, 18 Mar 2022 02:04:07 -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 S233743AbiCRIZy (ORCPT + 99 others); Fri, 18 Mar 2022 04:25:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233603AbiCRIZv (ORCPT ); Fri, 18 Mar 2022 04:25:51 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C494585978 for ; Fri, 18 Mar 2022 01:24:31 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4KKcQZ6QVkz9sg4; Fri, 18 Mar 2022 16:20:38 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) 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; Fri, 18 Mar 2022 16:24:29 +0800 Subject: Re: [PATCH v2 09/11] mm/migration: fix potential page refcounts leak in migrate_pages To: Feng Tang CC: , , , , , , , Andrew Morton References: <20220318070800.GB436@shbuild999.sh.intel.com> From: Miaohe Lin Message-ID: <4953e998-c088-29f7-e240-d27513bbfc93@huawei.com> Date: Fri, 18 Mar 2022 16:24:28 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20220318070800.GB436@shbuild999.sh.intel.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.76] 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,NICE_REPLY_A, 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 On 2022/3/18 15:08, Feng Tang wrote: >> 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. > > We just met a real world case for this when checking a malloc-oom > issue and our fix is similar with yours :). > Oh, what a coincidence! :) > So I think you can remove the 'potential' from the patch subject. > Feel free to add > > Tested-by: Feng Tang > Reviewed-by: Feng Tang Many thanks for your test and comment! > > Thanks, > Feng > >> 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 > > . >