Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp135303ybv; Thu, 6 Feb 2020 19:40:18 -0800 (PST) X-Google-Smtp-Source: APXvYqyCZOXAVJYQUELFD8WZ4h3pytBsB9ejXNEgGz+ZuQ7cYQGLdeIxwqulX/xCI4hkt7P8bdgx X-Received: by 2002:a05:6830:22ee:: with SMTP id t14mr1093928otc.236.1581046818341; Thu, 06 Feb 2020 19:40:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581046818; cv=none; d=google.com; s=arc-20160816; b=Yl2205LWioVQxLDEr06ZTv9O6XTvbJIq034aH7A9GcOg6hv61+/j/I17KkjQCvmxkD u0OPTXcaN5HoWD9w32G1DIye57AFKVtmDcE4E00fU8NGq04TgOah8QU7pyt4b9OH176h PSRXGX0XYrpDgkk+aR9Ubjp9hB3Aq5P3jpJfFSBg8wD9+PZHhd263UknWr00ooGjXLjv e1Us3G7QGs8gHyCS5sPR1JEt4p90G7udMH4GFOUWBgfF5wFgdb04rQg250cYWp08+HIs yMFP27FIgsUBMNR5mVojn2G/yVKZorOR7IFMaEfsj5kc7lt5AfIeLqlkambF8NAYvvmV d//g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=zdKJN+80LnhrM42H0YcEzysuucpfBmwOwmXaeST0eWY=; b=RnSQOg5l9n1FFdrTwO/HXO7pxxtPaoN6kPtVQbKFlP8kEuuYh06e6tesZOoQW7kveE wyXqu5Au/g9M5pkH1F27/ZlCLBlsqD0gHl9DQc9OV2lZlKhKsnYtrKXxC52eYpVTzk2V ZsaabnMZmQ2cZsQSxOord62F1iQL62EUPLTzRUPnTsOeA3qwDgELVcAYbY3F22ggnqjZ GW18vse4vP7BS7+brFTebZeYyAGOY5ZbI8vNBfHNPCUmwKHCe8Bx5pJiJIqof/vp/MQx YsZQCOC4OwXcnXgYS2j/zY1fE7R6Hesr4XoQcTkw27yCoLkcmWec6EwFOqRymh/IWAPK Zi4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=BCVsa9Vg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l23si918558otj.302.2020.02.06.19.40.05; Thu, 06 Feb 2020 19:40:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=BCVsa9Vg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727003AbgBGDhn (ORCPT + 99 others); Thu, 6 Feb 2020 22:37:43 -0500 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:13345 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727527AbgBGDhj (ORCPT ); Thu, 6 Feb 2020 22:37:39 -0500 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Thu, 06 Feb 2020 19:37:12 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Thu, 06 Feb 2020 19:37:37 -0800 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Thu, 06 Feb 2020 19:37:37 -0800 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 7 Feb 2020 03:37:37 +0000 Received: from hqnvemgw03.nvidia.com (10.124.88.68) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Fri, 7 Feb 2020 03:37:37 +0000 Received: from blueforge.nvidia.com (Not Verified[10.110.48.28]) by hqnvemgw03.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Thu, 06 Feb 2020 19:37:36 -0800 From: John Hubbard To: Andrew Morton CC: Al Viro , Christoph Hellwig , Dan Williams , Dave Chinner , Ira Weiny , Jan Kara , Jason Gunthorpe , Jonathan Corbet , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , "Kirill A . Shutemov" , Michal Hocko , "Mike Kravetz" , Shuah Khan , "Vlastimil Babka" , Matthew Wilcox , , , , , , LKML , John Hubbard , "Kirill A . Shutemov" Subject: [PATCH v5 06/12] mm/gup: require FOLL_GET for get_user_pages_fast() Date: Thu, 6 Feb 2020 19:37:29 -0800 Message-ID: <20200207033735.308000-7-jhubbard@nvidia.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200207033735.308000-1-jhubbard@nvidia.com> References: <20200207033735.308000-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1581046633; bh=zdKJN+80LnhrM42H0YcEzysuucpfBmwOwmXaeST0eWY=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:X-NVConfidentiality: Content-Transfer-Encoding:Content-Type; b=BCVsa9Vg/FLx131VkBwVusgApBWD3rXCMU4HwFYgqK+JHpePFTfpxlV7oG9uqvwoD eFInmWS/uaWR2xl9VFdCBWhGrmcdqU43SUDY+MjXrnqfaP1+yCtpfUdgqU2hzEGK3j OMpaRT/Yiw0G3m/vV1RCf5Xl1oK5n4Q587r5K2jjOC9vErW93juZY6sOFBaqP+MZok 7EdA7Ui/FblkaCwg16abHqUYqltQJA7CKenmPCbrJteRfvVY/d+b5anez4HgL/09d9 yLGxVuVVc7GjMkopOFdmOp6vT2zV+F4i1Lx9L2gWpSQfJxkLl+Xmb7ViCvcDclCSnF xK8ZrUQ/PlMtQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Internal to mm/gup.c, require that get_user_pages_fast() and __get_user_pages_fast() identify themselves, by setting FOLL_GET. This is required in order to be able to make decisions based on "FOLL_PIN, or FOLL_GET, or both or neither are set", in upcoming patches. Acked-by: Kirill A. Shutemov Reviewed-by: Jan Kara Signed-off-by: John Hubbard --- mm/gup.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index e5f75e886663..c8affbea2019 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2390,6 +2390,14 @@ int __get_user_pages_fast(unsigned long start, int n= r_pages, int write, unsigned long len, end; unsigned long flags; int nr =3D 0; + /* + * Internally (within mm/gup.c), gup fast variants must set FOLL_GET, + * because gup fast is always a "pin with a +1 page refcount" request. + */ + unsigned int gup_flags =3D FOLL_GET; + + if (write) + gup_flags |=3D FOLL_WRITE; =20 start =3D untagged_addr(start) & PAGE_MASK; len =3D (unsigned long) nr_pages << PAGE_SHIFT; @@ -2415,7 +2423,7 @@ int __get_user_pages_fast(unsigned long start, int nr= _pages, int write, if (IS_ENABLED(CONFIG_HAVE_FAST_GUP) && gup_fast_permitted(start, end)) { local_irq_save(flags); - gup_pgd_range(start, end, write ? FOLL_WRITE : 0, pages, &nr); + gup_pgd_range(start, end, gup_flags, pages, &nr); local_irq_restore(flags); } =20 @@ -2454,7 +2462,7 @@ static int internal_get_user_pages_fast(unsigned long= start, int nr_pages, int nr =3D 0, ret =3D 0; =20 if (WARN_ON_ONCE(gup_flags & ~(FOLL_WRITE | FOLL_LONGTERM | - FOLL_FORCE | FOLL_PIN))) + FOLL_FORCE | FOLL_PIN | FOLL_GET))) return -EINVAL; =20 start =3D untagged_addr(start) & PAGE_MASK; @@ -2521,6 +2529,13 @@ int get_user_pages_fast(unsigned long start, int nr_= pages, if (WARN_ON_ONCE(gup_flags & FOLL_PIN)) return -EINVAL; =20 + /* + * The caller may or may not have explicitly set FOLL_GET; either way is + * OK. However, internally (within mm/gup.c), gup fast variants must set + * FOLL_GET, because gup fast is always a "pin with a +1 page refcount" + * request. + */ + gup_flags |=3D FOLL_GET; return internal_get_user_pages_fast(start, nr_pages, gup_flags, pages); } EXPORT_SYMBOL_GPL(get_user_pages_fast); --=20 2.25.0