Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1099302ybz; Fri, 1 May 2020 14:35:34 -0700 (PDT) X-Google-Smtp-Source: APiQypJ+LYxXeqI6f9r47oP5zWKEpXSe/HSJVzJvc3ikcp20G3lolQYEBAxeXIA3HWaQUIxHFZT5 X-Received: by 2002:aa7:cdce:: with SMTP id h14mr5266977edw.51.1588368934141; Fri, 01 May 2020 14:35:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588368934; cv=none; d=google.com; s=arc-20160816; b=SnErc0ZIXlA1bK+m7/lirqXTwdyDKmED+epEP1xB2LjVsiLg4dfZwW579R2fo9cM1y sEv2ILGd6JCUGe6457/LhKyJGR97xLHpBcTWqcFIEz40tLUm1Hbb91pSbePxLGqqiVmn Zd313E5fN4u2q4lZkrjLwynL96l82evf8IM9MeSI4UAeqsu1A1EB4n0G0HhxJIV4TH+t leMnvDWj/SPPh++SUJcqsSf2PIng4SBJUYwGNIrB3uu/5+WH/7C09bt4dUzmMzf+YzAK u0ll1sxn8yG+LFZPxpecOQuTRKSudoAKvm4ydAjNa0tPs4BO2iMnrGVrj8ygHKNp2hY3 kBhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=/ss50mYtclSvHtRZUxtjzklZeDRr5uBZhGcufaww9YQ=; b=U9g/aThkQU7qq79j7fgCNucaR850S2bSIpAvP9rQ7cgPz4LuI5dKRw1d4tOZlitKas c4gjSKWkL1WLnHdDtlQWfBVUhBm/FufhAYpbcs9514cs33iYXuj9jCdxtR9D8/+rWwSO tnFtvK/a6gSV7WrLKatJng+yvcUE8p7t+Hp56oGV2I805T5j83zu8sMNgbRgNHyMS+zJ Jdc+5VP6W+eQfKhs+0Ty36/KMnNHbjBFHzjyXHc7IuTUAFoCJlbLWor8obP7AXq2mam4 R3zaeJ3B4T1Ry+g9U5AUiIueuvTNsJXsg3GQyoi4zPPTcMldld7EQBdrdBa6wE6Zm53V ulAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b="fzK/KHQn"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s15si2544999edr.462.2020.05.01.14.35.10; Fri, 01 May 2020 14:35:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b="fzK/KHQn"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726562AbgEAVdr (ORCPT + 99 others); Fri, 1 May 2020 17:33:47 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:7746 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726045AbgEAVdr (ORCPT ); Fri, 1 May 2020 17:33:47 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Fri, 01 May 2020 14:32:39 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Fri, 01 May 2020 14:33:46 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Fri, 01 May 2020 14:33:46 -0700 Received: from DRHQMAIL107.nvidia.com (10.27.9.16) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 1 May 2020 21:33:46 +0000 Received: from [10.2.55.159] (172.20.13.39) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 1 May 2020 21:33:46 +0000 Subject: Re: [PATCH] mm/gup.c: Handle error at earliest for incorrect nr_pages value To: Souptick Joarder , CC: , References: <1588277518-21425-1-git-send-email-jrdr.linux@gmail.com> X-Nvconfidentiality: public From: John Hubbard Message-ID: Date: Fri, 1 May 2020 14:33:45 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <1588277518-21425-1-git-send-email-jrdr.linux@gmail.com> X-Originating-IP: [172.20.13.39] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To DRHQMAIL107.nvidia.com (10.27.9.16) Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1588368759; bh=/ss50mYtclSvHtRZUxtjzklZeDRr5uBZhGcufaww9YQ=; h=X-PGP-Universal:Subject:To:CC:References:X-Nvconfidentiality:From: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=fzK/KHQnVa/a6WZRuvTdd3i9GOn1hnFmBgNAX7C8VTnV8Vy9YGPiHtsyzcq7dFHSQ tLcOa12Ng3TZAe9DuDCBKayi0igPsizn0cdbOk41LB+1IZ2hwcELvaW5qa5DXqzB9c Gxir0rmabitEWeAX7fK2vHn2fdOx8NAEZkBuvB5ODs8YKyOVq2y/WsZgHLZqR+JQNy BqFKI4+gylvLuK1OYmuGa/3tp09hoB+KOtGM9dqU40pFm559EBkLnr9jQ4xNFb+RoN vsXi7nt+tw6aAb0nBucSt3qRkI0tX0ONqS0uulbdTAqcqV7fR7rUQfj6tO6eWiOJEi jfL/+ugqsykeA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-04-30 13:11, Souptick Joarder wrote: > As per documentation, pin_user_pages_fast() & get_user_pages_fast() > will return 0, if nr_pages <= 0. But this can be figure out only after > going inside the internal_get_user_pages_fast(). > > This can be handled early. Adding a check for the same. Please, no. For precisely the reasons that Andrew gave: you are attempting to optimize for a case that doesn't matter other than for error handling, and which is already handled adequately. And as he also pointed out, it very slightly UN-optimizes the path that we *do* care about. So why are you still advocating for this? If you want to change the gup/pup API so that asking for zero pages means -EINVAL, then fine, go for it. That's a large thing, and a tree-wide audit, but if you feel it's worth pursuing then it's at least consistent. But this patch here needs to be abandoned. thanks, -- John Hubbard NVIDIA > > Signed-off-by: Souptick Joarder > --- > mm/gup.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/mm/gup.c b/mm/gup.c > index 50681f0..a13aaa6 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -2817,6 +2817,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, > */ > if (WARN_ON_ONCE(gup_flags & FOLL_PIN)) > return -EINVAL; > + if (nr_pages <= 0) > + return 0; > > /* > * The caller may or may not have explicitly set FOLL_GET; either way is > @@ -2854,6 +2856,8 @@ int pin_user_pages_fast(unsigned long start, int nr_pages, > /* FOLL_GET and FOLL_PIN are mutually exclusive. */ > if (WARN_ON_ONCE(gup_flags & FOLL_GET)) > return -EINVAL; > + if (nr_pages <= 0) > + return 0; > > gup_flags |= FOLL_PIN; > return internal_get_user_pages_fast(start, nr_pages, gup_flags, pages); >