linux-4.4.172 nvidia-340.107 error: too many arguments to function 'get_user_pages'

Hi!
Can’t compile NVIDIA-Linux-x86_64-340.107 driver for Linux-4.4.172.

In file included from /tmp/bld/NVIDIA-Linux-x86_64-340.107/kernel/os-mlock.c:15:0:
/tmp/bld/NVIDIA-Linux-x86_64-340.107/kernel/nv-linux.h:2100:9: error: too many arguments to function 'get_user_pages'
         get_user_pages(current, current->mm, start, nr_pages, write, force, pages, vmas)
         ^
/tmp/bld/NVIDIA-Linux-x86_64-340.107/kernel/os-mlock.c:48:11: note: in expansion of macro 'NV_GET_USER_PAGES'
     ret = NV_GET_USER_PAGES((unsigned long)address,
           ^
In file included from /tmp/bld/NVIDIA-Linux-x86_64-340.107/kernel/nv-linux.h:68:0,
                 from /tmp/bld/NVIDIA-Linux-x86_64-340.107/kernel/os-mlock.c:15:
include/linux/mm.h:1200:6: note: declared here
 long get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
      ^
scripts/Makefile.build:277: recipe for target '/tmp/bld/NVIDIA-Linux-x86_64-340.107/kernel/os-mlock.o' failed
make[2]: *** [/tmp/bld/NVIDIA-Linux-x86_64-340.107/kernel/os-mlock.o] Error 1
Makefile:1436: recipe for target '_module_/tmp/bld/NVIDIA-Linux-x86_64-340.107/kernel' failed
make[1]: *** [_module_/tmp/bld/NVIDIA-Linux-x86_64-340.107/kernel] Error 2
make[1]: Leaving directory '/usr/src/linux-4.4.172'
NVIDIA: left KBUILD.
nvidia.ko failed to build!
Makefile:192: recipe for target 'nvidia.ko' failed
make: *** [nvidia.ko] Error 1

The prototype of get_user_pages() was changed by the Linux kernel developers in 4.4.168 and later. You’ll need to update to a newer NVIDIA driver to pick up the corresponding change.

Best,
Cliff

See also https://devtalk.nvidia.com/default/topic/1046451/linux/linux-4-4-168-and-nvidia-linux-x86_64-410-93-and-get_user_pages-/1

A similar failure possibly having the same cause, different driver and kernel.

$ sudo apt-get install nvidia-304

Loading new nvidia-304-304.137 DKMS files…
First Installation: checking all kernels…
Building only for 4.4.0-193-generic
Building for architecture x86_64
Building initial module for 4.4.0-193-generic
Error! Bad return status for module build on kernel: 4.4.0-193-generic (x86_64)
Consult /var/lib/dkms/nvidia-304/304.137/build/make.log for more information.

From /var/lib/dkms/nvidia-304/304.137/build/make.log :

DKMS make.log for nvidia-304-304.137 for kernel 4.4.0-193-generic (x86_64)
Thu Oct 29 17:30:13 EDT 2020
NVIDIA: calling KBUILD…

In file included from /var/lib/dkms/nvidia-304/304.137/build/nv-mlock.c:15:0:
/var/lib/dkms/nvidia-304/304.137/build/nv-linux.h:1927:9: error: too many arguments to function ‘get_user_pages’
get_user_pages(current, current->mm, start, nr_pages, write, force, pages, vmas)
^
/var/lib/dkms/nvidia-304/304.137/build/nv-mlock.c:52:11: note: in expansion of macro ‘NV_GET_USER_PAGES’
ret = NV_GET_USER_PAGES((unsigned long)address,
^
In file included from /var/lib/dkms/nvidia-304/304.137/build/nv-linux.h:82:0,
from /var/lib/dkms/nvidia-304/304.137/build/nv-mlock.c:15:
include/linux/mm.h:1259:6: note: declared here
long get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
^
scripts/Makefile.build:285: recipe for target ‘/var/lib/dkms/nvidia-304/304.137/build/nv-mlock.o’ failed
make[3]: *** [/var/lib/dkms/nvidia-304/304.137/build/nv-mlock.o] Error 1
Makefile:1471: recipe for target ‘module/var/lib/dkms/nvidia-304/304.137/build’ failed
make[2]: *** [module/var/lib/dkms/nvidia-304/304.137/build] Error 2
NVIDIA: left KBUILD.
nvidia.ko failed to build!
Makefile:261: recipe for target ‘module’ failed
make[1]: *** [module] Error 1
makefile:59: recipe for target ‘module’ failed
make: *** [module] Error 2

Any thoughts on a workaround ?