Bug 669634

Summary: Hotplugging the same PF whose VF is already assigned to guest causes guest shut down
Product: Red Hat Enterprise Linux 6 Reporter: zhanghaiyan <yoyzhang>
Component: libvirtAssignee: Jiri Denemark <jdenemar>
Status: CLOSED WONTFIX QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: low    
Version: 6.1CC: ajia, chrisw, dallan, dyuan, eblake, llim, xen-maint
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: All   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-06-20 21:05:12 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description zhanghaiyan 2011-01-14 08:12:35 UTC
Description of problem:
Firstly, hot plug the VF to a guest. Then hot plug the same PF which generate the VF to guest. That causes the guest show down. and both PF and VF don't appear in guest's config file.

Version-Release number of selected component (if applicable):
- libvirt-0.8.7-1.el6.x86_64
- kernel-2.6.32-94.el6.x86_64
- qemu-kvm-0.12.1.2-2.128.el6.x86_64
Windows 2008 guest

How reproducible:
3/3

Steps to Reproduce:
# service NetworkManager stop
Stopping NetworkManager daemon:                            [  OK  ]
# getenforce 
Enforcing

1. VT-d enabled and VF is generated
# virsh nodedev-list --tree
computer
 |
  +- net_lo_00_00_00_00_00_00
  +- net_vnet0_fe_54_00_0e_b4_7b
  +- pci_0000_00_00_0
  +- pci_0000_00_01_0
  |   |
  |   +- pci_0000_03_00_0
  |   |   |
  |   |   +- net_eth0_00_1b_21_39_8b_18
  |   |     
  |   +- pci_0000_03_00_1
  |   |   |
  |   |   +- net_eth1_00_1b_21_39_8b_19
  |   |     
  |   +- pci_0000_03_10_0
  |   |   |
  |   |   +- net_eth5_76_b3_40_11_7f_3f
  |   |     
  |   +- pci_0000_03_10_1
  |       |
  |       +- net_eth7_b6_88_9e_af_00_7e
2. Confirm VF pci_0000_03_10_0 is generated from PF pci_0000_03_00_0
# virsh nodedev-dumpxml pci_0000_03_00_0
<device>
  <name>pci_0000_03_00_0</name>
  <parent>pci_0000_00_01_0</parent>
  <driver>
    <name>igb</name>
  </driver>
  <capability type='pci'>
    <domain>0</domain>
    <bus>3</bus>
    <slot>0</slot>
    <function>0</function>
    <product id='0x10c9'>82576 Gigabit Network Connection</product>
    <vendor id='0x8086'>Intel Corporation</vendor>
    <capability type='virt_functions'>
      <address domain='0x0000' bus='0x03' slot='0x10' function='0x0'/>
    </capability>
  </capability>
</device>
3. Detach VF from host
# virsh nodedev-dettach pci_0000_03_10_0
Device pci_0000_03_10_0 dettached
# virsh nodedev-reset pci_0000_03_10_0
Device pci_0000_03_10_0 reset
4.Hotplug the VF to guest
# cat VF.xml
<hostdev mode='subsystem' type='pci' managed='yes'>
     <source>
          <address bus='3' slot='0x10' function='0'/>
     </source>
</hostdev>
# virsh attach-device cdrom_test VF.xml
Device attached successfully
5. Detach PF from host
# virsh nodedev-dettach pci_0000_03_00_0
Device pci_0000_03_00_0 dettached
# virsh nodedev-reset pci_0000_03_00_0
Device pci_0000_03_00_0 reset 
6. Hotplug the PF to guest
# cat PF.xml
<hostdev mode='subsystem' type='pci' managed='yes'>
     <source>
          <address bus='3' slot='0' function='0'/>
    </source>
</hostdev>
# virsh attach-device cdrom_test nodedev.xml
Device attached successfully
7. # virsh list --all
 Id Name                 State
----------------------------------
  - cdrom_test           shut off
8. Try to reattach the PF to host
# virsh nodedev-dettach pci_0000_03_00_0
error: Failed to dettach device pci_0000_03_00_0
error: internal error Not detaching active device 0000:03:00.0

 
Actual results:
After step4, could see the VF in guest
After step6, windows guest is caused to shutdown. Both VF and PF cannot be found in guest config file. 

Expected results:
As the same VF is assigned to guest already, the PF cannot be assign to guest. So in step6, better to forbidden the operation

Additional info:

Comment 1 zhanghaiyan 2011-01-14 08:13:27 UTC
# tail -f /var/log/messages
Jan 14 15:51:07 dhcp-66-92-51 libvirtd: 15:51:07.491: 2278: info : qemudDispatchServer:1410 : Turn off polkit auth for privileged client pid 4277 from 127.0.0.1;0
Jan 14 15:51:17 dhcp-66-92-51 libvirtd: 15:51:17.982: 2278: info : qemudDispatchServer:1410 : Turn off polkit auth for privileged client pid 4378 from 127.0.0.1;0
Jan 14 15:51:36 dhcp-66-92-51 libvirtd: 15:51:36.548: 2278: info : qemudDispatchServer:1410 : Turn off polkit auth for privileged client pid 4550 from 127.0.0.1;0
Jan 14 15:51:36 dhcp-66-92-51 libvirtd: 15:51:36.743: 2281: info : qemuSecurityDACSetOwnership:40 : Setting DAC user and group on '/sys/bus/pci/devices/0000:03:00.0/resource' to '107:107'
Jan 14 15:51:36 dhcp-66-92-51 libvirtd: 15:51:36.743: 2281: info : qemuSecurityDACSetOwnership:40 : Setting DAC user and group on '/sys/bus/pci/devices/0000:03:00.0/config' to '107:107'
Jan 14 15:51:36 dhcp-66-92-51 libvirtd: 15:51:36.743: 2281: info : qemuSecurityDACSetOwnership:40 : Setting DAC user and group on '/sys/bus/pci/devices/0000:03:00.0/resource0' to '107:107'
Jan 14 15:51:36 dhcp-66-92-51 libvirtd: 15:51:36.743: 2281: info : qemuSecurityDACSetOwnership:40 : Setting DAC user and group on '/sys/bus/pci/devices/0000:03:00.0/resource1' to '107:107'
Jan 14 15:51:36 dhcp-66-92-51 libvirtd: 15:51:36.743: 2281: info : qemuSecurityDACSetOwnership:40 : Setting DAC user and group on '/sys/bus/pci/devices/0000:03:00.0/resource2' to '107:107'
Jan 14 15:51:36 dhcp-66-92-51 libvirtd: 15:51:36.743: 2281: info : qemuSecurityDACSetOwnership:40 : Setting DAC user and group on '/sys/bus/pci/devices/0000:03:00.0/resource3' to '107:107'
Jan 14 15:51:36 dhcp-66-92-51 libvirtd: 15:51:36.743: 2281: info : qemuSecurityDACSetOwnership:40 : Setting DAC user and group on '/sys/bus/pci/devices/0000:03:00.0/rom' to '107:107'
Jan 14 15:51:36 dhcp-66-92-51 libvirtd: 15:51:36.743: 2281: info : SELinuxSetFilecon:326 : Setting SELinux context on '/sys/bus/pci/devices/0000:03:00.0/resource' to 'system_u:object_r:svirt_image_t:s0:c93,c1011'
Jan 14 15:51:36 dhcp-66-92-51 libvirtd: 15:51:36.747: 2281: info : SELinuxSetFilecon:326 : Setting SELinux context on '/sys/bus/pci/devices/0000:03:00.0/config' to 'system_u:object_r:svirt_image_t:s0:c93,c1011'
Jan 14 15:51:36 dhcp-66-92-51 libvirtd: 15:51:36.747: 2281: info : SELinuxSetFilecon:326 : Setting SELinux context on '/sys/bus/pci/devices/0000:03:00.0/resource0' to 'system_u:object_r:svirt_image_t:s0:c93,c1011'
Jan 14 15:51:36 dhcp-66-92-51 libvirtd: 15:51:36.747: 2281: info : SELinuxSetFilecon:326 : Setting SELinux context on '/sys/bus/pci/devices/0000:03:00.0/resource1' to 'system_u:object_r:svirt_image_t:s0:c93,c1011'
Jan 14 15:51:36 dhcp-66-92-51 libvirtd: 15:51:36.747: 2281: info : SELinuxSetFilecon:326 : Setting SELinux context on '/sys/bus/pci/devices/0000:03:00.0/resource2' to 'system_u:object_r:svirt_image_t:s0:c93,c1011'
Jan 14 15:51:36 dhcp-66-92-51 libvirtd: 15:51:36.747: 2281: info : SELinuxSetFilecon:326 : Setting SELinux context on '/sys/bus/pci/devices/0000:03:00.0/resource3' to 'system_u:object_r:svirt_image_t:s0:c93,c1011'
Jan 14 15:51:36 dhcp-66-92-51 libvirtd: 15:51:36.747: 2281: info : SELinuxSetFilecon:326 : Setting SELinux context on '/sys/bus/pci/devices/0000:03:00.0/rom' to 'system_u:object_r:svirt_image_t:s0:c93,c1011'
Jan 14 15:51:36 dhcp-66-92-51 kernel: pci-stub 0000:03:00.0: claimed by stub
Jan 14 15:51:36 dhcp-66-92-51 kernel: pci-stub 0000:03:00.0: PCI INT A -> GSI 28 (level, low) -> IRQ 28
Jan 14 15:51:36 dhcp-66-92-51 kernel: qemu-kvm:3812 freeing invalid memtype f4020000-f4024000
Jan 14 15:51:36 dhcp-66-92-51 kernel: qemu-kvm:3812 freeing invalid memtype f4000000-f4004000
Jan 14 15:51:36 dhcp-66-92-51 kernel: pci-stub 0000:03:00.0: PCI INT A disabled
Jan 14 15:51:36 dhcp-66-92-51 kernel: Trying to free nonexistent resource <00000000f4000000-00000000f4003fff>
Jan 14 15:51:36 dhcp-66-92-51 kernel: Trying to free nonexistent resource <00000000f4020000-00000000f4023fff>
Jan 14 15:51:37 dhcp-66-92-51 libvirtd: 15:51:37.952: 2278: info : qemuSecurityDACRestoreSecurityFileLabel:80 : Restoring DAC user and group on '/sys/bus/pci/devices/0000:03:00.0/resource'
Jan 14 15:51:37 dhcp-66-92-51 libvirtd: 15:51:37.952: 2278: info : qemuSecurityDACSetOwnership:40 : Setting DAC user and group on '/sys/bus/pci/devices/0000:03:00.0/resource' to '0:0'
Jan 14 15:51:37 dhcp-66-92-51 libvirtd: 15:51:37.952: 2278: info : qemuSecurityDACRestoreSecurityFileLabel:80 : Restoring DAC user and group on '/sys/bus/pci/devices/0000:03:00.0/config'
Jan 14 15:51:37 dhcp-66-92-51 libvirtd: 15:51:37.952: 2278: info : qemuSecurityDACSetOwnership:40 : Setting DAC user and group on '/sys/bus/pci/devices/0000:03:00.0/config' to '0:0'
Jan 14 15:51:37 dhcp-66-92-51 libvirtd: 15:51:37.952: 2278: info : qemuSecurityDACRestoreSecurityFileLabel:80 : Restoring DAC user and group on '/sys/bus/pci/devices/0000:03:00.0/resource0'
Jan 14 15:51:37 dhcp-66-92-51 libvirtd: 15:51:37.952: 2278: info : qemuSecurityDACSetOwnership:40 : Setting DAC user and group on '/sys/bus/pci/devices/0000:03:00.0/resource0' to '0:0'
Jan 14 15:51:37 dhcp-66-92-51 libvirtd: 15:51:37.952: 2278: info : qemuSecurityDACRestoreSecurityFileLabel:80 : Restoring DAC user and group on '/sys/bus/pci/devices/0000:03:00.0/resource1'
Jan 14 15:51:37 dhcp-66-92-51 libvirtd: 15:51:37.952: 2278: info : qemuSecurityDACSetOwnership:40 : Setting DAC user and group on '/sys/bus/pci/devices/0000:03:00.0/resource1' to '0:0'
Jan 14 15:51:37 dhcp-66-92-51 libvirtd: 15:51:37.952: 2278: info : qemuSecurityDACRestoreSecurityFileLabel:80 : Restoring DAC user and group on '/sys/bus/pci/devices/0000:03:00.0/resource2'
Jan 14 15:51:37 dhcp-66-92-51 libvirtd: 15:51:37.952: 2278: info : qemuSecurityDACSetOwnership:40 : Setting DAC user and group on '/sys/bus/pci/devices/0000:03:00.0/resource2' to '0:0'
Jan 14 15:51:37 dhcp-66-92-51 libvirtd: 15:51:37.952: 2278: info : qemuSecurityDACRestoreSecurityFileLabel:80 : Restoring DAC user and group on '/sys/bus/pci/devices/0000:03:00.0/resource3'
Jan 14 15:51:37 dhcp-66-92-51 libvirtd: 15:51:37.952: 2278: info : qemuSecurityDACSetOwnership:40 : Setting DAC user and group on '/sys/bus/pci/devices/0000:03:00.0/resource3' to '0:0'
Jan 14 15:51:37 dhcp-66-92-51 libvirtd: 15:51:37.952: 2278: info : qemuSecurityDACRestoreSecurityFileLabel:80 : Restoring DAC user and group on '/sys/bus/pci/devices/0000:03:00.0/rom'
Jan 14 15:51:37 dhcp-66-92-51 libvirtd: 15:51:37.952: 2278: info : qemuSecurityDACSetOwnership:40 : Setting DAC user and group on '/sys/bus/pci/devices/0000:03:00.0/rom' to '0:0'
Jan 14 15:51:37 dhcp-66-92-51 libvirtd: 15:51:37.952: 2278: info : qemuSecurityDACRestoreSecurityFileLabel:80 : Restoring DAC user and group on '/var/lib/libvirt/images/cdrom_test.img'
Jan 14 15:51:37 dhcp-66-92-51 avahi-daemon[1808]: Withdrawing address record for fe80::fc54:ff:fe0e:b47b on vnet1.
Jan 14 15:51:37 dhcp-66-92-51 libvirtd: 15:51:37.953: 2278: info : qemuSecurityDACSetOwnership:40 : Setting DAC user and group on '/var/lib/libvirt/images/cdrom_test.img' to '0:0'
Jan 14 15:51:37 dhcp-66-92-51 libvirtd: 15:51:37.956: 2278: info : qemuSecurityDACRestoreSecurityFileLabel:80 : Restoring DAC user and group on '/dev/ttyS0'
Jan 14 15:51:37 dhcp-66-92-51 libvirtd: 15:51:37.956: 2278: info : qemuSecurityDACSetOwnership:40 : Setting DAC user and group on '/dev/ttyS0' to '0:0'
Jan 14 15:51:37 dhcp-66-92-51 libvirtd: 15:51:37.956: 2278: info : SELinuxRestoreSecurityFileLabel:391 : Restoring SELinux context on '/sys/bus/pci/devices/0000:03:00.0/resource'
Jan 14 15:51:37 dhcp-66-92-51 kernel: virbr0: port 2(vnet1) entering disabled state
Jan 14 15:51:37 dhcp-66-92-51 kernel: device vnet1 left promiscuous mode
Jan 14 15:51:37 dhcp-66-92-51 kernel: virbr0: port 2(vnet1) entering disabled state
Jan 14 15:51:38 dhcp-66-92-51 libvirtd: 15:51:38.037: 2278: info : SELinuxSetFilecon:326 : Setting SELinux context on '/sys/bus/pci/devices/0000:03:00.0/resource' to 'system_u:object_r:sysfs_t:s0'
Jan 14 15:51:38 dhcp-66-92-51 libvirtd: 15:51:38.037: 2278: info : SELinuxRestoreSecurityFileLabel:391 : Restoring SELinux context on '/sys/bus/pci/devices/0000:03:00.0/config'
Jan 14 15:51:38 dhcp-66-92-51 libvirtd: 15:51:38.109: 2278: info : SELinuxSetFilecon:326 : Setting SELinux context on '/sys/bus/pci/devices/0000:03:00.0/config' to 'system_u:object_r:sysfs_t:s0'
Jan 14 15:51:38 dhcp-66-92-51 libvirtd: 15:51:38.109: 2278: info : SELinuxRestoreSecurityFileLabel:391 : Restoring SELinux context on '/sys/bus/pci/devices/0000:03:00.0/resource0'
Jan 14 15:51:38 dhcp-66-92-51 libvirtd: 15:51:38.180: 2278: info : SELinuxSetFilecon:326 : Setting SELinux context on '/sys/bus/pci/devices/0000:03:00.0/resource0' to 'system_u:object_r:sysfs_t:s0'
Jan 14 15:51:38 dhcp-66-92-51 libvirtd: 15:51:38.180: 2278: info : SELinuxRestoreSecurityFileLabel:391 : Restoring SELinux context on '/sys/bus/pci/devices/0000:03:00.0/resource1'
Jan 14 15:51:38 dhcp-66-92-51 libvirtd: 15:51:38.252: 2278: info : SELinuxSetFilecon:326 : Setting SELinux context on '/sys/bus/pci/devices/0000:03:00.0/resource1' to 'system_u:object_r:sysfs_t:s0'
Jan 14 15:51:38 dhcp-66-92-51 libvirtd: 15:51:38.252: 2278: info : SELinuxRestoreSecurityFileLabel:391 : Restoring SELinux context on '/sys/bus/pci/devices/0000:03:00.0/resource2'
Jan 14 15:51:38 dhcp-66-92-51 libvirtd: 15:51:38.322: 2278: info : SELinuxSetFilecon:326 : Setting SELinux context on '/sys/bus/pci/devices/0000:03:00.0/resource2' to 'system_u:object_r:sysfs_t:s0'
Jan 14 15:51:38 dhcp-66-92-51 libvirtd: 15:51:38.323: 2278: info : SELinuxRestoreSecurityFileLabel:391 : Restoring SELinux context on '/sys/bus/pci/devices/0000:03:00.0/resource3'
Jan 14 15:51:38 dhcp-66-92-51 libvirtd: 15:51:38.393: 2278: info : SELinuxSetFilecon:326 : Setting SELinux context on '/sys/bus/pci/devices/0000:03:00.0/resource3' to 'system_u:object_r:sysfs_t:s0'
Jan 14 15:51:38 dhcp-66-92-51 libvirtd: 15:51:38.393: 2278: info : SELinuxRestoreSecurityFileLabel:391 : Restoring SELinux context on '/sys/bus/pci/devices/0000:03:00.0/rom'
Jan 14 15:51:38 dhcp-66-92-51 libvirtd: 15:51:38.464: 2278: info : SELinuxSetFilecon:326 : Setting SELinux context on '/sys/bus/pci/devices/0000:03:00.0/rom' to 'system_u:object_r:sysfs_t:s0'
Jan 14 15:51:38 dhcp-66-92-51 libvirtd: 15:51:38.464: 2278: info : SELinuxRestoreSecurityFileLabel:391 : Restoring SELinux context on '/var/lib/libvirt/images/cdrom_test.img'
Jan 14 15:51:38 dhcp-66-92-51 libvirtd: 15:51:38.540: 2278: info : SELinuxSetFilecon:326 : Setting SELinux context on '/var/lib/libvirt/images/cdrom_test.img' to 'system_u:object_r:virt_image_t:s0'
Jan 14 15:51:38 dhcp-66-92-51 libvirtd: 15:51:38.541: 2278: info : SELinuxRestoreSecurityFileLabel:391 : Restoring SELinux context on '/dev/ttyS0'
Jan 14 15:51:38 dhcp-66-92-51 libvirtd: 15:51:38.614: 2278: info : SELinuxSetFilecon:326 : Setting SELinux context on '/dev/ttyS0' to 'system_u:object_r:tty_device_t:s0'
Jan 14 15:51:38 dhcp-66-92-51 libvirtd: 15:51:38.614: 2278: error : qemuDomainReAttachHostdevDevices:250 : Failed to allocate pciDeviceList: Device 0000:03:10.0 not found: could not access /sys/bus/pci/devices/0000:03:10.0/config: No such file or directory

Comment 3 zhanghaiyan 2011-01-14 08:27:34 UTC
For rhel6 guest, the situation is even worse. After step5  try to Detach PF from host
# virsh nodedev-dettach pci_0000_03_00_0

The host is caused to reboot.

Comment 4 Dave Allan 2011-01-14 22:28:34 UTC
I spoke with cdub on IRC about this behavior, and he agrees with the description:

Expected results:
As the same VF is assigned to guest already, the PF cannot be assign to guest.
So in step6, better to forbidden the operation

Detecting that the VF is already assigned to the guest is the question.

Comment 5 zhanghaiyan 2011-01-19 07:41:52 UTC
Per comment 3, detach PF from host when the same VF is already assigned to RHEL guest will cause host reboot. So I guess maybe should forbidden from the earlier step 5 ?

Comment 7 Chris Wright 2011-03-31 16:22:31 UTC
(In reply to comment #4)
> I spoke with cdub on IRC about this behavior, and he agrees with the
> description:
> 
> Expected results:
> As the same VF is assigned to guest already, the PF cannot be assign to guest.
> So in step6, better to forbidden the operation
> 
> Detecting that the VF is already assigned to the guest is the question.

Yes, that's correct.  There should be enough knowledge there (PF <-> VF relationships and devices assigned to guests) to disallow that.

(In reply to comment #5)
> Per comment 3, detach PF from host when the same VF is already assigned to RHEL
> guest will cause host reboot. So I guess maybe should forbidden from the
> earlier step 5 ?

Yes.  The act of detaching the PF from the host will typically destroy all the associated VFs.