Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 753305 - app-emulation/qemu: usb host devices assigned to vm does not detects in linux guest os
Summary: app-emulation/qemu: usb host devices assigned to vm does not detects in linux...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: Normal major
Assignee: Matthias Maier
URL:
Whiteboard:
Keywords: PullRequest
Depends on:
Blocks:
 
Reported: 2020-11-06 11:50 UTC by Jan Baklo
Modified: 2020-11-24 08:40 UTC (History)
5 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Baklo 2020-11-06 11:50:27 UTC
With new libvirt-6.9.0, any USB host device connected to virtual machine does not find in guest Gentoo OS.
Tested in guest kernel 5.8.8 && 5.8.18 and host kernel 5.8.18.
Downgrading libvirt to 6.8.0 does disappear the issue.
Comment 1 lekto 2020-11-08 14:25:07 UTC
Same for me, but with Windows 10 guest.
Comment 2 lekto 2020-11-08 20:56:24 UTC
I did some bisecting and looks like this commit is causing it:
>bfb1ab1df12e8dccfde42d1a6019bf2e628bf366 is the first bad commit
>commit bfb1ab1df12e8dccfde42d1a6019bf2e628bf366
>Author: Michal Privoznik <mprivozn@redhat.com>
>Date:   Wed Sep 9 13:15:15 2020 +0200
>    
>    qemu: Use .hostdevice attribute for usb-host
>    
>    This originally started as bug 1595525 in which namespaces and
>    libusb used in QEMU were not playing nicely with each other. The
>    problem was that libusb built a cache of USB devices it saw
>    (which was a very limited set because of the namespace) and then
>    expected to receive udev events to keep the cache in sync. But
>    those udev events didn't come because on hotplug when we mknod()
>    devices in the namespace no udev event is generated. And what is
>    worse - libusb failed to open a device that wasn't in the cache.
>    
>    Without going further into what the problem was, libusb added a
>    new API for opening USB devices that avoids using cache which
>    QEMU incorporated and exposes under "hostdevice" attribute.
>    
>    What is even nicer is that QEMU uses qemu_open() for path
>    provided in the attribute and thus FD passing could be used.
>    Except qemu_open() expects so called FD sets instead of `getfd'
>    and these are not implemented in libvirt, yet.
>    
>    Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1877218
>    Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>    Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
>    Reviewed-by: Ján Tomko <jtomko@redhat.com>
>    
> src/qemu/qemu_command.c | 21 +++++++++++++--------
Comment 3 Anders Larsson 2020-11-17 17:56:18 UTC
Not exactly the same problem for me. For me USB keyboards works but not USB mice does not work. It shows up as "Unknown USB device (Invalid Configuration Descriptor)" in device manager on a Windows 10 VM.

Can confirm it is caused by commit bfb1ab1df12e8dccfde42d1a6019bf2e628bf366. Built libvirt and tried it on said commit and it did not work. It does work on the previous commit though (66c5674e797ee1f255c45db1509624537e451a64).

Had a chat on libvirt's IRC channel and they think it might be a bug in qemu or libusb.
Comment 4 Michal Privoznik 2020-11-23 11:54:12 UTC
(In reply to lekto from comment #2)
> I did some bisecting and looks like this commit is causing it:
> >bfb1ab1df12e8dccfde42d1a6019bf2e628bf366 is the first bad commit
> >commit bfb1ab1df12e8dccfde42d1a6019bf2e628bf366
> >Author: Michal Privoznik <mprivozn@redhat.com>
> >Date:   Wed Sep 9 13:15:15 2020 +0200
> >    
> >    qemu: Use .hostdevice attribute for usb-host


This commit switches qemu from using .hostbus= and .hostaddr= attributes to .hostdevice. There is nothing more in libvirt to it. Perhaps it's app-emulation/qemu where the bug is then?

I can't reproduce, but I also have the latest libusb: dev-libs/libusb-1.0.23-r1.
The QEMU commit that introduced .hostdevice mentions the minimal libusb version to be 1.0.23:

https://git.qemu.org/?p=qemu.git;a=commitdiff;h=9f815e83e983d247a3cd67579d2d9c1765adc644;hp=5c24bce3056ff209a1ecc50ff4b7e65b85ad8e74

Although, if older libusb was present then the .hostdevice attribute wouldn't exist and libvirt would use the old set of attributes.
Comment 5 Michal Privoznik 2020-11-24 07:24:51 UTC
Alright, turns out it is app-emulation/qemu bug:

https://gitlab.com/libvirt/libvirt/-/issues/99#note_453201795

I'll backport it.
Comment 6 Larry the Git Cow gentoo-dev 2020-11-24 08:38:54 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=94eaac2fffaaf94baceb34dc3b6d24bae62476b0

commit 94eaac2fffaaf94baceb34dc3b6d24bae62476b0
Author:     Michal Privoznik <mprivozn@redhat.com>
AuthorDate: 2020-11-24 07:26:19 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2020-11-24 08:38:50 +0000

    app-emulation/qemu: Work around libusb bug
    
    In its 6.9.0 relelase Libvirt changed way how USB devices are
    specified on QEMU's command line. While previously .hostbus= and
    .hostaddr= were used they were not really good fit and often get
    in way of another libvirt feature - namespaces (see
    v6.9.0-rc1~456 libvirt commit for more info). The new way of
    configuring USB devices is .hostdevice=/dev/bus/usb/.../... but
    it exposed a bug in libusb which is worked around in qemu (see
    v5.1.0-599-g202d69a715 QEMU commit for more info). Backport the
    workaround for the time being. It can be dropped when we rebase
    to 5.2.0.
    
    Closes: https://bugs.gentoo.org/753305
    Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
    Closes: https://github.com/gentoo/gentoo/pull/18385
    Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

 ...qemu-5.1.0-usb-host-workaround-libusb-bug.patch |  82 ++
 app-emulation/qemu/qemu-5.1.0-r3.ebuild            | 860 +++++++++++++++++++++
 2 files changed, 942 insertions(+)