我有一台运行 Ubuntu 16.04.1 的 Dell XPS 15 9550 笔记本电脑。我正在尝试设置一个具有 GPU 直通功能的 KVM 虚拟机,其中虚拟机使用 NVIDIA GeForce GTX 960M,主机使用英特尔集成显卡。
我尝试使用 pci-stub 和 vfio-pci 进行设置,但是在这两种情况下都无法获取 iommu 组:
01:00.0 3D controller [0302]: NVIDIA Corporation GM107M [GeForce GTX 960M] [10de:139b] (rev a2)
Subsystem: Dell GM107M [GeForce GTX 960M] [1028:06e4]
Kernel driver in use: nouveau
Kernel modules: nvidiafb, nouveau
我将 intel_iommu=on 添加到 Grub 设置中。我将以下内容添加到 /etc/modules 文件中。
vfio
vfio_iommu_type1
vfio_pci
kvm
kvm_intel
我检查了我的显卡属于哪个 iommu 组以及同一组中的其他设备:
00:00.0 Host bridge [0600]: Intel Corporation Sky Lake Host Bridge/DRAM Registers [8086:1910] (rev 07)
Subsystem: Dell Skylake Host Bridge/DRAM Registers [1028:06e4]
00:01.0 PCI bridge [0604]: Intel Corporation Sky Lake PCIe Controller (x16) [8086:1901] (rev 07)
Kernel driver in use: pcieport
Kernel modules: shpchp
00:02.0 VGA compatible controller [0300]: Intel Corporation Skylake Integrated Graphics [8086:191b] (rev 06)
DeviceName: Onboard IGD
Subsystem: Dell Skylake Integrated Graphics [1028:06e4]
Kernel driver in use: i915_bpo
Kernel modules: i915_bpo
00:04.0 Signal processing controller [1180]: Intel Corporation Skylake Processor Thermal Subsystem [8086:1903] (rev 07)
Subsystem: Dell Skylake Processor Thermal Subsystem [1028:06e4]
Kernel driver in use: proc_thermal
Kernel modules: processor_thermal_device
00:14.0 USB controller [0c03]: Intel Corporation Sunrise Point-H USB 3.0 xHCI Controller [8086:a12f] (rev 31)
Subsystem: Dell Sunrise Point-H USB 3.0 xHCI Controller [1028:06e4]
Kernel driver in use: xhci_hcd
00:14.2 Signal processing controller [1180]: Intel Corporation Sunrise Point-H Thermal subsystem [8086:a131] (rev 31)
Subsystem: Dell Sunrise Point-H Thermal subsystem [1028:06e4]
00:15.0 Signal processing controller [1180]: Intel Corporation Sunrise Point-H LPSS I2C Controller #0 [8086:a160] (rev 31)
Subsystem: Dell Sunrise Point-H Serial IO I2C Controller [1028:06e4]
Kernel driver in use: intel-lpss
Kernel modules: intel_lpss_pci
00:15.1 Signal processing controller [1180]: Intel Corporation Sunrise Point-H LPSS I2C Controller #1 [8086:a161] (rev 31)
Subsystem: Dell Sunrise Point-H Serial IO I2C Controller [1028:06e4]
Kernel driver in use: intel-lpss
Kernel modules: intel_lpss_pci
00:16.0 Communication controller [0780]: Intel Corporation Sunrise Point-H CSME HECI #1 [8086:a13a] (rev 31)
Subsystem: Dell Sunrise Point-H CSME HECI [1028:06e4]
Kernel driver in use: mei_me
Kernel modules: mei_me
00:17.0 SATA controller [0106]: Intel Corporation Sunrise Point-H SATA Controller [AHCI mode] [8086:a103] (rev 31)
Subsystem: Dell Sunrise Point-H SATA Controller [AHCI mode] [1028:06e4]
Kernel driver in use: ahci
Kernel modules: ahci
00:1c.0 PCI bridge [0604]: Intel Corporation Sunrise Point-H PCI Express Root Port #1 [8086:a110] (rev f1)
Kernel driver in use: pcieport
Kernel modules: shpchp
00:1c.1 PCI bridge [0604]: Intel Corporation Sunrise Point-H PCI Express Root Port #2 [8086:a111] (rev f1)
Kernel driver in use: pcieport
Kernel modules: shpchp
00:1d.0 PCI bridge [0604]: Intel Corporation Sunrise Point-H PCI Express Root Port #9 [8086:a118] (rev f1)
Kernel driver in use: pcieport
Kernel modules: shpchp
00:1d.4 PCI bridge [0604]: Intel Corporation Sunrise Point-H PCI Express Root Port #13 [8086:a11c] (rev f1)
Kernel driver in use: pcieport
Kernel modules: shpchp
00:1d.6 PCI bridge [0604]: Intel Corporation Sunrise Point-H PCI Express Root Port #15 [8086:a11e] (rev f1)
Kernel driver in use: pcieport
Kernel modules: shpchp
00:1f.0 ISA bridge [0601]: Intel Corporation Sunrise Point-H LPC Controller [8086:a14e] (rev 31)
Subsystem: Dell Sunrise Point-H LPC Controller [1028:06e4]
00:1f.2 Memory controller [0580]: Intel Corporation Sunrise Point-H PMC [8086:a121] (rev 31)
Subsystem: Dell Sunrise Point-H PMC [1028:06e4]
00:1f.3 Audio device [0403]: Intel Corporation Sunrise Point-H HD Audio [8086:a170] (rev 31)
Subsystem: Dell Sunrise Point-H HD Audio [1028:06e4]
Kernel driver in use: snd_hda_intel
Kernel modules: snd_hda_intel
00:1f.4 SMBus [0c05]: Intel Corporation Sunrise Point-H SMBus [8086:a123] (rev 31)
Subsystem: Dell Sunrise Point-H SMBus [1028:06e4]
Kernel modules: i2c_i801
01:00.0 3D controller [0302]: NVIDIA Corporation GM107M [GeForce GTX 960M] [10de:139b] (rev a2)
Subsystem: Dell GM107M [GeForce GTX 960M] [1028:06e4]
Kernel driver in use: nouveau
Kernel modules: nvidiafb, nouveau
02:00.0 Network controller [0280]: Broadcom Corporation BCM43602 802.11ac Wireless LAN SoC [14e4:43ba] (rev 01)
Subsystem: Dell BCM43602 802.11ac Wireless LAN SoC [1028:0020]
Kernel driver in use: brcmfmac
Kernel modules: brcmfmac
03:00.0 Unassigned class [ff00]: Realtek Semiconductor Co., Ltd. RTS525A PCI Express Card Reader [10ec:525a] (rev 01)
Subsystem: Dell RTS525A PCI Express Card Reader [1028:06e4]
Kernel driver in use: rtsx_pci
Kernel modules: rtsx_pci
04:00.0 Non-Volatile memory controller [0108]: Samsung Electronics Co Ltd NVMe SSD Controller [144d:a802] (rev 01)
Subsystem: Samsung Electronics Co Ltd NVMe SSD Controller [144d:a801]
Kernel driver in use: nvme
Kernel modules: nvme
$ find /sys/kernel/iommu_groups/ -type l
/sys/kernel/iommu_groups/0/devices/0000:00:00.0
/sys/kernel/iommu_groups/1/devices/0000:00:01.0
/sys/kernel/iommu_groups/1/devices/0000:01:00.0
/sys/kernel/iommu_groups/2/devices/0000:00:02.0
/sys/kernel/iommu_groups/3/devices/0000:00:04.0
/sys/kernel/iommu_groups/4/devices/0000:00:14.0
/sys/kernel/iommu_groups/4/devices/0000:00:14.2
/sys/kernel/iommu_groups/5/devices/0000:00:15.0
/sys/kernel/iommu_groups/5/devices/0000:00:15.1
/sys/kernel/iommu_groups/6/devices/0000:00:16.0
/sys/kernel/iommu_groups/7/devices/0000:00:17.0
/sys/kernel/iommu_groups/8/devices/0000:00:1c.0
/sys/kernel/iommu_groups/8/devices/0000:00:1c.1
/sys/kernel/iommu_groups/8/devices/0000:02:00.0
/sys/kernel/iommu_groups/8/devices/0000:03:00.0
/sys/kernel/iommu_groups/9/devices/0000:00:1d.0
/sys/kernel/iommu_groups/9/devices/0000:00:1d.4
/sys/kernel/iommu_groups/9/devices/0000:00:1d.6
/sys/kernel/iommu_groups/9/devices/0000:04:00.0
/sys/kernel/iommu_groups/10/devices/0000:00:1f.0
/sys/kernel/iommu_groups/10/devices/0000:00:1f.2
/sys/kernel/iommu_groups/10/devices/0000:00:1f.3
/sys/kernel/iommu_groups/10/devices/0000:00:1f.4
我的 NVIDIA GeForce GTX 960M [10de:139b] 位于第 1 组,英特尔公司 Sky Lake PCIe 控制器 (x16) [8086:1901] 也位于第 1 组。所以我创建了一个文件 /etc/modprobe.d/vfio-pci.conf 并添加了这两个的 id:
options vfio-pci ids=10de:139b,8086:1901
sudo update-initramfs -u
重启后,我检查了 NVidia 卡使用的内核驱动程序是否是 vfio-pci。但是,如上所述,情况并非如此。但是,当我检查系统日志时,我确实看到添加了这两个设备。
systemd-modules-load[1189]: Inserted module 'vfio'
systemd-modules-load[1189]: Inserted module 'vfio_iommu_type1'
systemd-modules-load[1189]: Inserted module 'vfio_pci'
kernel: [ 8.662599] vfio_pci: add [10de:139b[ffff:ffff]] class 0x000000/00000000
kernel: [ 8.662602] vfio_pci: add [8086:1901[ffff:ffff]] class 0x000000/00000000
systemd-modules-load[1199]: Inserted module 'vfio'
systemd-modules-load[1199]: Inserted module 'vfio_iommu_type1'
systemd-modules-load[1199]: Inserted module 'vfio_pci'
kernel: [ 8.344978] vfio_pci: add [10de:139b[ffff:ffff]] class 0x000000/00000000
kernel: [ 8.344981] vfio_pci: add [8086:1901[ffff:ffff]] class 0x000000/00000000
systemd-modules-load[1202]: Inserted module 'vfio'
systemd-modules-load[1202]: Inserted module 'vfio_iommu_type1'
systemd-modules-load[1202]: Inserted module 'vfio_pci'
kernel: [ 8.336405] vfio_pci: add [10de:139b[ffff:ffff]] class 0x000000/00000000
kernel: [ 8.336409] vfio_pci: add [8086:1901[ffff:ffff]] class 0x000000/00000000
systemd-modules-load[1202]: Inserted module 'vfio'
systemd-modules-load[1202]: Inserted module 'vfio_iommu_type1'
systemd-modules-load[1202]: Inserted module 'vfio_pci'
kernel: [ 8.454811] vfio_pci: add [10de:139b[ffff:ffff]] class 0x000000/00000000
kernel: [ 8.454814] vfio_pci: add [1028:06e4[ffff:ffff]] class 0x000000/00000000
kernel: [ 8.454816] vfio_pci: add [8086:1901[ffff:ffff]] class 0x000000/00000000
为什么vfio-pci驱动无法获取显卡?
答案1
我通过将模块放入 /etc/initramfs-tools/modules 中解决了这个问题。因为现在 vfio-pci 在 nouveau 已经占用 GPU 后加载。