bhyve usb passthrough - bhyve windows 10 guest

Hello everybody,
I recently installed windows 10 on 13.1 freebsd host following the instructions in the excelent article From 0 to Bhyve on FreeBSD 13.1 from klarasystems.com, except that I don't use the recommended desktop, but instead I use the i3 windows manager.
Everything works fine but I don't have access to usb devices from the windows guest.
Here is my /boot/loader.conf modified by adding the last two lines
Code:
kern.geom.label.disk_ident.enable="0"
kern.geom.label.gptid.enable="0"
cryptodev_load="YES"
zfs_load="YES"
kern.vty=vt
vmm_load="YES"
nmdm_load="YES"
#if_bridge_load="YES"
#if_tap_load="YES"
hw.vmm.amdvi.enable=1
pptdevs="3/0/3 3/0/4"
Here the result of the vm passthru
Code:
DEVICE     BHYVE ID     READY        DESCRIPTION
hostb0     0/0/0        No           Raven/Raven2 Root Complex
amdiommu0  0/0/2        No           Raven/Raven2 IOMMU
hostb1     0/1/0        No           Family 17h (Models 00h-1fh) PCIe Dummy Host Bridge
pcib1      0/1/2        No           Raven/Raven2 PCIe GPP Bridge [6:0]
pcib2      0/1/3        No           Raven/Raven2 PCIe GPP Bridge [6:0]
hostb2     0/8/0        No           Family 17h (Models 00h-1fh) PCIe Dummy Host Bridge
pcib3      0/8/1        No           Raven/Raven2 Internal PCIe GPP Bridge 0 to Bus A
pcib4      0/8/2        No           Raven/Raven2 Internal PCIe GPP Bridge 0 to Bus B
intsmb0    0/20/0       No           FCH SMBus Controller
isab0      0/20/3       No           FCH LPC Bridge
hostb3     0/24/0       No           Raven/Raven2 Device 24: Function 0
hostb4     0/24/1       No           Raven/Raven2 Device 24: Function 1
hostb5     0/24/2       No           Raven/Raven2 Device 24: Function 2
hostb6     0/24/3       No           Raven/Raven2 Device 24: Function 3
hostb7     0/24/4       No           Raven/Raven2 Device 24: Function 4
hostb8     0/24/5       No           Raven/Raven2 Device 24: Function 5
hostb9     0/24/6       No           Raven/Raven2 Device 24: Function 6
hostb10    0/24/7       No           Raven/Raven2 Device 24: Function 7
re0        1/0/0        No           RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller
none0      2/0/0        No           RTL8821CE 802.11ac PCIe Wireless Network Adapter
vgapci0    3/0/0        No           Picasso/Raven 2 [Radeon Vega Series / Radeon Vega Mobile Series]
hdac0      3/0/1        No           Raven/Raven2/Fenghuang HDMI/DP Audio Controller
none1      3/0/2        No           Family 17h (Models 10h-1fh) Platform Security Processor
ppt0       3/0/3        Yes          Raven USB 3.1
ppt1       3/0/4        Yes          Raven USB 3.1
none2      3/0/5        No           ACP/ACP3X/ACP6x Audio Coprocessor
hdac1      3/0/6        No           Family 17h/19h HD Audio Controller
none3      3/0/7        No           Raven/Raven2/Renoir Non-Sensor Fusion Hub KMDF driver
ahci0      4/0/0        No           FCH SATA Controller [AHCI mode]
Here is the content of my uefi.conf.
Code:
:
loader="uefi"
graphics="yes"
xhci_mouse="yes"

cpu=2
cpu_sockets=1
cpu_cores=2

memory=4G

ahci_device_limit="8"

#network0_type="e1000"
network0_type="virtio-net"
network0_switch="public"

disk0_type="nvme"
disk0_name="disk0.img"

disk1_type="ahci-cd"
disk1_dev="custom"
disk1_name="/zroot/bhyve/virtio-win-0.1.221.iso"


passthru0="3/0/3"
passthru1="3/0/4"


utctime="no"
I don't know which the correct syntax for passthru should be.
I also tried something like
Code:
:
passthru0="3/0/3=0:8"
passthru1="3/0/4=0:8"
with no success.
(On windows guest on Device Manager/xhci usb I have: Bus/Device/Function 0/8/0)
I mention that I use an HP 255 G7 AMD Ryzen 3 laptop.

Thanks in advance for any help.
 
Thanks for reply, SirDice
As I mentioned I don't use vbox, but bhyve and I understand that it is possible to passthrough usb devices with bhyve, but I don't know how to do it, especially how to edit the uefi.conf file. I don't know the correct syntax for
Code:
passthru0="..."
on uefi.conf.
Is necessary to write a
Code:
passthruX="..."
for each usb device listed in the result of vm passthru?
Are there devices that I should pass through besides those obviously labeled with "USB" ?
 
Oops. Only read USB pass-through, and remembered that other thread. Completely missed the bhyve(8) part of the question ?
 
crinx , take a look at the discussions here, maybe it will help somehow:
 
Thanks for replying, _al.
Still no success. I didn't find yet an example of a conf file with more devices that are passed through.
In the second link you provided
Code:
passthru0="0/20/0"
I also found an example of conf file at github.com/churchers/vm-bhyve/sample-templates/config.sample where the syntax is
Code:
passthru0="6/0/0=2:0"
Which one is correct? But what if there are more devices for passing through?
 
I don't use vm(8) , so I can't help here. I use bhyve(8) directly.

I have two dedicated PCI devices (which I don't use on the host):
Code:
pciconf -vl
...
xhci2@pci0:134:0:0: class=0x0c0330 rev=0x03 hdr=0x00 vendor=0x1912 device=0x0014
subvendor=0x1912 subdevice=0x0014
vendor  = 'Renesas Technology Corp.'
device  = 'uPD720201 USB 3.0 Host Controller'
class  = serial bus
subclass  = USB

xhci3@pci0:216:0:0: class=0x0c0330 rev=0x03 hdr=0x00 vendor=0x1912 device=0x0014
subvendor=0x1912 subdevice=0x0014
vendor  = 'Renesas Technology Corp.'
device  = 'uPD720201 USB 3.0 Host Controller'
class  = serial bus
subclass  = USB

Devices are passed thru
(/boot/loader.conf) :
Code:
pptdevs="134/0/0 216/0/0"
And I start the virtual machine like this:
Code:
bhyve -c 8,sockets=2,cores=2,threads=2 -m 16G -H -w -S \
-s 0,hostbridge \
-s 3,ahci-cd,/neat/iso/Win10_21H1_Russian_x64.iso \
-s 4,ahci-hd,/neat/bsd1/vms/w10.img \
-s 5,virtio-net,tap0 \
-s 7,passthru,134/0/0 \
-s 9,passthru,216/0/0 \
-s 29,fbuf,tcp=0.0.0.0:5900,w=1920,h=1200,wait \
-s 30,xhci,tablet \
-s 31,lpc \
-l com1,stdio \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd \
w10

Since you use a laptop, a solution with separate (dedicated) PCI USB XHCI devices will not work for you.

Which one is correct?
As for the syntax, I would look into the sysutils/vm-bhyve port source code.
 
passthru0="6/0/0=2:0"
Maybe you solved this but my guess is because of the slot number to passthru. Choose a bigger number like 20 just to test out.

Like this:
Code:
passthru="6/0/0=20:0"

The problem with vm-bhyve (AFAIK) is that you don't quite know which slots are being used... Or at least I don't know how to check that.

if not you could pass a direct bhyve option like:
Code:
bhyve_options="-s 8,hda,play=/dev/dsp1,rec=/dev/dsp1"

or in your case something like
Code:
bhyve_options="-s 9,passthru,216/0/0"
 
Hello Forum,
I finally manage to passthrough usb to the win10 guest.
Here is what worked for me:
After carefully reading wiki/freebsd.org/bhyve/pci_passthru (paying attention this time even to the LAST SENTENCE), in the /boot/loader.conf I reversed the order of two lines, namely, I put
Code:
hw.vmm.amdvi.enable=1
BEFORE
Code:
vmm_load="YES"
.
In uefi.conf I passed
Code:
passthru0="3/0/3=9:0"
And now it works.
This also works on another computer (not a laptop this time) with amd ryzen cpu also, on which I experienced initially the same problem.
So, I consider this problem solved, with an important takeaway for me: we need to read the excellent freebsd documentation carefully to the end.
 
Hello Forum,
I finally manage to passthrough usb to the win10 guest.
Here is what worked for me:
After carefully reading wiki/freebsd.org/bhyve/pci_passthru (paying attention this time even to the LAST SENTENCE), in the /boot/loader.conf I reversed the order of two lines, namely, I put
Code:
hw.vmm.amdvi.enable=1
BEFORE
Code:
vmm_load="YES"
.
In uefi.conf I passed
Code:
passthru0="3/0/3=9:0"
And now it works.
This also works on another computer (not a laptop this time) with amd ryzen cpu also, on which I experienced initially the same problem.
So, I consider this problem solved, with an important takeaway for me: we need to read the excellent freebsd documentation carefully to the end.
Hi, to confirm: did you manage to pass through the entire USB controller or just a specific port? I have a similar situation where I only have one controller and need to pass-through specific ports. I know you said you started with wanting to pass through just a port but I couldn't follow the conversation well enough
 
Hi, to confirm: did you manage to pass through the entire USB controller or just a specific port? I have a similar situation where I only have one controller and need to pass-through specific ports. I know you said you started with wanting to pass through just a port but I couldn't follow the conversation well enough
Hello, I am sorry for delay.
I don t have all the ports passed through, only three of them. I don t know how to map some specific port to certain bhyve passthrough specification
 
crinx Did you manage to pass only a subset of ports belonging to the same controller? You said you passed three of them. Do all three belong to the same controller? How many ports does this controller have in total?
 
crinx Did you manage to pass only a subset of ports belonging to the same controller? You said you passed three of them. Do all three belong to the same controller? How many ports does this controller have in total?
I believe that bhyve does not support "partial" passthru.
 
With bhyve pass-through you're passing through PCI devices like:

Bash:
# vm passthru
DEVICE     BHYVE ID     READY        DESCRIPTION
ppt2       0/20/0       Yes          Cannon Lake PCH USB 3.1 xHCI Host Controller

or if you like:
Bash:
# pciconf -lv ppt2
ppt2@pci0:0:20:0:       class=0x0c0330 rev=0x10 hdr=0x00 vendor=0x8086 device=0xa36d subvendor=0x17aa subdevice=0x3136
    vendor     = 'Intel Corporation'
    device     = 'Cannon Lake PCH USB 3.1 xHCI Host Controller'
    class      = serial bus
    subclass   = USB

which is an USB controller so all ports.

I'm not aware of a different bhyve mechanism specific to USB ports so it's "all ports or nothing".
One option might be to install a separate USB controller via PCIe card if you have a spare slot?
 
redmog is it possible to pass through a single USB device? Not a port, but a specific device already connected to the bus? My laptop has only one USB controller. I have to pass one device to bhyve. If I pass the whole USB controller the host becomes unusable.
 
Bhyve only passes through PCI devices - there's no mechanism to pass through USB devices that I'm aware of at this time.
You can only choose from devices listed by pciconf -l not usbconfig list.

Does your laptop have a spare M.2 socket? You could maybe extend that via a ribbon cable, attach an M.2 PCI-based USB controller and then your USB device? It wouldn't look pretty and it wouldn't be fast or support supplying much power (if any).
In a similar vein, you could try extending your laptop's M.2 socket and trying to connect directly to the USB lines, rather than PCI. However, they are probably served by the same USB controller so although you could try that approach I wouldn't hold your breath.

What is the USB device you want to connect?
 
redmog I have spare M.2 socket. However, this solution would look ugly, and is problematic if you carry your laptop around every day. I want to connect various programmers for FPGA devices.
 
Do your FPGA programmers support old-school serial instead of USB?

Because you could plug in a USB->RS232/TTL/etc. adapter and then pass the COM port directly from the FreeBSD host to the guest VM via bhyve's -l flag?
I pass the host's USB controller to a Win10 VM but pass a serial-based Zigbee controller to HomeAssistant in another VM via -l com2,/dev/cuau0 - actually appended to the bhyve_options config entry for vm-bhyve.
For a USB-based serial port, the device might be more like /dev/cuaU0 I think?
Is that an option for you?

For anyone that might do pass through a serial port
if the guest VM is expecting a specific bitrate, etc. and doesn't support configuring that itself
then before starting the VM use stty to config the COM port beforehand like so:
stty -f /dev/cuau0.init speed 115200 -ixon -ixoff

Adjust device name, speed, flags, etc. as appropriate.
 
This is even more of a bodge but how about USB over IP?
I'm not talking about simple adapters than map USB pairs to RJ45 pairs, but active devices that encapsulate USB messages over IP packets.

laptop -> network switch -> USB-over-IP adapter --USB--> FPGA programmer
install USB-over-IP driver in guest VM to present mock USB hub and your device

At least you'd have minimal latency in your favour?

I have zero experience of this - just trying to come up with more options for you
 
This is even more of a bodge but how about USB over IP?
I don't consider this as a bodge. This is quite clean software solution.

I have heard about USBIP. I guess I will try it as it seems to be the only solution. However, I am not sure about its status on Linux.
 
Back
Top