# nvidia kernel module does not load

## Kresp

My GPU is NVidia GT 9800. Nouveau works fine, but I need proprietary driver ATM.

I removed nouveau driver from kernel at all for the time being and installed nvidia-drivers-340.102 (340 is the last driver that supports this GPU).

Nvidia drivers don't compile cleanly on 4.10 kernel. Patches for the latest driver from Ubuntu/Arch don't apply to 340 so I added this patch to portage:

```

--- work/kernel/nv-linux.h

+++ work/kernel/nv-linux.h

@@ -270,7 +270,8 @@

 extern int nv_pat_mode;

-#if !defined(NV_VMWARE) && defined(CONFIG_HOTPLUG_CPU)

+// #if !defined(NV_VMWARE) && defined(CONFIG_HOTPLUG_CPU)

+#if 0

 #define NV_ENABLE_HOTPLUG_CPU

 #include <linux/cpu.h>              /* CPU hotplug support              */

 #include <linux/notifier.h>         /* struct notifier_block, etc       */

```

Build finishes, but driver fails to actually load.

lspci -k says:

```

25:00.0 VGA compatible controller: NVIDIA Corporation G92 [GeForce 9800 GT] (rev a2)

        Kernel modules: nvidia_drm, nvidia

```

But lsmod does not list either.

Also, modprobe for both fails:

```

$ sudo modprobe nvidia

modprobe: ERROR: could not insert 'nvidia': No such device

$ sudo modprobe nvidia_drm

modprobe: ERROR: could not insert 'nvidia_drm': No such device

```

Also, following is dumped from kernel:

```

[   85.197107] ------------[ cut here ]------------

[   85.197112] WARNING: CPU: 7 PID: 4455 at fs/proc/generic.c:345 proc_register+0xe5/0x110

[   85.197113] proc_dir_entry 'driver/nvidia' already registered

[   85.197113] Modules linked in: nvidia(PO+) ccp

[   85.197116] CPU: 7 PID: 4455 Comm: modprobe Tainted: P        W  O    4.10.6-gentoo #11

[   85.197116] Hardware name: Micro-Star International Co., Ltd MS-7A31/X370 XPOWER GAMING TITANIUM (MS-7A31), BIOS 1.30 03/16/2017

[   85.197117] Call Trace:

[   85.197120]  dump_stack+0x4d/0x65

[   85.197123]  __warn+0xcc/0xf0

[   85.197124]  warn_slowpath_fmt+0x4a/0x50

[   85.197125]  proc_register+0xe5/0x110

[   85.197126]  proc_mkdir_data+0x61/0x90

[   85.197127]  proc_mkdir_mode+0xe/0x10

[   85.197176]  nv_register_procfs+0x3a/0x1a0 [nvidia]

[   85.197226]  nvidia_init_module+0x293/0x7b5 [nvidia]

[   85.197276]  ? nv_drm_init+0x15/0x15 [nvidia]

[   85.197326]  init_module+0x51/0x94 [nvidia]

[   85.197328]  do_one_initcall+0x3f/0x170

[   85.197329]  ? __vunmap+0x7c/0xd0

[   85.197331]  ? kmem_cache_alloc_trace+0x33/0x150

[   85.197333]  do_init_module+0x5b/0x1cb

[   85.197335]  load_module+0x1ceb/0x2240

[   85.197336]  ? __symbol_put+0x30/0x30

[   85.197337]  ? kernel_read_file+0x16d/0x190

[   85.197338]  ? kernel_read_file_from_fd+0x44/0x70

[   85.197339]  SYSC_finit_module+0xa0/0xb0

[   85.197340]  SyS_finit_module+0x9/0x10

[   85.197342]  entry_SYSCALL_64_fastpath+0x13/0x94

[   85.197343] RIP: 0033:0x7fa3e38fe639

[   85.197343] RSP: 002b:00007fff41c9d158 EFLAGS: 00000202 ORIG_RAX: 0000000000000139

[   85.197344] RAX: ffffffffffffffda RBX: 0000000000f2f380 RCX: 00007fa3e38fe639

[   85.197345] RDX: 0000000000000000 RSI: 0000000000f2f580 RDI: 0000000000000003

[   85.197345] RBP: 0000000000f2f38f R08: 0000000000000000 R09: 000000000000005f

[   85.197345] R10: 0000000000000003 R11: 0000000000000202 R12: 0000000000f2f3c0

[   85.197346] R13: 000000000000001a R14: 0000000000f2f380 R15: 0000000000f2e010

[   85.197347] ---[ end trace d37fc3d50d9b253e ]---

[   85.197348] NVRM: failed to register procfs!

[   85.197367] NVRM: request_mem_region failed for 16M @ 0xf6000000. This can

[   85.197367] NVRM: occur when a driver such as rivatv is loaded and claims

[   85.197367] NVRM: ownership of the device's registers.

[   85.197369] nvidia: probe of 0000:25:00.0 failed with error -1

[   85.197380] NVRM: DRM init failed

[   85.199073] PGD 500b067

[   85.199074] PUD 500c063

[   85.199081] PMD fd649d067

[   85.199088] PTE 0

[   85.199096]

[   85.199106] Oops: 0000 [#1] SMP

[   85.199115] Modules linked in: nvidia(PO-) ccp

[   85.199130] CPU: 0 PID: 4462 Comm: nvidia-smi Tainted: P        W  O    4.10.6-gentoo #11

[   85.199154] Hardware name: Micro-Star International Co., Ltd MS-7A31/X370 XPOWER GAMING TITANIUM (MS-7A31), BIOS 1.30 03/16/2017

[   85.199188] task: ffff880fd7dcb500 task.stack: ffffc9000c610000

[   85.199206] RIP: 0010:proc_get_inode+0xbe/0x160

[   85.199219] RSP: 0018:ffffc9000c613cb0 EFLAGS: 00010246

[   85.199235] RAX: 0000000000008000 RBX: ffff880fd723d670 RCX: 0000000000000018

[   85.199255] RDX: ffffffffa0729e00 RSI: 0000000000000001 RDI: ffff880fd723d670

[   85.199276] RBP: ffffc9000c613cc0 R08: 000000000001ba40 R09: ffff880fd24049b0

[   85.199296] R10: 2f2f2f2f2f2f2f2f R11: ffff880fd4b83140 R12: ffff880fd3041bc0

[   85.199317] R13: ffff880fd723d3f8 R14: 0000000000000000 R15: 0000000000008000

[   85.199338] FS:  00007f944eae2700(0000) GS:ffff88101ec00000(0000) knlGS:0000000000000000

[   85.199362] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033

[   85.199378] CR2: ffffffffa0729e50 CR3: 0000000fd5862000 CR4: 00000000003406f0

[   85.199399] Call Trace:

[   85.199407]  proc_lookup_de+0x4f/0xb0

[   85.199418]  proc_lookup+0x16/0x20

[   85.199430]  path_openat+0x1090/0x1460

[   85.199442]  ? destroy_inode+0x30/0x60

[   85.199453]  ? evict+0x124/0x180

[   85.199463]  do_filp_open+0x79/0xd0

[   85.199474]  ? mntput+0x1f/0x30

[   85.199484]  ? kmem_cache_alloc+0x2f/0x150

[   85.199496]  ? getname_flags+0x51/0x1f0

[   85.199508]  do_sys_open+0x111/0x1f0

[   85.199519]  ? exit_to_usermode_loop+0x6d/0x90

[   85.199532]  SyS_open+0x19/0x20

[   85.199543]  entry_SYSCALL_64_fastpath+0x13/0x94

[   85.199556] RIP: 0033:0x7f944e20f9d0

[   85.199567] RSP: 002b:00007ffe38003068 EFLAGS: 00000246 ORIG_RAX: 0000000000000002

[   85.199589] RAX: ffffffffffffffda RBX: 00000000013c5630 RCX: 00007f944e20f9d0

[   85.199609] RDX: 00000000000001b6 RSI: 0000000000000000 RDI: 00007ffe38003250

[   85.199630] RBP: 0000000000000000 R08: 0000000000000008 R09: 0000000000000001

[   85.199650] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000

[   85.200151] R13: 0000000000000000 R14: 00007f944e1362b0 R15: 0000000000000000

[   85.200647] Code: 00 48 89 43 20 49 8b 54 24 28 48 85 d2 74 14 0f b7 03 66 25 00 f0 66 3d 00 80 74 0f 48 89 93 58 01 00 00 48 89 d8 5b 41 5c 5d c3 <48> 83 7a 50 00 48 c7 c0 40 13 a3 81 48 c7 c2 40 12 a3 81 48 0f

[   85.202262] CR2: ffffffffa0729e50

[   85.202788] ---[ end trace d37fc3d50d9b253f ]---

```

```

[  229.386635] ------------[ cut here ]------------

[  229.387164] WARNING: CPU: 1 PID: 4468 at fs/proc/generic.c:345 proc_register+0xe5/0x110

[  229.387715] proc_dir_entry 'driver/nvidia' already registered

[  229.388270] Modules linked in: nvidia(PO+) ccp

[  229.388834] CPU: 1 PID: 4468 Comm: modprobe Tainted: P      D W  O    4.10.6-gentoo #11

[  229.389419] Hardware name: Micro-Star International Co., Ltd MS-7A31/X370 XPOWER GAMING TITANIUM (MS-7A31), BIOS 1.30 03/16/2017

[  229.390638] Call Trace:

[  229.391242]  dump_stack+0x4d/0x65

[  229.391828]  __warn+0xcc/0xf0

[  229.392387]  warn_slowpath_fmt+0x4a/0x50

[  229.392943]  proc_register+0xe5/0x110

[  229.393491]  proc_mkdir_data+0x61/0x90

[  229.394036]  proc_mkdir_mode+0xe/0x10

[  229.394630]  nv_register_procfs+0x3a/0x1a0 [nvidia]

[  229.395216]  nvidia_init_module+0x293/0x7b5 [nvidia]

[  229.395803]  ? nv_drm_init+0x15/0x15 [nvidia]

[  229.396388]  init_module+0x51/0x94 [nvidia]

[  229.396924]  do_one_initcall+0x3f/0x170

[  229.397451]  ? __vunmap+0x7c/0xd0

[  229.397967]  ? kmem_cache_alloc_trace+0x33/0x150

[  229.398480]  do_init_module+0x5b/0x1cb

[  229.398986]  load_module+0x1ceb/0x2240

[  229.399490]  ? __symbol_put+0x30/0x30

[  229.399999]  ? kernel_read_file+0x16d/0x190

[  229.400509]  ? kernel_read_file_from_fd+0x44/0x70

[  229.401021]  SYSC_finit_module+0xa0/0xb0

[  229.401533]  SyS_finit_module+0x9/0x10

[  229.402050]  entry_SYSCALL_64_fastpath+0x13/0x94

[  229.402570] RIP: 0033:0x7fece68af639

[  229.403088] RSP: 002b:00007fffa7b2f068 EFLAGS: 00000202 ORIG_RAX: 0000000000000139

[  229.403627] RAX: ffffffffffffffda RBX: 00007fffa7b2d0b0 RCX: 00007fece68af639

[  229.404173] RDX: 0000000000000000 RSI: 0000000001ded660 RDI: 0000000000000003

[  229.404722] RBP: 00007fffa7b2d0b0 R08: 0000000000000000 R09: 000000000000005f

[  229.405269] R10: 0000000000000003 R11: 0000000000000202 R12: 0000000001deb010

[  229.405814] R13: 00007fffa7b2d0a8 R14: 0000000000000000 R15: 0000000001deb010

[  229.406359] ---[ end trace d37fc3d50d9b2540 ]---

[  229.406898] NVRM: failed to register procfs!

[  229.407445] NVRM: request_mem_region failed for 16M @ 0xf6000000. This can

[  229.407445] NVRM: occur when a driver such as rivatv is loaded and claims

[  229.407445] NVRM: ownership of the device's registers.

[  229.407905] general protection fault: 0000 [#2] SMP

[  229.407905] Modules linked in: nvidia(PO+) ccp

[  229.407907] CPU: 4 PID: 4474 Comm: nvidia-smi Tainted: P      D W  O    4.10.6-gentoo #11

[  229.407908] Hardware name: Micro-Star International Co., Ltd MS-7A31/X370 XPOWER GAMING TITANIUM (MS-7A31), BIOS 1.30 03/16/2017

[  229.407909] task: ffff880fd7906a00 task.stack: ffffc9000c780000

[  229.407912] RIP: 0010:queued_spin_lock_slowpath+0xe4/0x180

[  229.407913] RSP: 0018:ffffc9000c783c08 EFLAGS: 00010082

[  229.407914] RAX: 0000000000002042 RBX: 0000000000000246 RCX: 0000000000140000

[  229.407914] RDX: ff98b32300018949 RSI: 00000000810cc247 RDI: ffffc9000c613d90

[  229.407915] RBP: ffffc9000c783c08 R08: ffff88101ed18580 R09: 0000000000000000

[  229.407915] R10: ffff880fd4b83178 R11: 0000000000000000 R12: ffffc9000c783ca8

[  229.407915] R13: 00000000348b50bc R14: ffff880fd4b83200 R15: ffff880fd4b831f0

[  229.407916] FS:  00007f08556ec700(0000) GS:ffff88101ed00000(0000) knlGS:0000000000000000

[  229.407917] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033

[  229.407917] CR2: 00007f0854d9ce90 CR3: 0000000fd2fc1000 CR4: 00000000003406e0

[  229.407917] Call Trace:

[  229.407920]  _raw_spin_lock_irqsave+0x24/0x30

[  229.407922]  add_wait_queue+0x15/0x50

[  229.407924]  d_alloc_parallel+0x373/0x4a0

[  229.407925]  ? legitimize_path.isra.38+0x29/0x60

[  229.407926]  ? wake_up_q+0x70/0x70

[  229.407927]  path_openat+0xe37/0x1460

[  229.407928]  ? destroy_inode+0x30/0x60

[  229.407929]  ? evict+0x124/0x180

[  229.407930]  do_filp_open+0x79/0xd0

[  229.407931]  ? mntput+0x1f/0x30

[  229.407932]  ? kmem_cache_alloc+0x2f/0x150

[  229.407933]  ? getname_flags+0x51/0x1f0

[  229.407934]  do_sys_open+0x111/0x1f0

[  229.407935]  ? exit_to_usermode_loop+0x6d/0x90

[  229.407936]  SyS_open+0x19/0x20

[  229.407937]  entry_SYSCALL_64_fastpath+0x13/0x94

[  229.407938] RIP: 0033:0x7f0854e199d0

[  229.407938] RSP: 002b:00007ffd7cce9048 EFLAGS: 00000246 ORIG_RAX: 0000000000000002

[  229.407939] RAX: ffffffffffffffda RBX: 0000000000747630 RCX: 00007f0854e199d0

[  229.407939] RDX: 00000000000001b6 RSI: 0000000000000000 RDI: 00007ffd7cce9230

[  229.407940] RBP: 0000000000000000 R08: 0000000000000008 R09: 0000000000000001

[  229.407940] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000

[  229.407940] R13: 0000000000000000 R14: 00007f0854d402b0 R15: 0000000000000000

[  229.407941] Code: c1 e0 10 45 31 c9 85 c0 74 46 48 89 c2 c1 e8 12 48 c1 ea 0c 83 e8 01 83 e2 30 48 98 48 81 c2 80 85 01 00 48 03 14 c5 40 c8 c8 81 <4c> 89 02 41 8b 40 08 85 c0 75 0a f3 90 41 8b 40 08 85 c0 74 f6

[  229.407953] ---[ end trace d37fc3d50d9b2541 ]---

[  229.433009] nvidia: probe of 0000:25:00.0 failed with error -1

[  229.434155] NVRM: DRM init failed

```

----------

## Roman_Gruber

I had previous a Asus g70sg notebook. in the early days i had to patch my kernel. I did not use the patch command, i used an editor and manually changed those affected code lines.

Most of the time, in my experience, the kernel symbols were just changed.

I suggest, you open the patch in one window, see what should be changed, and change those lines by hand with an editor, with search, manually replace, and verifiy if there are other lines affected.

I did that for quite a while when my notebook was brand new => wrong memory bars for the nvidia gpu. later some other issues, adn end of life, two years ago, patch so the binary driver works.

Also when you have such dated gpu, you should try to stay at a dated kernel. so it makes things easier for you.

--

well

https://www.msi.com/Motherboard/X370-XPOWER-GAMING-TITANIUM.html#productFeature-section

Any reason why you are not getting something more power efficent from second hand? your gpu is, i assume wihtout checking 8 year old gpu. your mainboard is brand new.

--

you need to check which kernels symbols what else has changed over htose kernel versions to get the binary driver working. I also expect issues with the xorg server maybe ...

----------

## Kresp

 *Roman_Gruber wrote:*   

> 
> 
> Any reason why you are not getting something more power efficent from second hand? your gpu is, i assume wihtout checking 8 year old gpu. your mainboard is brand new.
> 
> 

 

It's secondary GPU I have laying around. If it's possible to use it, I'd like to reuse it.

There are this patches:

https://github.com/LibreELEC/LibreELEC.tv/pull/1121/commits/c23c406f0d58ad35dddcf84bff7aead47a015982

https://github.com/LibreELEC/LibreELEC.tv/pull/1121/commits/8d3956f72d79ea3648b19f4c705a38307bb03efb

But not all files mentioned in those are present in nvidia-drivers sources in portage. Present are: nv-linux.h, nv-p2p.c and nv-pat.c. Missing are mostly files with *drm* in they name.

----------

## genterminl

I don't know if this deserves a separate thread, but I get the same (or very similar) errors.  This happened after I upgraded nvidia-drivers from 340-101.r1 to 340.102.  Reverting (and reboot) and everything works fine again.

My GPU is: NVIDIA Corporation G84GL [Quadro FX 1700] (rev a1).  I did not notice any compile errors when emerging the new driver.  I am currently on gentoo-sources 4.9.6-r1, but will shortly try 4.9.16, to see if it makes any difference.  

I also find it odd that lspci -k shows nvidia in use for the card, but lsmod does NOT show anything relevant.

In case it helps, this shows two attempts to load the module 

```
Apr  3 18:40:55 localhost kernel: NVRM: failed to register procfs!

Apr  3 18:40:55 localhost kernel: NVRM: request_mem_region failed for 16M @ 0xfc000000. This can\x0aNVRM: occur when a driver such as rivatv is loaded and claims\x0aNVRM: ownership of the device's registers.

Apr  3 18:40:55 localhost kernel: NVRM: DRM init failed

Apr  3 19:16:29 localhost kernel: NVRM: failed to register procfs!

Apr  3 19:16:29 localhost kernel: NVRM: request_mem_region failed for 16M @ 0xfc000000. This can\x0aNVRM: occur when a driver such as rivatv is loaded and claims\x0aNVRM: ownership of the device's registers.

Apr  3 19:16:29 localhost kernel: NVRM: The NVIDIA probe routine failed for 1 device(s).

Apr  3 19:16:29 localhost kernel: NVRM: None of the NVIDIA graphics adapters were initialized!
```

Is this perhaps a real bug in the 340.102 driver?

----------

## Kresp

 *genterminl wrote:*   

> 
> 
> I also find it odd that lspci -k shows nvidia in use for the card, but lsmod does NOT show anything relevant.
> 
> 

 

I'm also perplexes by this. I just did emerge -cav nvidia-drivers. It did not remove *.ko modules already installed, which I deleted manually, but after reboot lspci -k still shows nvidia and nvidia_drm as loaded. modinfo for those says such modules can not be found.

----------

## Roman_Gruber

Did you rebuild the kernel, boot it, with CONFIG_LOCALVERSION="your stuff of choice" and CONFIG_LOCALVERSION_AUTO=y ?

----------

## genterminl

Why are those relevant?  However, yes, I have both of those set.  Note that when I upgraded nvidia-drivers, I did not change kernel at that time.  Now, I have compiled a new kernel, the older nvidia-driver works fine with it, but I will have to wait until I have enough time to test the newer nvidia-driver with the new kernel - hopefully in a day or two.

----------

## genterminl

Still no luck.  gentoo-sources-4.9.16 selected with eselect kernel.  nvidia-drivers-340-102 emerged, no apparent errors.  recompiled kernel and modules and reinstalled.  rebooted.  Still get the same errors.  At one point (but not sure exactly what triggered it) I got API mismatch: the client has the version 340.102 but this kernel module has the version 340.101.  At the moment, 340.101 is only installed for the two previous kernels, but not this one, and I see no evidence of any 101 under /lib.  rmmod nvidia says it is not loaded.  lspci -k says nvidia is the module being used for the card.

Any suggestions what else I might try?

----------

## Roman_Gruber

every rebuild kernel should have a different name. e.g. I use date code 

file should be named accordingly

uname -a

grub should be edited by hand, and should use human readable names there.

----------

## genterminl

Well, I'm not sure how embarrassed to feel here.  I simply forgot, and didn't notice, that I had previously applied a user user patch to nvidia-drivers-340-101 (with or without -r1) and once I applied that same patch to 102, it worked just fine.  At this point, I don't remember where I got the patch, but I've now seen it in more than one place out on the web.  The patch basically adds DRIVER_LEGACY to .driver_features in kernel/nv-drm.c, wrapped in an appropriate #if on the kernel version.  Once I confirm this seems stable, I'll probably file a bug against nvidia-drivers-340.102 when compiled with kernel 3.9.x.

Edit: corrected typo in nvidia-drivers version.Last edited by genterminl on Sun Apr 09, 2017 10:50 pm; edited 1 time in total

----------

## genterminl

It's never as simple as it sometimes seems.  I shut down the PC while I was away for a few days, and when I just started it up, I got those same errors trying to start X.  Fortunately, I figured this one out fairly quickly.  I have a grub entry for the most recently compiled kernel - pointing to the root drive as the same as / and pointing to the compiled kernel where it is left by "make all" before doing a "make install."  Once I am happy, I do the "make install" and put a specific entry in grub.conf with root pointing to the ./boot partition.  However, there turns out to be a difference, although the reasons are buried in history I can't remember.  The command line for the most recently compiled kernel includes "iommu=memaper=3" and the custom line does not.  That is the only difference I can find.  My motherboard/CPU (Asus M2N4-SLI, AMD Athlon(tm) 64 X2 Dual Core Processor 4000+) does not have iommu, but I really can't remember why I put this line in.  In any case, without it, I get the errors, but not with it.  This is for nvidia-drivers 340.102 and a 4.9.x kernel.  As far as I can tell, though, the patch I mentioned above IS also needed.

----------

## skazi

@Kresp

Try this two patches:

```

--- work/kernel/nv-linux.h

+++ work/kernel/nv-linux.h

@@ -270,7 +270,8 @@

 extern int nv_pat_mode;

-#if !defined(NV_VMWARE) && defined(CONFIG_HOTPLUG_CPU)

+// #if !defined(NV_VMWARE) && defined(CONFIG_HOTPLUG_CPU)

+#if 0

 #define NV_ENABLE_HOTPLUG_CPU

 #include <linux/cpu.h>              /* CPU hotplug support              */

 #include <linux/notifier.h>         /* struct notifier_block, etc       */

--- a/kernel/nv-pat.c

+++ b/kernel/nv-pat.c

@@ -210,14 +210,13 @@ nvidia_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu

 

     switch (action)

     {

-        case CPU_DOWN_FAILED:

         case CPU_ONLINE:

             if (cpu == (NvUPtr)hcpu)

                 nv_setup_pat_entries(NULL);

             else

                 NV_SMP_CALL_FUNCTION(nv_setup_pat_entries, hcpu, 1);

             break;

-        case CPU_DOWN_PREPARE:

+        case CPU_DOWN_PREPARE_FROZEN:

             if (cpu == (NvUPtr)hcpu)

                 nv_restore_pat_entries(NULL);

             else
```

```

--- a/kernel/nv-drm.c   2016-12-15 12:41:26.000000000 +0100

+++ b/kernel/nv-drm.c   2016-12-15 12:58:48.000000000 +0100

@@ -115,7 +115,11 @@

 };

 

 static struct drm_driver nv_drm_driver = {

+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)

+    .driver_features = DRIVER_GEM | DRIVER_PRIME | DRIVER_LEGACY,

+#else

     .driver_features = DRIVER_GEM | DRIVER_PRIME,

+#endif

     .load = nv_drm_load,

     .unload = nv_drm_unload,

     .fops = &nv_drm_fops,
```

I compiled nvidia-drivers-340.102 with kernel 4.10.10, and everything work fine. I got nvidia 8600GT.

----------

## orionbelt

skazi, i also have the GeForce 8600 GT video card, and came across this problem. I don't know if any Gentoo devs follow this thread, but i am wondering: What is the wisdom of having a thousand users apply this patch individually rather than applying it once and for all centrally at the repository level? The reason seems to be that "it's the maintainer's policy not to apply patches to address kernel compatibility issues as this is often a moving target". Why is it reasonable to expect the Gentoo user to apply the patches (i don't see any other reasonable option) but it is unreasonable to have them applied by Gentoo maintainers?

----------

## tld

I have a GeForce 6200 card on my old x86 system that's also limited to the 304 version drivers. I'm currently using x11-drivers/nvidia-drivers-304.134 with kernel sys-kernel/gentoo-sources-4.9.6-r1 with no problem using this patch:

```
--- work/kernel/nv-linux.h

+++ work/kernel/nv-linux.h

@@ -256,6 +256,15 @@

 #include <linux/seq_file.h>

 #endif

 

+/*

+ * As of version 304.131, os-agp.c and os-mtrr.c still use deprecated

+ * kernel APIs for mtrr which are no longer exported since 4.3, causing

+ * the module to error out when loaded.

+ */

+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)

+#undef CONFIG_MTRR

+#endif

+

 #if !defined(NV_VMWARE) && defined(CONFIG_MTRR)

 #include <asm/mtrr.h>

 #endif
```

EDIT: Sorry for the confusion here. I totally missed that the thread here is about the 340 legacy driver as apposed to the 304 driver I'm using (It's almost as if they did that to be confusing). Oddly enough, the most recent 304 driver (x11-drivers/nvidia-drivers-304.135) compiles and loads fine for me running 4.9.34. Seems odd that 340 would be such an issue.

TomLast edited by tld on Sun Jul 09, 2017 4:11 pm; edited 1 time in total

----------

## Clad in Sky

Does this problem only affect older NVidia gpus/ the 340... driver? Or would I run into the same problem with a GTX 1060 using the latest nvidia-drivers?

----------

## Maxxx

I have GTX 1070 with 378.13 driver version, in a 4.9.16 kernel, and i haven't any problems.

----------

## tld

Yea, this is specific to anything that can only use "legacy" drivers. nVidia is pretty good as far as getting new kernel support working for the current drivers, but for the legacy ones like 304, not so much.

Tom

----------

## ChrisJumper

I have trouble with the Kernel 4.9.36 and the nvidia-drivers-340.102-r1. There are some Patches for 4.9 and 4.11. Is there a patch available that work for modern Kernel-Sources?

Got there and try the Patch: pastebin.com/raw/stBSENAk

This is the Post for 340.102, but it was the same as for 340.102-r1:

```
>>> Unpacking source...

>>> Unpacking NVIDIA-Linux-x86-340.102.run to /var/tmp/portage/x11-drivers/nvidia-drivers-340.102/work

>>> Unpacking nvidia-settings-340.102.tar.bz2 to /var/tmp/portage/x11-drivers/nvidia-drivers-340.102/work

>>> Source unpacked in /var/tmp/portage/x11-drivers/nvidia-drivers-340.102/work

>>> Preparing source in /var/tmp/portage/x11-drivers/nvidia-drivers-340.102/work ...

 * Applying patches from /etc/portage/patches/x11-drivers/nvidia-drivers-340.102 ...

 *   nv_patch_340.102_linux_kernel_4.11.patch ...

The text leading up to this was:

--------------------------

|--- kernel/nv-linux.h

|+++ kernel/nv-linux.h

--------------------------

No file to patch.  Skipping patch.

2 out of 2 hunks ignored

The text leading up to this was:

--------------------------

|--- kernel/nv-pat.c

|+++ kernel/nv-pat.c

--------------------------

No file to patch.  Skipping patch.

4 out of 4 hunks ignored

The text leading up to this was:

--------------------------

|--- kernel/uvm/nvidia_uvm_lite.c

|+++ kernel/uvm/nvidia_uvm_lite.c

--------------------------

No file to patch.  Skipping patch.

1 out of 1 hunk ignored

The text leading up to this was:

--------------------------

|--- kernel/nv-drm.c   2017-03-31 03:42:21.000000000 +0200

|+++ kernel/nv-drm.c   2017-04-06 23:53:14.273356795 +0200

--------------------------

No file to patch.  Skipping patch.

3 out of 3 hunks ignored

The text leading up to this was:

--------------------------

|--- kernel/uvm/nvidia_uvm_linux.h  2017-03-31 03:42:21.000000000 +0200

|+++ kernel/uvm/nvidia_uvm_linux.h  2017-04-06 23:53:14.273356795 +0200

--------------------------

No file to patch.  Skipping patch.

2 out of 2 hunks ignored

The text leading up to this was:

--------------------------

|--- kernel/uvm/nvidia_uvm_lite.c  2017-03-31 03:42:21.000000000 +0200

|+++ kernel/uvm/nvidia_uvm_lite.c  2017-04-06 23:53:14.273356795 +0200

--------------------------

No file to patch.  Skipping patch.

3 out of 3 hunks ignored

The text leading up to this was:

--------------------------

|--- kernel/nv-drm.c

|+++ kernel/nv-drm.c

--------------------------

No file to patch.  Skipping patch.

patch unexpectedly ends in middle of line

```

Edit: Oh it compiles with that patch from here: pastebin.com/raw/mSwYvy1L belong to that thread.

Thank you David Flogeras for leading me to this over your bug report.

If the patch is just patch_nv1 its ignored by Portage. So i got the "driver nvidia is already registered" messages.

Did i do something wrong...? Or are just the hooks too different?

```
>>> Preparing source in /var/tmp/portage/x11-drivers/nvidia-drivers-340.102/work ...

 * Applying patches from /etc/portage/patches/x11-drivers/nvidia-drivers-340.102 ...

 *   nv_kernel_4.9.patch ...

The text leading up to this was:

--------------------------

|--- kernel/nv-drm.c    2016-12-15 12:41:26.000000000 +0100

|+++ kernel/nv-drm.c    2016-12-15 12:58:48.000000000 +0100

--------------------------

No file to patch.  Skipping patch.

patch unexpectedly ends in middle of line

1 out of 1 hunk ignored                                                                                                                          [ !! ]

 * ERROR: x11-drivers/nvidia-drivers-340.102::gentoo failed (prepare phase):

 *   patch -p1  failed with /etc/portage/patches/x11-drivers/nvidia-drivers-340.102/nv_kernel_4.9.patch

 * 

 * Call stack:

 *               ebuild.sh, line  115:  Called src_prepare

 *             environment, line 4965:  Called eapply_user

 *             environment, line 1255:  Called eapply '/etc/portage/patches/x11-drivers/nvidia-drivers-340.102'

 *             environment, line 1232:  Called _eapply_patch '/etc/portage/patches/x11-drivers/nvidia-drivers-340.102/nv_kernel_4.9.patch' '  '

 *             environment, line 1174:  Called __helpers_die 'patch -p1  failed with /etc/portage/patches/x11-drivers/nvidia-drivers-340.102/nv_kernel_4.9.patch'

 *   isolated-functions.sh, line  117:  Called die

 * The specific snippet of code:

 *              die "$@"

 * 

 * If you need support, post the output of `emerge --info '=x11-drivers/nvidia-drivers-340.102::gentoo'`,

 * the complete build log and the output of `emerge -pqv '=x11-drivers/nvidia-drivers-340.102::gentoo'`.

 * The complete build log is located at '/var/tmp/portage/x11-drivers/nvidia-drivers-340.102/temp/build.log'.

 * The ebuild environment file is located at '/var/tmp/portage/x11-drivers/nvidia-drivers-340.102/temp/environment'.

 * Working directory: '/var/tmp/portage/x11-drivers/nvidia-drivers-340.102/work'

 * S: '/var/tmp/portage/x11-drivers/nvidia-drivers-340.102/work/'
```

I try to apply this manually, and had some issues due to a typo of myself.

Last Edit: Oh yes the Patches got not applied due to a missing a/ b/ in front. I just used wget to download and rename the files.

```
--- a/kernel/nv-drm.c   2017-07-09 18:24:53.264368824 +0200

+++ b/kernel/nv-drm.c   2017-07-09 18:27:14.145367053 +0200

@@ -115,7 +115,11 @@

 };

 static struct drm_driver nv_drm_driver = {

+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)

+    .driver_features = DRIVER_GEM | DRIVER_PRIME | DRIVER_LEGACY,

+#else

     .driver_features = DRIVER_GEM | DRIVER_PRIME,

+#endif

     .load = nv_drm_load,

     .unload = nv_drm_unload,

     .fops = &nv_drm_fops,
```

----------

## soloslinger

Skazi's post/patches solved my issue for the following card:

```
01:00.0 VGA compatible controller: NVIDIA Corporation GT218 [GeForce 210] (rev a2)
```

Applied them using the steps listed here https://wiki.gentoo.org/wiki//etc/portage/patches with the eloquent names of 

```
/etc/portage/patches/x11-drivers/nvidia-drivers/first.patch

/etc/portage/patches/x11-drivers/nvidia-drivers/second.patch
```

A emerge @x11-module-rebuild later and everything worked.

Thank you Skazi!

[EDIT] ( Also.  If you care to share how you came across the solution, I'd like to know the steps you took in case I ever encounter something similar. )

soloslinger

----------

