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=-9.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 C74B3C433E2 for ; Thu, 3 Sep 2020 07:13:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 860D62071B for ; Thu, 3 Sep 2020 07:13:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M/tFSSmE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 860D62071B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 00CB76B0068; Thu, 3 Sep 2020 03:13:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F02206B006C; Thu, 3 Sep 2020 03:13:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DEE676B006E; Thu, 3 Sep 2020 03:13:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0209.hostedemail.com [216.40.44.209]) by kanga.kvack.org (Postfix) with ESMTP id CA5036B0068 for ; Thu, 3 Sep 2020 03:13:03 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 849D2824556B for ; Thu, 3 Sep 2020 07:13:03 +0000 (UTC) X-FDA: 77220883446.11.nose85_040d62d270a7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id D8CBA180F76A4 for ; Thu, 3 Sep 2020 07:12:58 +0000 (UTC) X-HE-Tag: nose85_040d62d270a7 X-Filterd-Recvd-Size: 8278 Received: from mail-lf1-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Thu, 3 Sep 2020 07:12:58 +0000 (UTC) Received: by mail-lf1-f68.google.com with SMTP id q8so1270462lfb.6 for ; Thu, 03 Sep 2020 00:12:58 -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:content-transfer-encoding; bh=+YHglauWyo1GpdJHdSOrL6fqb9MSa+7lxYYxKcetf0w=; b=M/tFSSmEvorZluN8EPZwgE5Tgn3kvpXb09Z3o12FeaxXZnpiVOm2R09pYwftnj4bMz YI5qV3nmRKPhR9Kzj9Xs4SHdUw2A8SejSAhbTu2ymuaH3OTHtgfmJiUwd6C1NeOl8tbc iwaC3enWC/wFq8pILWDBOJ8p+4Tb9VDbyRZfFJDlpMLfT1fBa/mt5s4sVnxArB8JVxFw 7YOD4is4mtZECMvMJnYfOwNylGf/2zQj4eiaNMGNTVf2qnixSNRhZ2AsegMdLaGQkk1k V6vSuk7WKbJUos5jcAZu58DYZtm4TgqGjAgEWfx5mUCrFMEY+QLcCfQ1kOHZg8t9GQap u17A== 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:content-transfer-encoding; bh=+YHglauWyo1GpdJHdSOrL6fqb9MSa+7lxYYxKcetf0w=; b=U6twsCvy01Cy+7nkbUXI3TYoHvaDC3TflIoVLlqU9svKrEYFUuokeskniM3KABXydY xkKckE/FnD6nIXA/w5yt9JYG3cX3XuFc3HgsHsUrtix03Kco3Vg6pmN2R9HHoHCkCtKb Sm7f8wed9tcCszEPPIHCxOR17OqiKjYALbuxdjSNrjXDwd/+f5x+8tA0wUEbjbpnjPRp XEY/aa6uGJEluPVf0wzVy8ZeDiW4Wqwe1jJ4zCU+owXmQwbmMhzutsm/T60qiSBqzvG5 UO6jLCvFfhHYbjk9RkFh1qEOSGbQOLz45KkiBH5eucLVPK+gjKWt9WGoYhnw3FF/zG6+ jAPA== X-Gm-Message-State: AOAM532W9xG3aKXsVjiI4E3msJwFpP1rRd4zCKSYLBZ4eFbkblVbdZoU NpwgaqGt6UagAko4ddrosina40b9oY+nYeABSPo= X-Google-Smtp-Source: ABdhPJz4vBiWgH7j7O6wQk0s6XYJWDAbW6Sz7JU6Ag7skgwd7SxNKZFkpJIGrf650+mdKX7h/zafyBdSX9nQ4Hw/+Xw= X-Received: by 2002:a19:ee0d:: with SMTP id g13mr495606lfb.139.1599117176910; Thu, 03 Sep 2020 00:12:56 -0700 (PDT) MIME-Version: 1.0 References: <20200819110100.23504-1-song.bao.hua@hisilicon.com> In-Reply-To: From: Souptick Joarder Date: Thu, 3 Sep 2020 12:42:44 +0530 Message-ID: Subject: Re: [PATCH] mm/gup: don't permit users to call get_user_pages with FOLL_LONGTERM To: John Hubbard Cc: Barry Song , Andrew Morton , Linux-MM , linux-kernel@vger.kernel.org, linuxarm@huawei.com, 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: D8CBA180F76A4 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 Wed, Aug 19, 2020 at 11:45 PM John Hubbard wrote: > > 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. > > > > 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. > > > > 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. We can use is_valid_gup_flags() inside -> get_user_pages_locked(), get_user_pages_unlocked(), pin_user_pages_locked() as well. Are you planning to add it in future patches ? > > thanks, > -- > John Hubbard > NVIDIA > > > > > 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(-) > > > > 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_REMO= TE); > > } > > > > +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 assertio= n: > > + */ > > + if (WARN_ON_ONCE(gup_flags & FOLL_PIN)) > > + return false; > > + /* > > + * FOLL_PIN is a prerequisite to FOLL_LONGTERM. Another way of sa= ying > > + * that is, FOLL_LONGTERM is a specific case, more restrictive ca= se 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 assertio= n: > > - */ > > - if (WARN_ON_ONCE(gup_flags & FOLL_PIN)) > > + if (!is_valid_gup_flags(gup_flags)) > > return -EINVAL; > > > > 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 assertio= n: > > - */ > > - if (WARN_ON_ONCE(gup_flags & FOLL_PIN)) > > + if (!is_valid_gup_flags(gup_flags)) > > return -EINVAL; > > > > 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; > > > > /* > > > >