linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Li Xinhai" <lixinhai.lxh@gmail.com>
To: yang.shi <yang.shi@linux.alibaba.com>,
	 "Vlastimil Babka" <vbabka@suse.cz>,  mhocko <mhocko@suse.com>,
	 mgorman <mgorman@techsingularity.net>,
	 akpm <akpm@linux-foundation.org>
Cc: stable <stable@vger.kernel.org>,
	 "linux-mm@kvack.org" <linux-mm@kvack.org>,
	 "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: Re: [PATCH] mm: mempolicy: fix the wrong return value and potential pages leak of mbind
Date: Thu, 31 Oct 2019 09:53:40 +0800	[thread overview]
Message-ID: <201910310953383205323@gmail.com> (raw)
In-Reply-To: <12ac5b41-27a6-5a5b-0d07-7e9cb847829d@linux.alibaba.com>

On 2019-10-31 at 02:14 Yang Shi wrote:
>
>
>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")
> 
Looks good to me.
Reviewed-by: Li Xinhai <lixinhai.lxh@gmail.com>

>> Reported-by: Li Xinhai <lixinhai.lxh@gmail.com>
>> Cc: Vlastimil Babka <vbabka@suse.cz>
>> Cc: Michal Hocko <mhocko@suse.com>
>> Cc: Mel Gorman <mgorman@techsingularity.net>
>> Cc: <stable@vger.kernel.org> v4.19 and v5.2+
>> Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
>> ---
>>   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);
>

  reply	other threads:[~2019-10-31  1:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-30 16:58 Yang Shi
2019-10-30 18:14 ` Yang Shi
2019-10-31  1:53   ` Li Xinhai [this message]
2019-10-31  4:31   ` Andrew Morton
2019-10-31  5:28     ` Li Xinhai
2019-10-31 15:47     ` Yang Shi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201910310953383205323@gmail.com \
    --to=lixinhai.lxh@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    --cc=mhocko@suse.com \
    --cc=stable@vger.kernel.org \
    --cc=vbabka@suse.cz \
    --cc=yang.shi@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox