# fixing nvidia-drivers with kernel-4.7

## ExecutorElassus

In case anybody else runs across the same issue I did:

the 4.7 kernel introduces a function that the nvidia-drivers installer already uses, leading to a failed emerge of nvidia-drivers. You can read about the issue and find the necessary patch on this thread.

Happy emerging,

EE

----------

## Fred Krogh

I haven't done much patching, but I didn't see anything there that I could use as patch just as it is.  I have added patches at /etc/portage/x11-drivers/nvidia-drievers-xxx in the past, but what I see at the link given does not look like those patches.  Am I missing something.  Thanks,

Fred

Think I was confused.  Thought I was trying to patch the nvidia-drivers, not stuff in the kernel.  I think I'll just wait.

----------

## ExecutorElassus

Post #4 of that thread (as of this writing, at least) contains a text block. Save that block as /etc/portage/patches/x11-drivers/nvidia-drivers-361.35/kernel-4.7.patch (or whatever you want to name it in that subdirectory), and remerge nvidia-drivers. You will need to manually edit that file, however, replacing every instance of "361.27" with "361.35" so that it applies to the correct version.

HTH,

EE

----------

## Fred Krogh

Thanks.  That was easy and it worked.

----------

## peter4

Don't you guys get the sandbox violations? I get this for every file the ebuild tries to compile, with or without the patch:

```

  x86_64-pc-linux-gnu-gcc -Wp,-MD,/var/tmp/portage/x11-drivers/nvidia-drivers-367.35-r1/work/kernel/nvidia-uvm/.uvm8_pushbuffer.o.d  -nostdinc -isystem /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include -I/usr/src/linux-4.7.0-gentoo/arch/x86/include -Iarch/x86/include/generated/uapi -Iarch/x86/include/generated  -I/usr/src/linux-4.7.0-gentoo/include -Iinclude -I/usr/src/linux-4.7.0-gentoo/arch/x86/include/uapi -Iarch/x86/include/generated/uapi -I/usr/src/linux-4.7.0-gentoo/include/uapi -Iinclude/generated/uapi -include /usr/src/linux-4.7.0-gentoo/include/linux/kconfig.h   -I/var/tmp/portage/x11-drivers/nvidia-drivers-367.35-r1/work/kernel -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -march=core2 -mno-red-zone -mcmodel=kernel -funit-at-a-time -maccumulate-outgoing-args -DCONFIG_X86_X32_ABI -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -fno-delete-null-pointer-checks -O2 --param=allow-store-data-races=0 -Wframe-larger-than=2048 -fno-stack-protector -Wno-unused-but-set-variable -fomit-frame-pointer -fno-var-tracking-assignments -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -Werror=incompatible-pointer-types -DCC_HAVE_ASM_GOTO   -I/var/tmp/portage/x11-drivers/nvidia-drivers-367.35-r1/work/kernel/common/inc   -I/var/tmp/portage/x11-drivers/nvidia-drivers-367.35-r1/work/kernel -Wall -MD -Wsign-compare -Wno-cast-qual -Wno-error -D__KERNEL__ -DMODULE -DNVRM -DNV_VERSION_STRING=\"367.35\" -Wno-unused-function -Wuninitialized -fno-strict-aliasing -mno-red-zone -mcmodel=kernel -DNV_UVM_ENABLE -Wno-sign-compare -Wno-format-extra-args -O2 -DNVIDIA_UVM_ENABLED -DNVIDIA_UNDEF_LEGACY_BIT_MACROS -DLinux -D__linux__   -I/var/tmp/portage/x11-drivers/nvidia-drivers-367.35-r1/work/kernel/nvidia-uvm  -DMODULE  -DKBUILD_BASENAME='"uvm8_pushbuffer"'  -DKBUILD_MODNAME='"nvidia_uvm"' -c -o /var/tmp/portage/x11-drivers/nvidia-drivers-367.35-r1/work/kernel/nvidia-uvm/uvm8_pushbuffer.o /var/tmp/portage/x11-drivers/nvidia-drivers-367.35-r1/work/kernel/nvidia-uvm/uvm8_pushbuffer.c

 * ACCESS DENIED:  fopen_wr:     /usr/src/linux-4.7.0-gentoo/uvm8_pushbuffer.d

/var/tmp/portage/x11-drivers/nvidia-drivers-367.35-r1/work/kernel/nvidia-uvm/uvm8_pushbuffer.c:31:0: fatal error: opening dependency file uvm8_pushbuffer.d: Permission denied

 #include "uvm_common.h"

 ^

compilation terminated.

```

Doesn't happen with kernel 4.6.5.

----------

## Fred Krogh

From backups, I can see that I used to have a uvm_common.h, but that is no longer in my system.

----------

## Mikkl

Hey Peter,

 *Quote:*   

> Don't you guys get the sandbox violations? I get this for every file the ebuild tries to compile, with or without the patch: 

 

have you set TRIM_UNUSED_KSYSMS to yes in your kernel config? I had the same violations and now have set it to "no" and emerging now works.

Greetins, Mikkl

----------

## Chiitoo

 *Mikkl wrote:*   

> Hey Peter,
> 
>  *Quote:*   Don't you guys get the sandbox violations? I get this for every file the ebuild tries to compile, with or without the patch:  
> 
> have you set TRIM_UNUSED_KSYSMS to yes in your kernel config? I had the same violations and now have set it to "no" and emerging now works.
> ...

 

Did you perhaps mean

```
TRIM_UNUSED_KSYMS
```

instead of 'KSYSMS'?  :]

I have 'CONFIG_TRIM_UNUSED_KSYMS is not set', and don't have that issue either.

For convenience, here's a patch I've been using.  It's slightly modified from the one available at the devtalk.nvidia.com post mentioned before (note the trailing whitespaces that may appear when “copy-pasting”):

```
--- kernel/nvidia-drm/nvidia-drm-fb.c

+++ kernel/nvidia-drm/nvidia-drm-fb.c

@@ -114,7 +114,7 @@

      * We don't support any planar format, pick up first buffer only.

      */

-    gem = drm_gem_object_lookup(dev, file, cmd->handles[0]);

+    gem = drm_gem_object_lookup(file, cmd->handles[0]);

     if (gem == NULL)

     {

--- kernel/nvidia-drm/nvidia-drm-gem.c

+++ kernel/nvidia-drm/nvidia-drm-gem.c

@@ -408,7 +408,7 @@

     mutex_lock(&dev->struct_mutex);

-    gem = drm_gem_object_lookup(dev, file, handle);

+    gem = drm_gem_object_lookup(file, handle);

     if (gem == NULL)

     {

--- kernel/nvidia-uvm/uvm_linux.h

+++ kernel/nvidia-uvm/uvm_linux.h

@@ -554,12 +554,13 @@

     INIT_RADIX_TREE(tree, GFP_NOWAIT);

 }

+/*

 static bool radix_tree_empty(struct radix_tree_root *tree)

 {

     void *dummy;

     return radix_tree_gang_lookup(tree, &dummy, 0, 1) == 0;

 }

-

+*/

 #if !defined(NV_USLEEP_RANGE_PRESENT)

 static void __sched usleep_range(unsigned long min, unsigned long max)
```

----------

## Mikkl

 *Quote:*   

> Did you perhaps mean
> 
> Code:	
> 
> TRIM_UNUSED_KSYMS	
> ...

 

 :Embarassed:  You're right. I should definitely learn how to properly copy'n'paste.

Besides from that, I'm now getting errors due to missing symbols when loading the nvidia kernel module...

Edit: OK, I just forgot to copy my kernel again after re-compiling without the stripped symbols. Another failed copy'n'paste job...

----------

## ycUygB1

I have added the patch to my overlay, hnaparst.

```
layman -a hnaparst

emerge =nvidia-drivers-367.35-r2
```

----------

## undrwater

 *hnaparst wrote:*   

> I have added the patch to my overlay, hnaparst.
> 
> ```
> layman -a hnaparst
> 
> ...

 

Thank you!  Will you be updating for newer kernel versions?

----------

## Pryka

And what about patch for 340.96? Only with that driver u can get support for older GPU.

----------

## ycUygB1

 *Pryka wrote:*   

> And what about patch for 340.96? Only with that driver u can get support for older GPU.

 

I do not own the legacy hardware, so it would be difficult to test.   If you have any ideas, I am all ears.  The patches are available on the various developer forums, but I am hesitant to produce a version for Gentoo without the ability to test it.

----------

## ycUygB1

 *undrwater wrote:*   

> 
> 
> Thank you!  Will you be updating for newer kernel versions?

 

It has not been a problem for a while.  However, it certainly is my intention to be able to run my own nvidia hardware with the latest kernel, so I guess I should answer yes to your question.

----------

## ycUygB1

 *Pryka wrote:*   

> And what about patch for 340.96? Only with that driver u can get support for older GPU.

 

I have added x11-drivers/nvidia-drivers-340.96-r6 to my overlay and verified that it emerges correctly with kernels 4.6.5 and 4.7.0

I have not tested it because I do not have legacy hardware.Last edited by ycUygB1 on Wed Aug 03, 2016 1:02 am; edited 1 time in total

----------

## Jaglover

Thanks! I have a MythTV frontend with this hardware, will test it soon.

----------

## Pryka

 *hnaparst wrote:*   

>  *Pryka wrote:*   And what about patch for 340.96? Only with that driver u can get support for older GPU. 
> 
> I have added x11-drivers/nvidia-drivers-340.96-r6 to my overlay and verified that it emerges correctly with kernels 4.6.5 and 4.7.0
> 
> I have not tested it because I do not have legacy hardware.

 

I will check it soon, THX!

----------

## Jaglover

Works on ION chipset. Thanks again!

----------

## haarp

 *Mikkl wrote:*   

> Hey Peter,
> 
>  *Quote:*   Don't you guys get the sandbox violations? I get this for every file the ebuild tries to compile, with or without the patch:  
> 
> have you set TRIM_UNUSED_KSYMS to yes in your kernel config? I had the same violations and now have set it to "no" and emerging now works.
> ...

 

Same here. Thanks for the tip!

The ebuild should probably check for that setting being present.

----------

## Pryka

 *hnaparst wrote:*   

>  *Pryka wrote:*   And what about patch for 340.96? Only with that driver u can get support for older GPU. 
> 
> I have added x11-drivers/nvidia-drivers-340.96-r6 to my overlay and verified that it emerges correctly with kernels 4.6.5 and 4.7.0
> 
> I have not tested it because I do not have legacy hardware.

 

Working on old 9600GT. Thank You.

----------

## Fred Krogh

Nvidia-drivers-370.23 with kernel 4.7.2 works just fine on my system with no patches.

----------

## musv

 *hnaparst wrote:*   

> I have added x11-drivers/nvidia-drivers-340.96-r6 to my overlay

 

Thanks a lot.

----------

