Bug 1225339
| Summary: | Libvirt should check if hostdev address matching with device type | ||
|---|---|---|---|
| Product: | Red Hat Enterprise Linux 7 | Reporter: | Pei Zhang <pzhang> |
| Component: | libvirt | Assignee: | Ján Tomko <jtomko> |
| Status: | CLOSED ERRATA | QA Contact: | jiyan <jiyan> |
| Severity: | medium | Docs Contact: | |
| Priority: | medium | ||
| Version: | 7.2 | CC: | dyuan, jiyan, jtomko, mzhan, rbalakri, xuzhang, yalzhang |
| Target Milestone: | rc | ||
| Target Release: | --- | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| Whiteboard: | |||
| Fixed In Version: | libvirt-3.7.0-1.el7 | Doc Type: | If docs needed, set a value |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2018-04-10 10:33:22 UTC | Type: | Bug |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
| Embargoed: | |||
Proposed upstream patch: https://www.redhat.com/archives/libvir-list/2017-August/msg00649.html 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
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.
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
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 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 |
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; ...