From owner-freebsd-emulation@FreeBSD.ORG Wed Nov 12 22:33:43 2014 Return-Path: Delivered-To: freebsd-emulation@freebsd.org Received: from hammer.pct.niksun.com (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by hub.freebsd.org (Postfix) with ESMTP id 2DAF7D41; Wed, 12 Nov 2014 22:33:43 +0000 (UTC) Message-ID: <5463E046.8080708@FreeBSD.org> Date: Wed, 12 Nov 2014 17:33:42 -0500 From: Jung-uk Kim User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Kevin Oberman Subject: Re: USB kills VMs on 4.3.18 References: <5463D1CC.8010501@FreeBSD.org> <5463D35E.1030908@FreeBSD.org> <5463D70D.70805@FreeBSD.org> In-Reply-To: <5463D70D.70805@FreeBSD.org> Content-Type: multipart/mixed; boundary="------------050509020602040404080703" Cc: =?windows-1252?Q?Bernhard_Fr=F6hlich?= , freebsd-emulation@freebsd.org X-BeenThere: freebsd-emulation@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Development of Emulators of other operating systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Nov 2014 22:33:43 -0000 This is a multi-part message in MIME format. --------------050509020602040404080703 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 11/12/2014 16:54, Jung-uk Kim wrote: > 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. :-( Argh... There was another typo. Now this version is compile-tested. I am very sorry for the trouble. Jung-uk Kim -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBAgAGBQJUY+BGAAoJEHyflib82/FG/1oH/2EDYuE0HaH+p4kdNzWvUMtt HyE/tPfu9/Dgmkl9NX7GnJHz5gdvCWwtHeCGG5qJLa8Z71tszUQK07+4Mm5ZUMXp 9CnT8jJ/eOaN5PzeYfK6b/iNhoBxEuOenS3JnhWXi9jwn8tPEeM/MPLeOtR3WkwH NtrZKC7El6m6rCpsnJ6Ha8JXh//7uGTNP/sACcL9oyCgrNo6dovgj7FxXu0Q0v8y hfQr+6MqxNRMInH0rXs46Bl0Vn9gYaPxZ5Uvx7LnxiBS6FuAbsCCH5RdD+vypEnV EmXHrqoSL5+/o+qV7bET7ApOK9tYIpppHYKH26Hb+4k08iSGcOhZZUsBO2LWhKE= =bxN8 -----END PGP SIGNATURE----- --------------050509020602040404080703 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 #include #include +#include #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->hPipeWakeupR); + 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 }; --------------050509020602040404080703--