How to assign devices with VT-d in KVM

How to assign devices with VT-d in KVM

[ edit]

VT-d support

  • In order to assign devices in KVM, you'll need a system which supports VT-d. This has nothing to do with the VT-x support of your CPU, VT-d needs to be supported by both your chipset on your motherboard and by your CPU.
  • If you are in doubt whether your motherboard or CPU supports VT-d or not, the Xen VT-d wikipage has some pointers of VT-d enabled chipsets, motherboards and CPUs:
       http://wiki.xensource.com/xenwiki/VTdHowTo
  • If your hardware doesn't have an IOMMU ("Intel VT-d" support in case of Intel - "AMD I/O Virtualization Technology" support in case of AMD), you'll not be able to assign devices in KVM. Some work towards allowing this were done, but the code never made it into KVM, due to various issues with the code. At the moment it doesn't seem like device assignment without hardware support, will ever be integrated into KVM.
  • Assignment of graphics cards are not officially supported at the moment, but there has been success passing through a secondary Radeon HD 5850 as a VM's secondary display. It also seems like one person is currently working on writing patches for primary display support in his spare time (February, 2010):
       http://www.spinics.net/lists/kvm/msg25977.html


[ edit]

Assigning device to guest

1. Modifying kernel config:

  • make menuconfig
  • set "Bus options (PCI etc.)" -> "Support for DMA Remapping Devices" to "*"
  • set "Bus options (PCI etc.)" -> "Enable DMA Remapping Devices" to "*"
  • set "Bus options (PCI etc.)" -> "PCI Stub driver" to "*"
  • optional setting:
       set "Bus options (PCI etc.)" -> "Support for Interrupt Remapping" to "*"
  • exit/save

2. build kernel:

  • make
  • make modules_install
  • make install

3. reboot and verify that your system has IOMMU support

  • AMD Machine
    • dmesg | grep AMD-Vi
     ...
     AMD-Vi: Enabling IOMMU at 0000:00:00.2 cap 0x40
     AMD-Vi: Lazy IO/TLB flushing enabled
     AMD-Vi: Initialized for Passthrough Mode
     ...
  • Intel Machine
    • dmesg | grep -e DMAR -e IOMMU
     ...
     DMAR:DRHD base: 0x000000feb03000 flags: 0x0
     IOMMU feb03000: ver 1:0 cap c9008020e30260 ecap 1000
     ...
  • If you get no output you'll need to fix this before moving on. Check if your hardware supports VT-d and check that it has been enabled in BIOS.

NOTE: If you still get an error "No IOMMU found." Check dmesg for errors suggesting your BIOS is broken. Another possible reason: CONFIG_DMAR_DEFAULT_ON is not set. In that case, pass "intel_iommu=on" as kernel parameter to enable it. AMD uses different kernel parameter than Intel, on AMD you need to pass "iommu=pt iommu=1".

4. unbind device from host kernel driver (example PCI device 01:00.0)

  • Load the PCI Stub Driver if it is compiled as a module
       modprobe pci_stub
  • lspci -n
  • locate the entry for device 01:00.0 and note down the vendor & device ID 8086:10b9
       ...
       01:00.0 0200: 8086:10b9 (rev 06)
       ...
  • echo "8086 10b9" > /sys/bus/pci/drivers/pci-stub/new_id
  • echo 0000:01:00.0 > /sys/bus/pci/devices/0000:01:00.0/driver/unbind
  • echo 0000:01:00.0 > /sys/bus/pci/drivers/pci-stub/bind

5. load KVM modules:

  • modprobe kvm
  • modprobe kvm-intel

6. assign device:

  • /usr/local/bin/qemu-system-x86_64 -m 512 -boot c -net none -hda /root/ia32e_rhel5u1.img -device pci-assign,host=01:00.0


[ edit]

VT-d device hotplug

KVM also supports hotplug devices with VT-d to guest. In guest command interface (you can press Ctrl+Alt+2 to enter it), you can use following command to hot add/remove devices to/from guest:

  • hot add:
       device_add pci-assign,host=01:00.0,id=mydevice
  • hot remove:
       device_del mydevice


[ edit]

Notes

  • VT-d spec specifies that all conventional PCI devices behind a PCIe-to PCI/PCI-X bridge or conventional PCI bridge can only be collectively assigned to the same guest. PCIe devices do not have this restriction.
  • If the device doesn't support MSI, and it shares IRQ with other devices, then it cannot be assigned due to host irq sharing for assigned devices is not supported. You will get warning message when you assign it. Notice this also apply to the devices which only support MSI-X.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值