Bug 870003

Summary: libvirt should forbid deleting usb controller when guest with smartcard
Product: Red Hat Enterprise Linux 6 Reporter: hongming <honzhang>
Component: libvirtAssignee: Michal Privoznik <mprivozn>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.4CC: acathrow, ajia, dallan, dyuan, eblake, jdenemar, jiahu, lnovich, mzhan, weizhan, zpeng
Target Milestone: rcKeywords: Upstream
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-0.10.2-19.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-11-21 08:34:09 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:
Bug Depends On:    
Bug Blocks: 958929    

Description hongming 2012-10-25 10:33:26 UTC
Description of problem:
When guest with smardcard device , delete the usb controller (The usb controller actually can't be deleted) and start guest . The following error occurs
error: Failed to start domain rhel6.3-new-test
error: internal error process exited while connecting to monitor: qemu-kvm: -device usb-ccid,id=ccid0: No 'USB' bus found for device 'usb-ccid' 

Version-Release number of selected component (if applicable):
libvirt-0.10.2-4.el6.x86_64
qemu-kvm-0.12.1.2-2.329.el6.x86_64


How reproducible:
100% 

Steps to Reproduce:
1. Use virt-manager to delete the usb controller from guest with smardcard. Or use virsh edit command.

# virsh edit rhel6.3 (Delete the following part and save)

<controller type='usb' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>

Domain rhel6.3 XML configuration not changed.


2. # virsh start rhel6.3-new-test
error: Failed to start domain rhel6.3-new-test
error: internal error process exited while connecting to monitor: qemu-kvm: -device usb-ccid,id=ccid0: No 'USB' bus found for device 'usb-ccid'

Actual results:
libvirt should forbid deleting usb controller when guest with smardcard 

Expected results:
It works fine 

Additional info:

Comment 2 Eric Blake 2012-10-25 12:40:27 UTC
Indeed - when smartcard was first added, -usb was unconditionally added; and when we changed the code to allow -usb to be omitted, we forgot to account for the impact it would have to smartcard that requires -usb.

Comment 3 Jiri Denemark 2012-10-25 17:31:24 UTC
I don't think this is quite right. USB controller is supposed to always be there, unless the XMl explicitly says <controller type='usb' model='none'/>. However, we should of course forbid such configuration. That said, if the code worked in the way it was designed, just removing the controller element should have no effect.

Comment 4 dyuan 2012-11-01 02:25:51 UTC
Another scenario 
1. remove the usb controller from the running guest with smartcard
2. managed save the guest
3. can't start the guest unless remove the managedsave file manually and ccid controller.

Comment 5 Michal Privoznik 2012-11-01 14:26:30 UTC
Patch proposed upstream:

https://www.redhat.com/archives/libvir-list/2012-November/msg00049.html

Comment 6 Michal Privoznik 2012-11-05 16:15:08 UTC
Another try:

https://www.redhat.com/archives/libvir-list/2012-November/msg00217.html

Comment 7 Michal Privoznik 2012-11-06 15:43:13 UTC
Moving to POST:

commit a95c9406a29aaba8fe21c4dca512dbc65942a29b
Author:     Michal Privoznik <mprivozn>
AuthorDate: Mon Nov 5 12:12:04 2012 +0100
Commit:     Michal Privoznik <mprivozn>
CommitDate: Tue Nov 6 10:11:35 2012 +0100

    tests: Add test for controller order

commit 0f720ab35a1a836aa23b66ef4bafbc5e57290357
Author:     Michal Privoznik <mprivozn>
AuthorDate: Mon Nov 5 11:51:44 2012 +0100
Commit:     Michal Privoznik <mprivozn>
CommitDate: Tue Nov 6 10:11:34 2012 +0100

    qemu: Add controllers in specified order
    
    qemu is sensitive to the order of arguments passed. Hence, if a
    device requires a controller, the controller cmd string must
    precede device cmd string. The same apply for controllers, when
    for instance ccid controller requires usb controller. So
    controllers create partial ordering in which they should be added
    to qemu cmd line.

commit 77b93dbc3e5fdffec60f631cd52c4dba0f2e0f29
Author:     Michal Privoznik <mprivozn>
AuthorDate: Mon Nov 5 11:42:51 2012 +0100
Commit:     Michal Privoznik <mprivozn>
CommitDate: Tue Nov 6 10:11:34 2012 +0100

    qemu: Wrap controllers code into dummy loop
    
    which just re-indent code and prepare it for next patch.


v1.0.0-36-ga95c940

Comment 17 Hu Jianwei 2013-07-09 08:35:23 UTC
This bug reproduced on libvirt-0.10.2-18.el6_4.9.x86_64 version, not reproduce on libvirt-0.10.2-19.el6.x86_64 version.


1. Added below xml to guest.
   <controller type='ccid' index='0'/>
    <smartcard mode='passthrough' type='spicevmc'>
      <address type='ccid' controller='0' slot='0'/>
    </smartcard>

2. start guest with old libvirt version after removing the usb controller.
[root@test1 ~]# rpm -q libvirt
libvirt-0.10.2-18.el6_4.9.x86_64
[root@test1 ~]# virsh start rhel6
error: Failed to start domain rhel6
error: internal error process exited while connecting to monitor: qemu-kvm: -device usb-ccid,id=ccid0: No 'USB' bus found for device 'usb-ccid'

3. start guest with the fixed libvirt version(libvirt-0.10.2-19.el6.x86_64) after removing the usb controller.
[root@test1 libvirt-0.10.2-19.el6]# virsh edit rhel6
Domain rhel6 XML configuration edited.

[root@test1 libvirt-0.10.2-19.el6]# virsh start rhel6
Domain rhel6 started

[root@test1 libvirt-0.10.2-19.el6]# virsh dumpxml rhel6 | grep -A5 usb
    <controller type='usb' index='0'>
      <alias name='usb0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
    <controller type='ccid' index='0'>
      <alias name='ccid0'/>
    </controller>

We can get the expected result, the guest can start, changed to verified.

Comment 18 Hu Jianwei 2013-07-29 06:56:45 UTC
Tested this bug on another scenario in comment 4.
https://bugzilla.redhat.com/show_bug.cgi?id=870003#c4
Another scenario 
1. remove the usb controller from the running guest with smartcard
2. managed save the guest
3. can't start the guest unless remove the managedsave file manually and ccid controller.

This scenario can reproduced on libvirt-0.10.2-18.el6_4.9.x86_64 version, not reproduce on libvirt-0.10.2-19.el6.x86_64 and the latest version libvirt-0.10.2-21.el6.

1. Removed usb controller from the running guest with smartcard.
virsh # edit r6
Domain r6 XML configuration edited.

2. Managed save the guest r6.
virsh # managedsave r6

Domain r6 state saved by libvirt

3. Start the guest. 
virsh # start r6
Domain r6 started

BR,
Jianwei

Comment 20 errata-xmlrpc 2013-11-21 08:34:09 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.

http://rhn.redhat.com/errata/RHBA-2013-1581.html