linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Nicholas Piggin <npiggin@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@redhat.com>
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>,
	linux-mm@kvack.org, Mel Gorman <mgorman@suse.de>,
	Yang Shi <shy828301@gmail.com>
Subject: Re: [PATCH] mm/migrate: fix page state accounting type conversion underflow
Date: Mon, 26 Jul 2021 11:43:30 +1000	[thread overview]
Message-ID: <1627263259.nzhjhfeuv9.astroid@bobo.none> (raw)
In-Reply-To: <1bc9f24a-c6ff-902e-bce0-165c235bb643@redhat.com>

Excerpts from David Hildenbrand's message of July 22, 2021 5:27 pm:
> On 22.07.21 07:48, Nicholas Piggin wrote:
>> Similarly to commit 2da9f6305f306 ("mm/vmscan: fix NR_ISOLATED_FILE
>> corruption on 64-bit"), fix -ve int -> unsigned int -> long bug.
>> 
>> Reported-by: Alexey Kardashevskiy <aik@ozlabs.ru>
>> Fixes: c5fc5c3ae0c84 ("mm: migrate: account THP NUMA migration counters correctly")
>> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
>> ---
>>   mm/migrate.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/mm/migrate.c b/mm/migrate.c
>> index 34a9ad3e0a4f..7e240437e7d9 100644
>> --- a/mm/migrate.c
>> +++ b/mm/migrate.c
>> @@ -2068,7 +2068,7 @@ int migrate_misplaced_page(struct page *page, struct vm_area_struct *vma,
>>   	LIST_HEAD(migratepages);
>>   	new_page_t *new;
>>   	bool compound;
>> -	unsigned int nr_pages = thp_nr_pages(page);
>> +	int nr_pages = thp_nr_pages(page);
>>   
>>   	/*
>>   	 * PTE mapped THP or HugeTLB page can't reach here so the page could
>> 
> 
> This is too fragile to silently break again IMHO. Should we similarly to 
> 2da9f6305f306 handle the conversion explicitly inside the 
> mod_node_page_state() call?

Casting to signed still has the fragility that the variable is unsigned
so negating it somewhere else would break. I was somewhat inconsistent 
in the fixes, but there is less code that uses the variable here so it's
simpler to change the type IMO.

Negating an unsigned type always gives you a non-negative number. 
Unfortunately types matter.

Thanks,
Nick


  parent reply	other threads:[~2021-07-26  1:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-22  5:48 [PATCH] mm/migrate: fix page state accounting type conversion underflow Nicholas Piggin
2021-07-22  7:27 ` David Hildenbrand
2021-07-22 19:20   ` Andrew Morton
2021-07-26  1:43   ` Nicholas Piggin [this message]
2021-07-27 16:19 ` Matthew Wilcox
2021-07-28 14:15   ` Aneesh Kumar K.V

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=1627263259.nzhjhfeuv9.astroid@bobo.none \
    --to=npiggin@gmail.com \
    --cc=aik@ozlabs.ru \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=shy828301@gmail.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;
as well as URLs for NNTP newsgroup(s).