From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65C00C433F5 for ; Fri, 18 Mar 2022 08:24:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A3B648D0002; Fri, 18 Mar 2022 04:24:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9EB298D0001; Fri, 18 Mar 2022 04:24:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D9608D0002; Fri, 18 Mar 2022 04:24:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 7DB448D0001 for ; Fri, 18 Mar 2022 04:24:36 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4682C23EFF for ; Fri, 18 Mar 2022 08:24:36 +0000 (UTC) X-FDA: 79256820552.13.C1C751D Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf17.hostedemail.com (Postfix) with ESMTP id 1AD8340026 for ; Fri, 18 Mar 2022 08:24:34 +0000 (UTC) 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-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 1AD8340026 X-Stat-Signature: eamccjncirybnicsfonowz9bx6yp4swc Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf17.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-HE-Tag: 1647591874-713656 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 > > . >