Page MenuHomeFreeBSD

bhyve: populate device version from backend
ClosedPublic

Authored by aokblast on Jul 23 2025, 4:26 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Oct 14, 1:50 PM
Unknown Object (File)
Sun, Oct 12, 7:40 PM
Unknown Object (File)
Sun, Oct 12, 2:36 PM
Unknown Object (File)
Sun, Oct 12, 1:34 AM
Unknown Object (File)
Fri, Oct 10, 3:27 AM
Unknown Object (File)
Thu, Oct 9, 10:26 PM
Unknown Object (File)
Thu, Oct 9, 10:26 PM
Unknown Object (File)
Thu, Oct 9, 10:26 PM
Subscribers

Details

Summary

The pci_xhci driver requires the USB device version to be known before allocating a hub port. To support this, we split the original xHCI initialization into two phases:

  1. Probe: Parse the nvlist and determine the device version.
  2. Init: Complete initialization and set up the softc details.

This change ensures proper hub port allocation based on accurate device
version.

Sponsored by: The FreeBSD Foundation

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

aokblast retitled this revision from The pci_xhci driver requires the USB device version to be known before allocating a hub port. To support this, we split the original xHCI initialization into two phases: to bhyve: populate the device version from the backend.Jul 23 2025, 4:27 PM
aokblast edited the summary of this revision. (Show Details)
aokblast retitled this revision from bhyve: populate the device version from the backend to bhyve: populate device version from backend.Jul 23 2025, 5:30 PM

I think this is fine, but I'd like one more reviewer to confirm.

usr.sbin/bhyve/pci_xhci.c
2856

Now we need to clean up the devsc in these error paths.

usr.sbin/bhyve/pci_xhci.c
2902

I think we probably also need to free dev->dev_sc here? Taking care to avoid a double free after the assignment XHCI_DEVINST_PTR(sc, dev->hci.hci_port) = dev above.

usr.sbin/bhyve/pci_xhci.c
2902

Emm, I think we have a memory leak problem before this patch. When control flow goto bad in

if (usb2_port == sc->usb2_port_start +
			    XHCI_MAX_DEVS / 2)

or

if (usb3_port == sc->usb3_port_start +
			    XHCI_MAX_DEVS / 2)

The last dev never freed. I think it should be fixed properly now.

Approved with the inline comments resolved.

usr.sbin/bhyve/pci_xhci.c
2841

Still need to free dev here.

2900
2902

Yes, I agree.

This revision is now accepted and ready to land.Aug 5 2025, 2:15 PM
This revision now requires review to proceed.Aug 5 2025, 2:25 PM
This revision is now accepted and ready to land.Aug 6 2025, 1:13 PM
usr.sbin/bhyve/pci_xhci.c
2788–2789

I think this line is unnecessary now since we decide to close manually for any error before

XHCI_DEVINST_PTR(sc, dev->hci.hci_port) = dev;

. I will delete it before merging back.