Bug 1261726

Summary: virsh hotplug/unplug host usb device disconnects spice
Product: Red Hat Enterprise Linux 7 Reporter: Xiaoqing Wei <xwei>
Component: qemu-kvm-rhevAssignee: Gerd Hoffmann <kraxel>
Status: CLOSED ERRATA QA Contact: Xujun Ma <xuma>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.2CC: chayang, huding, juzhang, knoel, michen, mrezanin, virt-bugs, virt-maint, weliao, yiwei
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Unspecified   
Whiteboard:
Fixed In Version: qemu-2.6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-11-07 20:37: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:

Description Xiaoqing Wei 2015-09-10 04:35:51 UTC
Description of problem:
virsh hotplug/unplug host usb device disconnects spice

Version-Release number of selected component (if applicable):
host:
kernel-3.10.0-314.el7.x86_64
qemu-kvm-rhev-2.3.0-22.el7.x86_64
spice-server-0.12.4-13.el7.x86_64
guest:
Windows 10 x86_64

How reproducible:
4/4

Steps to Reproduce:
1. boot a guest, with usb passthru from host, and usb-redir.

guest xml to be pasted in separated comment later.


/usr/libexec/qemu-kvm -name win10 -S -machine pc-i440fx-rhel7.2.0,accel=kvm,usb=off,vmport=off -cpu SandyBridge,hv_time,hv_relaxed,hv_vapic,hv_spinlocks=0x1fff -m 4096 -realtime mlock=off -smp 2,sockets=2,cores=1,threads=1 -uuid 6cb8fd4f-22b5-478e-9929-e417679bb1ad -no-user-config -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/win10.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=localtime,driftfix=slew -global kvm-pit.lost_tick_policy=discard -no-hpet -no-shutdown -global PIIX4_PM.disable_s3=1 -global PIIX4_PM.disable_s4=1 -boot strict=on \
\
\
\
-device nec-usb-xhci,id=usb,bus=pci.0,addr=0x6 \
\
\
-device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x5 -drive file=/home/win10.qcow2,if=none,id=drive-virtio-disk0,format=qcow2,cache=none,aio=native -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x7,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -drive file=/home/kvm_autotest_root/images/win8.1-64/autounattend.iso,if=none,id=drive-ide0-0-0,readonly=on,format=raw,cache=none -device ide-cd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 -netdev tap,fd=23,id=hostnet0,vhost=on,vhostfd=24 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:fa:f0:a7,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -chardev spicevmc,id=charchannel0,name=vdagent -device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=com.redhat.spice.0 -device usb-tablet,id=input0 -spice port=5907,addr=0.0.0.0,disable-ticketing,image-compression=off,seamless-migration=on -device qxl-vga,id=video0,ram_size=67108864,vram_size=67108864,vgamem_mb=16,bus=pci.0,addr=0x2 -device intel-hda,id=sound0,bus=pci.0,addr=0x4 -device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 \
\
\
-chardev spicevmc,id=charredir0,name=usbredir -device usb-redir,chardev=charredir0,id=redir0 -chardev spicevmc,id=charredir1,name=usbredir -device usb-redir,chardev=charredir1,id=redir1 \
\
\
-device usb-host,hostbus=1,hostaddr=5,id=hostdev0 \
\
\
\
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x8 -msg timestamp=on
2. remote-viewer spice://hostname:port


3. # cat hostdev.xml 
    <hostdev mode='subsystem' type='usb' managed='yes'>
      <source>
        <vendor id='0x0c76'/>
        <product id='0x160c'/>
      </source>
    </hostdev>

virsh detach-device win10 hostdev.xml


Actual results:
remote-viewer lost connection

Expected results:

spice connection should not lost
Additional info:

hot plug the device back would lead same disconnection
virsh attach-device win10 hostdev.xml

Comment 1 Xiaoqing Wei 2015-09-10 04:39:56 UTC
spice client debug log.


cat /home/spicelog 
[root@dhcp-9-122 ~]# remote-viewer spice://10.66.11.75:5906 --debug
(remote-viewer:1727): remote-viewer-DEBUG: No configuration file /root/.config/virt-viewer/settings
(remote-viewer:1727): remote-viewer-DEBUG: Opening display to spice://10.66.11.75:5906
(remote-viewer:1727): remote-viewer-DEBUG: Guest (null) has a spice display
(remote-viewer:1727): remote-viewer-DEBUG: After open connection callback fd=-1
(remote-viewer:1727): remote-viewer-DEBUG: Opening connection to display at spice://10.66.11.75:5906
(remote-viewer:1727): remote-viewer-DEBUG: New spice channel 0x3102520 SpiceMainChannel 0
(remote-viewer:1727): remote-viewer-DEBUG: notebook show status 0x3064280
(remote-viewer:1727): remote-viewer-DEBUG: main channel: opened
(remote-viewer:1727): remote-viewer-DEBUG: notebook show status 0x3064280
(remote-viewer:1727): remote-viewer-DEBUG: virt_viewer_app_set_uuid_string: UUID changed to 6cb8fd4f-22b5-478e-9929-e417679bb1ad
(remote-viewer:1727): remote-viewer-DEBUG: No guest-specific fullscreen config, using fallback
(remote-viewer:1727): remote-viewer-DEBUG: app is not in full screen
(remote-viewer:1727): remote-viewer-DEBUG: virt_viewer_app_set_uuid_string: UUID changed to 6cb8fd4f-22b5-478e-9929-e417679bb1ad
(remote-viewer:1727): remote-viewer-DEBUG: No guest-specific fullscreen config, using fallback
(remote-viewer:1727): remote-viewer-DEBUG: app is not in full screen
(remote-viewer:1727): remote-viewer-DEBUG: New spice channel 0x3234130 SpiceUsbredirChannel 1
(remote-viewer:1727): remote-viewer-DEBUG: new usbredir channel
(remote-viewer:1727): remote-viewer-DEBUG: New spice channel 0x323db70 SpiceUsbredirChannel 0
(remote-viewer:1727): remote-viewer-DEBUG: new usbredir channel
(remote-viewer:1727): remote-viewer-DEBUG: New spice channel 0x3240570 SpiceRecordChannel 0
(remote-viewer:1727): remote-viewer-DEBUG: New spice channel 0x3241960 SpicePlaybackChannel 0
(remote-viewer:1727): remote-viewer-DEBUG: new audio channel

(remote-viewer:1727): GSpice-WARNING **: PulseAudio context failed Connection refused

(remote-viewer:1727): GSpice-WARNING **: pa_context_connect() failed: Connection refused
(remote-viewer:1727): remote-viewer-DEBUG: New spice channel 0x3244750 SpiceCursorChannel 0
(remote-viewer:1727): remote-viewer-DEBUG: New spice channel 0x3246bc0 SpiceDisplayChannel 0
(remote-viewer:1727): remote-viewer-DEBUG: New spice channel 0x3248a00 SpiceInputsChannel 0
(remote-viewer:1727): remote-viewer-DEBUG: new inputs channel
(remote-viewer:1727): remote-viewer-DEBUG: creating spice display (#:0)
(remote-viewer:1727): remote-viewer-DEBUG: Insert display 0 0x306e830
(remote-viewer:1727): remote-viewer-DEBUG: Found a window without a display, reusing for this display...
(remote-viewer:1727): remote-viewer-DEBUG: Zoom level not changed, using: 100
(remote-viewer:1727): remote-viewer-DEBUG: notebook show display 0x3064280
(remote-viewer:1727): remote-viewer-DEBUG: Allocated 1024x768
(remote-viewer:1727): remote-viewer-DEBUG: Child allocate 1024x768





(remote-viewer:1727): remote-viewer-DEBUG: main channel: closed
(remote-viewer:1727): remote-viewer-DEBUG: Not removing main window 0 0x2f020b0
(remote-viewer:1727): remote-viewer-DEBUG: Destroy SPICE channel SpiceInputsChannel 0
(remote-viewer:1727): remote-viewer-DEBUG: Destroy SPICE channel SpiceDisplayChannel 0
(remote-viewer:1727): remote-viewer-DEBUG: zap display channel (#0)
(remote-viewer:1727): remote-viewer-DEBUG: Destroying spice display 0x306e830
(remote-viewer:1727): remote-viewer-DEBUG: Destroy SPICE channel SpiceCursorChannel 0
(remote-viewer:1727): remote-viewer-DEBUG: Destroy SPICE channel SpicePlaybackChannel 0
(remote-viewer:1727): remote-viewer-DEBUG: Destroy SPICE channel SpiceRecordChannel 0
(remote-viewer:1727): remote-viewer-DEBUG: Destroy SPICE channel SpiceUsbredirChannel 0
(remote-viewer:1727): remote-viewer-DEBUG: zap usbredir channel
(remote-viewer:1727): remote-viewer-DEBUG: Destroy SPICE channel SpiceUsbredirChannel 1
(remote-viewer:1727): remote-viewer-DEBUG: zap usbredir channel
(remote-viewer:1727): remote-viewer-DEBUG: Destroy SPICE channel SpiceMainChannel 0
(remote-viewer:1727): remote-viewer-DEBUG: zap main channel
(remote-viewer:1727): remote-viewer-DEBUG: notebook show status 0x3064280
(remote-viewer:1727): remote-viewer-DEBUG: Guest win10 display has disconnected, shutting down
(remote-viewer:1727): remote-viewer-DEBUG: Disposing window 0x2f020b0

(remote-viewer:1727): remote-viewer-DEBUG: Set connect info: (null),(null),(null),-1,(null),(null),(null),0
[root@dhcp-9-122 ~]# 
[root@dhcp-9-122 ~]# 

virt-viewer-2.0-6.el7.x86_64

Comment 2 Xiaoqing Wei 2015-09-10 04:41:24 UTC
# cat /home/remote-viewer-disconnected.xml 
<domain type='kvm' id='11'>
  <name>win10</name>
  <uuid>6cb8fd4f-22b5-478e-9929-e417679bb1ad</uuid>
  <memory unit='KiB'>4194304</memory>
  <currentMemory unit='KiB'>4194304</currentMemory>
  <vcpu placement='static'>2</vcpu>
  <resource>
    <partition>/machine</partition>
  </resource>
  <os>
    <type arch='x86_64' machine='pc-i440fx-rhel7.2.0'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <hyperv>
      <relaxed state='on'/>
      <vapic state='on'/>
      <spinlocks state='on' retries='8191'/>
    </hyperv>
    <vmport state='off'/>
  </features>
  <cpu mode='custom' match='exact'>
    <model fallback='allow'>SandyBridge</model>
  </cpu>
  <clock offset='localtime'>
    <timer name='rtc' tickpolicy='catchup'/>
    <timer name='pit' tickpolicy='delay'/>
    <timer name='hpet' present='no'/>
    <timer name='hypervclock' present='yes'/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <pm>
    <suspend-to-mem enabled='no'/>
    <suspend-to-disk enabled='no'/>
  </pm>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none' io='native'/>
      <source file='/home/win10.qcow2'/>
      <backingStore/>
      <target dev='vda' bus='virtio'/>
      <alias name='virtio-disk0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw' cache='none'/>
      <source file='/home/kvm_autotest_root/images/win8.1-64/autounattend.iso'/>
      <backingStore/>
      <target dev='hda' bus='ide'/>
      <readonly/>
      <alias name='ide0-0-0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <controller type='pci' index='0' model='pci-root'>
      <alias name='pci.0'/>
    </controller>
    <controller type='virtio-serial' index='0'>
      <alias name='virtio-serial0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </controller>
    <controller type='ide' index='0'>
      <alias name='ide'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <controller type='usb' index='0' model='ich9-ehci1'>
      <alias name='usb'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x7'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci1'>
      <alias name='usb'/>
      <master startport='0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0' multifunction='on'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci2'>
      <alias name='usb'/>
      <master startport='2'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x1'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci3'>
      <alias name='usb'/>
      <master startport='4'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x2'/>
    </controller>
    <interface type='bridge'>
      <mac address='52:54:00:fa:f0:a7'/>
      <source bridge='switch'/>
      <virtualport type='openvswitch'>
        <parameters interfaceid='1195237a-78b9-4270-9a28-2acf8255562c'/>
      </virtualport>
      <target dev='vnet0'/>
      <model type='virtio'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <serial type='pty'>
      <source path='/dev/pts/2'/>
      <target port='0'/>
      <alias name='serial0'/>
    </serial>
    <console type='pty' tty='/dev/pts/2'>
      <source path='/dev/pts/2'/>
      <target type='serial' port='0'/>
      <alias name='serial0'/>
    </console>
    <channel type='spicevmc'>
      <target type='virtio' name='com.redhat.spice.0' state='disconnected'/>
      <alias name='channel0'/>
      <address type='virtio-serial' controller='0' bus='0' port='1'/>
    </channel>
    <input type='tablet' bus='usb'>
      <alias name='input0'/>
    </input>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='spice' port='5906' autoport='no' listen='0.0.0.0'>
      <listen type='address' address='0.0.0.0'/>
      <image compression='off'/>
    </graphics>
    <sound model='ich6'>
      <alias name='sound0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </sound>
    <video>
      <model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1'/>
      <alias name='video0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <hostdev mode='subsystem' type='usb' managed='yes'>
      <source>
        <vendor id='0x0c76'/>
        <product id='0x160c'/>
        <address bus='1' device='5'/>
      </source>
      <alias name='hostdev0'/>
    </hostdev>
    <redirdev bus='usb' type='spicevmc'>
      <alias name='redir0'/>
    </redirdev>
    <redirdev bus='usb' type='spicevmc'>
      <alias name='redir1'/>
    </redirdev>
    <memballoon model='virtio'>
      <alias name='balloon0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </memballoon>
  </devices>
</domain>

Comment 4 Gerd Hoffmann 2015-09-15 08:18:25 UTC
Hmm, interesting.  I think spice can't hotplug usb-redir channels, but hotplugging usb-host should work just fine even with usb-redir active.

Does that happen with linux guests too?
Do you have any devices connected via usb-redir?
Does it still happen if you remove the usb-redir devices?

Comment 5 Xiaoqing Wei 2015-09-16 06:30:04 UTC
(In reply to Gerd Hoffmann from comment #4)
> Hmm, interesting.  I think spice can't hotplug usb-redir channels, but
> hotplugging usb-host should work just fine even with usb-redir active.
> 
> Does that happen with linux guests too?

Yes

> Do you have any devices connected via usb-redir?

No, it's empty slot

> Does it still happen if you remove the usb-redir devices?

No, with 2 attempts.

Comment 7 Gerd Hoffmann 2016-06-23 05:27:55 UTC
Hmm, doesn't reproduce here.
Can you retest whenever it still happes for you with a qemu 2.6 build?

Comment 8 juzhang 2016-06-23 05:33:07 UTC
Hi Wei,

Could you have a try?

Best Regards,
Junyi

Comment 9 weliao 2016-06-24 07:31:31 UTC
Hi Gerd,
   QE can't reproduce this bug with following versions:
  qemu-kvm-rhev-2.6.0-7.el7.x86_64
  3.10.0-445.el7.x86_64
  spice-server-0.12.4-17.el7.x86_64
the same test steps:
when plug/unplug host usb device
[root@dhcp-8-244 home]# virsh attach-device win10 hostdev.xml
Device attached successfully

[root@dhcp-8-244 home]# virsh detach-device win10 hostdev.xml
Device detached successfully

[root@dhcp-8-244 home]# virsh attach-device win10 hostdev.xml
Device attached successfully

[root@dhcp-8-244 home]# virsh detach-device win10 hostdev.xml
Device detached successfully

spice connection work well.

Comment 10 Gerd Hoffmann 2016-06-24 07:38:40 UTC
Good, seems the rebase picked up a fix.

Comment 12 Yiqian Wei 2016-09-13 05:41:19 UTC
 1.Reproduce this bug.
  Version:
       host:kernel-3.10.0-505.el7.x86_64
            qemu-kvm-rhev-2.3.0-22.el7.x86_64
            spice-server-0.12.4-18.el7.x86_64
       guest:win10

 Test results:      
      remote-viewer lost connection
  
 2.Retest------can't reproduce this bug.
  Version:
        host:kernel-3.10.0-505.el7.x86_64
             qemu-kvm-rhev-2.6.0-23.el7.x86_64
             spice-server-0.12.4-18.el7.x86_64
        guest:win10

  Test results:
      spice connection should not lost.

the same test steps:
1.boot a guest, with usb passthru from host, and usb-redir.
2.remote-viewer spice://hostname:port
3.virsh hotplug/unplug host usb device
  1) cat hostdev.xml 
     <hostdev mode='subsystem' type='usb' managed='yes'>
      <source>
        <vendor id='0x0951'/>
        <product id='0x1642'/>
      </source>
    </hostdev>
  2)virsh # detach-device win10 hostdev.xml 
         Device detached successfully

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

Comment 15 errata-xmlrpc 2016-11-07 20:37: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://rhn.redhat.com/errata/RHBA-2016-2673.html