From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLACK,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83502C4338F for ; Tue, 27 Jul 2021 16:20:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EE16961B80 for ; Tue, 27 Jul 2021 16:20:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EE16961B80 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 7247F8D0001; Tue, 27 Jul 2021 12:20:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D5376B005D; Tue, 27 Jul 2021 12:20:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C3338D0001; Tue, 27 Jul 2021 12:20:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0156.hostedemail.com [216.40.44.156]) by kanga.kvack.org (Postfix) with ESMTP id 404346B0036 for ; Tue, 27 Jul 2021 12:20:30 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id D9DDF8249980 for ; Tue, 27 Jul 2021 16:20:29 +0000 (UTC) X-FDA: 78408880578.16.8089AD0 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf05.hostedemail.com (Postfix) with ESMTP id 263CE50174BE for ; Tue, 27 Jul 2021 16:20:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=0MBERTD+dwfRSuLMZ1KhYx9kILrFUH33t4csC+u214s=; b=WaaTtJ+kNW/kGutbker0cwHWM+ Tv99r3pkkmmIoyIfbg1YerwQ8pr/TJbjyt92Avglb8/zNS7rlFcPgHbEwsvXDOZeqn0XZaQyywmB+ BiuNUq/+ZVi7yXprjFFaHuWOq5Zp/Zh1g2kIjxMgb8Wt/Qh7K77igKbbxKetQse9lu+2EZRC6rCWt JE10//MzfxI8FMVWtxPMh1QJuEU0xZgEUVAuclY+J/5bzZDpDY3X8CEEGaQaroLFP7jM7jLQzM1Mm cLqKpd5Zo4ca1CtvMgQioQfBQq7hReHwa+YrVY9TnKJV4/gfbBsA/SXJ0F7b6H2AxApc8YJ7TU04z GH24zZQw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m8Po5-00FBJx-Iq; Tue, 27 Jul 2021 16:19:56 +0000 Date: Tue, 27 Jul 2021 17:19:49 +0100 From: Matthew Wilcox To: Nicholas Piggin Cc: Andrew Morton , Mel Gorman , Yang Shi , linux-mm@kvack.org, Alexey Kardashevskiy Subject: Re: [PATCH] mm/migrate: fix page state accounting type conversion underflow Message-ID: References: <20210722054840.501423-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210722054840.501423-1-npiggin@gmail.com> Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=WaaTtJ+k; spf=none (imf05.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Rspamd-Server: rspam02 X-Stat-Signature: ta8m1oq4p9j7eogtk5iheu7b3jqm6hgd X-Rspamd-Queue-Id: 263CE50174BE X-HE-Tag: 1627402829-624521 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 > Fixes: c5fc5c3ae0c84 ("mm: migrate: account THP NUMA migration counters correctly") > Signed-off-by: Nicholas Piggin > --- > 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.