Bug 1877218 - hostd usb attach failure after attaching a non-existed 'optional' host usb
Summary: hostd usb attach failure after attaching a non-existed 'optional' host usb
Alias: None
Product: Red Hat Enterprise Linux Advanced Virtualization
Classification: Red Hat
Component: libvirt
Version: 8.2
Hardware: Unspecified
OS: Unspecified
Target Milestone: rc
: 8.3
Assignee: Michal Privoznik
QA Contact: lijuan men
Depends On: 1595525 1825941
Blocks: 1596031
TreeView+ depends on / blocked
Reported: 2020-09-09 06:29 UTC by Gerd Hoffmann
Modified: 2021-05-25 06:44 UTC (History)
23 users (show)

Fixed In Version: libvirt-7.0.0-1.el8
Doc Type: If docs needed, set a value
Doc Text:
Clone Of: 1595525
Last Closed: 2021-05-25 06:43:34 UTC
Type: Bug
Target Upstream Version: 6.9.0

Attachments (Terms of Use)

Description Gerd Hoffmann 2020-09-09 06:29:05 UTC
This is the qemu fix:

commit 9f815e83e983d247a3cd67579d2d9c1765adc644
Author: Gerd Hoffmann <kraxel@redhat.com>
Date:   Fri Jun 5 14:59:52 2020 +0200

    usb: add hostdevice property to usb-host
    The new property allows to specify usb host device name.  Uses standard
    qemu_open(), so both file system path (/dev/bus/usb/$bus/$dev on linux)
    and file descriptor passing can be used.
    Requires libusb 1.0.23 or newer.  The hostdevice property is only
    present in case qemu is compiled against a new enough library version,
    so the presence of the property can be used for feature detection.
    Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
    Message-Id: <20200605125952.13113-1-kraxel@redhat.com>

libvirt should use usb-host.hostdevice + filedescriptor passing if available.

Comment 1 Michal Privoznik 2020-09-14 08:02:04 UTC
I've posted patches upstream:


Note, they don't implement FD passing but they use usb-host.hostdevice attribute. This is enough to fix the bug beacuse libvirt does mknod() /dev/bus/usb/... nodes in the namespace. I'm working on the FD passing though and probably post it as a separate patch set.

Comment 3 Michal Privoznik 2020-10-01 09:14:09 UTC
Merged upstream as:

bfb1ab1df1 qemu: Use .hostdevice attribute for usb-host
66c5674e79 qemu_capabilities: Add QEMU_CAPS_USB_HOST_HOSTDEVICE


Comment 9 lijuan men 2021-02-04 09:32:27 UTC
verify the bug with libvirt-7.0.0-3.el8.x86_64 and qemu-kvm-5.2.0-4.module+el8.4.0+9676+589043b9.x86_64

1. Prepare a host with usb device and a running VM

# lsusb
Bus 001 Device 002: ID 2a4b:0400  

# virsh list 
 Id   Name   State
 1    juan   running

2. Attach/detach a non-existed 'optional' host usb

[root@lenovo-sr630-06 opt]# cat non-usb.xml 
<hostdev mode='subsystem' type='usb' managed='yes'>
<source startupPolicy='optional'>
    <vendor id='0x2a4b'/>
    <product id='0x0401'/>

[root@lenovo-sr630-06 opt]# virsh attach-device juan non-usb.xml 
Device attached successfully

[root@lenovo-sr630-06 opt]# virsh detach-device juan non-usb.xml 
Device detached successfully

3.attach/detach the existed host usb

[root@lenovo-sr630-06 opt]# cat usb.xml 
<hostdev mode='subsystem' type='usb' managed='yes'>
    <vendor id='0x2a4b'/>
    <product id='0x0400'/>

[root@lenovo-sr630-06 opt]# virsh attach-device juan usb.xml 
Device attached successfully

in the guest:
[root@localhost ~]# lsusb
Bus 001 Device 019: ID 2a4b:0400 

[root@lenovo-sr630-06 opt]# virsh detach-device juan usb.xml 
Device detached successfully

In the guest, there is not the usb device.

Comment 11 errata-xmlrpc 2021-05-25 06:43:34 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 (virt:av bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.


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