Skip to content

Commit c12d2da

Browse files
author
Ingo Molnar
committed
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: cde7014 ("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: cb10716 ("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>
1 parent 9735a22 commit c12d2da

File tree

3 files changed

+17
-143
lines changed

3 files changed

+17
-143
lines changed

include/linux/mm.h

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,78 +1250,20 @@ long get_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm,
12501250
unsigned long start, unsigned long nr_pages,
12511251
int write, int force, struct page **pages,
12521252
struct vm_area_struct **vmas);
1253-
long get_user_pages6(unsigned long start, unsigned long nr_pages,
1253+
long get_user_pages(unsigned long start, unsigned long nr_pages,
12541254
int write, int force, struct page **pages,
12551255
struct vm_area_struct **vmas);
1256-
long get_user_pages_locked6(unsigned long start, unsigned long nr_pages,
1256+
long get_user_pages_locked(unsigned long start, unsigned long nr_pages,
12571257
int write, int force, struct page **pages, int *locked);
12581258
long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm,
12591259
unsigned long start, unsigned long nr_pages,
12601260
int write, int force, struct page **pages,
12611261
unsigned int gup_flags);
1262-
long get_user_pages_unlocked5(unsigned long start, unsigned long nr_pages,
1262+
long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages,
12631263
int write, int force, struct page **pages);
12641264
int get_user_pages_fast(unsigned long start, int nr_pages, int write,
12651265
struct page **pages);
12661266

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-
*/
1292-
long
1293-
__gup_deprecated
1294-
get_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
1305-
long 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
1316-
long 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-
13251267
/* Container for pinned pfns / pages */
13261268
struct frame_vector {
13271269
unsigned int nr_allocated; /* Number of frames we have space for */

mm/gup.c

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define __DISABLE_GUP_DEPRECATED 1
21
#include <linux/kernel.h>
32
#include <linux/errno.h>
43
#include <linux/err.h>
@@ -839,15 +838,15 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk,
839838
* if (locked)
840839
* up_read(&mm->mmap_sem);
841840
*/
842-
long get_user_pages_locked6(unsigned long start, unsigned long nr_pages,
841+
long get_user_pages_locked(unsigned long start, unsigned long nr_pages,
843842
int write, int force, struct page **pages,
844843
int *locked)
845844
{
846845
return __get_user_pages_locked(current, current->mm, start, nr_pages,
847846
write, force, pages, NULL, locked, true,
848847
FOLL_TOUCH);
849848
}
850-
EXPORT_SYMBOL(get_user_pages_locked6);
849+
EXPORT_SYMBOL(get_user_pages_locked);
851850

852851
/*
853852
* Same as get_user_pages_unlocked(...., FOLL_TOUCH) but it allows to
@@ -892,13 +891,13 @@ EXPORT_SYMBOL(__get_user_pages_unlocked);
892891
* or if "force" shall be set to 1 (get_user_pages_fast misses the
893892
* "force" parameter).
894893
*/
895-
long get_user_pages_unlocked5(unsigned long start, unsigned long nr_pages,
894+
long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages,
896895
int write, int force, struct page **pages)
897896
{
898897
return __get_user_pages_unlocked(current, current->mm, start, nr_pages,
899898
write, force, pages, FOLL_TOUCH);
900899
}
901-
EXPORT_SYMBOL(get_user_pages_unlocked5);
900+
EXPORT_SYMBOL(get_user_pages_unlocked);
902901

903902
/*
904903
* get_user_pages_remote() - pin user pages in memory
@@ -972,15 +971,15 @@ EXPORT_SYMBOL(get_user_pages_remote);
972971
* and mm being operated on are the current task's. We also
973972
* obviously don't pass FOLL_REMOTE in here.
974973
*/
975-
long get_user_pages6(unsigned long start, unsigned long nr_pages,
974+
long get_user_pages(unsigned long start, unsigned long nr_pages,
976975
int write, int force, struct page **pages,
977976
struct vm_area_struct **vmas)
978977
{
979978
return __get_user_pages_locked(current, current->mm, start, nr_pages,
980979
write, force, pages, vmas, NULL, false,
981980
FOLL_TOUCH);
982981
}
983-
EXPORT_SYMBOL(get_user_pages6);
982+
EXPORT_SYMBOL(get_user_pages);
984983

985984
/**
986985
* 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,
14911490
int get_user_pages_fast(unsigned long start, int nr_pages, int write,
14921491
struct page **pages)
14931492
{
1494-
struct mm_struct *mm = current->mm;
14951493
int nr, ret;
14961494

14971495
start &= PAGE_MASK;
@@ -1503,8 +1501,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
15031501
start += nr << PAGE_SHIFT;
15041502
pages += nr;
15051503

1506-
ret = get_user_pages_unlocked(current, mm, start,
1507-
nr_pages - nr, write, 0, pages);
1504+
ret = get_user_pages_unlocked(start, nr_pages - nr, write, 0, pages);
15081505

15091506
/* Have to be a bit careful with return values */
15101507
if (nr > 0) {
@@ -1519,38 +1516,3 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
15191516
}
15201517

15211518
#endif /* CONFIG_HAVE_GENERIC_RCU_GUP */
1522-
1523-
long 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-
}
1533-
EXPORT_SYMBOL(get_user_pages8);
1534-
1535-
long 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-
}
1544-
EXPORT_SYMBOL(get_user_pages_locked8);
1545-
1546-
long 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-
}
1555-
EXPORT_SYMBOL(get_user_pages_unlocked7);
1556-

mm/nommu.c

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1717

18-
#define __DISABLE_GUP_DEPRECATED
19-
2018
#include <linux/export.h>
2119
#include <linux/mm.h>
2220
#include <linux/vmacache.h>
@@ -161,7 +159,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
161159
* slab page or a secondary page from a compound page
162160
* - don't permit access to VMAs that don't support it, such as I/O mappings
163161
*/
164-
long get_user_pages6(unsigned long start, unsigned long nr_pages,
162+
long get_user_pages(unsigned long start, unsigned long nr_pages,
165163
int write, int force, struct page **pages,
166164
struct vm_area_struct **vmas)
167165
{
@@ -175,15 +173,15 @@ long get_user_pages6(unsigned long start, unsigned long nr_pages,
175173
return __get_user_pages(current, current->mm, start, nr_pages, flags,
176174
pages, vmas, NULL);
177175
}
178-
EXPORT_SYMBOL(get_user_pages6);
176+
EXPORT_SYMBOL(get_user_pages);
179177

180-
long get_user_pages_locked6(unsigned long start, unsigned long nr_pages,
178+
long get_user_pages_locked(unsigned long start, unsigned long nr_pages,
181179
int write, int force, struct page **pages,
182180
int *locked)
183181
{
184-
return get_user_pages6(start, nr_pages, write, force, pages, NULL);
182+
return get_user_pages(start, nr_pages, write, force, pages, NULL);
185183
}
186-
EXPORT_SYMBOL(get_user_pages_locked6);
184+
EXPORT_SYMBOL(get_user_pages_locked);
187185

188186
long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm,
189187
unsigned long start, unsigned long nr_pages,
@@ -199,13 +197,13 @@ long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm,
199197
}
200198
EXPORT_SYMBOL(__get_user_pages_unlocked);
201199

202-
long get_user_pages_unlocked5(unsigned long start, unsigned long nr_pages,
200+
long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages,
203201
int write, int force, struct page **pages)
204202
{
205203
return __get_user_pages_unlocked(current, current->mm, start, nr_pages,
206204
write, force, pages, 0);
207205
}
208-
EXPORT_SYMBOL(get_user_pages_unlocked5);
206+
EXPORT_SYMBOL(get_user_pages_unlocked);
209207

210208
/**
211209
* follow_pfn - look up PFN at a user virtual address
@@ -1989,31 +1987,3 @@ static int __meminit init_admin_reserve(void)
19891987
return 0;
19901988
}
19911989
subsys_initcall(init_admin_reserve);
1992-
1993-
long 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-
}
2000-
EXPORT_SYMBOL(get_user_pages8);
2001-
2002-
long 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-
}
2010-
EXPORT_SYMBOL(get_user_pages_locked8);
2011-
2012-
long 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-
}
2018-
EXPORT_SYMBOL(get_user_pages_unlocked7);
2019-

0 commit comments

Comments
 (0)