From Fedora Project Wiki

(Mention /dev/vfio/vfio permissions bug)
(Drop outdated bug reference)
 
(4 intermediate revisions by the same user not shown)
Line 7: Line 7:
 
* Functioning F19+ host and F19+ VM.
 
* Functioning F19+ host and F19+ VM.
 
* PCI device you can afford to devote entirely to a VM
 
* PCI device you can afford to devote entirely to a VM
 +
* Verify your host as necessary hardware support for VFIO
 +
** If on an Intel CPU, this command should show at least 2 matches: <code>dmesg <nowiki>|</nowiki> grep -e DMAR -e IOMMU</code>
 +
** If on an AMD CPU, this command should show some output: <code>dmesg <nowiki>|</nowiki> grep AMD-Vi</code>
 +
* Some host PCIe device may not work inside the guest if the guest driver requires the device to appear as PCIe: the default QEMU configuration can only emulate PCI. If you know you have a PCIe only device, you will need to [[QA:Testcase_Virtualization_Q35_Chipset| create a VM using the Q35 chipset]], which can emulate PCIe.
  
 
|actions=
 
|actions=
 +
 +
== Using virt-manager ==
  
 
# Run virt-manager, open an existing shutoff guest and go to the details page.
 
# Run virt-manager, open an existing shutoff guest and go to the details page.
Line 18: Line 24:
 
# Select the device in virt-manager and ''Remove'' it
 
# Select the device in virt-manager and ''Remove'' it
  
== Device assignment with VFIO ==
+
== Hoptlug from the command line ==
 
 
[http://www.linux-kvm.org/wiki/images/d/d1/2011-forum-VFIO.pdf VFIO] is the new and improved PCI assignment method for kvm. It will likely become the default through libvirt in the future.
 
  
# Verify your host as necessary hardware support for VFIO
+
* Find the device you want to attach in the output of <code>lspci</code>, copy the address string at the start of the line, something like <code>02:00.0</code>
#* If on an Intel CPU, this command should show at least 2 matches: <code>dmesg <nowiki>|</nowiki> grep -e DMAR -e IOMMU</code>
+
* Attach the device to running VM 'test-day-vm' using virt-xml:
#* If on an AMD CPU, this command should show some output: <code>dmesg <nowiki>|</nowiki> grep AMD-Vi</code>
+
  sudo virt-xml test-day-vm --update --add-device --host-device 02:00.0
# On the host, do <code>sudo chmod 666 /dev/vfio/vfio</code>  ([https://bugzilla.redhat.com/show_bug.cgi?id=967230 this is an F19 bug])
+
* Verify the device is usable in the VM
# Follow the regular PCI assignment steps up to step 4.
+
* Remove the device from the running VM 'test-day-vm':
# Change the host device to use the VFIO method:
+
  sudo virt-xml test-day-vm --update --remove-device --host-device 02:00.0
#* <code>sudo virsh edit test-day-vm</code>
+
* Verify the device is visible and functioning on the host machine
#* Add <code><driver name="vfio"/></code> to the PCI <code><hostdev></code> block
 
#* Save and exit
 
# Continue on at step 4 in the above steps.
 
  
 
|results=
 
|results=

Latest revision as of 01:05, 14 April 2015

Description

Assign a physical PCI device to a KVM guest, and verify that it works as expected.

Setup

  • Functioning F19+ host and F19+ VM.
  • PCI device you can afford to devote entirely to a VM
  • Verify your host as necessary hardware support for VFIO
    • If on an Intel CPU, this command should show at least 2 matches: dmesg | grep -e DMAR -e IOMMU
    • If on an AMD CPU, this command should show some output: dmesg | grep AMD-Vi
  • Some host PCIe device may not work inside the guest if the guest driver requires the device to appear as PCIe: the default QEMU configuration can only emulate PCI. If you know you have a PCIe only device, you will need to create a VM using the Q35 chipset, which can emulate PCIe.

How to test

Using virt-manager

  1. Run virt-manager, open an existing shutoff guest and go to the details page.
  2. Add Hardware->PCI Host Device
  3. Choose the device you want to assign from the list, like: 00:19.0 Interface eth0 (82566DM-2 Gigabit Network Connection)
  4. Click Finish
  5. Start the guest and check the device is functional within the guest
  6. Shut down the guest and check the device is functional within the host
  7. Select the device in virt-manager and Remove it

Hoptlug from the command line

  • Find the device you want to attach in the output of lspci, copy the address string at the start of the line, something like 02:00.0
  • Attach the device to running VM 'test-day-vm' using virt-xml:
 sudo virt-xml test-day-vm --update --add-device --host-device 02:00.0
  • Verify the device is usable in the VM
  • Remove the device from the running VM 'test-day-vm':
 sudo virt-xml test-day-vm --update --remove-device --host-device 02:00.0
  • Verify the device is visible and functioning on the host machine

Expected Results

No obvious errors occur. PCI device assignment can be quirky and does not always work with every PCI device or host PCI layout. If you get an error, ask in #fedora-test-day IRC first and we can likely provide some direction.