VFIO kernel module fails to capture PCI device

  • Open
  • quality assurance status badge
One participant
  • Nick Zalutskiy
Submitted by
Nick Zalutskiy
Nick Zalutskiy wrote on 11 Jun 2022 15:40
(address . bug-guix@gnu.org)
Hello all,

I am trying to capture my graphics card at initrd, using vfio, to later pass it through to a virtual machine. Judging by dmesg, the VFIO module does load early, however, the card is not captured at that point and the amdgpu driver is later loaded instead.

This is what I have in my `operating-system` config:

Toggle quote (3 lines)
> (kernel-arguments '("iommu=pt" "vfio-pci.ids=1002:73bf"))
> (initrd-modules (cons* "vfio_pci" "vfio" "vfio_iommu_type1" "vfio_virqfd" %base-initrd-modules))

There are two video cards in the system, both AMD, but different models. The video card of interest is in a separate IOMMU group and the <vendor id>:<device id> combination is correct for my machine.

Best I can tell, vfio-pci.ids argument is not propagated to the module by initramfs. See the following:

Searching online I came up against a GitHub issue for a different initramfs generator that exhibited the same symptoms: VFIO module was loaded, kernel arguments were correct, yet the card was not captured by the vfio driver. The maintainer there did a great job tracking down and fixing the issue and came up with this insight https://github.com/anatol/booster/issues/20#issuecomment-808956316

Toggle quote (2 lines)
> After reading kmod code I found that kernel does not use cmdline params for loadable modules. It was surprising for me. Instead it is expected that userspace handles cmdline parsing and provides required module params explicitly.

Another way to attach the correct driver to the gpu is to run a script at initrd, which I don't know how to accomplish with Guix. This approach has the advantage of working with two identical video cards (or disks, etc) See https://wiki.archlinux.org/title/PCI_passthrough_via_OVMF#Using_identical_guest_and_host_GPUs

I tried following the kernel docs to rebind a different driver after boot, but I believe this doesn't work for video cards, and hasn't worked for me.

Any help is greatly appreciated!

Kernel docs for vfio

Arch guide for GPU passthrough

Thank you!

Attachment: file