Bug 1460093

Summary: [RHEV7.4] [usb-host] passthrough the same host's usb stick twice works,while it should not
Product: Red Hat Enterprise Linux 7 Reporter: hachen <hachen>
Component: qemu-kvm-rhevAssignee: Gerd Hoffmann <kraxel>
Status: CLOSED NOTABUG QA Contact: hachen <hachen>
Severity: unspecified Docs Contact:
Priority: medium    
Version: 7.4CC: aliang, chayang, coli, hachen, juzhang, knoel, michen, ngu, pingl, shuang, virt-maint, xuhan, xuwei
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-07-12 11:29:51 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 hachen 2017-06-09 05:53:25 UTC
Description of problem:
passthrough the same host's usb stick twice works,while it should not

Version-Release number of selected component (if applicable):
host:
qemu-kvm-rhev-2.9.0-8.el7.x86_64
kernel-3.10.0-679.el7.x86_64

guest:
kernel-3.10.0-514.25.2.el7.x86_64

How reproducible:
2/2

Steps to Reproduce:
1.start guest and passthrough usb stick twice
/usr/libexec/qemu-kvm \
    -name 'avocado-vt-vm1'  \
    -sandbox off  \
    -machine pc  \
    -nodefaults  \
    -vga qxl  \
    -device pvpanic,ioport=0x505,id=idofUNxk  \
    -device ich9-usb-ehci1,id=usb1,addr=0x1d.7,multifunction=on,bus=pci.0 \
    -device ich9-usb-uhci1,id=usb1.0,multifunction=on,masterbus=usb1.0,addr=0x1d.0,firstport=0,bus=pci.0 \
    -device ich9-usb-uhci2,id=usb1.1,multifunction=on,masterbus=usb1.0,addr=0x1d.2,firstport=2,bus=pci.0 \
    -device ich9-usb-uhci3,id=usb1.2,multifunction=on,masterbus=usb1.0,addr=0x1d.4,firstport=4,bus=pci.0 \
    -drive id=drive_image1,if=none,snapshot=off,aio=native,cache=none,format=raw,file=/home/kvm_autotest_root/images/rhel73-64-virtio.raw \
    -device virtio-blk-pci,id=image1,drive=drive_image1,bootindex=1,bus=pci.0,addr=0x3 \
    -device virtio-net-pci,mac=9a:59:5a:5b:5c:5d,id=idxhRW1O,vectors=4,netdev=idodoD3p,bus=pci.0,addr=0x4  \
    -netdev tap,id=idodoD3p \
    -m 8192  \
    -vnc :0 \
    -smp 8,cores=4,threads=1,sockets=2  \
    -cpu 'Opteron_G5',+kvm_pv_unhalt \
    -device usb-tablet,id=usb-tablet1,bus=usb1.0,port=3  \
    -rtc base=utc,clock=host,driftfix=slew  \
    -boot order=cdn,once=c,menu=on,strict=off \
    -enable-kvm \
    -monitor stdio \
    -qmp tcp:localhost:4444,server,nowait \
    -device usb-host,hostbus=1,hostaddr=5,id=host-usbstick,bus=usb1.0 \
    -device usb-host,hostbus=1,hostaddr=5,id=host-usbstick1,bus=usb1.0 \

Actual results:

host hmp:
(qemu) libusb: error [submit_bulk_transfer] submiturb failed error -1 errno=16 
(qemu) qemu-kvm: libusb_set_configuration: -6 [BUSY]
libusb: error [submit_bulk_transfer] submiturb failed error -1 errno=16
libusb: error [release_interface] release interface failed, error -1 errno 22

In guest:
# dmesg | grep usb
[    2.465519] usb 1-1: new high-speed USB device number 2 using ehci-pci
[    2.771020] usb 1-1: New USB device found, idVendor=0951, idProduct=1642
[    2.771435] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    2.771901] usb 1-1: Product: DT 101 G2
[    2.772136] usb 1-1: Manufacturer: Kingston
[    2.772387] usb 1-1: SerialNumber: 001CC0EC32C7BB4107110077
[    3.035566] usb 1-2: new high-speed USB device number 3 using ehci-pci
[    3.317812] usb 1-2: New USB device found, idVendor=0951, idProduct=1642
[    3.318202] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    3.318629] usb 1-2: Product: DT 101 G2
[    3.318855] usb 1-2: Manufacturer: Kingston
[    3.319097] usb 1-2: SerialNumber: 001CC0EC32C7BB4107110077
[    3.319999] usb 1-2: can't set config #1, error -32
[    3.421553] usb 1-3: new high-speed USB device number 4 using ehci-pci
[    3.540710] usb 1-3: New USB device found, idVendor=0627, idProduct=0001
[    3.541126] usb 1-3: New USB device strings: Mfr=1, Product=3, SerialNumber=5
[    3.541545] usb 1-3: Product: QEMU USB Tablet
[    3.541805] usb 1-3: Manufacturer: QEMU
[    3.542027] usb 1-3: SerialNumber: 42

# lsusb
Bus 001 Device 004: ID 0627:0001 Adomax Technology Co., Ltd 
Bus 001 Device 003: ID 0951:1642 Kingston Technology DT101 G2
Bus 001 Device 002: ID 0951:1642 Kingston Technology DT101 G2
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

#fdisk -l
Disk /dev/sda: 15.5 GB, 15513354240 bytes, 30299520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Expected results:
In guest:
# dmesg | grep usb
same as the actual result

# lsusb
only one usb stg shown here,eg:
Bus 001 Device 004: ID 0627:0001 Adomax Technology Co., Ltd 
Bus 001 Device 002: ID 0951:1642 Kingston Technology DT101 G2
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
  
#fdisk -l
usb stg should not be shown

Additional info:

Comment 2 Ademar Reis 2017-06-12 15:24:17 UTC
I'm assuming this is not a regression. Please confirm.

Comment 3 hachen 2017-06-13 06:09:15 UTC
Same issue on 
host:
qemu-kvm-rhev-2.6.0-28.el7_3.9.x86_64
kernel-3.10.0-679.el7.x86_64

guest:
kernel-3.10.0-514.25.2.el7.x86_64

It is not a regression.

Comment 4 Gerd Hoffmann 2017-07-12 11:29:51 UTC
Hmm, behaviour looks sensible to me.  Only one instance of the device actually works.  The second instance throws an error (can't set config #1), because the device is busy.  So only one storage device (/dev/sdx) shows up in the guest.

Reading the usb descriptors works even in case the device is in use, so lsusb shows both instances (and lsusb on the host shows the usb devices too even when they are in use by a guest).