[SOLVED] NVIDIA 340.107 - Linux 5.0-rc5 : Failed to build kernel module

NVIDIA installer for driver 340.107 fails to build a module nvidia.ko for Linux kernel 5.0-rc5.

Here is where the build fails (from the nvidia-installer.log):

/home/ejm/NVIDIA-Linux-x86_64-340.107/kernel/nv-drm.c: In function ‘nv_alloc_os_descriptor_handle’:
/home/ejm/NVIDIA-Linux-x86_64-340.107/kernel/nv-drm.c:255:5: error: implicit declaration of function ‘drm_gem_object_unreference_unlocked’; did you mean ‘drm_gem_object_put_unlocked’? [-Werror=implicit-function-declaration]
     drm_gem_object_unreference_unlocked(&nv_obj->base);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     drm_gem_object_put_unlocked

nvidia-installer.log (182 KB)

Working patch for NVIDIA driver 340.107 & Linux Kernel 5.0.

Thanks to Alberto Milone, NVIDIA driver maintainer for Ubuntu.

Pastebin link: [url]https://pastebin.com/raw/qsqxsBmZ[/url]

Zip file of patch attached: nv_patch.zip

Note: Use -l or --ignore-whitespace in the patch command

Example: patch -p0 -l < nv_patch_340.107_linux_kernel_5.0
nv_patch.zip (2.15 KB)

This isn’t enough if DKMS is used (which is rather handy), for that the nv-time.h needs to be added to the top-level .manifest file

Encountered the same problem on Linux kernel 5.1.2. Applied the patch from topic, added nv-time.h to top-level .manifest file as suggested in a post above, but still encountering the original error, just on different line (the one from the patch):

/home/lzhev/NVIDIA-Linux-x86_64-340.107/kernel/nv-drm.c: In function ‘nv_drm_gem_object_unreference_unlocked’:
   /home/lzhev/NVIDIA-Linux-x86_64-340.107/kernel/nv-drm.c:46:5: error: implicit declaration of function ‘drm_gem_object_unreference_unlocked’; did you mean ‘nv_drm_gem_object_unreference_unlocked’? [-Werror=implicit-function-declaration]
        drm_gem_object_unreference_unlocked(&nv_gem->base);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        nv_drm_gem_object_unreference_unlocked
   cc1: some warnings being treated as errors

Any suggestions?

UPDATE: solved the problem, there was my mistake applying the patch (broken diff), confirm patch solving this problem.
nvidia-installer.log (158 KB)

This also worked with the 340.107 driver and the latest CentOS 7.7 kernel - 3.10.0-1062.1.1.el7.x86_64.

I get the same error with a fresh installation of Centos 7.8. Linux kernel 3.10.0-1127.19.1.el7.x86_64

In file included from /var/lib/dkms/nvidia/410.48/build/nvidia-drm/nvidia-drm-gem-nvkms-memory.h:30:0,
from /var/lib/dkms/nvidia/410.48/build/nvidia-drm/nvidia-drm-fb.h:31,
from /var/lib/dkms/nvidia/410.48/build/nvidia-drm/nvidia-drm-drv.c:27:
/var/lib/dkms/nvidia/410.48/build/nvidia-drm/nvidia-drm-gem.h: In function ‘nv_drm_gem_handle_create_drop_reference’:
/var/lib/dkms/nvidia/410.48/build/nvidia-drm/nvidia-drm-gem.h:82:5: error: implicit declaration of function ‘drm_gem_object_unreference_unlocked’ [-Werror=implicit-function-declaration]
drm_gem_object_unreference_unlocked(&nv_gem->base);
^
/var/lib/dkms/nvidia/410.48/build/nvidia-drm/nvidia-drm-gem.h: In function ‘nv_drm_gem_object_unreference’:
/var/lib/dkms/nvidia/410.48/build/nvidia-drm/nvidia-drm-gem.h:157:5: error: implicit declaration of function ‘drm_gem_object_unreference’ [-Werror=implicit-function-declaration]
drm_gem_object_unreference(&nv_gem->base);
^
In file included from /var/lib/dkms/nvidia/410.48/build/nvidia-drm/nvidia-drm-drv.c:34:0:
/var/lib/dkms/nvidia/410.48/build/nvidia-drm/nvidia-drm-helper.h: In function ‘nv_drm_dev_free’:
/var/lib/dkms/nvidia/410.48/build/nvidia-drm/nvidia-drm-helper.h:42:5: error: implicit declaration of function ‘drm_dev_free’ [-Werror=implicit-function-declaration]
drm_dev_free(dev);
^
cc1: some warnings being treated as errors
make[2]: *** [/var/lib/dkms/nvidia/410.48/build/nvidia-drm/nvidia-drm-drv.o] Error 1
make[2]: *** Waiting for unfinished jobs…
make[1]: *** [module/var/lib/dkms/nvidia/410.48/build] Error 2
make[1]: Leaving directory `/usr/src/kernels/3.10.0-1127.19.1.el7.x86_64’

I tried applying the patch, but the source code has changed so much since 340 that just about all of the hunks failed. Does NVidia not have a permanent fix for this? I googled for it but can’t find anything but this thread.