Bug 194196 - emulators/virtualbox-ose: crashes when USB device attached
Summary: emulators/virtualbox-ose: crashes when USB device attached
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Some People
Assignee: Hans Petter Selasky
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-10-06 17:44 UTC by 214748mv
Modified: 2014-12-01 21:44 UTC (History)
8 users (show)

See Also:
214748mv: maintainer-feedback? (vbox)


Attachments
New USB patch (5.38 KB, patch)
2014-11-28 16:39 UTC, Hans Petter Selasky
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description 214748mv 2014-10-06 17:44:59 UTC
Attaching an USB device to a Virtual Machine result in a error:

Failed to create a proxy devices for the USB device. (Error: VERR_READ_ERROR)
Result Code: 
NS_ERROR_FAILURE (0x80004005)
Component: 
Console
Interface: 
IConsole {8ab7c520-2442-4b66-8d74-4ff1e195d2b6}

More info at the FreeDBS forum https://forums.freebsd.org/viewtopic.php?f=5&t=48134
Comment 1 Bugzilla Automation freebsd_committer freebsd_triage 2014-10-06 17:44:59 UTC
Auto-assigned to maintainer vbox@FreeBSD.org
Comment 2 tabulator 2014-10-06 21:22:59 UTC
I want to confirm this bug.

On 10.0-RELEASE I cannot get any USB devices into the guest VM (MS Windows XP), which worked before Virtualbox version 4.3.16. They are not detected anymore.

On 10.1-RC1 Virtualbox 4.3.16 crashes when there is a usbfilter entry specified.

Everything seems to work correctly when I remove my usbfilter entry.
Comment 3 tabulator 2014-10-07 19:52:46 UTC
I tested 10.0-RELEASE and 10.1-RC1 with the older version VirtualBox-4.3.12_2 (SVN revision 367888). Works like expected. It seems there is a breakage in 4.3.16.
Comment 4 214748mv 2014-10-21 19:50:25 UTC
This bug is still present in version 4.3.18. Verified on:
$ uname -a
FreeBSD clover-nas2 9.3-STABLE FreeBSD 9.3-STABLE #0 r271760: Thu Sep 18 16:25:02 CEST 2014     ssh@clover-nas2:/usr/obj/usr/src/sys/GENERIC  amd64
Comment 5 pwr2srv 2014-10-22 16:56:03 UTC
Upgraded via portmaster to virtualbox-ose-4.3.18 today and bug remains.
Comment 6 Denis Akiyakov 2014-10-22 17:12:14 UTC
Also, update ports today and this bug appear.
Comment 7 Walter Schwarzenfeld 2014-10-22 17:25:19 UTC
Same problem  FreeBSD 9.3-RELEASE-p2 amd64. virtualbox-version 4.13.18.
Comment 8 Jung-uk Kim freebsd_committer freebsd_triage 2014-11-24 23:26:42 UTC
This is a known problem.  FYI, 4.3.14 introduced new USB support code and I just added a stub to make it compile at the time.  Unfortunately, I had no free time to complete it but decke committed the incomplete code with 4.3.16.

Hans, can you please take a look at the following upstream change?

https://www.virtualbox.org/changeset/49814
Comment 9 Hans Petter Selasky freebsd_committer freebsd_triage 2014-11-25 06:53:44 UTC
Hi,

Looking at:

https://svnweb.freebsd.org/ports/head/emulators/virtualbox-ose/files/patch-src-VBox-Devices-USB-freebsd-USBProxyDevice-freebsd.cpp?revision=373388&view=markup


I think you should set cMillies = 0, right
after RTPipeRead(pDevFBSD->hPipeWakeupR, &bRead, 1, &cbIgnored), so that the function actually returns when the hPipeWakeupR is signalled. I think the purpose of the hPipeWakeupR is to force the reaper to return to the caller.


Else it looks good!

Test with a USB webcam, USB audio device and/or a USB memory stick and it should be fine.

--HPS
Comment 10 Jung-uk Kim freebsd_committer freebsd_triage 2014-11-25 19:32:19 UTC
(In reply to Hans Petter Selasky from comment #9)
> I think you should set cMillies = 0, right
> after RTPipeRead(pDevFBSD->hPipeWakeupR, &bRead, 1, &cbIgnored), so that the
> function actually returns when the hPipeWakeupR is signalled.

Thanks for the suggestion.

Unfortunately, it didn't improve the situation, e.g., "VBoxManage list usbhost" shows all devices are busy, guests with valid USB filter refuse to start, etc. :-(
Comment 11 Hans Petter Selasky freebsd_committer freebsd_triage 2014-11-26 08:09:04 UTC
Did you enable VBox debugging? It should have the possibility to have some nice printouts from the USB subsystem which should tell what is going on!

--HPS
Comment 12 Hans Petter Selasky freebsd_committer freebsd_triage 2014-11-28 15:47:22 UTC
I've reproduced the issue and found the root cause. Will upload a new patch soonish.

--HPS
Comment 13 Hans Petter Selasky freebsd_committer freebsd_triage 2014-11-28 16:39:21 UTC
Created attachment 149966 [details]
New USB patch

Hi,

Replace "files/patch-src-VBox-Devices-USB-freebsd-USBProxyDevice-freebsd.cpp" using this attachment and try again!

Issue #1)
Change wrong callback area size from "sizeof(PUSBPROXYDEVFBSD)" into "sizeof(USBPROXYDEVFBSD)"

Issue #2)
Implement new "usbProxyFreeBSDWakeup" callback function.

Issue #3)
Don't free the private USB data in the USB close function.

--HPS
Comment 14 Hans Petter Selasky freebsd_committer freebsd_triage 2014-11-28 16:44:12 UTC
FYI:

https://www.marshut.net/kswtpp/freebsd-virtualbox-usb-support.html
Comment 15 Juergen Lock freebsd_committer freebsd_triage 2014-11-28 20:10:10 UTC
Patch from comment 13 seems to be working for an usb remote emulating a keyboard, and for a flash drive after setting hw.usb.ehci.no_hs=1 (tested mounting and ls -l), both using a FreeBSD 10.0 guest.
Comment 16 214748mv 2014-11-30 18:48:12 UTC
I have tested the patch with virtualbox-ose-4.3.20 and a 4GB SanDisk Cruzer Blade 1.01 USB stick formatted with FAT32.
With an Ubuntu Mate x86 VM the stick do not works: when I connect the stick, the VM and the VM VirtualBox Manager do not respond to the user. I need to kill both.
With a Windows XP VM the stick usually works: I can format it, copy and remove files but stressing a bit the system I receive the same error as in Ubuntu VM. For example  I can not copy a 300MB file on the stick from the Windows VM.
Comment 17 Hans Petter Selasky freebsd_committer freebsd_triage 2014-11-30 19:11:34 UTC
Hi,

This sounds like a different problem. I suspect that there is some interaction issues, that you maybe need to remove "device umass" from the kernel and remove "/boot/kernel/umass.ko" so that the umass is not trying to access the device while VirtualBox does. I don't remember right now if the FreeBSD virtualbox USB backend detach the kernel drivers or not.

--HPS
Comment 18 commit-hook freebsd_committer freebsd_triage 2014-12-01 21:23:55 UTC
A commit references this bug:

Author: jkim
Date: Mon Dec  1 21:23:05 UTC 2014
New revision: 373722
URL: https://svnweb.freebsd.org/changeset/ports/373722

Log:
  Fix crash with USB devices attached.

  PR:		194196

Changes:
  head/emulators/virtualbox-ose/Makefile
  head/emulators/virtualbox-ose/files/patch-src-VBox-Devices-USB-freebsd-USBProxyDevice-freebsd.cpp
Comment 19 Jung-uk Kim freebsd_committer freebsd_triage 2014-12-01 21:27:42 UTC
(In reply to Hans Petter Selasky from comment #13)
> Created attachment 149966 [details]
> New USB patch
> 
> Hi,
> 
> Replace
> "files/patch-src-VBox-Devices-USB-freebsd-USBProxyDevice-freebsd.cpp" using
> this attachment and try again!
> 
> Issue #1)
> Change wrong callback area size from "sizeof(PUSBPROXYDEVFBSD)" into
> "sizeof(USBPROXYDEVFBSD)"
> 
> Issue #2)
> Implement new "usbProxyFreeBSDWakeup" callback function.
> 
> Issue #3)
> Don't free the private USB data in the USB close function.

Good catch!  It worked for me.
Comment 20 214748mv 2014-12-01 21:29:42 UTC
(In reply to Hans Petter Selasky from comment #17)
> Hi,
> 
> This sounds like a different problem. I suspect that there is some
> interaction issues, that you maybe need to remove "device umass" from the
> kernel and remove "/boot/kernel/umass.ko" so that the umass is not trying to
> access the device while VirtualBox does. I don't remember right now if the
> FreeBSD virtualbox USB backend detach the kernel drivers or not.
> 
> --HPS

Unfortunately removing umass from the kernel does not solve the problem for me. The stick works in the same way with or without umass.
Regards
Maurizio
Comment 21 Hans Petter Selasky freebsd_committer freebsd_triage 2014-12-01 21:44:51 UTC
I'll see if I can find some time to test USB in VirtualBox a bit more ...