# remove nvidia module without reboot? [solved]

## dasPaul

Hi

My normal system configuration is:

Primary Intel GPU for desktop/X11

Secondary Nividia GPU for pci-passthrough/nvenc-encoding/OpenCl tasks

Per default I boot with vfio that grabs the nvidia card just before anything else would...

Then I could just normally start qemu with the nvidia card as pci-passthrough.

After I finished my gaming session in qemu I would like to use the nvidia card for

ffmpeg encoding tasks, so I unload vfio module and do my stuff with ffmpeg.

That somehow automatically loaded all the nvidia modules.

Now if I want to start another gaming-qemu session, how can I unload all the nvidia modules

and re-enable vfio?

I tried to unload nvidia_drm/nvidia_modeset/nvidia_uvm in any combination but it simply says:

```
modprobe -r nvidia

modprobe: FATAL: Module nvidia_drm is in use.

modprobe: FATAL: Error running remove command for nvidia
```

I have no idea what else prevents the modules from unloading them...

Any ideas?

----------

## Naib

Either there is still an Xorg or other session still running or not all the modules are unloaded

 *Quote:*   

> $ lsmod
> 
> Module                  Size  Used by
> 
> nct6775                53248  0
> ...

 

from my output you can see there is a dependancy to the modules but nvidia_drm is the 

```
alias nvidia="/etc/init.d/xdm stop && rmmod nvidia_drm && rmmod nvidia_modeset && rmmod nvidia && modprobe nvidia && /etc/init.d/xdm start"
```

From a kernel module point of view, drm does need to be removed 1st (which you are doing).

So there must be an application still using the driver:

```
lsof /dev/nvidia0 | grep mem

X          3505 root  mem    CHR  195,0          1204 /dev/nvidia0

Discord    3934  Naib  mem    CHR  195,0          1204 /dev/nvidia0

steam      4948  Naib  mem    CHR  195,0          1204 /dev/nvidia0

steam      4952  Naib  mem    CHR  195,0          1204 /dev/nvidia0

steamwebh  4956  Naib  mem    CHR  195,0          1204 /dev/nvidia0

hon-x86_6 13930  Naib  mem    CHR  195,0          1204 /dev/nvidia0

hon-x86_6 13945  Naib  mem    CHR  195,0          1204 /dev/nvidia0

chrome    14154  Naib  mem    CHR  195,0          1204 /dev/nvidia0

chrome    14233  Naib  mem    CHR  195,0          1204 /dev/nvidia0

```

----------

## dasPaul

Problem solved. 

I just noticed that I accidentally uncommented the modules in my "/etc/modprobe.d/blacklist.conf"

So the nvidia modules got loaded from boot by whatever (even with enabled vfio that should prevent this if my understanding is correct) and they somehow dig deeper into the system, especially nvidia_drm... 

If I do now my cuda/nvenc stuff it automatically loads only "nvidia" and nvidia_uvm, no drm... and those two I can simply unload.

----------

