kvm GPU透传进虚拟机

最近给服务器装了kvm虚拟机,服务器上有多张显卡,想透传给虚拟机使用

我的环境是ubuntu16.01

IOMMU

dmesg | grep -i -e DMAR -e IOMMU

发现缺少IOMMU:

[    0.000000] ACPI: DMAR 0x000000003B7C7000 000100 (v01 INSYDE HSW-LPT  00000001 ACPI 00040000)
[    0.072640] DMAR: Host address width 46
[    0.072642] DMAR: DRHD base: 0x000000fbffc000 flags: 0x0
[    0.072648] DMAR: dmar0: reg_base_addr fbffc000 ver 1:0 cap 8d2078c106f0466 ecap f020df
[    0.072649] DMAR: DRHD base: 0x000000bbffc000 flags: 0x1
[    0.072653] DMAR: dmar1: reg_base_addr bbffc000 ver 1:0 cap 8d2078c106f0466 ecap f020df
[    0.072654] DMAR: RMRR base: 0x0000002cd89000 end: 0x0000002cd8bfff
[    0.072655] DMAR: ATSR flags: 0x0
[    0.072657] DMAR: ATSR flags: 0x0
[    0.072658] DMAR: RHSA base: 0x000000bbffc000 proximity domain: 0x0
[    0.072659] DMAR: RHSA base: 0x000000fbffc000 proximity domain: 0x1
[    0.072661] DMAR-IR: IOAPIC id 10 under DRHD base  0xfbffc000 IOMMU 0
[    0.072662] DMAR-IR: IOAPIC id 8 under DRHD base  0xbbffc000 IOMMU 1
[    0.072663] DMAR-IR: IOAPIC id 9 under DRHD base  0xbbffc000 IOMMU 1
[    0.072664] DMAR-IR: HPET id 0 under DRHD base 0xbbffc000
[    0.072665] DMAR-IR: x2apic is disabled because BIOS sets x2apic opt out bit.
[    0.072666] DMAR-IR: Use 'intremap=no_x2apic_optout' to override the BIOS setting.
[    0.073539] DMAR-IR: Enabled IRQ remapping in xapic mode
[   19.077793] vboxpci: IOMMU not found (not registered)

解决:

sudo vim /etc/default/grub

GRUB_CMDLINE_LINUX=""加上intel_iommu=on
kvm GPU透传进虚拟机_第1张图片
执行:

sudo grub-mkconfig -o /boot/grub/grub.cfg
sudo reboot

注意,机器一定要重启

然后执行dmesg | grep -e DMAR -e IOMMU,发现IOMMU已经enabled了

为虚拟机添加显卡设备

kvm虚拟机设置页面,点击add hardwarem,选择PCI host device,选中你的显卡。然后重启虚拟机
kvm GPU透传进虚拟机_第2张图片
虚拟机中自行安装nvidia驱动,安装成功后就能用nvidia-smi看到显卡信息了

你可能感兴趣的:(开发小笔记,linux,kvm)