Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp440422ybe; Wed, 4 Sep 2019 23:46:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqxAXEhQKpywXUrzRH3gj10/+q2R2wj44JuDZtTvUhvp2fuZEWqxx0TwZ+yagJiwVfpf3mzn X-Received: by 2002:a65:60cd:: with SMTP id r13mr1770191pgv.315.1567665967365; Wed, 04 Sep 2019 23:46:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567665967; cv=none; d=google.com; s=arc-20160816; b=L+qVsn6fZgXN0rdwqX6tNgK0/HN2bwXsVU3MyliLXIKSsBlEJHwj9Jz94pE5JMDqSd 4Lr1xIBDnPka0M2rfmJsA4a4PtUeNLdH0NMA8ibMOYvy47vT2qaqETJ/mVy8RYdvWUzp Z+CF/5eT2mSW3mf/XgvL6fByl2QdIbwi2h9pNtxoLUKj81ytoFIEuSbfF8f09nUyYh9b B07mizyu7gA+K7VXbxC0+oj6xCvMeHEkdHm9BiYCsko/sCuyEPDMtImGf/h6Qveqj2iw M6JROe/eEcxjUPOu8cE4eDFtUdGX1VtQ9oOqIjrY1rME5cIOczcNUm5jpLSXj63AkwBA 3j7g== 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:in-reply-to :references:subject:cc:to:mime-version:user-agent:from:date :message-id; bh=blFRNPbVCTbipUSo7bKVgTRU0V/T434X34Jtq3l4VQQ=; b=yrjCMVS9QDup4MklI+zveeAdQmXPyiLlaKOqFC7MnLdQo7oOWH61TVjX2T3UW5F+JC 0kgBbQ8p38E4LuPlpmH4r6wjmR5ayLhPObk+1uGxeQ5xgDcrjflvxE8HC/0uXwdhH3XA uMeKDpY9qj2K9uZw5SObocOLM7khw2fy/EqDUxiJeyMqURyRnDTmUkIqf4umXoeXwRC+ A/6t255tiTbL/VG/ds3UzM7vk1D0b7atQkwr0YXbJiwljZ1G16Ocr/TSB/wX8jikb954 3OFmErMRWe3vnPYEghyYv77HffVwJhbQuN3205wRp0sXNVTNVGkq3yZ9Wv5bUR35+pIO Hung== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j2si1221419pjw.1.2019.09.04.23.45.40; Wed, 04 Sep 2019 23:46:07 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731015AbfIEGSO (ORCPT + 99 others); Thu, 5 Sep 2019 02:18:14 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:6676 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725921AbfIEGSO (ORCPT ); Thu, 5 Sep 2019 02:18:14 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id EA4B7F2C9DDCA2E5A9B3; Thu, 5 Sep 2019 14:18:12 +0800 (CST) Received: from [127.0.0.1] (10.177.29.68) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.439.0; Thu, 5 Sep 2019 14:18:11 +0800 Message-ID: <5D70A8A2.3040701@huawei.com> Date: Thu, 5 Sep 2019 14:18:10 +0800 From: zhong jiang User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 To: Andrew Morton CC: Vlastimil Babka , , , , , Ira Weiny , "Aneesh Kumar K.V" Subject: Re: [PATCH] mm: Unsigned 'nr_pages' always larger than zero References: <1567592763-25282-1-git-send-email-zhongjiang@huawei.com> <5505fa16-117e-8890-0f48-38555a61a036@suse.cz> <20190904114820.42d9c4daf445ded3d0da52ab@linux-foundation.org> In-Reply-To: <20190904114820.42d9c4daf445ded3d0da52ab@linux-foundation.org> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.29.68] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/9/5 2:48, Andrew Morton wrote: > On Wed, 4 Sep 2019 13:24:58 +0200 Vlastimil Babka wrote: > >> On 9/4/19 12:26 PM, zhong jiang wrote: >>> With the help of unsigned_lesser_than_zero.cocci. Unsigned 'nr_pages"' >>> compare with zero. And __get_user_pages_locked will return an long value. >>> Hence, Convert the long to compare with zero is feasible. >> It would be nicer if the parameter nr_pages was long again instead of unsigned >> long (note there are two variants of the function, so both should be changed). > nr_pages should be unsigned - it's a count of pages! > > The bug is that __get_user_pages_locked() returns a signed long which > can be a -ve errno. > > I think it's best if __get_user_pages_locked() is to get itself a new > local with the same type as its return value. Something like: > > --- a/mm/gup.c~a > +++ a/mm/gup.c > @@ -1450,6 +1450,7 @@ static long check_and_migrate_cma_pages( > bool drain_allow = true; > bool migrate_allow = true; > LIST_HEAD(cma_page_list); > + long ret; > > check_again: > for (i = 0; i < nr_pages;) { > @@ -1511,17 +1512,18 @@ check_again: > * again migrating any new CMA pages which we failed to isolate > * earlier. > */ > - nr_pages = __get_user_pages_locked(tsk, mm, start, nr_pages, > + ret = __get_user_pages_locked(tsk, mm, start, nr_pages, > pages, vmas, NULL, > gup_flags); > > - if ((nr_pages > 0) && migrate_allow) { > + nr_pages = ret; > + if (ret > 0 && migrate_allow) { > drain_allow = true; > goto check_again; > } > } > > - return nr_pages; > + return ret; > } > #else > static long check_and_migrate_cma_pages(struct task_struct *tsk, Firstly, I consider the some modified method as you has writen down above. It seems to work well. According to Vlastimil's feedback, I repost the patch in v2, changing the parameter to long to fix the issue. which one do you prefer? Thanks, zhong jiang