Bug 270900 - emulators/virtualbox-ose USB passthrough fails with Failed to create a proxy device for the USB device. (Error: VERR_INVALID_PARAMETER)
Summary: emulators/virtualbox-ose USB passthrough fails with Failed to create a proxy ...
Status: Open
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Virtualbox Team (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-04-17 16:08 UTC by groenveld
Modified: 2024-05-08 18:03 UTC (History)
9 users (show)

See Also:
bugzilla: maintainer-feedback? (vbox)


Attachments
patch from 6.1.36 to 6.1.42 and llvm14 (4.33 KB, patch)
2023-04-17 16:08 UTC, groenveld
grahamperrin: maintainer-approval? (vbox)
Details | Diff
VBox.log (109.21 KB, text/plain)
2023-04-17 16:13 UTC, groenveld
no flags Details
USB passthrough fix after 9b077d72bcc313baea2b9283afc7f568739eaadc (389 bytes, patch)
2024-02-04 21:53 UTC, Igor Malyshev
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description groenveld 2023-04-17 16:08:46 UTC
Created attachment 241544 [details]
patch from 6.1.36 to 6.1.42 and llvm14

$ uname -srvK
FreeBSD 14.0-CURRENT FreeBSD 14.0-CURRENT #0 main-n262122-2ef2c26f3f13: Thu Apr 13 08:06:35 UTC 2023     root@releng1.nyi.freebsd.org:/usr/obj/usr/src/amd64.amd64/sys/GENERIC 1400086

$ VBoxManage --version
6.1.42r155177

$ VBoxManage startvm bar --type gui


I've attached the VBox.log and git diff

At first glance, doesn't appear to be a permissions issue but a change in the USB API in Current.
John
groenveld@acm.org
Comment 1 groenveld 2023-04-17 16:13:33 UTC
Created attachment 241545 [details]
VBox.log

VBox.log correlates the GUI  

Failed to create a proxy device for the USB device. (Error: VERR_INVALID_PARAMETER)


00:00:24.961804 usbProxyConstruct: Failed to open '/dev/ugen0.6', rc=VERR_INVALID_PARAMETER

00:00:24.961881 ERROR [COM]: aRC=NS_ERROR_FAILURE (0x80004005) aIID={872da645-4a9b-1727-bee2-5585105b9eed} aComponent={ConsoleWrap} aText={Failed to create a proxy device for the USB device. (Error: VERR_INVALID_PARAMETER)}, preserve=false aResultDetail=-2
Comment 2 groenveld 2023-04-18 14:20:25 UTC
(In reply to groenveld from comment #0)

Almost certainly a change in CURRENT as it works here:
$ uname -srvKU
FreeBSD 14.0-CURRENT FreeBSD 14.0-CURRENT #0 main-n262010-f21faa67ab6b: Thu Apr  6 07:56:57 UTC 2023     root@releng1.nyi.freebsd.org:/usr/obj/usr/src/amd64.amd64/sys/GENERIC 1400085 1400085

John
groenveld@acm.org
Comment 3 groenveld 2023-05-19 17:48:00 UTC
Reproduced with 6.1.44.
John
groenveld@acm.org

$ pkg info virtualbox-ose
virtualbox-ose-6.1.44_1
Name           : virtualbox-ose
Version        : 6.1.44_1
Installed on   : Fri May 19 11:31:57 2023 EDT
Origin         : emulators/virtualbox-ose
Architecture   : FreeBSD:14:amd64
Prefix         : /usr/local
Categories     : emulators
Licenses       : GPLv2
Maintainer     : vbox@FreeBSD.org
WWW            : https://www.virtualbox.org/
Comment        : General-purpose full virtualizer for x86 hardware
Options        :
        AIO            : on
        ALSA           : off
        DBUS           : on
        DEBUG          : off
        GUESTADDITIONS : off
        MANUAL         : off
        NLS            : on
        OPUS           : off
        PYTHON         : off
        QT5            : on
        R0LOGGING      : off
        UDPTUNNEL      : on
        VDE            : off
        VNC            : on
        VPX            : off
        WEBSERVICE     : on
        X11            : on
Shared Libs required:
        libxml2.so.2
        libxcb.so.1
        libvncserver.so.1
        libpng16.so.16
        libcurl.so.4
        libXt.so.6
        libXext.so.6
        libXcursor.so.1
        libX11.so.6
        libSDL-1.2.so.0
        libQt5X11Extras.so.5
        libQt5Widgets.so.5
        libQt5PrintSupport.so.5
        libQt5OpenGL.so.5
        libQt5Gui.so.5
        libQt5Core.so.5
        libGL.so.1
Annotations    :
        FreeBSD_version: 1400088
        cpe            : cpe:2.3:a:oracle:vm_virtualbox:6.1.44:::::freebsd14:x64:1
Flat size      : 165MiB
Description    :
Oracle VM VirtualBox is a hosted hypervisor for x86 virtualisation.
Supported guests include BSD, Haiku, Linux, OS/2, ReactOS, Solaris and
Windows.

Guest Additions are available from: emulators/virtualbox-ose-additions

For the Extension Pack: FreeBSD is not a supported host platform.
Installation of the Pack will not extend the feature set.

WWW: https://www.virtualbox.org/
Comment 4 groenveld 2023-08-19 00:08:15 UTC
This *might* be fallout from this commit:
commit 9b077d72bcc313baea2b9283afc7f568739eaadc
Author: Hans Petter Selasky <hselasky@FreeBSD.org>
Date:   Fri Mar 31 19:14:18 2023 +0200

    usb(4): Separate the fast path and the slow path to avoid races and use-after-free for the USB FS interface.




The error message, "Failed to create a proxy device for the USB device" is here:
./work/VirtualBox-6.1.46/src/VBox/Main/src-client/ConsoleImpl.cpp

The error message, "usbProxyConstruct: Failed to open" is here:
./work/VirtualBox-6.1.46/src/VBox/Devices/USB/USBProxyDevice.cpp

Not sure what are the underlying calls to the USB(4).
John
groenveld@acm.org
Comment 5 groenveld 2023-09-18 22:34:10 UTC
Here's the vbox.log snippet with debug enabled.

00:00:19.593390 usbProxyConstruct: Failed to open '/dev/ugen0.2', rc=VERR_INVALID_PARAMETER
00:00:19.594118 
00:00:19.594121 !!Assertion Failed!!
00:00:19.594122 Expression: <NULL>
00:00:19.594125 Location  : /usr/ports/emulators/virtualbox-ose/work/VirtualBox-6.1.46/src/VBox/VMM/VMMR3/PDMUsb.cpp(717) int pdmR3UsbCreateDevice(PVM, PPDMUSBHUB, PPDMUSB, int, PCRTUUID, PCFGMNODE *, VUSBSPEED, const char *)
00:00:19.594190 Stack     :
00:00:19.594191 00000008221982e7
00:00:19.594193 
00:00:19.594275 Failed to construct 'USBProxy'/0! VERR_INVALID_PARAMETER (-2) - Invalid parameter.


In order to build emulators/virtualbox-ose I needed to rebuild devel/gsoap with debug enabled.
A quick kludge:
git diff
diff --git a/devel/gsoap/Makefile b/devel/gsoap/Makefile
index 253374b56909..9b2eaf9c601b 100644
--- a/devel/gsoap/Makefile
+++ b/devel/gsoap/Makefile
@@ -26,7 +26,7 @@ PORTSCOUT=    limit:^2\.8\.[0-9][0-9][0-9]$
 
 WRKSRC=                ${WRKDIR}/${PORTNAME}-${PORTVERSION:R}
 
-OPTIONS_DEFINE=                        IPV6
+OPTIONS_DEFINE=                        IPV6 
 OPTIONS_DEFAULT=               IPV6 OPENSSL
 OPTIONS_RADIO=                 SSL
 OPTIONS_RADIO_SSL=             GNUTLS OPENSSL
@@ -35,7 +35,7 @@ GNUTLS_LIB_DEPENDS=           libgcrypt.so:security/libgcrypt \
                                libgpg-error.so:security/libgpg-error
 GNUTLS_CONFIGURE_ON=           --enable-gnutls
 GNUTLS_LDFLAGS=                        -L${LOCALBASE}/lib
-IPV6_CONFIGURE_ENABLE=         ipv6
+IPV6_CONFIGURE_ENABLE=         ipv6 debug
 OPENSSL_CONFIGURE_ENABLE=      ssl
 
 post-patch:

John
groenveld@acm.org
Comment 6 groenveld 2023-09-25 17:51:04 UTC
USBProxyDevice-freebsd.cpp

usbProxyFreeBSDFsInit calls usbProxyFreeBSDDoIoCtl which issues 
iCmd=0x801055c3 which returns 22 which converts to -2.
John
groenveld@acm.org
Comment 7 Sergey V. Dyatko 2023-10-17 15:06:19 UTC
Hi, after reverting 9b077d72bcc313baea2b9283afc7f568739eaadc all works fine again

FreeBSD laptop.domain 15.0-CURRENT FreeBSD 15.0-CURRENT #24 main-n265517-37236ab7e4e8-dirty: Tue Oct 17 18:00:07 +03 2023     root@laptop.domain:/usr/obj/usr/src/amd64.amd64/sys/GENERIC-NODEBUG amd64

virtualbox-ose-6.1.46
Comment 8 groenveld 2023-10-20 23:13:52 UTC
(In reply to Sergey V. Dyatko from comment #7)
git revert 9b077d72bcc313baea2b9283afc7f568739eaadc with releng/14.0 branch also fixed 14.0-RC2.

John
groenveld@acm.org
Comment 9 Alex Soto Aguilera 2023-11-16 20:41:00 UTC
After upgrade to 14.0-RELEASE, usb passtrought stops working. I can see this lines in the logfile:

00:00:00.251832 usbProxyConstruct: Failed to open '/dev/ugen0.2', rc=VERR_INVALID_PARAMETER
00:00:00.251988 ERROR [COM]: aRC=NS_ERROR_FAILURE (0x80004005) aIID={872da645-4a9b-1727-bee2-5585105b9eed} aComponent={ConsoleWrap} aText={Failed to create a proxy device for the USB device. (Error: V
ERR_INVALID_PARAMETER)}, preserve=false aResultDetail=-2
Comment 10 Alex Soto Aguilera 2023-11-18 07:49:29 UTC
(In reply to Alex Soto Aguilera from comment #9)

I baypassed this error with my device "Conbee II" trough serial port bypass.

In case anyone has the same problem I solved it like this:

vboxmanage modifyvm homeassistant --uart1 0x2E8 3
vboxmanage modifyvm homeassistant --uartmode1 /dev/ttyU0
Comment 11 Igor Malyshev 2024-02-04 21:53:00 UTC
Created attachment 248190 [details]
USB passthrough fix after 9b077d72bcc313baea2b9283afc7f568739eaadc

after 9b077d72bcc313baea2b9283afc7f568739eaadc this was changed
-	if (fs_ep_ptr == NULL || ep_index_max > 127)
+	if (fs_ep_ptr == NULL || ep_index_max > USB_FS_XFER_MAX)
where USB_FS_XFER_MAX defined as 126 but in src/VBox/Devices/USB/freebsd/USBProxyDevice-freebsd.cpp USBFBSD_MAXENDPOINTS defined as 127 so change it to 126.
patch attached.
Comment 12 groenveld 2024-02-04 23:49:40 UTC
(In reply to Igor Malyshev from comment #11)

Thank you.
Tested on 14.0-RELEASE-p4

John
groenveld@acm.org

$ cat files/patch-src_VBox_Devices_USB_freebsd_USBProxyDevice-freebsd.cpp
--- src/VBox/Devices/USB/freebsd/USBProxyDevice-freebsd.cpp.orig        2024-01-11 12:23:15 UTC
+++ src/VBox/Devices/USB/freebsd/USBProxyDevice-freebsd.cpp
@@ -57,7 +57,7 @@
 #include "../USBProxyDevice.h"
 
 /** Maximum endpoints supported. */
-#define USBFBSD_MAXENDPOINTS 127
+#define USBFBSD_MAXENDPOINTS 126
 #define USBFBSD_MAXFRAMES 56
 
 /** This really needs to be defined in vusb.h! */
Comment 13 russo 2024-05-08 18:03:21 UTC
FWIW, I was just bitten by this issue on FreeBSD 13.3-STABLE, because the relevant commit 9b077d72 to /usr/src/ that broke Virtualbox USB passthrough was cherry-picked into 13/stable in commit 53e253c7.

So the patch provided in the attachment is necessary in the 13.x branch after that commit.

I have confirmed that applying the patch does indeed fix the broken USB issue, and after adding the patch to the ports tree and rebuilding, I can connect to the USB device I was trying to attach.