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=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 1893FC4360C for ; Wed, 16 Oct 2019 09:07:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CF81A2168B for ; Wed, 16 Oct 2019 09:07:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CF81A2168B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 807A48E0006; Wed, 16 Oct 2019 05:07:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B84C8E0001; Wed, 16 Oct 2019 05:07:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F50F8E0006; Wed, 16 Oct 2019 05:07:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0122.hostedemail.com [216.40.44.122]) by kanga.kvack.org (Postfix) with ESMTP id 501D98E0001 for ; Wed, 16 Oct 2019 05:07:55 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id E5BB018135282 for ; Wed, 16 Oct 2019 09:07:54 +0000 (UTC) X-FDA: 76049070468.13.rain22_7f3321407db38 X-HE-Tag: rain22_7f3321407db38 X-Filterd-Recvd-Size: 3820 Received: from huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Oct 2019 09:07:53 +0000 (UTC) Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 8E101E8B6CE97A3F1163; Wed, 16 Oct 2019 17:07:50 +0800 (CST) Received: from [127.0.0.1] (10.177.29.68) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.439.0; Wed, 16 Oct 2019 17:07:45 +0800 Message-ID: <5DA6DDE0.6000804@huawei.com> Date: Wed, 16 Oct 2019 17:07:44 +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: John Hubbard CC: Andrew Morton , 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> <73c49a1b-4f42-c21d-ccd8-2b063cdf1293@nvidia.com> In-Reply-To: <73c49a1b-4f42-c21d-ccd8-2b063cdf1293@nvidia.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.29.68] X-CFilter-Loop: Reflected 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 2019/9/5 14:19, John Hubbard wrote: > On 9/4/19 11:48 AM, 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! >> > > Yes! > >> 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, >> > > +1 for this approach, please. > > > thanks, Hi, Andrew I didn't see the fix for the issue in the upstream. Your proposal should be appiled to upstream. Could you appiled the patch or repost by me ? Thanks, zhogn jiang