admin管理员组

文章数量:1531792

一、问题现象

使用SR-IOV虚拟网卡创建KVM虚拟机,创建虚拟机添加“–hostdev=xxxx”参数,或者修改虚拟机XML配置文件增加 “hostdev”,创建SR-IOV虚拟网卡时会报错如下:

ERROR unsupported configuration: host doesn’t support passthrough of host PCI devices

二、 确认开启SR-IOV全部支持

以下忘记第二项不设置或打开都会导致以上问题。

1、在BIOS里开启网卡SR-IOV

注:即使BIOS里开启全局SRIOV,网卡也依然可以当作普通网卡使用

2、在BIOS里开启VT-d支持

3、在grub配置iommu支持

修改/boot/grub2/grub.cfg或 /etc/grub2.cfg文件(软链接),在linux16加载内核镜像一行追加“intel_iommu=on iommu=pt”,“iommu.passthrough=1”不加也可,包含在“intel_iommu=on”

[root@localhost ~]# ls -l /etc/grub2.cfg lrwxrwxrwx. 1 root root 22
Nov 19 17:54 /etc/grub2.cfg -> …/boot/grub2/grub.cfg

linux16 /vmlinuz-3.10.0-514.el7.x86_64 root=/dev/mapper/cl-root ro
crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap rhgb quiet
intel_iommu=on iommu=pt

也可修改/etc/default/grub文件,在GRUB_CMDLINE_LINUX最后追加“intel_iommu=on iommu=pt”参数,然后执行grub2-mkconfig -o /boot/grub2/grub.cfg刷新 grub.cfg 文件;

[root@localhost ~]# cat /etc/default/grub GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="( s e d ′ s , r e l e a s e . ∗ (sed 's, release
.*(sed ′ s,release.∗,g’ /etc/system-release)" GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT=“console”
GRUB_CMDLINE_LINUX=“crashkernel=auto rd.lvm.lv=cl/root
rd.lvm.lv=cl/swap rhgb quiet intel_iommu=on iommu=pt
iommu.passthrough=1” GRUB_DISABLE_RECOVERY=“true”

[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg Generating
grub configuration file … Found linux image:
/boot/vmlinuz-3.10.0-514.el7.x86_64 Found initrd image:
/boot/initramfs-3.10.0-514.el7.x86_64.img Found linux image:
/boot/vmlinuz-0-rescue-e5ec5990f1e548bea132e3458196c892 Found initrd
image: /boot/initramfs-0-rescue-e5ec5990f1e548bea132e3458196c892.img
done

注:额外追加“console=ttyS0,115200”参数可支持串口显示;

4、虚拟化支持及开启成功验证

1)验证BIOS里开启SR-IOV和Intel VT-d,Grub开启IOMMU生效方法如下:

[root@localhost ~]# cat /proc/cmdline | grep intel_iommu
BOOT_IMAGE=/vmlinuz-3.10.0-514.el7.x86_64 root=/dev/mapper/cl-root ro
crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap rhgb quiet
intel_iommu=on iommu=pt iommu.passthrough=1

[root@localhost ~]# dmesg | grep -e IOMMU
[ 0.000000] DMAR: IOMMU enabled
[ 0.064288] DMAR-IR: IOAPIC id 3 under DRHD base 0xfbffc000 IOMMU 0
[ 0.064289] DMAR-IR: IOAPIC id 1 under DRHD base 0xc7ffc000 IOMMU 1
[ 0.064290] DMAR-IR: IOAPIC id 2 under DRHD base 0xc7ffc000 IOMMU 1

BIOS里只开启SR-IOV,忘记开启Intel VT-d时只会打印:

[root@localhost ~]# dmesg | grep -e IOMMU
[ 0.000000] DMAR: IOMMU enabled

并且创建虚拟机添加“–hostdev=xxxx”参数,创建SR-IOV虚拟网卡时会报错如下:

ERROR unsupported configuration: host doesn’t support passthrough of host PCI devices

2)验证vfio加载正常:

[root@localhost ~]# lsmod | grep vfio
vfio_iommu_type1       17632  1 
vfio_pci               36948  1 
vfio                   26136  5 vfio_iommu_type1,vfio_pci
irqbypass              13503  4 kvm,vfio_pci

注意:重启后“lsmod | grep vfio”并不会有显示,只有虚拟机创建后才会加载启动vfio,看到显示。

Centos7使用SR-IOV创建KVM虚拟机具体方法参见:使用SR-IOV创建KVM虚拟机

本文标签: 报错虚拟机IOVkvmSR