Test Steps --- 1) Create cloud-init data ISO to initialize cloud images: cat >meta-data <user-data </dev/null; sleep 1 echo $PCI | sudo tee /sys/bus/pci/drivers/vfio-pci/bind; sleep 1 echo 1 | sudo tee /sys/module/vfio_iommu_type1/parameters/allow_unsafe_interrupts 7) Enable memory overcommit to allow early start of VM w/ 1TB RAM: echo 1 | sudo tee /proc/sys/vm/overcommit_memory 8) Verify the error with memory size above limit: $ sudo qemu-system-x86_64 -nographic -device vfio-pci,host=$PCI -m 1035265 qemu-system-x86_64: -device vfio-pci,host=0000:00:03.0: VFIO_MAP_DMA failed: Invalid argument qemu-system-x86_64: -device vfio-pci,host=0000:00:03.0: vfio 0000:00:03.0: failed to setup container for group 2: memory listener initialization failed: Region pc.ram: vfio_dma_map(0x555f589100d0, 0x100000000, 0xfc00100000, 0x7e5b41400000) = -22 (Invalid argument) 9) Verify no error with memory size within limit: (the VM proceeds to hit an out-of-memory, expected) $ sudo qemu-system-x86_64 -nographic -device vfio-pci,host=$PCI -m 1035264 [ 189.172048] Out of memory: Killed process 900 (qemu-system-x86) total-vm:1060941712kB, anon-rss:3760888kB, file-rss:2704kB, shmem-rss:0kB, UID:0 pgtables:7528kB oom_score_adj:0 Killed 10) Similarly with libvirt: cat >vm.xml < vm PCI=0000:00:03.0 hvm 1011
EOF $ virsh create vm.xml error: Failed to create domain from vm.xml error: internal error: qemu unexpectedly closed the monitor: 2023-03-02T13:08:34.125944Z qemu-system-x86_64: -device vfio-pci,host=0000:00:03.0,id=hostdev0,bus=pci.3,addr=0x1: VFIO_MAP_DMA failed: Invalid argument 2023-03-02T13:08:34.157967Z qemu-system-x86_64: -device vfio-pci,host=0000:00:03.0,id=hostdev0,bus=pci.3,addr=0x1: vfio 0000:00:03.0: failed to setup container for group 2: memory listener initialization failed: Region pc.ram: vfio_dma_map(0x5651a01a1d40, 0x100000000, 0xfc40000000, 0x7ec3e1400000) = -22 (Invalid argument) $ sed s/1011/1010/ -i vm.xml $ virsh create vm.xml [ 1759.875400] Out of memory: Killed process 2989 (qemu-system-x86) total-vm:1059950088kB, anon-rss:3728948kB, file-rss:2576kB, shmem-rss:0kB, UID:64055 pgtables:7472kB oom_score_adj:0 error: Failed to create domain from vm.xml error: internal error: qemu unexpectedly closed the monitor