Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2289162ybz; Thu, 30 Apr 2020 14:26:37 -0700 (PDT) X-Google-Smtp-Source: APiQypIoJ0kmHe/dw6rmDrlClf2INHdG0dQiaOEe0qpL67KdkRdXv43GlrDPqFPTYPrc43HY7Hhj X-Received: by 2002:a17:906:4e02:: with SMTP id z2mr440171eju.212.1588281997090; Thu, 30 Apr 2020 14:26:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588281997; cv=none; d=google.com; s=arc-20160816; b=x2G5YjAPUYeEvZrEHC/wPsiKs5outIEHMGbMAbel8mBUbZ4jUbAEKNB+uViikahGSa m/AhgENW+kqRd0843+fvUuJTQ15Ea2ejNtInsuUtase+DhdWr4oFupFFoyR+PXHGB/zQ Er66JvDB+fAR23QZOLhyZ5XMyDmive8uQbpsQKSBvSvY+I8Y7YK28c5Yg+DAXTzuQVsM AuMxYFvJhvMW4JrubRfDK67HZLmvKYTzDdC0zyEiA+Y3TbokB1FSo3GRwBz5zq+1Sy+M k2z3O65y3KxIuNSr6UwIuG09ZItopnDYRV4wvfxrmXPT8gi10YQp6OS8ZIyK+lf9Otjp /GGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=geuVUz5tp740jN4XoO/qLUmFsD3OglQYfc7WRJ+BE5k=; b=JnIojOpzwcUuUzKhROphVk9ej7l1DGdnHYXjNkN4zjliQskt4Qf5m5g7zt/NFjhhWg uEgSuerZgri30XGfuwXWiLfMPclVilRMbmuvg+Z62fTYH0nmN/24Qa9Jkm6ILPHNDQTH 6JddlhWcHO5KsqGGve0jN4mdD3M4R5Fi9pnsMMEVROWuL++XpfAUCUUuF8CVuwVidLbJ O5B/3F4EaF/luYEj60nvFBBTaUxw0f4zjqyT4Wglu2+EESaK4+9dsVxeJ767mu/U62SU /9bP1NaqUu7duv8YCao5w5XmEeU9dl/OYaqeU+E0Z8HTKfwcvV6bXkmCiBvct93b0eIK YvcQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g22si583625ejw.60.2020.04.30.14.26.14; Thu, 30 Apr 2020 14:26:37 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727089AbgD3VYO (ORCPT + 99 others); Thu, 30 Apr 2020 17:24:14 -0400 Received: from mga12.intel.com ([192.55.52.136]:51418 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726818AbgD3VYO (ORCPT ); Thu, 30 Apr 2020 17:24:14 -0400 IronPort-SDR: ojCHCygKZP267MKtt84Z2Ed6iGkr0lVqWQmLWntTVLOlCFnhVTyGwRkXVsbFx9+GcBY3ZaeDrw kYMgG4kBUnqA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Apr 2020 14:24:12 -0700 IronPort-SDR: Df7fajOEj/tSyneF9JgWSfkmFSgTUO/AJCWyEyuqP4sIDUhH2Gh1ZRARhBNSCthaiL+g72hSEZ RN8wUzEqy0qw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,337,1583222400"; d="scan'208";a="405551477" Received: from iweiny-desk2.sc.intel.com ([10.3.52.147]) by orsmga004.jf.intel.com with ESMTP; 30 Apr 2020 14:24:12 -0700 Date: Thu, 30 Apr 2020 14:24:12 -0700 From: Ira Weiny To: Souptick Joarder Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/gup.c: Handle error at earliest for incorrect nr_pages value Message-ID: <20200430212411.GB582335@iweiny-DESK2.sc.intel.com> References: <1588277518-21425-1-git-send-email-jrdr.linux@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1588277518-21425-1-git-send-email-jrdr.linux@gmail.com> User-Agent: Mutt/1.11.1 (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 01, 2020 at 01:41:58AM +0530, 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(). Why is nr_pages not unsigned? I seem to have convinced myself before that there was a good reason for it but really what is the point of calling either of these functions with nr_pages not > 0? > > This can be handled early. Adding a check for the same. > > 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; I think the documentation may be wrong here... Is there a caller who expects a return of 0 for this behavior? It seems like these should be a warn on and return -EINVAL. I just don't see the use case here. Ira > > /* > * 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); > -- > 1.9.1 > >