Error compiling driver for uniprocessor kernel

An error occurs when compiling recent versions of the nvidia driver for a uniprocessor kernel. I’ve tried 361.42, 364.15, and 364.19 all to similar result:

/var/tmp/portage/x11-drivers/nvidia-drivers-361.42/work/kernel/nvidia/nv_uvm_interface.c: In function ‘nvUvmInterfaceDeRegisterUvmOps’:
/var/tmp/portage/x11-drivers/nvidia-drivers-361.42/work/kernel/nvidia/nv_uvm_interface.c:1164:5: error: implicit declaration of function ‘NV_ON_EACH_CPU’ [-Werror=implicit-function-declaration]
NV_ON_EACH_CPU(flush_top_half, NULL, 1);
^
cc1: some warnings being treated as errors

The on_each_cpu part of conftest.sh checks that on_each_cpu function exists if CONFIG_SMP is defined in generated/autoconf.h of your kernel and undefines NV_ON_EACH_CPU_PRESENT in the case you are not using an SMP kernel. This causes NV_ON_EACH_CPU to never be defined in kernel/common/inc/nv-linux.h . I solved the issue with the following patch:

— a/kernel/nvidia/nv_uvm_interface.c 2016-04-28 19:48:14.083538872 -0600
+++ b/kernel/nvidia/nv_uvm_interface.c 2016-04-28 19:48:02.767412339 -0600
@@ -1161,7 +1161,11 @@
// Note that since we dropped the lock, another set of callbacks could have
// already been registered. That’s ok, since we just need to wait for old
// ones to finish.
+#if defined(NV_ON_EACH_CPU)
NV_ON_EACH_CPU(flush_top_half, NULL, 1);
+#else

  • flush_top_half(NULL);
    +#endif
    }
    EXPORT_SYMBOL(nvUvmInterfaceDeRegisterUvmOps);

It may be better to just define NV_ON_EACH_CPU in nv-linux.h instead in the case NV_ON_EACH_CPU_PRESENT isn’t defined or maybe change the way conftest.sh works as on_each_cpu is actually still defined on uniprocessor kernels (at least it is in 4.4.8)

I think I got same problem with >nvidia-driver-358.16: (on Kernel 4.1.37 as well as 4.4.39)

/var/tmp/portage/x11-drivers/nvidia-drivers-375.26/work/kernel/nvidia/nv_uvm_interface.c: In function ‘nvUvmInterfaceDeRegisterUvmOps’:
/var/tmp/portage/x11-drivers/nvidia-drivers-375.26/work/kernel/nvidia/nv_uvm_interface.c:1248:5: error: implicit declaration of function ‘NV_ON_EACH_CPU’ [-Werror=implicit-function-declaration]
NV_ON_EACH_CPU(flush_top_half, NULL, 1);
^
cc1: some warnings being treated as errors
make[3]: *** [/usr/src/linux-4.1.37-gentoo/scripts/Makefile.build:259: /var/tmp/portage/x11-drivers/nvidia-drivers-375.26/work/kernel/nvidia/nv_uvm_interface.o] Error 1
make[2]: *** [/usr/src/linux-4.1.37-gentoo/Makefile:1387: module/var/tmp/portage/x11-drivers/nvidia-drivers-375.26/work/kernel] Error 2