[PATCH 4.4] mm/gup: add compat macro for get_user_pages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Signed-off-by: Konstantin Khlebnikov <khlebnikov@xxxxxxxxxxxxxx>
---
 include/linux/mm.h |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 77066c96f5e9..5337d4b59052 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -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 */




[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux