Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 May 2021 18:47:54 +0300
From:      Naina Patrascu <patrascu.naina14@gmail.com>
To:        freebsd-hackers@freebsd.org
Cc:        lucian_ioan.popescu@stud.acs.upb.ro,  Elena Mihailescu <elenamihailescu22@gmail.com>
Subject:   Indexing problem with address number of a USB device
Message-ID:  <CAKHb35vf=63QRtMWGT-u3KGYXxp678GHk9ygfE77UBhOE4bgtQ@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
Hello,

We are working on the USB passthrough functionality for bhyve. We are
currently focusing on the passthrough of a USB stick and a USB keyboard.

We are facing an indexing problem when trying to assign a USB device to a
virtual machine.
For example, we have the USB keyboard at busnum=1 and devaddr=2 on the
FreeBSD host virtual machine:

# usbconfig -d ugen1.2
ugen1.2: <Gaming KB Gaming KB> at usbus1, cfg=0 md=HOST spd=LOW (1.5Mbps)
pwr=ON (100mA)

We specify to "bhyve" command to pass through the device to a guest virtual
machine: -s 30,xhci,1-2

As part of the enumeration process, the host controller executes the
internal scan to discover the physical devices and to compare them with the
ones assigned with the bhyve command.
But the USB device is discovered at bus 1 address 1, and we have to adjust
accordingly when parsing the bus-port to match the port number:

04f3:152e 1-1 connecting.
04f3:152e 1-1 belong to this vm.
04F3:152E 1-1 is attached to virtual port 5.

We hardcoded when parsing bus-port: port -= 1.
When trying to pass through a USB stick, we have to increase the port
number to match the one discovered in the internal scan:

# usbconfig -d ugen3.2
ugen3.2: <Kingston DataTraveler 3.0> at usbus3, cfg=0 md=HOST spd=HIGH
(480Mbps) pwr=ON (300mA)

0951:1666 3-3 connecting.
0951:1666 3-3 belong to this vm.
0951:1666 3-3 is attached to virtual port 1.

In our last investigation, we discovered that when increasing the number of
USB devices on the FreeBSD host vm, the port indexes of the devices
discovered by the internal scan, also varies.

In function [1] we get the physical devices using libusb library and then
we execute the internal scan using function [2]. We get the information
about the physical device in function [3], also using libusb library.

Can you help us understand where this problem could come from and how to
debug it?

Thank you!

[1]
https://github.com/FreeBSD-UPB/freebsd-src/blob/a861e57e10512c0e3406762ffba2249bbd786492/usr.sbin/bhyve/usb_pmapper.c#L121
[2]
https://github.com/FreeBSD-UPB/freebsd-src/blob/a861e57e10512c0e3406762ffba2249bbd786492/usr.sbin/bhyve/usb_pmapper.c#L76
[3]
https://github.com/FreeBSD-UPB/freebsd-src/blob/a861e57e10512c0e3406762ffba2249bbd786492/usr.sbin/bhyve/usb_pmapper.c#L24



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAKHb35vf=63QRtMWGT-u3KGYXxp678GHk9ygfE77UBhOE4bgtQ>