linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mm: Unsigned 'nr_pages' always larger than zero
@ 2019-09-05  2:17 zhong jiang
  2019-09-05  3:12 ` Matthew Wilcox
  0 siblings, 1 reply; 3+ messages in thread
From: zhong jiang @ 2019-09-05  2:17 UTC (permalink / raw)
  To: akpm, vbabka; +Cc: mhocko, zhongjiang, linux-mm, linux-kernel

With the help of unsigned_lesser_than_zero.cocci. Unsigned 'nr_pages'
compare with zero. And __gup_longterm_locked pass an long local variant
'rc' to check_and_migrate_cma_pages. Hence it is nicer to change the
parameter to long to fix the issue.

Fixes: 932f4a630a69 ("mm/gup: replace get_user_pages_longterm() with FOLL_LONGTERM")
Signed-off-by: zhong jiang <zhongjiang@huawei.com>
---
 mm/gup.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mm/gup.c b/mm/gup.c
index 23a9f9c..ee0b71f 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1433,13 +1433,13 @@ static struct page *new_non_cma_page(struct page *page, unsigned long private)
 static long check_and_migrate_cma_pages(struct task_struct *tsk,
 					struct mm_struct *mm,
 					unsigned long start,
-					unsigned long nr_pages,
+					long nr_pages,
 					struct page **pages,
 					struct vm_area_struct **vmas,
 					unsigned int gup_flags)
 {
-	unsigned long i;
-	unsigned long step;
+	long i;
+	long step;
 	bool drain_allow = true;
 	bool migrate_allow = true;
 	LIST_HEAD(cma_page_list);
@@ -1520,7 +1520,7 @@ static long check_and_migrate_cma_pages(struct task_struct *tsk,
 static long check_and_migrate_cma_pages(struct task_struct *tsk,
 					struct mm_struct *mm,
 					unsigned long start,
-					unsigned long nr_pages,
+					long nr_pages,
 					struct page **pages,
 					struct vm_area_struct **vmas,
 					unsigned int gup_flags)
-- 
1.7.12.4



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] mm: Unsigned 'nr_pages' always larger than zero
  2019-09-05  2:17 [PATCH v2] mm: Unsigned 'nr_pages' always larger than zero zhong jiang
@ 2019-09-05  3:12 ` Matthew Wilcox
  2019-09-05  6:09   ` zhong jiang
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Wilcox @ 2019-09-05  3:12 UTC (permalink / raw)
  To: zhong jiang; +Cc: akpm, vbabka, mhocko, linux-mm, linux-kernel

On Thu, Sep 05, 2019 at 10:17:51AM +0800, zhong jiang wrote:
> With the help of unsigned_lesser_than_zero.cocci. Unsigned 'nr_pages'
> compare with zero. And __gup_longterm_locked pass an long local variant
> 'rc' to check_and_migrate_cma_pages. Hence it is nicer to change the
> parameter to long to fix the issue.

I think this patch is right, but I have concerns about this cocci grep.

The code says:

                if ((nr_pages > 0) && migrate_allow) {

There's nothing wrong with this (... other than the fact that nr_pages might
happen to be a negative errno).  nr_pages might be 0, and this would be
exactly the right test for that situation.  I suppose some might argue
that this should be != 0 instead of > 0, but it depends on the situation
which one would read better.

So please don't blindly make these changes; you're right this time.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] mm: Unsigned 'nr_pages' always larger than zero
  2019-09-05  3:12 ` Matthew Wilcox
@ 2019-09-05  6:09   ` zhong jiang
  0 siblings, 0 replies; 3+ messages in thread
From: zhong jiang @ 2019-09-05  6:09 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: akpm, vbabka, mhocko, linux-mm, linux-kernel

On 2019/9/5 11:12, Matthew Wilcox wrote:
> On Thu, Sep 05, 2019 at 10:17:51AM +0800, zhong jiang wrote:
>> With the help of unsigned_lesser_than_zero.cocci. Unsigned 'nr_pages'
>> compare with zero. And __gup_longterm_locked pass an long local variant
>> 'rc' to check_and_migrate_cma_pages. Hence it is nicer to change the
>> parameter to long to fix the issue.
> I think this patch is right, but I have concerns about this cocci grep.
>
> The code says:
>
>                 if ((nr_pages > 0) && migrate_allow) {
>
> There's nothing wrong with this (... other than the fact that nr_pages might
> happen to be a negative errno).  nr_pages might be 0, and this would be
> exactly the right test for that situation.  I suppose some might argue
> that this should be != 0 instead of > 0, but it depends on the situation
> which one would read better.
>
> So please don't blindly make these changes; you're right this time.
Thanks for your affirmation.  but Andrew come up with anther fix,  using an local long variant
to store the nr_pages.  which one do you prefer ?

Thanks,
zhong jiang



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-09-05  6:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-05  2:17 [PATCH v2] mm: Unsigned 'nr_pages' always larger than zero zhong jiang
2019-09-05  3:12 ` Matthew Wilcox
2019-09-05  6:09   ` zhong jiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).