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 X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25EC6CA9EC6 for ; Wed, 30 Oct 2019 18:15:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 96DC4208E3 for ; Wed, 30 Oct 2019 18:15:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 96DC4208E3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 316596B0266; Wed, 30 Oct 2019 14:15:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2C5AA6B0269; Wed, 30 Oct 2019 14:15:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1DBFE6B026A; Wed, 30 Oct 2019 14:15:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0104.hostedemail.com [216.40.44.104]) by kanga.kvack.org (Postfix) with ESMTP id EDBE66B0266 for ; Wed, 30 Oct 2019 14:15:11 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 917BD81F6 for ; Wed, 30 Oct 2019 18:15:11 +0000 (UTC) X-FDA: 76101252822.22.bat83_2d3397abe1a21 X-HE-Tag: bat83_2d3397abe1a21 X-Filterd-Recvd-Size: 4311 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Wed, 30 Oct 2019 18:15:10 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04423;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0Tgir3np_1572459299; Received: from US-143344MP.local(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0Tgir3np_1572459299) by smtp.aliyun-inc.com(127.0.0.1); Thu, 31 Oct 2019 02:15:07 +0800 Subject: Re: [PATCH] mm: mempolicy: fix the wrong return value and potential pages leak of mbind To: lixinhai.lxh@gmail.com, vbabka@suse.cz, mhocko@suse.com, mgorman@techsingularity.net, akpm@linux-foundation.org Cc: stable@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <1572454731-3925-1-git-send-email-yang.shi@linux.alibaba.com> From: Yang Shi Message-ID: <12ac5b41-27a6-5a5b-0d07-7e9cb847829d@linux.alibaba.com> Date: Wed, 30 Oct 2019 11:14:58 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <1572454731-3925-1-git-send-email-yang.shi@linux.alibaba.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US 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 10/30/19 9:58 AM, Yang Shi wrote: > The commit d883544515aa ("mm: mempolicy: make the behavior consistent > when MPOL_MF_MOVE* and MPOL_MF_STRICT were specified") fixed the return > value of mbind() for a couple of corner cases. But, it altered the > errno for some other cases, for example, mbind() should return -EFAULT > when part or all of the memory range specified by nodemask and maxnode > points outside your accessible address space, or there was an unmapped > hole in the specified memory range specified by addr and len. > > Fixed this by preserving the errno returned by queue_pages_range(). > And, the pagelist may be not empty even though queue_pages_range() > returns error, put the pages back to LRU since mbind_range() is not called > to really apply the policy so those pages should not be migrated, this > is also the old behavior before the problematic commit. Forgot fixes tag. Fixes: d883544515aa ("mm: mempolicy: make the behavior consistent when MPOL_MF_MOVE* and MPOL_MF_STRICT were specified") > Reported-by: Li Xinhai > Cc: Vlastimil Babka > Cc: Michal Hocko > Cc: Mel Gorman > Cc: v4.19 and v5.2+ > Signed-off-by: Yang Shi > --- > mm/mempolicy.c | 14 +++++++++----- > 1 file changed, 9 insertions(+), 5 deletions(-) > > diff --git a/mm/mempolicy.c b/mm/mempolicy.c > index 4ae967b..e08c941 100644 > --- a/mm/mempolicy.c > +++ b/mm/mempolicy.c > @@ -672,7 +672,9 @@ static int queue_pages_test_walk(unsigned long start, unsigned long end, > * 1 - there is unmovable page, but MPOL_MF_MOVE* & MPOL_MF_STRICT were > * specified. > * 0 - queue pages successfully or no misplaced page. > - * -EIO - there is misplaced page and only MPOL_MF_STRICT was specified. > + * errno - i.e. misplaced pages with MPOL_MF_STRICT specified (-EIO) or > + * memory range specified by nodemask and maxnode points outside > + * your accessible address space (-EFAULT) > */ > static int > queue_pages_range(struct mm_struct *mm, unsigned long start, unsigned long end, > @@ -1286,7 +1288,7 @@ static long do_mbind(unsigned long start, unsigned long len, > flags | MPOL_MF_INVERT, &pagelist); > > if (ret < 0) { > - err = -EIO; > + err = ret; > goto up_out; > } > > @@ -1305,10 +1307,12 @@ static long do_mbind(unsigned long start, unsigned long len, > > if ((ret > 0) || (nr_failed && (flags & MPOL_MF_STRICT))) > err = -EIO; > - } else > - putback_movable_pages(&pagelist); > - > + } else { > up_out: > + if (!list_empty(&pagelist)) > + putback_movable_pages(&pagelist); > + } > + > up_write(&mm->mmap_sem); > mpol_out: > mpol_put(new);