RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1225339 - Libvirt should check if hostdev address matching with device type
Summary: Libvirt should check if hostdev address matching with device type
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt
Version: 7.2
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: rc
: ---
Assignee: Ján Tomko
QA Contact: jiyan
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-05-27 07:25 UTC by Pei Zhang
Modified: 2018-04-10 10:35 UTC (History)
7 users (show)

Fixed In Version: libvirt-3.7.0-1.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-04-10 10:33:22 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHEA-2018:0704 0 None None None 2018-04-10 10:35:51 UTC

Description Pei Zhang 2015-05-27 07:25:02 UTC
Description of problem:
For assigning a host device to guest , libvirt should check that the hostdev address is matched with device type .  

Version-Release number of selected component (if applicable):

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

How reproducible:
100%

Steps to Reproduce:

1. test with host USB device

1.1 start guest with host USB device with address type is pci ,guest fail to start
# virsh dumpxml r7.2 | 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

1.2 start a healthy guest , attach a usb device with address type is PCI
#virsh start r7.2
Domain r7.2 started

#cat host.xml
<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'/>
    </hostdev>

# virsh attach-device r7.2 host.xml
error: Failed to attach device from host.xml
error: internal error: unable to execute QEMU command 'device_add': Device 'usb-host' can't go on a PCI bus

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 .

2.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.2 start guest , guest start successfully .
#virsh start r7.2
Domain r7.2 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>

2.3 start host scsi device with usb address
# virsh dumpxml r7.2 |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>
      <address type='usb' bus='0' port='1'/> <==== type is usb
    </hostdev>

#virsh start r7.2
error: Failed to start domain r7.2
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


Actual results:
As step 1 and step 2 , configuration with wrong hostdev address , fail to start guest , fail to attach device .

Expected results:
Libvirt should check invalid configure guest xml like above and report clear error message .


Additional info:

As talked with my colleague ,we thought that libvirt should do some limits/checking for usb and scsi hostdev before passing command lines to qemu-kvm.

For example:

for a usb type host dev should only permit VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB type;
for a scsi type host dev should only permit VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE type.

or just like pci type of hostdev in virDomainHostdevDefParseXML:
...
    if (def->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
        switch (def->source.subsys.type) {
        case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
            if (def->inftype != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
                def->inftype != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                               _("PCI host devices must use 'pci' address type"));
                goto error;
            }
            break;
...

Comment 2 Ján Tomko 2015-06-17 16:03:01 UTC
Upstream patch:
https://www.redhat.com/archives/libvir-list/2015-June/msg00887.html

Comment 4 Ján Tomko 2017-08-23 14:40:27 UTC
Proposed upstream patch:
https://www.redhat.com/archives/libvir-list/2017-August/msg00649.html

Comment 5 Ján Tomko 2017-08-24 07:48:33 UTC
Pushed as:
commit 126e6f381a5429b27aac008c4873f101116da95d
Author:     Ján Tomko <jtomko>
CommitDate: 2017-08-24 09:28:53 +0200

    conf: check address type for USB hostdevs
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1225339

git describe: v3.6.0-195-g126e6f381

Comment 7 jiyan 2017-10-24 03:02:34 UTC
Test env components:
qemu-kvm-rhev-2.10.0-3.el7.x86_64
kernel-3.10.0-742.el7.x86_64
libvirt-3.8.0-1.el7.x86_64

Test Scenario:
The following scenarios are tested for SCSI hostdev, <hostdev mode='subsystem' type='scsi'>
Scenario-1: Edit / Start VM with valid or invalid address for scsi hostdev
1.1 Edit VM by adding the following 'pci address' hostdev info and try to save it, reasonable error info raises.
# virsh edit pc
    ...
    <hostdev mode='subsystem' type='scsi' managed='no'>
      <source protocol='iscsi' name='iqn.2003-01.org.linux-iscsi.10.x8664:sn.757c5523fee3/0'>
        <host name='10.66.4.235' port='3260'/>
      </source>
      <alias name='hostdev0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </hostdev>
   ...
error: XML error: SCSI host device must use 'drive' address type
Failed. Try again? [y,n,i,f,?]: 

1.2 Edit VM by adding the following 'usb address' hostdev info and try to save it, reasonable error info raises.
# virsh edit pc
    ...
    <hostdev mode='subsystem' type='scsi' managed='no'>
      <source protocol='iscsi' name='iqn.2003-01.org.linux-iscsi.10.x8664:sn.757c5523fee3/0'>
        <host name='10.66.4.235' port='3260'/>
      </source>
      <alias name='hostdev0'/>
      <address type='usb' bus='0' port='1'/>
    </hostdev>
    ...
error: XML error: SCSI host device must use 'drive' address type
Failed. Try again? [y,n,i,f,?]: 

1.3 Edit VM by adding the following 'drive address' hostdev info and try to save it, save the dumpxml file and start VM successfully
# virsh edit pc
    ...
    <hostdev mode='subsystem' type='scsi' managed='no'>
      <source protocol='iscsi' name='iqn.2003-01.org.linux-iscsi.10.x8664:sn.757c5523fee3/0'>
        <host name='10.66.4.235' port='3260'/>
      </source>
      <alias name='hostdev0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </hostdev>
    ...
Domain pc XML configuration edited.

# virsh start pc
Domain pc started

# virsh dumpxml pc |grep hostdev -A7
    <hostdev mode='subsystem' type='scsi' managed='no'>
      <source protocol='iscsi' name='iqn.2003-01.org.linux-iscsi.10.x8664:sn.757c5523fee3/0'>
        <host name='10.66.4.235' port='3260'/>
      </source>
      <alias name='hostdev0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </hostdev>

# ps -ef |grep pc |sed 's/-drive/\n-drive/g'
-drive file=iscsi://10.66.4.235:3260/iqn.2003-01.org.linux-iscsi.10.x8664%3Asn.757c5523fee3/0,if=none,format=raw,id=drive-hostdev0 

1.4 Edit VM by adding the following 'none address' hostdev info and try to save it, save the dumpxml file and start VM successfully
# virsh edit pc
    ...
    <hostdev mode='subsystem' type='scsi' managed='no'>
      <source protocol='iscsi' name='iqn.2003-01.org.linux-iscsi.10.x8664:sn.757c5523fee3/0'>
        <host name='10.66.4.235' port='3260'/>
      </source>
    </hostdev>
    ...
Domain pc XML configuration edited.

# virsh start pc
Domain pc started

# virsh dumpxml pc |grep hostdev -A7
    <hostdev mode='subsystem' type='scsi' managed='no'>
      <source protocol='iscsi' name='iqn.2003-01.org.linux-iscsi.10.x8664:sn.757c5523fee3/0'>
        <host name='10.66.4.235' port='3260'/>
      </source>
      <alias name='hostdev0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </hostdev>

# ps -ef |grep pc |sed 's/-drive/\n-drive/g'
-drive file=iscsi://10.66.4.235:3260/iqn.2003-01.org.linux-iscsi.10.x8664%3Asn.757c5523fee3/0,if=none,format=raw,id=drive-hostdev0 

Scenario-2: Hot-plug scsi hostdev with valid or invalid address to VM
2.1 Hot-plug scsi hostdev with  'pci address'  to VM, reasonable error info raises
# virsh list --all |grep pc
 31    pc                             running

# cat hostdev.xml 
    <hostdev mode='subsystem' type='scsi' managed='no'>
      <source protocol='iscsi' name='iqn.2003-01.org.linux-iscsi.10.x8664:sn.757c5523fee3/0'>
        <host name='10.66.4.235' port='3260'/>
      </source>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </hostdev>

# virsh attach-device pc hostdev.xml 
error: Failed to attach device from hostdev.xml
error: XML error: SCSI host device must use 'drive' address type

2.2 Hot-plug scsi hostdev with  'usb address'  to VM, reasonable error info raises
# virsh list --all |grep pc
 31    pc                             running

# cat hostdev.xml 
    <hostdev mode='subsystem' type='scsi' managed='no'>
      <source protocol='iscsi' name='iqn.2003-01.org.linux-iscsi.10.x8664:sn.757c5523fee3/0'>
        <host name='10.66.4.235' port='3260'/>
      </source>
      <alias name='hostdev0'/>
      <address type='usb' bus='0' port='1'/>
    </hostdev>

# virsh attach-device pc hostdev.xml 
error: Failed to attach device from hostdev.xml
error: XML error: SCSI host device must use 'drive' address type

2.3 Hot-plug scsi hostdev with  'drive address'  to VM successfully
# virsh list --all |grep pc
 31    pc                             running

# cat hostdev.xml 
    <hostdev mode='subsystem' type='scsi' managed='no'>
      <source protocol='iscsi' name='iqn.2003-01.org.linux-iscsi.10.x8664:sn.757c5523fee3/0'>
        <host name='10.66.4.235' port='3260'/>
      </source>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </hostdev>

# virsh attach-device pc hostdev.xml 
Device attached successfully

# virsh dumpxml pc |grep hostdev -A7
    <hostdev mode='subsystem' type='scsi' managed='no'>
      <source protocol='iscsi' name='iqn.2003-01.org.linux-iscsi.10.x8664:sn.757c5523fee3/0'>
        <host name='10.66.4.235' port='3260'/>
      </source>
      <alias name='hostdev0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </hostdev>

2.4 Hot-plug scsi hostdev with  'none address'  to VM successfully
# virsh list --all |grep pc
 31    pc                             running

# cat hostdev.xml 
    <hostdev mode='subsystem' type='scsi' managed='no'>
      <source protocol='iscsi' name='iqn.2003-01.org.linux-iscsi.10.x8664:sn.757c5523fee3/0'>
        <host name='10.66.4.235' port='3260'/>
      </source>
    </hostdev>

# virsh attach-device pc hostdev.xml 
Device attached successfully

# virsh dumpxml pc |grep hostdev -A7
    <hostdev mode='subsystem' type='scsi' managed='no'>
      <source protocol='iscsi' name='iqn.2003-01.org.linux-iscsi.10.x8664:sn.757c5523fee3/0'>
        <host name='10.66.4.235' port='3260'/>
      </source>
      <alias name='hostdev0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </hostdev>

All the results are as expected, move this bug to be verified.

Comment 8 jiyan 2017-10-24 05:32:15 UTC
Hi Ján, I met another problem about hostdev address when verifying the bug, could you please help to check whether it is a bug? Thank you in advance.

Description about the problem:
After hot-plugging scsi hostdev to VM through xml file without address, hot-unplugging the scsi hostdev from VM through xml file with illegal address can also succeed.

Steps to reproduce the problem:
1. Prepare a running VM
# virsh list --all |grep pc
 32    pc                             running

2. Hot-plug scsi hostdev to VM through xml file without address
# cat hostdev_none.xml 
    <hostdev mode='subsystem' type='scsi' managed='no'>
      <source protocol='iscsi' name='iqn.2003-01.org.linux-iscsi.10.x8664:sn.757c5523fee3/0'>
        <host name='10.66.4.235' port='3260'/>
      </source>
      <alias name='hostdev0'/>
    </hostdev>

# virsh attach-device pc hostdev_none.xml 
Device attached successfully

# virsh dumpxml pc |grep hostdev -A4
    <hostdev mode='subsystem' type='scsi' managed='no'>
      <source protocol='iscsi' name='iqn.2003-01.org.linux-iscsi.10.x8664:sn.757c5523fee3/0'>
        <host name='10.66.4.235' port='3260'/>
      </source>
      <alias name='hostdev0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </hostdev>

3. Hot-unplug the scsi hostdev from VM through xml file with pci address
# cat hostdev_pci.xml 
    <hostdev mode='subsystem' type='scsi' managed='no'>
      <source protocol='iscsi' name='iqn.2003-01.org.linux-iscsi.10.x8664:sn.757c5523fee3/0'>
        <host name='10.66.4.235' port='3260'/>
      </source>
      <alias name='hostdev0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </hostdev>

# virsh detach-device pc hostdev_pci.xml 
Device detached successfully

# virsh dumpxml pc |grep hostdev -A4
No input

Comment 9 Ján Tomko 2017-10-26 07:46:29 UTC
Device detach is very forgiving when matching the devices. If you specify device XML that differs only in some attributes or is too broad, libvirt still might find a device to detach. This vagueness is even documented in the virDomainDetachDeviceFlags API description:
https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainDetachDeviceFlags

Comment 13 errata-xmlrpc 2018-04-10 10:33:22 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://access.redhat.com/errata/RHEA-2018:0704


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