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 42C30C433EF for ; Fri, 18 Mar 2022 07:08:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 958468D0002; Fri, 18 Mar 2022 03:08:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E0FB8D0001; Fri, 18 Mar 2022 03:08:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7828D8D0002; Fri, 18 Mar 2022 03:08:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0207.hostedemail.com [216.40.44.207]) by kanga.kvack.org (Postfix) with ESMTP id 69B528D0001 for ; Fri, 18 Mar 2022 03:08:06 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1D12EA3EF0 for ; Fri, 18 Mar 2022 07:08:06 +0000 (UTC) X-FDA: 79256627772.22.5500525 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf31.hostedemail.com (Postfix) with ESMTP id 6F93720010 for ; Fri, 18 Mar 2022 07:08:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1647587285; x=1679123285; h=date:from:to:cc:subject:message-id:mime-version; bh=3+ru1OtoV1JaDhmrBMAF64b5LEXwd/7ge8uP0B7ptPs=; b=crWYt3ua54k2cO8IXlhY6dLfOOd/IuN0ulhfYHMVlKG0jl4XGHzkVupF bt66GIHhZ4eMtfn9pbFgjhojCgUkIn6jPWUYyqKWg0d4elvuuI1unEBVX ipRhqfehZlG2RAXVtlzV/xT4N2RDe+ee7fOyQpBFRfqar0uxt8mwKaMVL XaY9g2P0Xp1wyqpaoJZixcUmPsPpG3L8BX6waB9hDn3xQ+9x+bPRAVZbY NCVeAbAVg2+iTTxfC7fBuk0IzA1nPU8LwJBIMREVZMuoep9geD0r/N7SM kcFab9evsA/eei2lg5+KozZuyq7JFfgx2eW6XSaHrjyk9w/5O72wd4Nly g==; X-IronPort-AV: E=McAfee;i="6200,9189,10289"; a="255903403" X-IronPort-AV: E=Sophos;i="5.90,191,1643702400"; d="scan'208";a="255903403" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2022 00:08:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,191,1643702400"; d="scan'208";a="541712979" Received: from shbuild999.sh.intel.com (HELO localhost) ([10.239.146.138]) by orsmga007.jf.intel.com with ESMTP; 18 Mar 2022 00:08:01 -0700 Date: Fri, 18 Mar 2022 15:08:00 +0800 From: Feng Tang To: Miaohe Lin , akpm@linux-foundation.org Cc: ziy@nvidia.com, baolin.wang@linux.alibaba.com, ying.huang@intel.com, songmuchun@bytedance.com, apopple@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 09/11] mm/migration: fix potential page refcounts leak in migrate_pages Message-ID: <20220318070800.GB436@shbuild999.sh.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Rspamd-Queue-Id: 6F93720010 X-Stat-Signature: rceijyzzex6q9o53epibkti544m3qmuw X-Rspam-User: Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=crWYt3ua; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf31.hostedemail.com: domain of feng.tang@intel.com has no SPF policy when checking 192.55.52.120) smtp.mailfrom=feng.tang@intel.com X-Rspamd-Server: rspam02 X-HE-Tag: 1647587285-874493 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: > 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 :). So I think you can remove the 'potential' from the patch subject. Feel free to add Tested-by: Feng Tang Reviewed-by: Feng Tang 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