Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Nov 2014 16:54:21 -0500
From:      Jung-uk Kim <jkim@FreeBSD.org>
To:        Kevin Oberman <rkoberman@gmail.com>
Cc:        =?windows-1252?Q?Bernhard_Fr=F6hlich?= <decke@bluelife.at>, freebsd-emulation@freebsd.org
Subject:   Re: USB kills VMs on 4.3.18
Message-ID:  <5463D70D.70805@FreeBSD.org>
In-Reply-To: <5463D35E.1030908@FreeBSD.org>
References:  <CAN6yY1s36=Xmghq_jGbY5p321ef_tv6PsnRCBgvva=OX8jXDhA@mail.gmail.com> <5463D1CC.8010501@FreeBSD.org> <5463D35E.1030908@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------000508010406070901090704
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 11/12/2014 16:38, Jung-uk Kim wrote:
> On 11/12/2014 16:31, Jung-uk Kim wrote:
>> On 11/10/2014 02:00, Kevin Oberman wrote:
>>> Sine the upgrade to VB 4.3.18 plugging in my Logitech Harmony 
>>> control into the USB port of my laptop causes the VM to abort 
>>> instantly. It will not even start ot boot up until I unplug the
>>>  device. The device is reserved for VB and has worked fine in
>>> the past.
> 
>>> Looks like some sort of regression.Since the VM dies instantly 
>>> and block it from rebooting, I'm not to sure how to get any
>>> debug information on it.
> 
>>> FreeBSD rogue 10.1-PRERELEASE FreeBSD 10.1-PRERELEASE #0
>>> r273452: Tue Oct 21 23:00:15 PDT 2014 
>>> root@rogue:/usr/obj/usr/src/sys/GENERIC  amd64
> 
>> FYI, incomplete USB support code was committed with r368359.
> 
>> https://svnweb.freebsd.org/changeset/ports/368359
> 
>> The USB patch was originally came from this commit:
> 
>> https://redports.org/changeset/29393
> 
>> i.e., it was just a stub.
> 
>> Please try the attached patch, i.e., just replace 
>> patch-src-VBox-Devices-USB-freebsd-USBProxyDevice-freebsd.cpp in 
>> files directory with it, rebuild, and try again.  Note this
>> patch may still be incomplete.
> 
> Here goes the patch again, sorry.

There was a typo in the patch. :-(

Please try this instead, sorry.

Jung-uk Kim
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBAgAGBQJUY9cNAAoJEHyflib82/FGbqkH/iqnpOsnxQKGU2Ob2OAgnkf9
t91Be4mCBFPzKp0QRR3XIqmb3FKQKRUIelwPbwi621e6Tlpw11Hx11xmyv+4rGgC
a08AMOH5GUE8WGbt07V/Cp2/YWkJw+v7JCTJerMDdRgAIovQUteFEE6uMG1OPE5B
p4FCB47GDvdIzmMU45OeHihr9QVdOB3NBeL6AZ6GZHjw+Kpw8akmFTWfx922g5k0
P0RQMXe70IPiK+iQey9JMgMePEzcUS8nFBK9WoOk/M0HvdNc4fNUUfxbiH1Ho+zg
E3tS5zTMOuhEiUUNGzX779UBSG5vYHpuopjZyD6woVo2Ywr6BYvkiXAplRBsMIg=
=cA0u
-----END PGP SIGNATURE-----

--------------000508010406070901090704
Content-Type: text/plain; charset=UTF-8;
 name="patch-src-VBox-Devices-USB-freebsd-USBProxyDevice-freebsd.cpp.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="patch-src-VBox-Devices-USB-freebsd-USBProxyDevice-freebsd.cp";
 filename*1="p.txt"

--- src/VBox/Devices/USB/freebsd/USBProxyDevice-freebsd.cpp.orig	2014-10-11 08:06:56.000000000 -0400
+++ src/VBox/Devices/USB/freebsd/USBProxyDevice-freebsd.cpp	2014-11-12 16:07:28.000000000 -0500
@@ -52,6 +52,7 @@
 #include <iprt/asm.h>
 #include <iprt/string.h>
 #include <iprt/file.h>
+#include <iprt/pipe.h>
 #include "../USBProxyDevice.h"
 
 /** Maximum endpoints supported. */
@@ -95,12 +96,16 @@
 {
     /** The open file. */
     RTFILE                 hFile;
-    /** Software endpoint structures */
-    USBENDPOINTFBSD        aSwEndpoint[USBFBSD_MAXENDPOINTS];
     /** Flag whether an URB is cancelling. */
     bool                   fCancelling;
     /** Flag whether initialised or not */
     bool                   fInit;
+    /** Pipe handle for waking up - writing end. */
+    RTPIPE                 hPipeWakeupW;
+    /** Pipe handle for waking up - reading end. */
+    RTPIPE                 hPipeWakeupR;
+    /** Software endpoint structures */
+    USBENDPOINTFBSD        aSwEndpoint[USBFBSD_MAXENDPOINTS];
     /** Kernel endpoint structures */
     struct usb_fs_endpoint aHwEndpoint[USBFBSD_MAXENDPOINTS];
 } USBPROXYDEVFBSD, *PUSBPROXYDEVFBSD;
@@ -383,10 +388,17 @@
         rc = usbProxyFreeBSDFsInit(pProxyDev);
         if (RT_SUCCESS(rc))
         {
-            LogFlow(("usbProxyFreeBSDOpen(%p, %s): returns successfully hFile=%RTfile iActiveCfg=%d\n",
-                     pProxyDev, pszAddress, pDevFBSD->hFile, pProxyDev->iActiveCfg));
+            /*
+             * Create wakeup pipe.
+             */
+            rc = RTPipeCreate(&pDevFBSD->hPipeWakeupR, &pDevFBSD->hPipeWakeupW, 0);
+            if (RT_SUCCESS(rc))
+            {
+                LogFlow(("usbProxyFreeBSDOpen(%p, %s): returns successfully hFile=%RTfile iActiveCfg=%d\n",
+                         pProxyDev, pszAddress, pDevFBSD->hFile, pProxyDev->iActiveCfg));
 
-            return VINF_SUCCESS;
+                return VINF_SUCCESS;
+            }
         }
 
         RTFileClose(hFile);
@@ -449,11 +461,13 @@
 
     usbProxyFreeBSDFsUnInit(pProxyDev);
 
+    RTPipeClose(pDevFBSD->hPipeWakeupR);
+    RTPipeClose(pDevFBSD->hPipeWakeupW);
+
     RTFileClose(pDevFBSD->hFile);
     pDevFBSD->hFile = NIL_RTFILE;
 
     RTMemFree(pDevFBSD);
-    pProxyDev->Backend.pv = NULL;
 
     LogFlow(("usbProxyFreeBSDClose: returns\n"));
 }
@@ -822,7 +836,7 @@
     PUSBENDPOINTFBSD pEndpointFBSD;
     PVUSBURB pUrb;
     struct usb_fs_complete UsbFsComplete;
-    struct pollfd PollFd;
+    struct pollfd pfd[2];
     int rc;
 
     LogFlow(("usbProxyFreeBSDUrbReap: pProxyDev=%p, cMillies=%u\n",
@@ -948,14 +962,32 @@
     }
     else if (cMillies && rc == VERR_RESOURCE_BUSY)
     {
-        /* Poll for finished transfers */
-        PollFd.fd = RTFileToNative(pDevFBSD->hFile);
-        PollFd.events = POLLIN | POLLRDNORM;
-        PollFd.revents = 0;
+        pfd[0].fd = RTFileToNative(pDevFBSD->hFile);
+        pfd[0].events = POLLIN | POLLRDNORM;
+        pfd[0].revents = 0;
+
+        pfd[1].fd = RTPipeToNative(pDevFBSD->hWakeupPipeR);
+        pfd[1].events = POLLIN;
+        pfd[1].revents = 0;
 
-        rc = poll(&PollFd, 1, (cMillies == RT_INDEFINITE_WAIT) ? INFTIM : cMillies);
+        rc = poll(pfd, 2, (cMillies == RT_INDEFINITE_WAIT) ? INFTIM : cMillies);
         if (rc >= 1)
         {
+            if (pfd[1].revents & POLLIN)
+            {
+                /* Got woken up, drain pipe. */
+                uint8_t bRead;
+                size_t cbIgnored = 0;
+                RTPipeRead(pDevFBSD->hPipeWakeupR, &bRead, 1, &cbIgnored);
+
+                /*
+                 * It is possible that we got woken up and have an URB pending
+                 * for completion. Do it on the way out. Otherwise return
+                 * immediately to the caller.
+                 */
+                if (!(pfd[0].revents & POLLIN))
+                    return NULL;
+            }
             goto repeat;
         }
         else
@@ -984,6 +1016,16 @@
     return usbProxyFreeBSDEndpointClose(pProxyDev, index);
 }
 
+static DECLCALLBACK(int) usbProxyFreeBSDWakeup(PUSBPROXYDEV pProxyDev)
+{
+    PUSBPROXYDEVFBSD pDevFBSD = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVFBSD);
+    size_t cbIgnored;
+
+    LogFlowFunc(("pProxyDev=%p\n", pProxyDev));
+
+    return RTPipeWrite(pDevFBSD->hPipeWakeupW, "", 1, &cbIgnored);
+}
+
 /**
  * The FreeBSD USB Proxy Backend.
  */
@@ -1005,6 +1047,7 @@
     usbProxyFreeBSDUrbQueue,
     usbProxyFreeBSDUrbCancel,
     usbProxyFreeBSDUrbReap,
+    usbProxyFreeBSDWakeup,
     0
 };
 

--------------000508010406070901090704--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5463D70D.70805>