From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751712AbdCPP1u (ORCPT ); Thu, 16 Mar 2017 11:27:50 -0400 Received: from mga14.intel.com ([192.55.52.115]:19935 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754412AbdCPP1r (ORCPT ); Thu, 16 Mar 2017 11:27:47 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,173,1486454400"; d="scan'208";a="1143341453" From: "Kirill A. Shutemov" To: Linus Torvalds , Andrew Morton , x86@kernel.org, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" Cc: Dave Hansen , "Aneesh Kumar K . V" , Steve Capper , Dann Frazier , Catalin Marinas , linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCH 6/7] mm/gup: Provide hook to check if __GUP_fast() is allowed for the range Date: Thu, 16 Mar 2017 18:26:54 +0300 Message-Id: <20170316152655.37789-7-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170316152655.37789-1-kirill.shutemov@linux.intel.com> References: <20170316152655.37789-1-kirill.shutemov@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is preparation patch for transition of x86 to generic GUP_fast() implementation. On x86, get_user_pages_fast() does few sanity checks to see if we can call __get_user_pages_fast() for the range. Wrapping protection should be useful for generic code too. Signed-off-by: Kirill A. Shutemov --- mm/gup.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index e04f76594eb9..a6e21380c8b0 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1600,6 +1600,21 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write, return nr; } +#ifndef gup_fast_permitted +/* + * Check if it's allowed to use __get_user_pages_fast() for the range or + * need to fallback to non-fast version. + */ +bool gup_fast_permitted(unsigned long start, int nr_pages, int write) +{ + unsigned long len, end; + + len = (unsigned long) nr_pages << PAGE_SHIFT; + end = start + len; + return end >= start; +} +#endif + /** * get_user_pages_fast() - pin user pages in memory * @start: starting user address @@ -1619,11 +1634,14 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write, int get_user_pages_fast(unsigned long start, int nr_pages, int write, struct page **pages) { - int nr, ret; + int nr = 0, ret = 0; start &= PAGE_MASK; - nr = __get_user_pages_fast(start, nr_pages, write, pages); - ret = nr; + + if (gup_fast_permitted(start, nr_pages, write)) { + nr = __get_user_pages_fast(start, nr_pages, write, pages); + ret = nr; + } if (nr < nr_pages) { /* Try to get the remaining pages with get_user_pages */ -- 2.11.0