File systemtap-get_user_pages-4.9-kernel.patch of Package systemtap

From: David Smith <dsmith@redhat.com>
Date:   Fri Dec 9 11:41:35 2016 -0600
Subject: Fix BZ1386120 by updating systemtap to handle the 4.9 kernel
Git-commit: 00960517fb4a4d8388854b470da30e0c886b0e89 [partial]
References: bsc#1031409
Signed-off-by: Tony Jones <tonyj@suse.de>

[SUSE: drop changes other than get_user_pages]

    Fix BZ1386120 by updating systemtap to handle the 4.9 kernel.
    
    * runtime/linux/access_process_vm.h (__access_process_vm_): Use
      STAPCONF_GET_USER_PAGES_REMOTE_FLAGS to handle get_user_pages_remote()
      kernel function API change.

diff --git a/buildrun.cxx b/buildrun.cxx
index 7c68ba03e..f5019b925 100644
--- a/buildrun.cxx
+++ b/buildrun.cxx
@@ -447,6 +448,8 @@ compile_pass (systemtap_session& s)
   output_autoconf(s, o, "autoconf-mod_kallsyms.c",
 		  "STAPCONF_MOD_KALLSYMS", NULL);
   output_exportconf(s, o, "get_user_pages_remote", "STAPCONF_GET_USER_PAGES_REMOTE");
+  output_autoconf(s, o, "autoconf-get_user_pages_remote-flags.c",
+		  "STAPCONF_GET_USER_PAGES_REMOTE_FLAGS", NULL);
 
   o << module_cflags << " += -include $(STAPCONF_HEADER)" << endl;
 
diff --git a/runtime/linux/access_process_vm.h b/runtime/linux/access_process_vm.h
index 214d4e254..d9400d723 100644
--- a/runtime/linux/access_process_vm.h
+++ b/runtime/linux/access_process_vm.h
@@ -33,7 +33,14 @@ __access_process_vm_ (struct task_struct *tsk, unsigned long addr, void *buf,
       void *maddr;
 
 #ifdef STAPCONF_GET_USER_PAGES_REMOTE
+#ifdef STAPCONF_GET_USER_PAGES_REMOTE_FLAGS
+      unsigned int flags = FOLL_FORCE;
+      if (write)
+	  flags |= FOLL_WRITE;
+      ret = get_user_pages_remote (tsk, mm, addr, 1, flags, &page, &vma);
+#else  /* !STAPCONF_GET_USER_PAGES_REMOTE_FLAGS */
       ret = get_user_pages_remote (tsk, mm, addr, 1, write, 1, &page, &vma);
+#endif /* !STAPCONF_GET_USER_PAGES_REMOTE_FLAGS */
 #else
       ret = get_user_pages (tsk, mm, addr, 1, write, 1, &page, &vma);
 #endif
diff --git a/runtime/linux/autoconf-get_user_pages_remote-flags.c b/runtime/linux/autoconf-get_user_pages_remote-flags.c
new file mode 100644
index 000000000..1313e8957
--- /dev/null
+++ b/runtime/linux/autoconf-get_user_pages_remote-flags.c
@@ -0,0 +1,42 @@
+#ifdef STAPCONF_GET_USER_PAGES_REMOTE
+#include <linux/mm.h>
+
+//
+// The following kernel commit changed the get_user_pages_remote()
+// function signature:
+//
+// commit 9beae1ea89305a9667ceaab6d0bf46a045ad71e7
+// Author: Lorenzo Stoakes <lstoakes@gmail.com>
+// Date:   Thu Oct 13 01:20:17 2016 +0100
+//
+//    mm: replace get_user_pages_remote() write/force parameters with gup_flags
+//
+//    This removes the 'write' and 'force' from get_user_pages_remote() and
+//    replaces them with 'gup_flags' to make the use of FOLL_FORCE explicit in
+//    callers as use of this flag can result in surprising behaviour (and
+//    hence bugs) within the mm subsystem.
+//
+// This changed the function signature from:
+//
+// long get_user_pages_remote(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);
+//
+// to:
+//
+// long get_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm,
+//                            unsigned long start, unsigned long nr_pages,
+//                            unsigned int gup_flags, struct page **pages,
+//                            struct vm_area_struct **vmas);
+//
+
+long gupr_wrapper(struct task_struct *tsk, struct mm_struct *mm,
+		  unsigned long start, unsigned long nr_pages,
+		  unsigned int gup_flags, struct page **pages,
+		  struct vm_area_struct **vmas)
+{
+    return get_user_pages_remote(tsk, mm, start, nr_pages, gup_flags,
+				 pages, vmas);
+}
+#endif
openSUSE Build Service is sponsored by