Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp5019712imm; Fri, 18 May 2018 15:03:54 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr8V+K4MiFu6AbY7C9foCJCnYLOcKcVsyzzFRQK5ZZJMMtkjUaMW6+zxCRAr1Qtg7vfTorr X-Received: by 2002:a17:902:ea:: with SMTP id a97-v6mr10908862pla.28.1526681034734; Fri, 18 May 2018 15:03:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526681034; cv=none; d=google.com; s=arc-20160816; b=tZo6MOWdrTsWf9a2Hg4Dk16o1oFmHPEz8KetQ8MxpZzDxyF3HjCojQm2Xa7pPLv77T sQisyOK/lcX5TSPZ4Yr2uDXhptPURc1zlRzcOeonTOwzDIYugy7tkgX/TGb1GBe0xza7 46dgV/tcw2LlW7yQCoq0zv1g1luyxhej5XH9oVtuQSCDjv09qWdStx+WvIgdTvrk3h1P 3xuWqaq82B1VidGbtDsixuHjJyrQCGHOdzAaW45wiYn7Cw335KGVqXtG3y7j1SpL1Yxc OAzg/ZyeViPsc4DZTydi9Lryr6Ky2VvWMFOPOSRruzeSgB3OQTJxgnijv1ric9K43ERk D9Aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=AOJYj77iCG8bCEWkWg/OAlPPRvJ75iUEz9Hj7Yeu878=; b=sO1s+kFzgzwJzhlD2ROSwqgQ/cU08nd4fLj4o0innyGtup0tNvk8+kcHXoP7xDK2sL /wwJufwusFd1F8eR+wfTTt5G/huQZtVkh+kNvyUbT/OLdUBS0ljp/g7J0e+W2zclix/8 gjY9sKtpUVe6iaDw2s6nhQD0tkkqqsj14R0eGasi/gpTxqa2tj3X2o0TusgFbpbDxig3 OSd+5CEAwI+FYxU6GqqU+zHIySwx2EL1AmPuIed4ynKngQus+tBkHbDOJP0KpTnVQNKW Q+zMczu/EhWqMUONPo+4wkNU7yuG3rG+ih4Fu4GBEfnF+uClXJO5QK3QGL8bxS2au7AV UjJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=hIb3Ys5b; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t1-v6si6669854pgr.681.2018.05.18.15.03.39; Fri, 18 May 2018 15:03:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=hIb3Ys5b; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752204AbeERWCT (ORCPT + 99 others); Fri, 18 May 2018 18:02:19 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:36788 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751458AbeERWCR (ORCPT ); Fri, 18 May 2018 18:02:17 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w4ILuOXu066396; Fri, 18 May 2018 22:01:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=AOJYj77iCG8bCEWkWg/OAlPPRvJ75iUEz9Hj7Yeu878=; b=hIb3Ys5btfqXLhVnZxpSiRITPrH//lhWY9ViRgexbJ6bD+krCNzeIRr41zfYDZyL4su4 14e/mu6EBBiPWYEhvnH/Ako5bTMITYWliG8/e6ARInZUUYHJRhVr94GTNskTOs78Bbvc SaYdByM0BPBYiv4Q8Iwwasf6q68K0yuWZtvm5yEgazhz6tklhdpsOG4yuF+SSysj7wTO Il6oFW+4YHRREEnR+hKfUwattLqF80Akso4oOLTw2LkNu7TCyTmo2/VHxxUWdDzoyIo/ 7xfkoHCnMomR89i7hbPPYVVqkYa1xFgQOukosjVd+CTode+SSVydv/eUMzlGImEschZ+ dg== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2hx29wq34g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 May 2018 22:01:27 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w4IM1QpJ020058 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 May 2018 22:01:26 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w4IM1MfY014375; Fri, 18 May 2018 22:01:22 GMT Received: from [192.168.1.164] (/50.38.38.67) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 18 May 2018 15:01:22 -0700 Subject: Re: [PATCH v2 1/4] mm: change type of free_contig_range(nr_pages) to unsigned long To: Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org Cc: Reinette Chatre , Michal Hocko , Christopher Lameter , Guy Shattah , Anshuman Khandual , Michal Nazarewicz , David Nellans , Laura Abbott , Pavel Machek , Dave Hansen , Andrew Morton , Joonsoo Kim , Marek Szyprowski References: <20180503232935.22539-1-mike.kravetz@oracle.com> <20180503232935.22539-2-mike.kravetz@oracle.com> <87d74ce0-b135-064d-a589-64235e44c388@suse.cz> From: Mike Kravetz Message-ID: <87943a21-4465-31bd-ed37-69253879ec47@oracle.com> Date: Fri, 18 May 2018 15:01:20 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <87d74ce0-b135-064d-a589-64235e44c388@suse.cz> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8897 signatures=668699 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1805180232 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/18/2018 02:12 AM, Vlastimil Babka wrote: > On 05/04/2018 01:29 AM, Mike Kravetz wrote: >> free_contig_range() is currently defined as: >> void free_contig_range(unsigned long pfn, unsigned nr_pages); >> change to, >> void free_contig_range(unsigned long pfn, unsigned long nr_pages); >> >> Some callers are passing a truncated unsigned long today. It is >> highly unlikely that these values will overflow an unsigned int. >> However, this should be changed to an unsigned long to be consistent >> with other page counts. >> >> Signed-off-by: Mike Kravetz >> --- >> include/linux/gfp.h | 2 +- >> mm/cma.c | 2 +- >> mm/hugetlb.c | 2 +- >> mm/page_alloc.c | 6 +++--- >> 4 files changed, 6 insertions(+), 6 deletions(-) >> >> diff --git a/include/linux/gfp.h b/include/linux/gfp.h >> index 1a4582b44d32..86a0d06463ab 100644 >> --- a/include/linux/gfp.h >> +++ b/include/linux/gfp.h >> @@ -572,7 +572,7 @@ static inline bool pm_suspended_storage(void) >> /* The below functions must be run on a range from a single zone. */ >> extern int alloc_contig_range(unsigned long start, unsigned long end, >> unsigned migratetype, gfp_t gfp_mask); >> -extern void free_contig_range(unsigned long pfn, unsigned nr_pages); >> +extern void free_contig_range(unsigned long pfn, unsigned long nr_pages); >> #endif >> >> #ifdef CONFIG_CMA >> diff --git a/mm/cma.c b/mm/cma.c >> index aa40e6c7b042..f473fc2b7cbd 100644 >> --- a/mm/cma.c >> +++ b/mm/cma.c >> @@ -563,7 +563,7 @@ bool cma_release(struct cma *cma, const struct page *pages, unsigned int count) >> >> VM_BUG_ON(pfn + count > cma->base_pfn + cma->count); >> >> - free_contig_range(pfn, count); >> + free_contig_range(pfn, (unsigned long)count); > > I guess this cast from uint to ulong doesn't need to be explicit? But > instead, cma_release() signature could be also changed to ulong, because > some of its callers do pass those? Correct, that cast is not needed. I like the idea of changing cma_release() to take ulong. Until you mentioned this, I did not realize that some callers were passing in a truncated ulong. As noted in my commit message, this truncation is unlikely to be an issue. But, I think we should 'fix' them if we can. I'll spin another version with this change. > >> cma_clear_bitmap(cma, pfn, count); >> trace_cma_release(pfn, pages, count); >> >> diff --git a/mm/hugetlb.c b/mm/hugetlb.c >> index 218679138255..c81072ce7510 100644 >> --- a/mm/hugetlb.c >> +++ b/mm/hugetlb.c >> @@ -1055,7 +1055,7 @@ static void destroy_compound_gigantic_page(struct page *page, >> >> static void free_gigantic_page(struct page *page, unsigned int order) >> { >> - free_contig_range(page_to_pfn(page), 1 << order); >> + free_contig_range(page_to_pfn(page), 1UL << order); >> } >> >> static int __alloc_gigantic_page(unsigned long start_pfn, >> diff --git a/mm/page_alloc.c b/mm/page_alloc.c >> index 905db9d7962f..0fd5e8e2456e 100644 >> --- a/mm/page_alloc.c >> +++ b/mm/page_alloc.c >> @@ -7937,9 +7937,9 @@ int alloc_contig_range(unsigned long start, unsigned long end, >> return ret; >> } >> >> -void free_contig_range(unsigned long pfn, unsigned nr_pages) >> +void free_contig_range(unsigned long pfn, unsigned long nr_pages) >> { >> - unsigned int count = 0; >> + unsigned long count = 0; >> >> for (; nr_pages--; pfn++) { >> struct page *page = pfn_to_page(pfn); >> @@ -7947,7 +7947,7 @@ void free_contig_range(unsigned long pfn, unsigned nr_pages) >> count += page_count(page) != 1; >> __free_page(page); >> } >> - WARN(count != 0, "%d pages are still in use!\n", count); >> + WARN(count != 0, "%ld pages are still in use!\n", count); > > Maybe change to %lu while at it? Yes > BTW, this warning can theoretically produce false positives, because > page users have to deal with page_count() being incremented by e.g. > parallel pfn scanners using get_page_unless_zero(). We also don't detect > refcount leaks in general. Should we remove it or change it to VM_WARN > if it's still useful for debugging? Added Marek on Cc: as he is the one who originally added this message (although it has been a long time). I do not know what specific issue he was concerned with. A search found a few bug reports related to this warning. In these cases, it clearly was not a false positive but some other issue. It 'appears' the message helped in those cases. However, I would hate for a support organization to spend a bunch of time doing investigation for a false positive. At the very least, I think we should add a message/comment about the possibility of false positives in the code. I would be inclined to change it to VM_WARN, but it would be good to get input from others who might find it useful as it. -- Mike Kravetz > >> } >> #endif >> >> >