+From 6fe0c6bd4b3bbac5cf868b927973255961b28ff4 Mon Sep 17 00:00:00 2001
+From: Paolo Pisati <paolo.pisati@canonical.com>
+Date: Tue, 18 Jul 2023 12:14:47 +0000
+Subject: [PATCH 1/2] Linux 6.5: garbage collect all references to
+ get_user_pages_remote()
+
+Upstream commit ca5e863233e8f6acd1792fd85d6bc2729a1b2c10 "mm/gup: remove
+vmas parameter from get_user_pages_remote()" changed the API: since we
+reference get_user_pages_remote() (but don't use it anywhere), garbage
+collect all reference.
+
+Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
+---
+ common/inc/nv-mm.h | 99 -------------
+ conftest.sh | 130 ------------------
+ 2 files changed, 229 deletions(-)
+
+diff --git a/kernel/common/inc/nv-mm.h b/kernel/common/inc/nv-mm.h
+index aec55b0b..51d0df4a 100644
+--- a/kernel/common/inc/nv-mm.h
++++ b/kernel/common/inc/nv-mm.h
+@@ -98,105 +98,6 @@ typedef int vm_fault_t;
+ #endif
+ #endif
+
+-/*
+- * get_user_pages_remote() was added by commit 1e9877902dc7
+- * ("mm/gup: Introduce get_user_pages_remote()") in v4.6 (2016-02-12).
+- *
+- * The very next commit cde70140fed8 ("mm/gup: Overload get_user_pages()
+- * functions") deprecated the 8-argument version of get_user_pages for the
+- * non-remote case (calling get_user_pages with current and current->mm).
+- *
+- * The guidelines are: call NV_GET_USER_PAGES_REMOTE if you need the 8-argument
+- * version that uses something other than current and current->mm. Use
+- * NV_GET_USER_PAGES if you are refering to current and current->mm.
+- *
+- * Note that get_user_pages_remote() requires the caller to hold a reference on
+- * the task_struct (if non-NULL and if this API has tsk argument) and the mm_struct.
+- * This will always be true when using current and current->mm. If the kernel passes
+- * the driver a vma via driver callback, the kernel holds a reference on vma->vm_mm
+- * over that callback.
+- *
+- * get_user_pages_remote() write/force parameters were replaced
+- * with gup_flags by commit 9beae1ea8930 ("mm: replace get_user_pages_remote()
+- * write/force parameters with gup_flags") in v4.9 (2016-10-13).
+- *
+- * get_user_pages_remote() added 'locked' parameter by commit 5b56d49fc31d
+- * ("mm: add locked parameter to get_user_pages_remote()") in
+- * v4.10 (2016-12-14).
+- *
+- * get_user_pages_remote() removed 'tsk' parameter by
+- * commit 64019a2e467a ("mm/gup: remove task_struct pointer for
+- * all gup code") in v5.9-rc1 (2020-08-11).
+- *
+- */
+-
+-#if defined(NV_GET_USER_PAGES_REMOTE_PRESENT)
+- #if defined(NV_GET_USER_PAGES_REMOTE_HAS_WRITE_AND_FORCE_ARGS)
+- #define NV_GET_USER_PAGES_REMOTE get_user_pages_remote
+- #else
+- static inline long NV_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)
+- {
+- unsigned int flags = 0;
+-
+- if (write)
+- flags |= FOLL_WRITE;
+- if (force)
+- flags |= FOLL_FORCE;
+-
+- #if defined(NV_GET_USER_PAGES_REMOTE_HAS_LOCKED_ARG)
+- #if defined (NV_GET_USER_PAGES_REMOTE_HAS_TSK_ARG)
+- return get_user_pages_remote(tsk, mm, start, nr_pages, flags,
+- pages, vmas, NULL);
+- #else
+- return get_user_pages_remote(mm, start, nr_pages, flags,
+- pages, vmas, NULL);
+- #endif
+-
+- #else
+-
+- return get_user_pages_remote(tsk, mm, start, nr_pages, flags,
+- pages, vmas);
+-
+- #endif
+-
+- }
+- #endif
+-#else
+- #if defined(NV_GET_USER_PAGES_HAS_WRITE_AND_FORCE_ARGS)
+- #define NV_GET_USER_PAGES_REMOTE NV_GET_USER_PAGES
+- #else
+- #include <linux/mm.h>
+- #include <linux/sched.h>
+-
+- static inline long NV_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)
+- {
+- unsigned int flags = 0;
+-
+- if (write)
+- flags |= FOLL_WRITE;
+- if (force)
+- flags |= FOLL_FORCE;
+-
+- return get_user_pages(tsk, mm, start, nr_pages, flags, pages, vmas);
+- }
+- #endif
+-#endif
+-
+-
+ /*
+ * The .virtual_address field was effectively renamed to .address, by these
+ * two commits:
+diff --git a/kernel/conftest.sh b/kernel/conftest.sh
+index 24daa850..abe435ff 100755
+--- a/kernel/conftest.sh
++++ b/kernel/conftest.sh
+@@ -3081,136 +3081,6 @@ compile_test() {
+ return
+ ;;
+
+- get_user_pages_remote)
+- #
+- # Determine if the function get_user_pages_remote() is
+- # present and has write/force/locked/tsk parameters.
+- #
+- # get_user_pages_remote() was added by:
+- # 2016 Feb 12: 1e9877902dc7e11d2be038371c6fbf2dfcd469d7
+- #
+- # get_user_pages[_remote]() write/force parameters
+- # replaced with gup_flags:
+- # 2016 Oct 12: 768ae309a96103ed02eb1e111e838c87854d8b51
+- # 2016 Oct 12: 9beae1ea89305a9667ceaab6d0bf46a045ad71e7
+- #
+- # get_user_pages_remote() added 'locked' parameter
+- # 2016 Dec 14:5b56d49fc31dbb0487e14ead790fc81ca9fb2c99
+- #
+- # get_user_pages_remote() removed 'tsk' parameter by
+- # commit 64019a2e467a ("mm/gup: remove task_struct pointer for
+- # all gup code") in v5.9-rc1 (2020-08-11).
+- #
+- # conftest #1: check if get_user_pages_remote() is available
+- # return if not available.
+- # Fall through to conftest #2 if it is present
+-
+- echo "$CONFTEST_PREAMBLE
+- #include <linux/mm.h>
+- void conftest_get_user_pages_remote(void) {
+- get_user_pages_remote();
+- }" > conftest$$.c
+-
+- $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1
+- rm -f conftest$$.c
+-
+- if [ -f conftest$$.o ]; then
+- echo "#undef NV_GET_USER_PAGES_REMOTE_PRESENT" | append_conftest "functions"
+- echo "#undef NV_GET_USER_PAGES_REMOTE_HAS_TSK_ARG" | append_conftest "functions"
+- echo "#undef NV_GET_USER_PAGES_REMOTE_HAS_WRITE_AND_FORCE_ARGS" | append_conftest "functions"
+- echo "#undef NV_GET_USER_PAGES_REMOTE_HAS_LOCKED_ARG" | append_conftest "functions"
+- rm -f conftest$$.o
+- return
+- fi
+-
+- # conftest #2: check if get_user_pages_remote() has write and
+- # force arguments. Return if these arguments are present
+- # Fall through to conftest #3 if these args are absent.
+- echo "#define NV_GET_USER_PAGES_REMOTE_PRESENT" | append_conftest "functions"
+- echo "$CONFTEST_PREAMBLE
+- #include <linux/mm.h>
+- 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) {
+- return 0;
+- }" > conftest$$.c
+-
+- $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1
+- rm -f conftest$$.c
+-
+- if [ -f conftest$$.o ]; then
+- echo "#define NV_GET_USER_PAGES_REMOTE_HAS_TSK_ARG" | append_conftest "functions"
+- echo "#define NV_GET_USER_PAGES_REMOTE_HAS_WRITE_AND_FORCE_ARGS" | append_conftest "functions"
+- echo "#undef NV_GET_USER_PAGES_REMOTE_HAS_LOCKED_ARG" | append_conftest "functions"
+- rm -f conftest$$.o
+- return
+- fi
+-
+- echo "#undef NV_GET_USER_PAGES_REMOTE_HAS_WRITE_AND_FORCE_ARGS" | append_conftest "functions"
+-
+- #
+- # conftest #3: check if get_user_pages_remote() has locked argument
+- # Return if these arguments are present. Fall through to conftest #4
+- # if these args are absent.
+- #
+- echo "$CONFTEST_PREAMBLE
+- #include <linux/mm.h>
+- 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,
+- int *locked) {
+- return 0;
+- }" > conftest$$.c
+-
+- $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1
+- rm -f conftest$$.c
+-
+- if [ -f conftest$$.o ]; then
+- echo "#define NV_GET_USER_PAGES_REMOTE_HAS_TSK_ARG" | append_conftest "functions"
+- echo "#define NV_GET_USER_PAGES_REMOTE_HAS_LOCKED_ARG" | append_conftest "functions"
+- rm -f conftest$$.o
+- return
+- fi
+-
+- #
+- # conftest #4: check if get_user_pages_remote() does not take
+- # tsk argument.
+- #
+- echo "$CONFTEST_PREAMBLE
+- #include <linux/mm.h>
+- long get_user_pages_remote(struct mm_struct *mm,
+- unsigned long start,
+- unsigned long nr_pages,
+- unsigned int gup_flags,
+- struct page **pages,
+- struct vm_area_struct **vmas,
+- int *locked) {
+- return 0;
+- }" > conftest$$.c
+-
+- $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1
+- rm -f conftest$$.c
+-
+- if [ -f conftest$$.o ]; then
+- echo "#undef NV_GET_USER_PAGES_REMOTE_HAS_TSK_ARG" | append_conftest "functions"
+- echo "#define NV_GET_USER_PAGES_REMOTE_HAS_LOCKED_ARG" | append_conftest "functions"
+- rm -f conftest$$.o
+- else
+-
+- echo "#define NV_GET_USER_PAGES_REMOTE_HAS_TSK_ARG" | append_conftest "functions"
+- echo "#undef NV_GET_USER_PAGES_REMOTE_HAS_LOCKED_ARG" | append_conftest "functions"
+- fi
+- ;;
+-
+ usleep_range)
+ #
+ # Determine if the function usleep_range() is present.
+--
+2.40.1
+