aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2016-04-04 04:24:58 -0400
committerIngo Molnar <mingo@kernel.org>2016-04-07 04:46:14 -0400
commitc12d2da56d0e07d230968ee2305aaa86b93a6832 (patch)
tree18305357f1190cd1fc750e1d093fe610429e7628
parent9735a22799b9214d17d3c231fe377fc852f042e9 (diff)
mm/gup: Remove the macro overload API migration helpers from the get_user*() APIs
The pkeys changes brought about a truly hideous set of macros in: cde70140fed8 ("mm/gup: Overload get_user_pages() functions") ... which macros are (ab-)using the fact that __VA_ARGS__ can be used to shift parameter positions in macro arguments without breaking the build and so can be used to call separate C functions depending on the number of arguments of the macro. This allowed easy migration of these 3 GUP APIs, as both these variants worked at the C level: old: ret = get_user_pages(current, current->mm, address, 1, 1, 0, &page, NULL); new: ret = get_user_pages(address, 1, 1, 0, &page, NULL); ... while we also generated a (functionally harmless but noticeable) build time warning if the old API was used. As there are over 300 uses of these APIs, this trick eased the migration of the API and avoided excessive migration pain in linux-next. Now, with its work done, get rid of all of that complication and ugliness: 3 files changed, 16 insertions(+), 140 deletions(-) ... where the linecount of the migration hack was further inflated by the fact that there are NOMMU variants of these GUP APIs as well. Much of the conversion was done in linux-next over the past couple of months, and Linus recently removed all remaining old API uses from the upstream tree in the following upstrea commit: cb107161df3c ("Convert straggling drivers to new six-argument get_user_pages()") There was one more old-API usage in mm/gup.c, in the CONFIG_HAVE_GENERIC_RCU_GUP code path that ARM, ARM64 and PowerPC uses. After this commit any old API usage will break the build. [ Also fixed a PowerPC/HAVE_GENERIC_RCU_GUP warning reported by Stephen Rothwell. ] Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Dave Hansen <dave@sr71.net> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--include/linux/mm.h64
-rw-r--r--mm/gup.c52
-rw-r--r--mm/nommu.c44
3 files changed, 17 insertions, 143 deletions
diff --git a/include/linux/mm.h b/include/linux/mm.h
index ed6407d1b7b5..d6508a025a31 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1250,78 +1250,20 @@ long get_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm,
1250 unsigned long start, unsigned long nr_pages, 1250 unsigned long start, unsigned long nr_pages,
1251 int write, int force, struct page **pages, 1251 int write, int force, struct page **pages,
1252 struct vm_area_struct **vmas); 1252 struct vm_area_struct **vmas);
1253long get_user_pages6(unsigned long start, unsigned long nr_pages, 1253long get_user_pages(unsigned long start, unsigned long nr_pages,
1254 int write, int force, struct page **pages, 1254 int write, int force, struct page **pages,
1255 struct vm_area_struct **vmas); 1255 struct vm_area_struct **vmas);
1256long get_user_pages_locked6(unsigned long start, unsigned long nr_pages, 1256long get_user_pages_locked(unsigned long start, unsigned long nr_pages,
1257 int write, int force, struct page **pages, int *locked); 1257 int write, int force, struct page **pages, int *locked);
1258long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm, 1258long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm,
1259 unsigned long start, unsigned long nr_pages, 1259 unsigned long start, unsigned long nr_pages,
1260 int write, int force, struct page **pages, 1260 int write, int force, struct page **pages,
1261 unsigned int gup_flags); 1261 unsigned int gup_flags);
1262long get_user_pages_unlocked5(unsigned long start, unsigned long nr_pages, 1262long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages,
1263 int write, int force, struct page **pages); 1263 int write, int force, struct page **pages);
1264int get_user_pages_fast(unsigned long start, int nr_pages, int write, 1264int get_user_pages_fast(unsigned long start, int nr_pages, int write,
1265 struct page **pages); 1265 struct page **pages);
1266 1266
1267/* suppress warnings from use in EXPORT_SYMBOL() */
1268#ifndef __DISABLE_GUP_DEPRECATED
1269#define __gup_deprecated __deprecated
1270#else
1271#define __gup_deprecated
1272#endif
1273/*
1274 * These macros provide backward-compatibility with the old
1275 * get_user_pages() variants which took tsk/mm. These
1276 * functions/macros provide both compile-time __deprecated so we
1277 * can catch old-style use and not break the build. The actual
1278 * functions also have WARN_ON()s to let us know at runtime if
1279 * the get_user_pages() should have been the "remote" variant.
1280 *
1281 * These are hideous, but temporary.
1282 *
1283 * If you run into one of these __deprecated warnings, look
1284 * at how you are calling get_user_pages(). If you are calling
1285 * it with current/current->mm as the first two arguments,
1286 * simply remove those arguments. The behavior will be the same
1287 * as it is now. If you are calling it on another task, use
1288 * get_user_pages_remote() instead.
1289 *
1290 * Any questions? Ask Dave Hansen <dave@sr71.net>
1291 */
1292long
1293__gup_deprecated
1294get_user_pages8(struct task_struct *tsk, struct mm_struct *mm,
1295 unsigned long start, unsigned long nr_pages,
1296 int write, int force, struct page **pages,
1297 struct vm_area_struct **vmas);
1298#define GUP_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, get_user_pages, ...) \
1299 get_user_pages
1300#define get_user_pages(...) GUP_MACRO(__VA_ARGS__, \
1301 get_user_pages8, x, \
1302 get_user_pages6, x, x, x, x, x)(__VA_ARGS__)
1303
1304__gup_deprecated
1305long get_user_pages_locked8(struct task_struct *tsk, struct mm_struct *mm,
1306 unsigned long start, unsigned long nr_pages,
1307 int write, int force, struct page **pages,
1308 int *locked);
1309#define GUPL_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, get_user_pages_locked, ...) \
1310 get_user_pages_locked
1311#define get_user_pages_locked(...) GUPL_MACRO(__VA_ARGS__, \
1312 get_user_pages_locked8, x, \
1313 get_user_pages_locked6, x, x, x, x)(__VA_ARGS__)
1314
1315__gup_deprecated
1316long get_user_pages_unlocked7(struct task_struct *tsk, struct mm_struct *mm,
1317 unsigned long start, unsigned long nr_pages,
1318 int write, int force, struct page **pages);
1319#define GUPU_MACRO(_1, _2, _3, _4, _5, _6, _7, get_user_pages_unlocked, ...) \
1320 get_user_pages_unlocked
1321#define get_user_pages_unlocked(...) GUPU_MACRO(__VA_ARGS__, \
1322 get_user_pages_unlocked7, x, \
1323 get_user_pages_unlocked5, x, x, x, x)(__VA_ARGS__)
1324
1325/* Container for pinned pfns / pages */ 1267/* Container for pinned pfns / pages */
1326struct frame_vector { 1268struct frame_vector {
1327 unsigned int nr_allocated; /* Number of frames we have space for */ 1269 unsigned int nr_allocated; /* Number of frames we have space for */
diff --git a/mm/gup.c b/mm/gup.c
index 7f1c4fb77cfa..63d5e002768b 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1,4 +1,3 @@
1#define __DISABLE_GUP_DEPRECATED 1
2#include <linux/kernel.h> 1#include <linux/kernel.h>
3#include <linux/errno.h> 2#include <linux/errno.h>
4#include <linux/err.h> 3#include <linux/err.h>
@@ -839,7 +838,7 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk,
839 * if (locked) 838 * if (locked)
840 * up_read(&mm->mmap_sem); 839 * up_read(&mm->mmap_sem);
841 */ 840 */
842long get_user_pages_locked6(unsigned long start, unsigned long nr_pages, 841long get_user_pages_locked(unsigned long start, unsigned long nr_pages,
843 int write, int force, struct page **pages, 842 int write, int force, struct page **pages,
844 int *locked) 843 int *locked)
845{ 844{
@@ -847,7 +846,7 @@ long get_user_pages_locked6(unsigned long start, unsigned long nr_pages,
847 write, force, pages, NULL, locked, true, 846 write, force, pages, NULL, locked, true,
848 FOLL_TOUCH); 847 FOLL_TOUCH);
849} 848}
850EXPORT_SYMBOL(get_user_pages_locked6); 849EXPORT_SYMBOL(get_user_pages_locked);
851 850
852/* 851/*
853 * Same as get_user_pages_unlocked(...., FOLL_TOUCH) but it allows to 852 * Same as get_user_pages_unlocked(...., FOLL_TOUCH) but it allows to
@@ -892,13 +891,13 @@ EXPORT_SYMBOL(__get_user_pages_unlocked);
892 * or if "force" shall be set to 1 (get_user_pages_fast misses the 891 * or if "force" shall be set to 1 (get_user_pages_fast misses the
893 * "force" parameter). 892 * "force" parameter).
894 */ 893 */
895long get_user_pages_unlocked5(unsigned long start, unsigned long nr_pages, 894long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages,
896 int write, int force, struct page **pages) 895 int write, int force, struct page **pages)
897{ 896{
898 return __get_user_pages_unlocked(current, current->mm, start, nr_pages, 897 return __get_user_pages_unlocked(current, current->mm, start, nr_pages,
899 write, force, pages, FOLL_TOUCH); 898 write, force, pages, FOLL_TOUCH);
900} 899}
901EXPORT_SYMBOL(get_user_pages_unlocked5); 900EXPORT_SYMBOL(get_user_pages_unlocked);
902 901
903/* 902/*
904 * get_user_pages_remote() - pin user pages in memory 903 * get_user_pages_remote() - pin user pages in memory
@@ -972,7 +971,7 @@ EXPORT_SYMBOL(get_user_pages_remote);
972 * and mm being operated on are the current task's. We also 971 * and mm being operated on are the current task's. We also
973 * obviously don't pass FOLL_REMOTE in here. 972 * obviously don't pass FOLL_REMOTE in here.
974 */ 973 */
975long get_user_pages6(unsigned long start, unsigned long nr_pages, 974long get_user_pages(unsigned long start, unsigned long nr_pages,
976 int write, int force, struct page **pages, 975 int write, int force, struct page **pages,
977 struct vm_area_struct **vmas) 976 struct vm_area_struct **vmas)
978{ 977{
@@ -980,7 +979,7 @@ long get_user_pages6(unsigned long start, unsigned long nr_pages,
980 write, force, pages, vmas, NULL, false, 979 write, force, pages, vmas, NULL, false,
981 FOLL_TOUCH); 980 FOLL_TOUCH);
982} 981}
983EXPORT_SYMBOL(get_user_pages6); 982EXPORT_SYMBOL(get_user_pages);
984 983
985/** 984/**
986 * populate_vma_page_range() - populate a range of pages in the vma. 985 * populate_vma_page_range() - populate a range of pages in the vma.
@@ -1491,7 +1490,6 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
1491int get_user_pages_fast(unsigned long start, int nr_pages, int write, 1490int get_user_pages_fast(unsigned long start, int nr_pages, int write,
1492 struct page **pages) 1491 struct page **pages)
1493{ 1492{
1494 struct mm_struct *mm = current->mm;
1495 int nr, ret; 1493 int nr, ret;
1496 1494
1497 start &= PAGE_MASK; 1495 start &= PAGE_MASK;
@@ -1503,8 +1501,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
1503 start += nr << PAGE_SHIFT; 1501 start += nr << PAGE_SHIFT;
1504 pages += nr; 1502 pages += nr;
1505 1503
1506 ret = get_user_pages_unlocked(current, mm, start, 1504 ret = get_user_pages_unlocked(start, nr_pages - nr, write, 0, pages);
1507 nr_pages - nr, write, 0, pages);
1508 1505
1509 /* Have to be a bit careful with return values */ 1506 /* Have to be a bit careful with return values */
1510 if (nr > 0) { 1507 if (nr > 0) {
@@ -1519,38 +1516,3 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
1519} 1516}
1520 1517
1521#endif /* CONFIG_HAVE_GENERIC_RCU_GUP */ 1518#endif /* CONFIG_HAVE_GENERIC_RCU_GUP */
1522
1523long get_user_pages8(struct task_struct *tsk, struct mm_struct *mm,
1524 unsigned long start, unsigned long nr_pages,
1525 int write, int force, struct page **pages,
1526 struct vm_area_struct **vmas)
1527{
1528 WARN_ONCE(tsk != current, "get_user_pages() called on remote task");
1529 WARN_ONCE(mm != current->mm, "get_user_pages() called on remote mm");
1530
1531 return get_user_pages6(start, nr_pages, write, force, pages, vmas);
1532}
1533EXPORT_SYMBOL(get_user_pages8);
1534
1535long get_user_pages_locked8(struct task_struct *tsk, struct mm_struct *mm,
1536 unsigned long start, unsigned long nr_pages,
1537 int write, int force, struct page **pages, int *locked)
1538{
1539 WARN_ONCE(tsk != current, "get_user_pages_locked() called on remote task");
1540 WARN_ONCE(mm != current->mm, "get_user_pages_locked() called on remote mm");
1541
1542 return get_user_pages_locked6(start, nr_pages, write, force, pages, locked);
1543}
1544EXPORT_SYMBOL(get_user_pages_locked8);
1545
1546long get_user_pages_unlocked7(struct task_struct *tsk, struct mm_struct *mm,
1547 unsigned long start, unsigned long nr_pages,
1548 int write, int force, struct page **pages)
1549{
1550 WARN_ONCE(tsk != current, "get_user_pages_unlocked() called on remote task");
1551 WARN_ONCE(mm != current->mm, "get_user_pages_unlocked() called on remote mm");
1552
1553 return get_user_pages_unlocked5(start, nr_pages, write, force, pages);
1554}
1555EXPORT_SYMBOL(get_user_pages_unlocked7);
1556
diff --git a/mm/nommu.c b/mm/nommu.c
index de8b6b6580c1..bf94913dbbb6 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -15,8 +15,6 @@
15 15
16#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 16#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17 17
18#define __DISABLE_GUP_DEPRECATED
19
20#include <linux/export.h> 18#include <linux/export.h>
21#include <linux/mm.h> 19#include <linux/mm.h>
22#include <linux/vmacache.h> 20#include <linux/vmacache.h>
@@ -161,7 +159,7 @@ finish_or_fault:
161 * slab page or a secondary page from a compound page 159 * slab page or a secondary page from a compound page
162 * - don't permit access to VMAs that don't support it, such as I/O mappings 160 * - don't permit access to VMAs that don't support it, such as I/O mappings
163 */ 161 */
164long get_user_pages6(unsigned long start, unsigned long nr_pages, 162long get_user_pages(unsigned long start, unsigned long nr_pages,
165 int write, int force, struct page **pages, 163 int write, int force, struct page **pages,
166 struct vm_area_struct **vmas) 164 struct vm_area_struct **vmas)
167{ 165{
@@ -175,15 +173,15 @@ long get_user_pages6(unsigned long start, unsigned long nr_pages,
175 return __get_user_pages(current, current->mm, start, nr_pages, flags, 173 return __get_user_pages(current, current->mm, start, nr_pages, flags,
176 pages, vmas, NULL); 174 pages, vmas, NULL);
177} 175}
178EXPORT_SYMBOL(get_user_pages6); 176EXPORT_SYMBOL(get_user_pages);
179 177
180long get_user_pages_locked6(unsigned long start, unsigned long nr_pages, 178long get_user_pages_locked(unsigned long start, unsigned long nr_pages,
181 int write, int force, struct page **pages, 179 int write, int force, struct page **pages,
182 int *locked) 180 int *locked)
183{ 181{
184 return get_user_pages6(start, nr_pages, write, force, pages, NULL); 182 return get_user_pages(start, nr_pages, write, force, pages, NULL);
185} 183}
186EXPORT_SYMBOL(get_user_pages_locked6); 184EXPORT_SYMBOL(get_user_pages_locked);
187 185
188long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm, 186long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm,
189 unsigned long start, unsigned long nr_pages, 187 unsigned long start, unsigned long nr_pages,
@@ -199,13 +197,13 @@ long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm,
199} 197}
200EXPORT_SYMBOL(__get_user_pages_unlocked); 198EXPORT_SYMBOL(__get_user_pages_unlocked);
201 199
202long get_user_pages_unlocked5(unsigned long start, unsigned long nr_pages, 200long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages,
203 int write, int force, struct page **pages) 201 int write, int force, struct page **pages)
204{ 202{
205 return __get_user_pages_unlocked(current, current->mm, start, nr_pages, 203 return __get_user_pages_unlocked(current, current->mm, start, nr_pages,
206 write, force, pages, 0); 204 write, force, pages, 0);
207} 205}
208EXPORT_SYMBOL(get_user_pages_unlocked5); 206EXPORT_SYMBOL(get_user_pages_unlocked);
209 207
210/** 208/**
211 * follow_pfn - look up PFN at a user virtual address 209 * follow_pfn - look up PFN at a user virtual address
@@ -1989,31 +1987,3 @@ static int __meminit init_admin_reserve(void)
1989 return 0; 1987 return 0;
1990} 1988}
1991subsys_initcall(init_admin_reserve); 1989subsys_initcall(init_admin_reserve);
1992
1993long get_user_pages8(struct task_struct *tsk, struct mm_struct *mm,
1994 unsigned long start, unsigned long nr_pages,
1995 int write, int force, struct page **pages,
1996 struct vm_area_struct **vmas)
1997{
1998 return get_user_pages6(start, nr_pages, write, force, pages, vmas);
1999}
2000EXPORT_SYMBOL(get_user_pages8);
2001
2002long get_user_pages_locked8(struct task_struct *tsk, struct mm_struct *mm,
2003 unsigned long start, unsigned long nr_pages,
2004 int write, int force, struct page **pages,
2005 int *locked)
2006{
2007 return get_user_pages_locked6(start, nr_pages, write,
2008 force, pages, locked);
2009}
2010EXPORT_SYMBOL(get_user_pages_locked8);
2011
2012long get_user_pages_unlocked7(struct task_struct *tsk, struct mm_struct *mm,
2013 unsigned long start, unsigned long nr_pages,
2014 int write, int force, struct page **pages)
2015{
2016 return get_user_pages_unlocked5(start, nr_pages, write, force, pages);
2017}
2018EXPORT_SYMBOL(get_user_pages_unlocked7);
2019