Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1104098ybz; Fri, 1 May 2020 14:42:59 -0700 (PDT) X-Google-Smtp-Source: APiQypK67HbUtA3NhL/iCRXIz41awpD/GiDoJMJ9hzb10LB2HQCS2e8+d+otOSut8sez3xQMbjhP X-Received: by 2002:aa7:cc03:: with SMTP id q3mr5415940edt.131.1588369379724; Fri, 01 May 2020 14:42:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588369379; cv=none; d=google.com; s=arc-20160816; b=Ay6Cr11Lh5f/DV9WdcM4UPDyj7JWF9dCzTU6Byq0ToZGp1BGtjIgwH3mZqLiKWtKcq FaU3c0K82kxtb6RKjRj4VW7ATebx3Idhyo+4rgSev4n+w0QP1ZdNAwenDMhz4qhS+xMx aMhzla1WDYR9PCVGav4mCuz0yxVktVckDuD19JxNVFw+4P0oOEntDWTxlfQ/7Uy6dHoW NJEOsqq5ABCTEpot3uR4gNo8fVcJahksr8ArTR7JxZcd3AgdMAAhbPMwjNbRqD1VkTU/ 1sw3s/Bumzr/om9TnIi/ib6IfJZPdUFbqhcl07u6HMtibnmQXnQedpZoO0QdyxjfqH/3 4qqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=lmcdipzgY1Nm1KXrImEVFcXHk9g8rdDKWZCNtxFitno=; b=GhYEPDkLxfchTPS/x7Y0K5l6C35y2XHUNNUduAi2dKDduV3cs+Ob6YcQBLpQb7yc5y 7RsFfaCbg2iHexAulQH7vLGrKrpZ/9yEG9lZcA/kaJRXlxdmzKJPAZVEOH0CCIQ7y/lJ eXKr/CZjrRXeSYk0kmDDiwi1Vh+YmfHDr7Uea6R50SRTYRjX4t3y6/wSSqEbKYqRQEzM X+7Q9tKUmi8mF1sF2PDo1ZjzNPs9vmeprCt64unqRz78mM07Jp9lhbTMHASWvtxWtcD/ op5ayJ+b798l68kzqV1MOiqL/4GH0F67C5jw9zoGW3xNS6WQESihbNfGcFASHVv4YqD2 8bhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FGlzSNtx; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dv25si2449301ejb.270.2020.05.01.14.42.37; Fri, 01 May 2020 14:42:59 -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=@gmail.com header.s=20161025 header.b=FGlzSNtx; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726900AbgEAVit (ORCPT + 99 others); Fri, 1 May 2020 17:38:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726045AbgEAVis (ORCPT ); Fri, 1 May 2020 17:38:48 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72367C061A0C for ; Fri, 1 May 2020 14:38:48 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id f18so3811617lja.13 for ; Fri, 01 May 2020 14:38:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=lmcdipzgY1Nm1KXrImEVFcXHk9g8rdDKWZCNtxFitno=; b=FGlzSNtxTM+Pacz+O/M9t0vRdXoDnTsFtPa7jbcIqF34jEjXmAxn+k/Sd0TI8nkvas 0eTH8/sQlFcmK9KtbHE6QbEslIvvYRvcP417Js4Gt9zc1QBLalx6s1nU57/nai9FIxZZ Fd2tGphBTKPMiRmuErFAlderCbJaRiqEuXzLVoX7K00NXnznk4eSMnISP3agPakhuA8R VuprJMSY31APUe1S+hOlQZQGW1SOlv7apQ6SB93/JtZGr7S8HPRcoQy/p6dcZ8k34EZK 9YMjTe8f9VPCJF7wQ0a1KTnpbgBRRBI1pxTSRIUzfEKU9XTkI1j//j3L/uIBeUb+x6h0 DY2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=lmcdipzgY1Nm1KXrImEVFcXHk9g8rdDKWZCNtxFitno=; b=J0/SVrO4O4K8tLYRAxjbZDjGkv+TsWC2ZcI79OB+Pg4XbraxbMrONt/vCkVnVAtKe9 UpnnPSeBcr+e5/1bN7rObFLwBf65U6Xfkcg7y2tuI+bl69qmLVDE2WNTgVqbexPXI3fB nw3q0fHLLD+sPmggW30syCfu+GLYFBNQBcoStl5oVOKXErmpFkfMSe8xZgSOKkBpGnsl oVMD4DKiIehXuuNoieYQ5hau2EdH0OUieT3Fk6hk63nlexHSkXAM8Rlm2QRPy7yh0yLm MGzstD6AjmxZd+kKD6J00E3d/TUBeX2Vk9tl5WE/PyEL9cfRZwajy0LT9aTxnfpgxOM5 /YJw== X-Gm-Message-State: AGi0Pub5ucgnS0FMH4/7P10YMLmOttmR+3+torFnr+yNCrhDk8+VFLIc QpmZZH4f9of/8dIqe99iyoQZlN58u0R8+EukoFE= X-Received: by 2002:a2e:7815:: with SMTP id t21mr3504664ljc.146.1588369126880; Fri, 01 May 2020 14:38:46 -0700 (PDT) MIME-Version: 1.0 References: <1588277518-21425-1-git-send-email-jrdr.linux@gmail.com> In-Reply-To: From: Souptick Joarder Date: Sat, 2 May 2020 03:16:40 +0530 Message-ID: Subject: Re: [PATCH] mm/gup.c: Handle error at earliest for incorrect nr_pages value To: John Hubbard Cc: Andrew Morton , Linux-MM , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, May 2, 2020 at 3:03 AM John Hubbard wrote: > > 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. Sure, will drop this patch. > > > 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); > > >