From: Matthew Wilcox <willy@infradead.org>
To: Nicholas Piggin <npiggin@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Mel Gorman <mgorman@suse.de>, Yang Shi <shy828301@gmail.com>,
linux-mm@kvack.org, Alexey Kardashevskiy <aik@ozlabs.ru>
Subject: Re: [PATCH] mm/migrate: fix page state accounting type conversion underflow
Date: Tue, 27 Jul 2021 17:19:49 +0100 [thread overview]
Message-ID: <YQAyJQXdI3E6sq3r@casper.infradead.org> (raw)
In-Reply-To: <20210722054840.501423-1-npiggin@gmail.com>
On Thu, Jul 22, 2021 at 03:48:40PM +1000, 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);
This has prompted me to go off and look through the folio work. There
are a number of similar problems. It's sad that gcc doesn't have a
warning that catched this (although Clang does!) I've filed
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101645
In the meantime, I'm going to change:
- folio_nr_pages() now returns 'long' instead of 'unsigned long'.
- Everywhere that assigns it to a variable changes its type from 'int'
or 'unsigned int' or 'unsigned long' to 'long'.
The only place this looks a little dodgy is:
+static inline bool folio_contains(struct folio *folio, pgoff_t index)
+{
+ /* HugeTLBfs indexes the page cache in units of hpage_size */
+ if (folio_test_hugetlb(folio))
+ return folio->index == index;
+ return index - folio_index(folio) < folio_nr_pages(folio);
+}
but i'm pretty sure that's OK because index & folio_index are
both unsigned long, and by my reading of the C spec, that
promotes long to unsigned long, and so we do an unsigned comparison
(meaning that index 3, folio_index() 4 will wrap around to ULONG_MAX
and the comparison will return false, as expected.
I also intend to change update_lru_size() to take a long.
This patch is insufficient ... mem_cgroup_move_account() has the same bug.
I'm not quite sure how to handle this patch -- I'm going to replace all
this in 5.15, but this should be backported to earlier kernels.
next prev parent reply other threads:[~2021-07-27 16:20 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
2021-07-27 16:19 ` Matthew Wilcox [this message]
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=YQAyJQXdI3E6sq3r@casper.infradead.org \
--to=willy@infradead.org \
--cc=aik@ozlabs.ru \
--cc=akpm@linux-foundation.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@suse.de \
--cc=npiggin@gmail.com \
--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).