nvidia driver fails to build on newer kernels

Ubuntu 16.04 Server edition, Cuda 10.0 installed with the local deb like: “sudo apt install cuda-10-0”

Have I done something wrong or might this be an upstream bug? The driver works fine on the old 410 kernel, just won’t build against the new kernel.

Output of install command:

....
Adding new group `nvidia-persistenced' (GID 122) ...                                                                                                                                                  [31/545]
Adding new user `nvidia-persistenced' (UID 113) with group `nvidia-persistenced' ...
Not creating home directory `/'.
Loading new nvidia-410-410.48 DKMS files...
First Installation: checking all kernels...
Building for 4.4.0-142-generic and 4.4.0-170-generic
Building for architecture x86_64
Building initial module for 4.4.0-142-generic
Secure Boot not enabled on this system.
Done.

nvidia_410:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/4.4.0-142-generic/updates/dkms/

nvidia_410_modeset.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/4.4.0-142-generic/updates/dkms/

nvidia_410_drm.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/4.4.0-142-generic/updates/dkms/

nvidia_410_uvm.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/4.4.0-142-generic/updates/dkms/

depmod....

DKMS: install completed.
Building initial module for 4.4.0-170-generic
ERROR: Cannot create report: [Errno 17] File exists: '/var/crash/nvidia-410.0.crash'
Error! Bad return status for module build on kernel: 4.4.0-170-generic (x86_64)
Consult /var/lib/dkms/nvidia-410/410.48/build/make.log for more information.
Setting up nvidia-410-dev (410.48-0ubuntu1) ...
Setting up libcuda1-410 (410.48-0ubuntu1) ...
Setting up nvidia-opencl-icd-410 (410.48-0ubuntu1) ...
Setting up nvidia-modprobe (410.48-0ubuntu1) ...
Setting up nvidia-settings (410.48-0ubuntu1) ...
Setting up cuda-drivers (410.48-1) ...
Setting up cuda-runtime-10-0 (10.0.130-1) ...
Setting up cuda-demo-suite-10-0 (10.0.130-1) ...
Setting up cuda-10-0 (10.0.130-1) ...
Setting up nvidia-prime (0.8.2) ...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
Processing triggers for initramfs-tools (0.122ubuntu8.16) ...
update-initramfs: Generating /boot/initrd.img-4.4.0-170-generic
Processing triggers for ureadahead (0.100.0-19.1) ...

Contents of /var/lib/dkms/nvidia-410/410.48/build/make.log

......
In file included from /var/lib/dkms/nvidia-410/410.48/build/common/inc/nv-linux.h:21:0,
                 from /var/lib/dkms/nvidia-410/410.48/build/nvidia/os-mlock.c:15:
/var/lib/dkms/nvidia-410/410.48/build/nvidia/os-mlock.c: In function ‘os_lock_user_pages’:
/var/lib/dkms/nvidia-410/410.48/build/nvidia/os-mlock.c:120:48: warning: passing argument 6 of ‘get_user_pages’ makes pointer from integer without a cast [-Wint-conversion]
                             page_count, write, force, user_pages, NULL);
                                                ^
/var/lib/dkms/nvidia-410/410.48/build/common/inc/nv-mm.h:44:70: note: in definition of macro ‘NV_GET_USER_PAGES’
         get_user_pages(current, current->mm, start, nr_pages, write, force, pages, vmas)
                                                                      ^
In file included from /var/lib/dkms/nvidia-410/410.48/build/common/inc/nv-pgprot.h:17:0,
                 from /var/lib/dkms/nvidia-410/410.48/build/common/inc/nv-linux.h:20,
                 from /var/lib/dkms/nvidia-410/410.48/build/nvidia/os-mlock.c:15:
include/linux/mm.h:1256:6: note: expected ‘struct page **’ but argument is of type ‘NvBool {aka unsigned char}’
 long get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
      ^
In file included from /var/lib/dkms/nvidia-410/410.48/build/common/inc/nv-linux.h:21:0,
                 from /var/lib/dkms/nvidia-410/410.48/build/nvidia/os-mlock.c:15:
/var/lib/dkms/nvidia-410/410.48/build/nvidia/os-mlock.c:120:55: warning: passing argument 7 of ‘get_user_pages’ from incompatible pointer type [-Wincompatible-pointer-types]
                             page_count, write, force, user_pages, NULL);
                                                       ^
/var/lib/dkms/nvidia-410/410.48/build/common/inc/nv-mm.h:44:77: note: in definition of macro ‘NV_GET_USER_PAGES’
         get_user_pages(current, current->mm, start, nr_pages, write, force, pages, vmas)
                                                                             ^
In file included from /var/lib/dkms/nvidia-410/410.48/build/common/inc/nv-pgprot.h:17:0,
                 from /var/lib/dkms/nvidia-410/410.48/build/common/inc/nv-linux.h:20,
                 from /var/lib/dkms/nvidia-410/410.48/build/nvidia/os-mlock.c:15:
include/linux/mm.h:1256:6: note: expected ‘struct vm_area_struct **’ but argument is of type ‘struct page **’
 long get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
      ^
In file included from /var/lib/dkms/nvidia-410/410.48/build/common/inc/nv-linux.h:21:0,
                 from /var/lib/dkms/nvidia-410/410.48/build/nvidia/os-mlock.c:15:
/var/lib/dkms/nvidia-410/410.48/build/common/inc/nv-mm.h:44: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-410/410.48/build/nvidia/os-mlock.c:119: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-410/410.48/build/common/inc/nv-pgprot.h:17:0,
                 from /var/lib/dkms/nvidia-410/410.48/build/common/inc/nv-linux.h:20,
                 from /var/lib/dkms/nvidia-410/410.48/build/nvidia/os-mlock.c:15:
include/linux/mm.h:1256: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-410/410.48/build/nvidia/os-mlock.o' failed
make[2]: *** [/var/lib/dkms/nvidia-410/410.48/build/nvidia/os-mlock.o] Error 1
make[2]: *** Waiting for unfinished jobs....
Makefile:1460: recipe for target '_module_/var/lib/dkms/nvidia-410/410.48/build' failed
make[1]: *** [_module_/var/lib/dkms/nvidia-410/410.48/build] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.4.0-170-generic'
Makefile:79: recipe for target 'modules' failed
make: *** [modules] Error 2

This is a common occurrence.

Either use a newer driver, or switch to a linux install that has the kernel that is indicated in the CUDA linux install guide.

If you switch to the latest driver for your GPU, that should work with any currently available CUDA toolkit.