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=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 4A041C4363A for ; Mon, 26 Oct 2020 23:59:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C95B320773 for ; Mon, 26 Oct 2020 23:59:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="YB25exIy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C95B320773 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 298B76B005D; Mon, 26 Oct 2020 19:59:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 246D26B0062; Mon, 26 Oct 2020 19:59:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C0D06B006C; Mon, 26 Oct 2020 19:59:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0116.hostedemail.com [216.40.44.116]) by kanga.kvack.org (Postfix) with ESMTP id C8DF06B005D for ; Mon, 26 Oct 2020 19:59:16 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 6D75D180AD802 for ; Mon, 26 Oct 2020 23:59:16 +0000 (UTC) X-FDA: 77415745512.14.suit81_0303d2527277 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 49DF918229818 for ; Mon, 26 Oct 2020 23:59:16 +0000 (UTC) X-HE-Tag: suit81_0303d2527277 X-Filterd-Recvd-Size: 7646 Received: from nat-hk.nvidia.com (nat-hk.nvidia.com [203.18.50.4]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Mon, 26 Oct 2020 23:59:14 +0000 (UTC) Received: from HKMAIL103.nvidia.com (Not Verified[10.18.92.100]) by nat-hk.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Tue, 27 Oct 2020 07:59:10 +0800 Received: from HKMAIL103.nvidia.com (10.18.16.12) by HKMAIL103.nvidia.com (10.18.16.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 26 Oct 2020 23:59:10 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.176) by HKMAIL103.nvidia.com (10.18.16.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Mon, 26 Oct 2020 23:59:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mpbTM169MJNAx26lZqpvhlZhIl1OGv/jAFhOng5txp7ykVW60l/TzTCFh6mpx70nBxow96TgdP4leTvlhAfJbepJ0JbfmIvaMW6TgSD0GVswdq8v3Ork1hUhwzG3lAZwHTk62UvXP7CapzD/hwe8kvzc8YSaIppeJMmKI3ZJvzSZthbJ9W/Kn/L3tAs/w+V6PEzpUZEcS6yxq9SPji4VKCBNou1IShOqLNBwqQ4+gS8YWW3RMFXkgX06KW1s/B/wsCeWPaZ0VkMvaLpF10RLneCZyJBSIqtDKjQbZWTOc2VFF7bKJtxlZGJK+TJ6LF1JQEqQrK5hFk6YDgQbXN283Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0G2MtcEyKqDowZPRjXkL9Xo5WtQtV8ZJaFSxUo6t9Zg=; b=PuR8XHuPmK6LiZV0gU0LPuVfffj3JE8HQTPLgODi92MH7a06LXNmPUHPzN4APBVwAEC8+20NOl7yP07lVbh7D7/oZOo2JBQ4aXkHVgKcdE14lbv0cRH5PyuP804JAfeehYKBUqVsUrsS6VEt26NF6zPgKLjNi66IO2OkhKws4qnTp1s/FC5D0tVmdCd80TFvuV/0MslP+zyxv8n+FKcEnVrQoP5781KAfdSfCusgT3o1bVI3aZLwScTr0ofMjfqR+/8zyuaDB1Y2T5+dOOtdXAIXzofxRol80Od1LvvPDGLWtj5GNzrsWtFTGVcj8FghUfLd1h4YSABBiPOWdDIblg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM5PR1201MB0203.namprd12.prod.outlook.com (2603:10b6:4:56::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.28; Mon, 26 Oct 2020 23:59:05 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::cdbe:f274:ad65:9a78]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::cdbe:f274:ad65:9a78%7]) with mapi id 15.20.3477.028; Mon, 26 Oct 2020 23:59:05 +0000 Date: Mon, 26 Oct 2020 20:59:03 -0300 From: Jason Gunthorpe To: John Hubbard CC: , Andrea Arcangeli , Andrew Morton , Christoph Hellwig , Hugh Dickins , Jan Kara , Jann Horn , Kirill Shutemov , Kirill Tkhai , Linux-MM , Michal Hocko , Oleg Nesterov , Peter Xu Subject: Re: [PATCH 1/2] mm: reorganize internal_get_user_pages_fast() Message-ID: <20201026235903.GE1523783@nvidia.com> References: <1-v1-281e425c752f+2df-gup_fork_jgg@nvidia.com> <16c50bb0-431d-5bfb-7b80-a8af0b4da90f@nvidia.com> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <16c50bb0-431d-5bfb-7b80-a8af0b4da90f@nvidia.com> X-ClientProxiedBy: YTBPR01CA0036.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:14::49) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by YTBPR01CA0036.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:14::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18 via Frontend Transport; Mon, 26 Oct 2020 23:59:05 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kXCOF-00958G-OB; Mon, 26 Oct 2020 20:59:03 -0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1603756750; bh=0G2MtcEyKqDowZPRjXkL9Xo5WtQtV8ZJaFSxUo6t9Zg=; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:Date: From:To:CC:Subject:Message-ID:References:Content-Type: Content-Disposition:In-Reply-To:X-ClientProxiedBy:MIME-Version: X-MS-Exchange-MessageSentRepresentingType; b=YB25exIyAL+YAPKP7yj154gTGRS2pmOJB+2EbNMUvuBicq9xzuxiLEQWM/AXIA2qs fiV5QxFtNSEu7a1QJdKWgJtE5hXjqFhtJx4LXh0U07R+57TsEb9HvKEIpuhVMLbcA9 /xmV5Uak31mcgCoaQZ/3SeTd/CkqOfT3pKnJkgh1jQnvAos7RE55hwCxIcDCIC9zBc fI1bT26a+U5C9x/MbkocNLBlhMMlGl/eyi53TgH85spMxC4BicaNbXzLueHJB6+vpg wLnHkVpOR9YXNh4oaW9TR7+JlckQROz/iCUsj0cVbB5QMGVvFjn9BvFvDJFyiZVB84 Jur+Vpb0chEqw== 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 Fri, Oct 23, 2020 at 09:44:17PM -0700, John Hubbard wrote: > > Signed-off-by: Jason Gunthorpe > > mm/gup.c | 88 +++++++++++++++++++++++++++++--------------------------- > > 1 file changed, 46 insertions(+), 42 deletions(-) > > > > diff --git a/mm/gup.c b/mm/gup.c > > index 102877ed77a4b4..ecbe1639ea2af7 100644 > > +++ b/mm/gup.c > > @@ -2671,13 +2671,42 @@ static int __gup_longterm_unlocked(unsigned long start, int nr_pages, > > return ret; > > } > > +static unsigned int lockless_pages_from_mm(unsigned long addr, > > It would be slightly more consistent to use "start" here, too, instead of addr. > > Separately, I'm not joyful about the change to unsigned int for the > return type. I understand why you did it and that's perfectly sound > reasoning: there is no -ERRNO possible here, and nr_pinned will always > be >=0. And it's correct, although it does have a type mismatch in the > return value. I did it because I had to check that ignoring a negative return or doing some wonky negative arithmetic wasn't some sneaky beahvior. It isn't, the value is really unsigned. So I documented it to save the next person this work. I think the proper response is to ultimately change the gup_pgd_range() call tree to take the unsigned as well. > a) change all the nr_pages and nr_pinned throughout, to "long", or > > b) change all the nr_pages and nr_pinned all function args, and use int > return types throughout, as a "O or -ERRNO, only" return value > convention. The gup_pgd_range() this stuff largely does return I think gup_pgd_range() works as it does due to > > + start += (unsigned long)nr_pinned << PAGE_SHIFT; > > + pages += nr_pinned; > > + ret = __gup_longterm_unlocked(start, nr_pages - nr_pinned, gup_flags, > > + pages); > > + if (ret < 0) { > > /* Have to be a bit careful with return values */ > > ...and can we move that comment up one level, so that it reads: > > /* Have to be a bit careful with return values */ > if (ret < 0) { > if (nr_pinned) > return nr_pinned; > return ret; > } > return ret + nr_pinned; I actually deliberately put it inside the if because there is nothing tricky about ret < 0, that is basically perfectly normal. It is only the logic to drop the error code sometimes that is tricky.. > Thinking about this longer term, it would be nice if the whole gup/pup API > set just stopped pretending that anyone cares about partial success, because > they *don't*. If we had return values of "0 or -ERRNO" throughout, and an > additional set of API wrappers that did some sort of limited retry just like > some of the callers do, that would be a happier story. It seems like a good idea to me I'll get the other notes in a v2 Thanks, Jason