Bug 736437 - pci_stub driver is still used for PCI device after virsh destroy
Summary: pci_stub driver is still used for PCI device after virsh destroy
Keywords:
Status: CLOSED DUPLICATE of bug 736214
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: libvirt
Version: 6.2
Hardware: All
OS: Linux
high
high
Target Milestone: rc
: ---
Assignee: Eric Blake
QA Contact: Virtualization Bugs
URL:
Whiteboard:
Depends On: 740686
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-09-07 17:10 UTC by Miroslav Vadkerti
Modified: 2011-10-14 21:48 UTC (History)
10 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 740686 (view as bug list)
Environment:
Last Closed: 2011-10-14 21:48:39 UTC


Attachments (Terms of Use)

Description Miroslav Vadkerti 2011-09-07 17:10:45 UTC
Description of problem:
When you destroy a domain which has attached PCI device using PCI passthrough, the pci_stub driver is still used for the device and it is not switched back to the correct driver (i.e. igb or igbvf in my reproducer)

In the reproducer I use Intel 82576 that should have proper PCI PT support:
01:00.0 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)
01:00.1 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)

Version-Release number of selected component (if applicable):
kernel-2.6.32-193.el6.x86_64
libvirt-0.9.4-7.el6.x86_64
qemu-kvm-0.12.1.2-2.183.el6.x86_64

How reproducible:
100%

Steps to Reproduce:
1. Configure system for PCI device assignement by enabling VT-d extensions [1]

2. Create a new domain with the xml below. Please note that the image file RHEL6.1A.img is a default installation of RHEL6.1. Also be sure to change the attached PCI device.

# cat RHEL6.1A.xml
<domain type='kvm'>
  <name>RHEL6.1A</name>
  <memory>256000</memory>
  <currentMemory>256000</currentMemory>
  <vcpu>1</vcpu>
  <os>
    <type arch='x86_64' machine='rhel6.0.0'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw' cache='none'/>
      <source file='/var/lib/libvirt/images/RHEL6.1A.img'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>
    <serial type='pty'>
      <target port='0'/>
    </serial>
    <console type='pty'>
      <target port='0'/>
    </console>
    <input type='tablet' bus='usb'/>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes'/>
    <video>
      <model type='cirrus' vram='9216' heads='1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <hostdev mode="subsystem" type="pci" managed="yes">
        <source>
            <address domain="0x0000" bus="0x01" slot="0x00" function="0x1"/>
        </source>
    </hostdev>
 </devices>

 <seclabel type='static' model='selinux'>
    <label>system_u:system_r:svirt_t:s0:c50,c70</label>
 </seclabel>

</domain>

# virsh create RHEL6.1A.xml
Domain RHEL6.1A created from RHEL6.1A.xml

3. Check to which driver is PCI device attached:
# readlink /sys/bus/pci/devices/0000\:01\:00.1/driver
../../../../bus/pci/drivers/pci-stub

4. Now destroy the domain
# virsh destroy RHEL6.1A

5. Check to which driver is PCI device attached:
# readlink /sys/bus/pci/devices/0000\:01\:00.1/driver
../../../../bus/pci/drivers/pci-stub

Actual results:
PCI device still attached to pci_stub driver:
# readlink /sys/bus/pci/devices/0000\:01\:00.1/driver
../../../../bus/pci/drivers/pci-stub

Expected results:
PCI device attached to the correct driver for the device after detroying the domain (igb or igbvf in case of this reproducer):
# readlink /sys/bus/pci/devices/0000\:01\:00.1/driver
../../../../bus/pci/drivers/igb

Links:
[1]
http://documentation-stage.bne.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html-single/Virtualization/index.html#chap-Virtualization-PCI_passthrough

Comment 1 Eric Blake 2011-09-08 13:53:20 UTC
I'll take a look into this next week once I've got access to some hardware to try and reproduce it

Comment 9 Eric Blake 2011-09-20 23:35:32 UTC
I think I have reproduced the bug using just hot-plug/hot-unplug on my local machine (no need to even stop the domain), but I still need to understand the code better to understand what I will be patching.  It should be easy enough to fix, though, once I understand what the code is already doing with pci-stub management.

Comment 10 Eric Blake 2011-09-22 22:50:03 UTC
Actually, I'm starting to think that this behavior is intentional.  Libvirt provides the virNodeDeviceReAttach API (exposed via 'virsh nodedev-reattach) as a way to tell libvirt to release a pci device back to the host.

In your particular example, you want to run:

virsh nodedev-reattach pci_0000_03_10_0

which will fail if any domains are configured to use the device, but which should succeed at restoring the driver back to igbvf if libvirt truly is no longer using the device.

Creating a domain with a passthrough device without first calling virNodeDeviceDettach (yes, that spelling error is in the public API) means that libvirt may automatically attempt the detach, but there is no automatic counterpart for a reattach.  I suppose that it might be possible to request that libvirt add automatic reattach since it already has automatic detach, but that should be discussed on the upstream libvirt list, and I'm not sure it is worth it.

So for now, I'm inclined to close this bug (automatic reattach) as not a bug, after waiting a day or so for any further comments.

Meanwhile, I will create a new bug about the fact that 'virsh nodedev-*' is completely undocumented.  I think the documentation aspect can be cleaned up in time for RHEL 6.2, but it does not have the same impact as this bug.

Comment 11 Eric Blake 2011-09-22 23:00:25 UTC
(In reply to comment #10)
> Meanwhile, I will create a new bug about the fact that 'virsh nodedev-*' is
> completely undocumented.  I think the documentation aspect can be cleaned up in
> time for RHEL 6.2, but it does not have the same impact as this bug.

doc issue tracked in bug 740686

Comment 15 Eric Blake 2011-10-06 15:19:05 UTC
Teaching libvirt to auto-reassign devices back to the kernel after removing them from guests goes along nicely with the concept of managed devices, but that is a feature request, not a bug fix.  Moving this RFE to RHEL 6.3; the Common Criteria list agreed that while the current behavior of requiring manual 'virsh nodedev-reattach' is not optimal, it does work and there is no security risk that needs to be addressed in the 6.2 timeframe.

Comment 16 Eric Blake 2011-10-14 21:48:39 UTC
I'm closing this as a duplicate; the patch for bug 736214 solves the issue for all <hostdev managed=1>.

*** This bug has been marked as a duplicate of bug 736214 ***


Note You need to log in before you can comment on or make changes to this bug.