Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] Auto loading vfio-pci
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
Kresp
n00b
n00b


Joined: 17 Oct 2016
Posts: 73

PostPosted: Tue Aug 15, 2017 11:08 am    Post subject: [SOLVED] Auto loading vfio-pci Reply with quote

I use vfio-pci to passthrough my GPU to VM.
However, the module does not load automatically on boot.
Code:

$ 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:
Code:

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:
Code:

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
Back to top
View user's profile Send private message
Myu
Apprentice
Apprentice


Joined: 22 Oct 2014
Posts: 164
Location: Belgium

PostPosted: Tue Aug 15, 2017 11:17 am    Post subject: Reply with quote

Hello,

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

Add in /etc/conf.d/modules :

Code:
modules="vfio vfio-pci vfio_iommu_type1 vfio_virqfd"


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

Code:

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
_________________
Gentoo stable with bits of ~amd64 // Xfce 4.13 + Compiz Reloaded.
Back to top
View user's profile Send private message
Kresp
n00b
n00b


Joined: 17 Oct 2016
Posts: 73

PostPosted: Wed Aug 16, 2017 1:09 pm    Post subject: Reply with quote

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


Code:
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.
Back to top
View user's profile Send private message
Myu
Apprentice
Apprentice


Joined: 22 Oct 2014
Posts: 164
Location: Belgium

PostPosted: Thu Aug 17, 2017 5:51 am    Post subject: Reply with quote

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 :)

Hope this helps !
_________________
Gentoo stable with bits of ~amd64 // Xfce 4.13 + Compiz Reloaded.
Back to top
View user's profile Send private message
Kresp
n00b
n00b


Joined: 17 Oct 2016
Posts: 73

PostPosted: Sat Aug 26, 2017 3:00 am    Post subject: Reply with quote

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:
Code:

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum