All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: zhong jiang <zhongjiang@huawei.com>,
	mhocko@kernel.org, anshuman.khandual@arm.com, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, Ira Weiny <ira.weiny@intel.com>,
	"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Subject: Re: [PATCH] mm: Unsigned 'nr_pages' always larger than zero
Date: Wed, 4 Sep 2019 22:40:22 +0200	[thread overview]
Message-ID: <29d686c3-9407-e953-42f4-a4224b9333e7@suse.cz> (raw)
In-Reply-To: <20190904114820.42d9c4daf445ded3d0da52ab@linux-foundation.org>

On 9/4/19 8:48 PM, Andrew Morton wrote:
> On Wed, 4 Sep 2019 13:24:58 +0200 Vlastimil Babka <vbabka@suse.cz> wrote:
> 
>> On 9/4/19 12:26 PM, zhong jiang wrote:
>>> With the help of unsigned_lesser_than_zero.cocci. Unsigned 'nr_pages"'
>>> compare with zero. And __get_user_pages_locked will return an long value.
>>> Hence, Convert the long to compare with zero is feasible.
>>
>> It would be nicer if the parameter nr_pages was long again instead of unsigned
>> long (note there are two variants of the function, so both should be changed).
> 
> nr_pages should be unsigned - it's a count of pages!

Hm right, I thought check_and_migrate_cma_pages() could be already
called with negative nr_pages from __gup_longterm_locked(), but I missed
there's a if (rc < 0) goto out before that.

> The bug is that __get_user_pages_locked() returns a signed long which
> can be a -ve errno.
> 
> I think it's best if __get_user_pages_locked() is to get itself a new

You mean check_and_migrate_cma_pages()

> local with the same type as its return value.  Something like:

Agreed.

> --- a/mm/gup.c~a
> +++ a/mm/gup.c
> @@ -1450,6 +1450,7 @@ static long check_and_migrate_cma_pages(
>  	bool drain_allow = true;
>  	bool migrate_allow = true;
>  	LIST_HEAD(cma_page_list);
> +	long ret;

Should be initialized to nr_pages in case we don't go via "if
(!list_empty(&cma_page_list))" at all.

>  
>  check_again:
>  	for (i = 0; i < nr_pages;) {
> @@ -1511,17 +1512,18 @@ check_again:
>  		 * again migrating any new CMA pages which we failed to isolate
>  		 * earlier.
>  		 */
> -		nr_pages = __get_user_pages_locked(tsk, mm, start, nr_pages,
> +		ret = __get_user_pages_locked(tsk, mm, start, nr_pages,
>  						   pages, vmas, NULL,
>  						   gup_flags);
>  
> -		if ((nr_pages > 0) && migrate_allow) {
> +		nr_pages = ret;
> +		if (ret > 0 && migrate_allow) {
>  			drain_allow = true;
>  			goto check_again;
>  		}
>  	}
>  
> -	return nr_pages;
> +	return ret;
>  }
>  #else
>  static long check_and_migrate_cma_pages(struct task_struct *tsk,
> 
> 


  parent reply	other threads:[~2019-09-04 20:40 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-04 10:26 [PATCH] mm: Unsigned 'nr_pages' always larger than zero zhong jiang
2019-09-04 11:24 ` Vlastimil Babka
2019-09-04 18:25   ` Weiny, Ira
2019-09-04 18:39     ` Matthew Wilcox
2019-09-04 18:48   ` Andrew Morton
2019-09-04 20:20     ` Weiny, Ira
2019-09-04 20:40     ` Vlastimil Babka [this message]
2019-09-05  6:18     ` zhong jiang
2019-09-05  7:19       ` Vlastimil Babka
2019-09-05  6:19     ` John Hubbard
2019-10-16  9:07       ` zhong jiang
2019-10-17  0:49         ` Andrew Morton
2019-10-17  1:38           ` zhong jiang
2019-09-04 19:01   ` Andrew Morton
2019-09-04 20:44     ` Vlastimil Babka
2019-09-05  2:05   ` zhong jiang
2019-10-17  3:19 zhong jiang
2019-10-17 18:01 ` Ira Weiny
2019-10-18  2:01   ` zhong jiang
2019-10-17 20:42 ` John Hubbard
2019-10-18  2:15   ` zhong jiang
2019-10-18 14:00   ` zhong jiang
2019-10-18 16:07     ` Alexander Duyck
2019-10-21 15:11       ` zhong jiang
2019-10-21 12:57   ` Vlastimil Babka
2019-10-21 13:47     ` zhong jiang

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=29d686c3-9407-e953-42f4-a4224b9333e7@suse.cz \
    --to=vbabka@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=aneesh.kumar@linux.vnet.ibm.com \
    --cc=anshuman.khandual@arm.com \
    --cc=ira.weiny@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=zhongjiang@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.