kubevirt: Nvidia driver installation fails due to invalid PCI I/O region when passing through high vram GPU (24+ GB) when EFI bios enabled

Problem:

I’m using kubevirt to create guest VM’s via gpu-passthrough with a m40 24GB, when installing the GPU drivers, the process fails with the error:

[   72.161016] nvidia-nvlink: Nvlink Core is being initialized, major device number 236
[   72.161022] NVRM: This PCI I/O region assigned to your NVIDIA device is invalid:
               NVRM: BAR0 is 0M @ 0x0 (PCI:0000:08:00.0)
[   72.162204] nvidia: probe of 0000:08:00.0 failed with error -1
[   72.162223] NVRM: The NVIDIA probe routine failed for 1 device(s).

VM Config

Name:         debian12
Namespace:    debian12
Labels:       argocd.argoproj.io/instance=debian12-cloud-vm
              kubevirt.io/os=linux
              metallb-service=debian12
Annotations:  kubevirt.io/latest-observed-api-version: v1
              kubevirt.io/storage-observed-api-version: v1
API Version:  kubevirt.io/v1
Kind:         VirtualMachine
Metadata:
  Creation Timestamp:  2024-01-27T16:17:55Z
  Finalizers:
    kubevirt.io/virtualMachineControllerFinalize
  Generation:        1
  Resource Version:  11613480
  UID:               25ddc05c-9c72-402c-bfa0-740c177357e1
Spec:
  Run Strategy:  RerunOnFailure
  Template:
    Metadata:
      Creation Timestamp:  <nil>
      Labels:
        Kubevirt - Service:  debian12
        kubevirt.io/domain:  debian12
    Spec:
      Architecture:  amd64
      Domain:
        Cpu:
          Cores:    4
          Sockets:  1
          Threads:  1
        Devices:
          Autoattach Graphics Device:  true
          Autoattach Pod Interface:    true
          Autoattach Serial Console:   true
          Disks:
            Boot Order:  2
            Disk:
              Bus:       virtio
            Name:        harddrive
            Boot Order:  1
            Cdrom:
              Bus:       sata
              Readonly:  true
            Name:        cloudinitvolume
          Gpus:
            Device Name:  nvidia.com/GM200GL_Tesla_M40
            Name:         gpu0
          Inputs:
            Bus:   virtio
            Name:  tablet1
            Type:  tablet
          Interfaces:
            Bridge:
            Name:  default
        Features:
          Acpi:
          Kvm:
          Smm:
            Enabled:  true
        Firmware:
          Bootloader:
            Efi:
              Secure Boot:  false
        Machine:
          Type:  q35
        Resources:
          Limits:
            Memory:  8Gi
      Networks:
        Name:  default
        Pod:
      Volumes:
        Name:  harddrive
        Persistent Volume Claim:
          Claim Name:  harddrive
        Cloud Init No Cloud:
          User Data:  #cloud-config

Possible workaround

When creating the guest VM with plain QEMU, this error can be avoided by providing the firmware option -fw_cfg name=opt/ovmf/X-PciMmio64Mb,string=65536

QEMU command:

sudo qemu-system-x86_64 \
    -machine accel=kvm,type=q35 \
    -cpu host,kvm=off,hv_vendor_id=null,check=off,hypervisor=off \
    -smp 4,sockets=1,cores=4,threads=1,maxcpus=4 \
    -m 8G \
    -object iothread,id=io1 \
    -device virtio-blk-pci,drive=disk1,iothread=io1 \
    -drive if=none,id=disk1,cache=none,format=qcow2,aio=threads,file=hdd.img \
    -drive file=Win10-2.iso,index=1,media=cdrom \
    -drive file=virtio-win-0.1.215.iso,index=2,media=cdrom \
    -object iothread,id=ioGames \
    -device virtio-blk-pci,drive=diskGames,iothread=ioGames \
    -drive if=none,id=diskGames,cache=none,format=qcow2,aio=threads,file=/mnt/raid1/hdd2-2.img \
    -boot menu=on \
    -serial none \
    -parallel none \
    -bios /usr/share/ovmf/OVMF.fd \
    -usbdevice tablet \
    -vga none -serial stdio -parallel none \
    -device vfio-pci,host=04:00.0,multifunction=on \
    -fw_cfg name=opt/ovmf/X-PciMmio64Mb,string=65536 \
    -netdev tap,id=network1,ifname=tap1,script=no,downscript=no \
    -device virtio-net-pci,netdev=network1,mac=BD:BA:12:13:EE:FF \
    -vnc 192.168.50.100:1

However I do not see any way to currently provide this firmware option to my Kubevirt VM

What you expected to happen:

Can it be possible to pass option to the firmware as follows?

        Firmware:
          X-PciMmio64Mb: 65536
          Bootloader:
            Efi:
              Secure Boot:  false

How to reproduce it (as minimally and precisely as possible): Steps to reproduce the behavior.

Not sure if the issue is specifically the M40 24GB as i have seen others run into this problem with A5000s, but it should be reproducible if you pass through a 24+GB GPU to the guest vm and then try to install the nvidia display driver

Additional context:

Environment:

  • KubeVirt version (use virtctl version): 1.0.0
  • Kubernetes version (use kubectl version): v1.27.9+k3s1
  • VM or VMI specifications: N/A
  • Cloud provider or hardware configuration: bare-metal
  • OS (e.g. from /etc/os-release): host os is debain12, happend on all guest OSes
  • Kernel (e.g. uname -a): 5.19 and 6.1
  • Install tools: helm

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 49 (25 by maintainers)

Most upvoted comments

In libvirt domain xml, this should do the trick:

<sysinfo type='fwcfg'>
  <entry name='opt/ovmf/X-PciMmio64Mb'>65536</entry>
</sysinfo>

We can add a KubeVirt option to add that block to VMs, it’s “just” a matter of deciding how the API should look like. Design proposal anyone? 😃

Yes, <sysinfo> cannot be used to provide qemu/ovmf blobs, sorry for misleading you… I asked around, and for now the only way to do this is through a qemu arg (https://unix.stackexchange.com/questions/235414/libvirt-how-to-pass-qemu-command-line-args). I will file an RFE against libvirt to add proper support for this, but please note that they will then have to file an RFE against the OVMF project to graduate PciMmio64Mb out of the experimental state (that’s what X- means). So that will take time. Edit: ahem, yeah, see above… Edit2: RFE: https://issues.redhat.com/browse/RHEL-35391

That’s great, Harvester is using KubeVirt too. Can harvester contribute a fix to KubeVirt, @mitchty?