Bug 1043436 - Refuse to start a domain with a USB disk attached to a PCI bus
Summary: Refuse to start a domain with a USB disk attached to a PCI bus
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt
Version: 7.0
Hardware: x86_64
OS: Linux
medium
low
Target Milestone: rc
: ---
Assignee: Jiri Denemark
QA Contact: Virtualization Bugs
URL:
Whiteboard:
Depends On: 1043374
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-12-16 10:18 UTC by Jiri Denemark
Modified: 2015-11-19 05:44 UTC (History)
7 users (show)

Fixed In Version: libvirt-1.2.15-1.el7
Doc Type: Bug Fix
Doc Text:
Clone Of: 1043374
Environment:
Last Closed: 2015-11-19 05:44:26 UTC
Target Upstream Version:
pzhang: needinfo-


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2015:2202 0 normal SHIPPED_LIVE libvirt bug fix and enhancement update 2015-11-19 08:17:58 UTC

Description Jiri Denemark 2013-12-16 10:18:39 UTC
+++ This bug was initially created as a clone of Bug #1043374 +++

Description of problem:
Libvirt should check unnecessary pci-address for usb type disk before starting domain

Version-Release number of selected component (if applicable):
libvirt-0.10.2-29.el6.x86_64
qemu-kvm-0.12.1.2-2.398.el6.x86_64
kernel-2.6.32-412.el6.x86_64

How reproducible:
100%

Steps to Reproduce:
1. Edit domain and add a unavailable pci address to usb disk
   <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/usb-img/usb.img'/>
      <target dev='sdd' bus='usb'/>
      <alias name='usb-disk3'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </disk>

2. Dump domain xml
[root@test777 ~]# virsh dumpxml r6
...
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/usb-img/usb.img'/>
      <target dev='sdd' bus='usb'/>
      <alias name='usb-disk3'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </disk>
...

3. Start domain
[root@test777 ~]# virsh start r6
Domain r6 started

[root@test777 ~]# virsh dumpxml r6
...
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/usb-img/usb.img'/>
      <target dev='sdd' bus='usb'/>
      <alias name='usb-disk3'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </disk>
...

Actual results:
See above steps.

Expected results:
Libvirt should fail to start domain when we configure some wrong elements for usb disk. The expected results should be same as below:

Need give error info like bus='ide' or bus='scsi':
# virsh start rhel6u2
error: Failed to start domain rhel6u2
error: internal error unexpected address type for ide disk

# virsh start rhel6u2
error: Failed to start domain rhel6u2
error: internal error unexpected address type for scsi disk


Additional info:
On rhel7 host, I can not reproduce it.

Version:
libvirt-1.1.1-13.el7.x86_64
qemu-kvm-1.5.3-19.el7.x86_64
kernel-3.10.0-54.el7.x86_64

[root@ibm-x3850x5-07 216365]# virsh dumpxml r7
...
<disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/usb-img/usb-a-a.img'/>
      <target dev='sdd' bus='usb'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x0e' function='0x0'/>
    </disk>
...

[root@ibm-x3850x5-07 216365]# virsh start r7
error: Failed to start domain r7
error: internal error: early end of file from monitor: possible problem:
qemu-kvm: -device usb-storage,bus=pci.0,addr=0xe,drive=drive-usb-disk3,id=usb-disk3: Device 'usb-storage' can't go on a PCI bus

While the domain failed to start on RHEL7, libvirt still doesn't do a good job and tries to actually start the domain with a USB disk attached to a PCI bus.

Comment 3 Jiri Denemark 2015-04-30 12:21:15 UTC
Patch sent upstream for review: https://www.redhat.com/archives/libvir-list/2015-April/msg01549.html

Comment 4 Jiri Denemark 2015-04-30 13:38:53 UTC
Pushed upstream as v1.2.15-rc1-32-g6280294:

commit 6280294574473760b585ed2298e9512499ad7816
Author: Jiri Denemark <jdenemar@redhat.com>
Date:   Thu Apr 30 14:16:40 2015 +0200

    qemu: Check address type for USB disks
    
    Only USB addresses are allowed for USB disks. Report an error if another
    address is configured.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1043436
    
    Signed-off-by: Jiri Denemark <jdenemar@redhat.com>

Comment 6 Pei Zhang 2015-05-22 09:18:40 UTC
I can reproduce it on libvirt-0.10.2-29.el6.x86_64 .

verify version:
libvirt-1.2.15-2.el7.x86_64
qemu-kvm-rhev-2.3.0-1.el7.x86_64
kernel-3.10.0-234.el7.x86_64

steps:
1.start a guest with a usb disk without address , guest xml like following :
<disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/qcow2.img'/>
      <target dev='sde' bus='usb'/>
    </disk>
Domain r7.2-new started

2.destroy guest and edit guest xml set usb disk with a PCI address 
#virsh edit r7.2-new
<disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/qcow2.img'/>
      <target dev='sde' bus='usb'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </disk>

then start guest 
#virsh start r7.2-new
error: Failed to start domain r7.2-new
error: internal error: unexpected address type for usb disk

3.destroy guest and edit guest xml set usb disk with address which type is drive
#virsh edit r7.2-new
 <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/qcow2.img'/>
      <target dev='sde' bus='usb'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>

#virsh start r7.2-new
error: Failed to start domain r7.2-new
error: internal error: unexpected address type for usb disk

4.destroy guest and edit guest xml set a usb disk with USB address
#virsh start r7.2-new
Domain r7.2-new started

#virsh dumpxml r7.2-new | grep disk -A 9
<disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/qcow2.img'/>
      <backingStore/>
      <target dev='sde' bus='usb'/>
      <alias name='usb-disk4'/>
      <address type='usb' bus='0' port='2'/>
    </disk>

Now , libvirt refuse to start a domain with a USB disk configured with non USB addresses .

Comment 7 Pei Zhang 2015-05-22 10:36:29 UTC
Hi ,
Jiri . 
I also tested this scenario with host device . and  I have found two issues during my testing . I wonder these can be modified in this patch or should open new bug to trace them .
Thanks in advance !

issue 1 : test with host USB device

problem : Start a guest with a host USB device which address is PCI , guest fail to start , but If it's better that libvirt forbid configure guest xml like this and no need to try to actually to start it .

1.start guest with host USB device with address type is pci
# virsh dumpxml r7.2-new | grep hostdev -A 9
 <hostdev mode='subsystem' type='usb' managed='no'>
      <source>
        <vendor id='0x0781'/>
        <product id='0x5567'/>
      </source>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/>   <==== type is PCI
    </hostdev>

#virsh start testvm
error: Failed to start domain testvm
error: internal error: process exited while connecting to monitor: 2015-05-22T05:23:29.677447Z qemu-kvm: -device usb-host,hostbus=2,hostaddr=6,id=hostdev0,bus=pci.0,addr=0xa: Device 'usb-host' can't go on a PCI bus



issue 2 : test with host scsi device
problem : For host scsi device , libvirt should also check if address configuration is valid. Start guest with host scsi device with address type is PCI , guest start successfully . Start guest with host scsi device with address type is usb , output  unfriendly error message . 

1.start guest with host scsi device with address type is pci

# virsh dumpxml testvm | grep hostdev -A 9
<hostdev mode='subsystem' type='scsi' managed='no'>
      <source protocol='iscsi' name='iqn.2008-09.5.165.3ffe.104:server.target2/1'>
        <host name='$IP' port='3260'/>
      </source>
      <alias name='hostdev1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>   <=== type is PCI
    </hostdev>

2.start guest , guest start successfully .
#virsh start r7.2-new
Domain r7.2-new started

# virsh dumpxml testvm | grep hostdev -A 9
<hostdev mode='subsystem' type='scsi' managed='no'>
      <source protocol='iscsi' name='iqn.2008-09.5.165.3ffe.104:server.target2/1'>
        <host name='$IP' port='3260'/>
      </source>
      <alias name='hostdev1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>   <=== type is PCI
    </hostdev>

3.start host scsi device with usb address
# virsh dumpxml r7.2-new |grep hostdev -A 9
    <hostdev mode='subsystem' type='scsi' managed='no'>
      <source protocol='iscsi' name='iqn.2008-09.5.165.3ffe.104:server.target2/1'>
        <host name='10.66.5.165' port='3260'/>
      </source>
      <address type='usb' bus='0' port='1'/> <==== type is usb
    </hostdev>

#virsh start r7.2-new
error: Failed to start domain r7.2-new
error: internal error: process exited while connecting to monitor: 2015-05-22T08:28:46.464675Z qemu-kvm: -device scsi-generic,bus=scsi0.0,channel=0,scsi-id=-1878988912,lun=32700,drive=usb-hostdev0,id=hostdev0: Parameter 'scsi-id' expects uint32_t

4.start a guest with host sscsi device and without address element , it will generated a address which type is 'drive'

<hostdev mode='subsystem' type='scsi' managed='no'>
      <source protocol='iscsi' name='iqn.2008-09.5.165.3ffe.104:server.target2/1'>
        <host name='10.66.5.165' port='3260'/>
      </source>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </hostdev>


5.start scsi disk with pci address 

 <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/qcow2.img'/>
      <target dev='sde' bus='scsi'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/>
    </disk>

#virsh start r7.2-new
error: Failed to start domain testvm
error: internal error: unexpected address type for scsi disk

Comment 8 Pei Zhang 2015-05-27 07:33:28 UTC
As talked with my colleague , fill a bug to track issue in comment 7 
https://bugzilla.redhat.com/show_bug.cgi?id=1225339

and according to comment 6 , move this bug to verified .

Comment 10 errata-xmlrpc 2015-11-19 05:44:26 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2015-2202.html


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