Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp134920ybv; Thu, 6 Feb 2020 19:39:46 -0800 (PST) X-Google-Smtp-Source: APXvYqwhMC5PKWh9e0zH2awLdHqanC2kT3Gu65GLeWSWdOpGM2EdDc4CpwcpgAb1p1mDe/My9GDg X-Received: by 2002:a9d:4706:: with SMTP id a6mr1007415otf.331.1581046786470; Thu, 06 Feb 2020 19:39:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581046786; cv=none; d=google.com; s=arc-20160816; b=M+nyuWDz/SLbHzDB8hNr/egJivHnHiDVqrEgZEXgi8R3X0MZlHGwWECK2P5sKwibfu hHOkmgdnGzy2Mp8qNZ19eF7j6IcPyVFV+53XD94bK1EMWhDxsyctqhzzDr4MOmVXNfIt bnQA166KaqItmU7BsGGFRrMr5II0CY/LCVIvIZUf71J4tnZyzL3UlRrfJ+C5i7+eQQXJ xeFoSodcYlshkCfBNEXoojRjaoMtMwwMUM4H/EnJkE0U+bzZdD9MCwp/k3rwAryeD8dv HMRwEqmTCwdOt7Px7wh3bFre5WSuuoRPJ8ucJrdtIC/LHWUnDJJaQmLGPB0yVp9YQOEP Adog== 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=5eZvoA5nW7X3dfTYOUjuH4An39unHi+TdehpbIAk1Fs=; b=zvY0McsCMPfiqjG+XouYQ1DE3Ip4tjW4zfT9jzwNWk+5qZicBdMXbtnyYNuyqBEhuT P7RDR8PpIOrG9DoiVcwj/Q4898MC98V9tLgjrSnRt+zyJYKYHh6cTNXulAyay1u3aif3 OBqQALfPYFDFGQvrPYihUHSGs4KqxYadHKqSdbCTp1UYlehgvXN99xp6ynOlT9z+GoPe lSkUrtzJHwE4bzrcZDcVq+gM6j+/06XSZjc9hvqJFzNLdqa94P819XFfujkeDfWPzN5R Cwcy5R1usfRZzZ9U/Tw81mRtBHqg9TzMEtkuTYAW4ElUJhG0nw8XDa+BDYLjSuLzwrit G+RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=aC+144I7; 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 k9si3221653oiw.262.2020.02.06.19.39.35; Thu, 06 Feb 2020 19:39:46 -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=aC+144I7; 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 S1727787AbgBGDiP (ORCPT + 99 others); Thu, 6 Feb 2020 22:38:15 -0500 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:4792 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727562AbgBGDhl (ORCPT ); Thu, 6 Feb 2020 22:37:41 -0500 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Thu, 06 Feb 2020 19:36:38 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Thu, 06 Feb 2020 19:37:37 -0800 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Thu, 06 Feb 2020 19:37:37 -0800 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 7 Feb 2020 03:37:36 +0000 Received: from hqnvemgw03.nvidia.com (10.124.88.68) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Fri, 7 Feb 2020 03:37:36 +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 02/12] mm/gup: split get_user_pages_remote() into two routines Date: Thu, 6 Feb 2020 19:37:25 -0800 Message-ID: <20200207033735.308000-3-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=1581046598; bh=5eZvoA5nW7X3dfTYOUjuH4An39unHi+TdehpbIAk1Fs=; 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=aC+144I78xWccDzSifaSOZfqkHcg4OCzgMSFlOAiFFWe5dUHWOwFhXIxuAq1qy8Uj JIlU4ca5BeRRuAyJSQgmdCnfCzQjV8Qrodk1+yCtUjpWwMNsKRCR2gNbopyz/XKVQz LUR/qVseFtbbMQscPIClUMQG/Fbm2Kpk2kTe/BdNS5AaMVmeWxL3r954W2qXkexBQL WfMfGMLiGVs9RDDGwb3Q99ct5UrpuWHoYte2StDFHnLdAuPFx3lZwjZloCIuJakQio gGEqGEvKgg5cidaniL6kAmzCkftFlItiuWlT6qG7ZBGW8Zy2SgqWt+Ea4WLCWDt965 nTCVNlCeedIsQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org An upcoming patch requires reusing the implementation of get_user_pages_remote(). Split up get_user_pages_remote() into an outer routine that checks flags, and an implementation routine that will be reused. This makes subsequent changes much easier to understand. There should be no change in behavior due to this patch. Acked-by: Kirill A. Shutemov Reviewed-by: Jan Kara Signed-off-by: John Hubbard --- mm/gup.c | 56 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 1b521e0ac1de..b699500da077 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1557,6 +1557,37 @@ static __always_inline long __gup_longterm_locked(st= ruct task_struct *tsk, } #endif /* CONFIG_FS_DAX || CONFIG_CMA */ =20 +#ifdef CONFIG_MMU +static long __get_user_pages_remote(struct task_struct *tsk, + struct mm_struct *mm, + unsigned long start, unsigned long nr_pages, + unsigned int gup_flags, struct page **pages, + struct vm_area_struct **vmas, int *locked) +{ + /* + * Parts of FOLL_LONGTERM behavior are incompatible with + * FAULT_FLAG_ALLOW_RETRY because of the FS DAX check requirement on + * vmas. However, this only comes up if locked is set, and there are + * callers that do request FOLL_LONGTERM, but do not set locked. So, + * allow what we can. + */ + if (gup_flags & FOLL_LONGTERM) { + if (WARN_ON_ONCE(locked)) + return -EINVAL; + /* + * This will check the vmas (even if our vmas arg is NULL) + * and return -ENOTSUPP if DAX isn't allowed in this case: + */ + return __gup_longterm_locked(tsk, mm, start, nr_pages, pages, + vmas, gup_flags | FOLL_TOUCH | + FOLL_REMOTE); + } + + return __get_user_pages_locked(tsk, mm, start, nr_pages, pages, vmas, + locked, + gup_flags | FOLL_TOUCH | FOLL_REMOTE); +} + /* * get_user_pages_remote() - pin user pages in memory * @tsk: the task_struct to use for page fault accounting, or @@ -1619,7 +1650,6 @@ static __always_inline long __gup_longterm_locked(str= uct task_struct *tsk, * should use get_user_pages because it cannot pass * FAULT_FLAG_ALLOW_RETRY to handle_mm_fault. */ -#ifdef CONFIG_MMU long get_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm, unsigned long start, unsigned long nr_pages, unsigned int gup_flags, struct page **pages, @@ -1632,28 +1662,8 @@ long get_user_pages_remote(struct task_struct *tsk, = struct mm_struct *mm, if (WARN_ON_ONCE(gup_flags & FOLL_PIN)) return -EINVAL; =20 - /* - * Parts of FOLL_LONGTERM behavior are incompatible with - * FAULT_FLAG_ALLOW_RETRY because of the FS DAX check requirement on - * vmas. However, this only comes up if locked is set, and there are - * callers that do request FOLL_LONGTERM, but do not set locked. So, - * allow what we can. - */ - if (gup_flags & FOLL_LONGTERM) { - if (WARN_ON_ONCE(locked)) - return -EINVAL; - /* - * This will check the vmas (even if our vmas arg is NULL) - * and return -ENOTSUPP if DAX isn't allowed in this case: - */ - return __gup_longterm_locked(tsk, mm, start, nr_pages, pages, - vmas, gup_flags | FOLL_TOUCH | - FOLL_REMOTE); - } - - return __get_user_pages_locked(tsk, mm, start, nr_pages, pages, vmas, - locked, - gup_flags | FOLL_TOUCH | FOLL_REMOTE); + return __get_user_pages_remote(tsk, mm, start, nr_pages, gup_flags, + pages, vmas, locked); } EXPORT_SYMBOL(get_user_pages_remote); =20 --=20 2.25.0