Skip to contentSkip to conversation

mm/gup: add compat macro for get_user_pages

PATCH In review Konstantin Khlebnikov 2 participants 2 messages Jan 31, 2019 Stable branch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/gup: add compat macro for get_user_pages

This fixes API breakage introduced in v4.4.168 commit 8e50b8b07f46 ("mm: replace get_user_pages() write/force parameters with gup_flags"). For example odious nvidia out-of-tree modules does not compile.

After that commit prototype of get_user_pages() looks like:

long get_user_pages(task, mm, start, nr_pages, gup_flags, pages, vmas)

that's incompatible neither with v4.4 and before:

long get_user_pages(task, mm, start, nr_pages, write, force, pages, vmas)

nor with v4.6 and later:

long get_user_pages(start, nr_pages, gup_flags, pages, vmas)

This patch uses the same va-args macro magic as commit cde70140fed8 ("mm/gup: Overload get_user_pages() functions").

The alternative is upgrading GUP API to modern state.

---
 include/linux/mm.h |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
include/linux/mm.h +23 -0
index 77066c96f5e9..5337d4b59052 100644
@@ -2334,5 +2334,28 @@ void __init setup_nr_node_ids(void);
 static inline void setup_nr_node_ids(void) {}
 #endif
 
+#ifdef MODULE
+
+/* Compat API for external modules */
+
+static inline __deprecated
+long get_user_pages8(struct task_struct *tsk, struct mm_struct *mm,
+		     unsigned long start, unsigned long nr_pages,
+		     int write, int force, struct page **pages,
+		     struct vm_area_struct **vmas)
+{
+	return get_user_pages(tsk, mm, start, nr_pages,
+			      (write ? FOLL_WRITE : 0) |
+			      (force ? FOLL_FORCE : 0),
+			      pages, vmas);
+}
+
+#define GUP_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, gup, ...) gup
+
+#define get_user_pages(...) GUP_MACRO(__VA_ARGS__, \
+	get_user_pages8, get_user_pages, x, x, x, x, x, x)(__VA_ARGS__)
+
+#endif /* MODULE */
+
 #endif /* __KERNEL__ */
 #endif /* _LINUX_MM_H */
#1 lore raw
Quoted 3 lines · Konstantin Khlebnikov

This fixes API breakage introduced in v4.4.168 commit 8e50b8b07f46 ("mm: replace get_user_pages() write/force parameters with gup_flags"). For example odious nvidia out-of-tree modules does not compile.

There is no guarantee of in-kernel api "stability" in any kernel tree, sorry.

As all of the in-kernel users are working just fine, there is no need for this type of crazy patch to be accepted.

thanks,

greg k-h