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=-11.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 61B56C433DF for ; Wed, 19 Aug 2020 17:44:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 26581206DA for ; Wed, 19 Aug 2020 17:44:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 26581206DA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C214D8D0024; Wed, 19 Aug 2020 13:44:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BD3358D0002; Wed, 19 Aug 2020 13:44:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE9518D0024; Wed, 19 Aug 2020 13:44:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0114.hostedemail.com [216.40.44.114]) by kanga.kvack.org (Postfix) with ESMTP id 997718D0002 for ; Wed, 19 Aug 2020 13:44:57 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 56111181AC9BF for ; Wed, 19 Aug 2020 17:44:57 +0000 (UTC) X-FDA: 77168043834.21.bat97_200fe5727029 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 1C6CA180442C0 for ; Wed, 19 Aug 2020 17:44:57 +0000 (UTC) X-HE-Tag: bat97_200fe5727029 X-Filterd-Recvd-Size: 6117 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Wed, 19 Aug 2020 17:44:55 +0000 (UTC) IronPort-SDR: swY06h4g+P7+PNAcs7T/tOAAAyC5UtKfloKPcvoeU2Wi5hQk7YSdNN2Le9xe4+uTgx7MNlt0NR lOEYXV9TcQLA== X-IronPort-AV: E=McAfee;i="6000,8403,9718"; a="152776910" X-IronPort-AV: E=Sophos;i="5.76,332,1592895600"; d="scan'208";a="152776910" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2020 10:44:54 -0700 IronPort-SDR: lvWAKSOz/gYMlM8RHyPflbusPtjx/GMfDwuX4T8/btt5FTlvvXnv7z4AlyTB542e7y+X1acUpf Aee+KmKw5f4Q== X-IronPort-AV: E=Sophos;i="5.76,332,1592895600"; d="scan'208";a="472320725" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2020 10:44:53 -0700 Date: Wed, 19 Aug 2020 10:44:53 -0700 From: Ira Weiny To: Barry Song Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxarm@huawei.com, John Hubbard , Jan Kara , =?iso-8859-1?B?Suly9G1l?= Glisse , "Matthew Wilcox (Oracle)" , Al Viro , Christoph Hellwig , Dan Williams , Dave Chinner , Jason Gunthorpe , Jonathan Corbet , Michal Hocko , Mike Kravetz , Shuah Khan , Vlastimil Babka Subject: Re: [PATCH] mm/gup: don't permit users to call get_user_pages with FOLL_LONGTERM Message-ID: <20200819174452.GA104589@iweiny-DESK2.sc.intel.com> References: <20200819110100.23504-1-song.bao.hua@hisilicon.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <20200819110100.23504-1-song.bao.hua@hisilicon.com> User-Agent: Mutt/1.11.1 (2018-12-01) X-Rspamd-Queue-Id: 1C6CA180442C0 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 Content-Transfer-Encoding: quoted-printable 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 Wed, Aug 19, 2020 at 11:01:00PM +1200, Barry Song wrote: > gug prohibits users from calling get_user_pages() with FOLL_PIN. But it > allows users to call get_user_pages() with FOLL_LONGTERM only. It seems > insensible. >=20 > since FOLL_LONGTERM is a stricter case of FOLL_PIN, we should prohibit > users from calling get_user_pages() with FOLL_LONGTERM while not with > FOLL_PIN. >=20 > mm/gup_benchmark.c used to be the only user who did this improperly. > But it has been fixed by moving to use pin_user_pages(). >=20 > Cc: John Hubbard > Cc: Jan Kara > Cc: J=E9r=F4me Glisse > Cc: "Matthew Wilcox (Oracle)" > Cc: Al Viro > Cc: Christoph Hellwig > Cc: Dan Williams > Cc: Dave Chinner > Cc: Jason Gunthorpe > Cc: Jonathan Corbet > Cc: Michal Hocko > Cc: Mike Kravetz > Cc: Shuah Khan > Cc: Vlastimil Babka > Signed-off-by: Barry Song Seems reasonable to me. Reviewed-by: Ira Weiny > --- > mm/gup.c | 37 ++++++++++++++++++++++--------------- > 1 file changed, 22 insertions(+), 15 deletions(-) >=20 > diff --git a/mm/gup.c b/mm/gup.c > index ae096ea7583f..4da669f79566 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -1789,6 +1789,25 @@ static long __get_user_pages_remote(struct mm_st= ruct *mm, > gup_flags | FOLL_TOUCH | FOLL_REMOTE); > } > =20 > +static bool is_valid_gup_flags(unsigned int gup_flags) > +{ > + /* > + * FOLL_PIN must only be set internally by the pin_user_pages*() APIs= , > + * never directly by the caller, so enforce that with an assertion: > + */ > + if (WARN_ON_ONCE(gup_flags & FOLL_PIN)) > + return false; > + /* > + * FOLL_PIN is a prerequisite to FOLL_LONGTERM. Another way of saying > + * that is, FOLL_LONGTERM is a specific case, more restrictive case o= f > + * FOLL_PIN. > + */ > + if (WARN_ON_ONCE(gup_flags & FOLL_LONGTERM)) > + return false; > + > + return true; > +} > + > /** > * get_user_pages_remote() - pin user pages in memory > * @mm: mm_struct of target mm > @@ -1854,11 +1873,7 @@ long get_user_pages_remote(struct mm_struct *mm, > unsigned int gup_flags, struct page **pages, > struct vm_area_struct **vmas, int *locked) > { > - /* > - * FOLL_PIN must only be set internally by the pin_user_pages*() APIs= , > - * never directly by the caller, so enforce that with an assertion: > - */ > - if (WARN_ON_ONCE(gup_flags & FOLL_PIN)) > + if (!is_valid_gup_flags(gup_flags)) > return -EINVAL; > =20 > return __get_user_pages_remote(mm, start, nr_pages, gup_flags, > @@ -1904,11 +1919,7 @@ long get_user_pages(unsigned long start, unsigne= d long nr_pages, > unsigned int gup_flags, struct page **pages, > struct vm_area_struct **vmas) > { > - /* > - * FOLL_PIN must only be set internally by the pin_user_pages*() APIs= , > - * never directly by the caller, so enforce that with an assertion: > - */ > - if (WARN_ON_ONCE(gup_flags & FOLL_PIN)) > + if (!is_valid_gup_flags(gup_flags)) > return -EINVAL; > =20 > return __gup_longterm_locked(current->mm, start, nr_pages, > @@ -2810,11 +2821,7 @@ EXPORT_SYMBOL_GPL(get_user_pages_fast_only); > int get_user_pages_fast(unsigned long start, int nr_pages, > unsigned int gup_flags, struct page **pages) > { > - /* > - * FOLL_PIN must only be set internally by the pin_user_pages*() APIs= , > - * never directly by the caller, so enforce that: > - */ > - if (WARN_ON_ONCE(gup_flags & FOLL_PIN)) > + if (!is_valid_gup_flags(gup_flags)) > return -EINVAL; > =20 > /* > --=20 > 2.27.0 >=20 >=20 >=20