# [SOLVED] Auto loading vfio-pci

## Kresp

I use vfio-pci to passthrough my GPU to VM.

However, the module does not load automatically on boot.

```

$ cat /etc/modprobe.d/vfio-pci.conf

options vfio-pci ids=1002:67df,1002:aaf0

```

Every time I turn my machine on, I have to manually do:

```

modprobe vfio-pci

chown root:kvm /dev/vfio

chmod g+X /dev/vfio

```

Latter two commands I need to run qemu without sudo.

I already have this udev rule:

```

SUBSYSTEM=="vfio", OWNER="root", GROUP="kvm"

```

But I can not find a way to automatically set proper permissions for parent directory.

My user is member of kvm group.

So, I have to problems: how do I force vfio-pci to auto load on boot, and where do I change attrs for /dev/vfio?Last edited by Kresp on Sat Aug 26, 2017 3:01 am; edited 2 times in total

----------

## Myu

Hello,

About to automatic loading, I use openRC so I cannot really tell about systemd, that being said :

Add in /etc/conf.d/modules :

```
modules="vfio vfio-pci vfio_iommu_type1 vfio_virqfd"
```

Then make sure that the modules service is started at boot time 

```

rc-config list | grep modules

rc-config add modules
```

On my end I didn't had to fidlle with /dev/vfio perms :

drwxr-xr-x  2 root root        80 Aug 15 11:39 vfio

----------

## Kresp

Adding vfio-pci helped, but only if snd_hda_intel is blacklisted.

 *Myu wrote:*   

> 
> 
> ```
> modules="vfio-pci"
> ```
> ...

 

Otherwise it grabs RX 480's HDMI audio and system locks after trying to insert vfio-pci module.

How do I load snd_hda_intel only for specific device?

On my system it works with GTX 960 HDMI audio, RX 480 HDMI audio and onboard ALC1220 codec.

I'd like to whitelist it for only ALC1220.

Also, /dev/vfio is 660 by default, so I still ned to chmod+chown after boot.

----------

## Myu

Good question, I'm not sure I know an answer about loading the module for a specific device, most likely it can be done

From my experience, I've found that building snd_hda_intel in-kernel made things so much smoother to get audio at boot time on the host then be able to get audio when starting the VM.

I usually pass through my onboard audio chipset to the VM i.e

Before (at boot time)

Dwarf linux # lspci -nnk | grep --context=3 1e20

[...]

00:1b.0 Audio device [0403]: Intel Corporation 7 Series/C216 Chipset Family High Definition Audio Controller [8086:1e20] (rev 04)

	Subsystem: ASRock Incorporation 7 Series/C216 Chipset Family High Definition Audio Controller [1849:8892]

	Kernel driver in use: snd_hda_intel

[...]

After (when starting up the VM)

Dwarf linux # lspci -nnk | grep --context=3 1e20

[...]

00:1b.0 Audio device [0403]: Intel Corporation 7 Series/C216 Chipset Family High Definition Audio Controller [8086:1e20] (rev 04)

	Subsystem: ASRock Incorporation 7 Series/C216 Chipset Family High Definition Audio Controller [1849:8892]

	Kernel driver in use: vfio-pci

[...]

If you're not against a small kernel rebuilt, I think this might be interesting to try out  :Smile: 

Hope this helps !

----------

## Kresp

man modprobe.d ponted to install keyword, which was exactly what I needed to fix module loading order.

I removed snd_hda_intel from blacklist, and left this:

```

options vfio-pci ids=1002:67df,1002:aaf0

install vfio-pci /sbin/modprobe -r snd_hda_intel; /sbin/modprobe --ignore-install vfio-pci ids=1002:67df,1002:aaf0; /sbin/modprobe snd_hda_intel

```

--ignore-install is necessary, or else it recurses.

It's possible to replace modprobe -r with with /bin/echo deviceId to device/driver/unbind, but this ID changes whenever you swap or remove PCI-E devices, so I decided it's safer to remove module altogether, and bind it only after vfio-pci is done.

----------

