NVIDIA – Driver Fix, for Kernel 4.0. and Earlier..
I have hacked together a kernel-version-friendly fix for the latest NVIDIA driver (346.35) which works with Kernel 4.0-rc1 (and later) and also for previous kernel versions.. Thanks are due to juston_li for producing the actual code changes needed.. https://devtalk.nvidia.com/default/topic/813458/linux/linux-4-0-rc1-346-35-build-error-_cr4-functions-fix/
Unpack the NVIDIA driver:
./NVIDIA-Linux-x86_64-346.35.run -x
Edit NVIDIA-Linux-x86_64-346.35/kernel/nv-pat.c
Around line 34, change
{ unsigned long cr0 = read_cr0(); write_cr0(((cr0 & (0xdfffffff)) | 0x40000000)); wbinvd(); *cr4 = read_cr4(); if (*cr4 & 0x80) write_cr4(*cr4 & ~0x80); __flush_tlb(); }
to
{ unsigned long cr0 = read_cr0(); write_cr0(((cr0 & (0xdfffffff)) | 0x40000000)); wbinvd(); #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0) *cr4 = read_cr4(); if (*cr4 & 0x80) write_cr4(*cr4 & ~0x80); __flush_tlb(); #else *cr4 = __read_cr4(); if (*cr4 & 0x80) __write_cr4(*cr4 & ~0x80); __flush_tlb(); #endif }
..and around line 46, change
wbinvd(); __flush_tlb(); write_cr0((cr0 & 0x9fffffff)); if (cr4 & 0x80) write_cr4(cr4); }
to
wbinvd(); __flush_tlb(); write_cr0((cr0 & 0x9fffffff)); #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0) if (cr4 & 0x80) write_cr4(cr4); #else if (cr4 & 0x80) __write_cr4(cr4); #endif }
Then recompile, etc…
I have tested this with both Kernel 4.0-rc1 and 3.19.0, and the compile now completes successfully on both versions..
Robert Gadsdon. February 23, 2015.
Can you please elaborate on the recompile etc. step
In NVIDIA-Linux-x86_64-346.35/kernel, just # make clean, and then # make install
RG.
I made the changes in NVIDIA-Linux-x86_64-346.35/kernel. When I attempt to # make clean && make install I get an error about /usr/src/linux-4.0-rc1 is not clean, run ‘make mrproper’. I run make mrproper and I get another error saying that the kernel isn’t configured for loadable modules. If I run ‘make oldconfig’ and do a make menuconfig the Enable loadable module support is configured. Any ideas? I’ve never had this much trouble trying to install nvidia drivers for a kernel update before.
Same to me.
Recompile with command line(such as boot into recovery mode), not in X windows, work for me.
I have made the changes but get the following error
ERROR: Failed to run `/usr/sbin/dkms build -m nvidia -v 340.76 -k 4.0.5-200.fc21.x86_64`:
Kernel preparation unnecessary for this kernel. Skipping…
Building module:
cleaning build area…
make KERNELRELEASE=4.0.5-200.fc21.x86_64 module KERNEL_UNAME=4.0.5-200.fc21.x86_64; make -C uvm module KERNEL_UNAME=4.0.5-200.fc21.x86_64
KBUILD_EXTMOD=/var/lib/dkms/nvidia/340.76/build/uvm; make -C uvm module KERNEL_UNAME=4.0.5-200.fc21.x86_64 KBUILD_EXTMOD=/var/lib/dkms/nvidia/340.76/build/uvm; make -C
uvm module KERNEL_UNAME=4.0.5-200.fc21.x86_64 KBUILD_EXTMOD=/var/lib/dkms/nvidia/340.76/build/uvm………………………….(bad exit status: 2)
Error! Bad return status for module build on kernel: 4.0.5-200.fc21.x86_64 (x86_64)
Consult /var/lib/dkms/nvidia/340.76/build/make.log for more information.
Got it working using – http://blog.linuxchris.com/?p=133
I assume you were using an older version of the NVIDIA driver because it supports your model of card? Newer versions work fine..
RG.