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=-12.7 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,NICE_REPLY_A,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 37790C433E1 for ; Wed, 19 Aug 2020 18:15:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ECD3620758 for ; Wed, 19 Aug 2020 18:15:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="JKKUjIko" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ECD3620758 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 70D178D004D; Wed, 19 Aug 2020 14:15:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6BE118D0002; Wed, 19 Aug 2020 14:15:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D4EF8D004D; Wed, 19 Aug 2020 14:15:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 483868D0002 for ; Wed, 19 Aug 2020 14:15:06 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id DF54B3499 for ; Wed, 19 Aug 2020 18:15:05 +0000 (UTC) X-FDA: 77168119770.11.seed13_13008802702a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id AD339180F8B86 for ; Wed, 19 Aug 2020 18:15:05 +0000 (UTC) X-HE-Tag: seed13_13008802702a X-Filterd-Recvd-Size: 7115 Received: from hqnvemgate25.nvidia.com (hqnvemgate25.nvidia.com [216.228.121.64]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Wed, 19 Aug 2020 18:15:04 +0000 (UTC) Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Wed, 19 Aug 2020 11:14:04 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Wed, 19 Aug 2020 11:15:03 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Wed, 19 Aug 2020 11:15:03 -0700 Received: from [10.2.49.218] (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 19 Aug 2020 18:14:56 +0000 Subject: Re: [PATCH] mm/gup: don't permit users to call get_user_pages with FOLL_LONGTERM To: Barry Song , , , CC: , Jan Kara , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , "Matthew Wilcox (Oracle)" , Al Viro , "Christoph Hellwig" , Dan Williams , "Dave Chinner" , Jason Gunthorpe , "Jonathan Corbet" , Michal Hocko , Mike Kravetz , Shuah Khan , Vlastimil Babka References: <20200819110100.23504-1-song.bao.hua@hisilicon.com> From: John Hubbard Message-ID: Date: Wed, 19 Aug 2020 11:14:55 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <20200819110100.23504-1-song.bao.hua@hisilicon.com> X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1597860845; bh=gNdAT/etTZwZteED0BIN2T3CZYf5c64GDyXgROoUS1o=; h=X-PGP-Universal:Subject:To:CC:References:From:Message-ID:Date: User-Agent:MIME-Version:In-Reply-To:X-Originating-IP: X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=JKKUjIkoVN9iC4WXRB5nrYw218IysKH7+JRf9wi0cjxJrbhYBwzeU5CV+QVHgt1tF XW03l6xc9F9fGw7Wr3N0EWXpC83URUk9jPN5SyYmRdGkht8QLZValtcSwUZ05bIwL0 fUC73aIfquDBW7xe298badhDUMs+2OuBVtpSYI+k1RAbSncdUuRLDISrRucv7RXUpW 1VOFlOxO7UptMfR0ahtUoUvreYKH4JmeZQnvZqvY3tplSsA/7E2U655uBLII6aOkjU SoMDfOrkPqlsJII+J7QyGDd2OJy2w/tESfrhtPctzDjWobfW0RC4iZdsxhx0NayF8k AH42Yl+2/kodg== X-Rspamd-Queue-Id: AD339180F8B86 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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 8/19/20 4:01 AM, Barry Song wrote: > gug prohibits users from calling get_user_pages() with FOLL_PIN. But it Maybe Andrew can fix the typo above: gug --> gup. > 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(). For future patches, you don't have to write everything in the commit log. Some things are better placed in a cover letter or after the "---" line, because they don't need to be recorded forever. Anyway, the diffs seem fine, assuming that you've audited the call sites. thanks, --=20 John Hubbard NVIDIA >=20 > Cc: John Hubbard > Cc: Jan Kara > Cc: J=C3=A9r=C3=B4me 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 > --- > 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_stru= ct *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 of > + * 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, unsigned = 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