# bhyve + crazy idea: virtual device drivers possible?



## BSDBernd (Oct 24, 2014)

Hi,

_L_et us assume that you have a part of your computer, say a wireless device, that is not yet detected by the host operating system (in our case FreeBSD). What if you could solve that issue by letting your guest OS that, let us assume, has a driver for that wireless device, detect that device and you could then use somehow (!?) the guest OS to deal with the wireless? When your computer boots up, it would then use virtual drivers and real drivers, somehow . If something like that would be possible, then virtual machines would become even more important. Before I ask the the developers of bhyve about this,  I thought I'd better post the question here first, to possibly receive laughter twice . What do you think, is something like this possible?


----------



## usdmatt (Oct 24, 2014)

I can't see why you shouldn't be able to pass an unsupported device through to a VM. When using PCI pass-through with bhyve() (or any other hypervisor), the host system has no interaction with the device at all. The VM will just see it as a normal device and should be able to use it (assuming it has drivers).

You wouldn't have any access at all to the device from the host though. As part of using bhyve passthrough, you have to configure the FreeBSD boot loader to completely ignore the device. You can't load a driver in the guest and expect the device to now be accessible and working from the host. In the example of wireless, if you wanted FreeBSD to be able to use the wireless interface to access the network, you'd have to create a bit of an awkward setup:

Pass the raw wireless device through to the guest.
Configure wireless networking in the guest and set it up as a router.
Set the FreeBSD host to use the guest as its gateway, so traffic flows from the host, through a network bridge to the guest, then out over the wireless to the network.


----------



## kpa (Oct 24, 2014)

I'm guessing the question is actually if the device that is controlled by the guest operating system could then be made directly visible to the host OS as if it was connected to the host OS as a supported device. The answer is a strict no because operating systems and device drivers are not (yet) designed for such re-use.


----------



## BSDBernd (Oct 24, 2014)

usdmatt: Wow, you made more precise what I wanted to do. If this really works and I understand that right, then you can get around having no driver for your wireless. Wouldn't that be great? O.k. you would need additional computational power, but that would solve the problem.

kpa: No, I really only wanted to have wireless Internet using the fact that my guest OS has the wireless driver.

This is all quite interesting! Thank you people for that information.


----------



## Kiiski (Oct 26, 2014)

Hi,

It's not really something strictly related to the original question, but maybe someone besides me finds it interesting too.

Something like that is being done with rump kernels by Antti Kantee. A lot of information about it can be found on the Internet, but here is one that slightly touches the original question: http://blog.netbsd.org/tnf/entry/a_rump_kernel_hypervisor_for. And here are nice presentations.


----------



## kpedersen (Oct 27, 2014)

I guess something similar could be done with VirtualBox. Install a Windows XP guest, plug in and pass it through a USB WiFi dongle and then bridge the network and share the Internet connection.


----------



## BSDBernd (Oct 27, 2014)

kpedersen said:


> I guess similar could be done with VirtualBox. Install a Windows XP guest, plug in and pass through a usb WiFi dongle and then bridge the network and share the internet connection.


I had installed FreeBSD 11.0-CURRENT on my Macbook Air Mid 2011 (I had not a single problem with the install, I installed it besides Mac OS X). The problem came later with the wireless device. I have a Broadcom wireless device in my Mac which is not yet supported by FreeBSD.

Since I almost certainly would install a guest operating system on my FreeBSD host, I really wouldn't lose much with the above strategy.

This all shows how important virtualization is.


----------



## BSDBernd (Jan 19, 2015)

Just one comment to this all: Bhyve is a great thing: Imagine you could create a small Linux distribution which is pumped full of drivers and does nothing else than providing drivers, so that only computing power is used up by drivers, then you could use that with bhyve as a kind of driver cartridge. How wonderful this all is. Other operating systems which have even more problems with drivers could do the same thing. This all is very interesting ...


----------



## usdmatt (Jan 19, 2015)

I think you may be taking the idea a bit far. It's highly likely that bhyve will never have a feature that allows you to load a device and driver in one Linux guest, then make use of that device (via the Linux driver) inside another guest or the host. For a start the other guest/host would need to know how to talk to the Linux driver.

My idea with the wireless network card was not to have any sort of device sharing, but purely to use the Linux guest as a mini router, taking packets in via an ethernet bridge between host->guest then forwarding them over the wireless from Linux. This is a complete hack, and of no real value unless you're really stuck in a one-off situation where you need Internet access. It's not really feasible as a long term or production solution.


----------



## BSDBernd (Jan 20, 2015)

usdmatt said:


> I think you may be taking the idea a bit far. It's highly likely that bhyve will never have a feature that allows you to load a device and driver in one Linux guest, then make use of that device (via the Linux driver) inside another guest or the host. For a start the other guest/host would need to know how to talk to the Linux driver.
> 
> My idea with the wireless network card was not to have any sort of device sharing, but purely to use the Linux guest as a mini router, taking packets in via an ethernet bridge between host->guest then forwarding them over the wireless from Linux. This is a complete hack, and of no real value unless you're really stuck in a one-off situation where you need Internet access. It's not really feasible as a long term or production solution.



You are right, I was may be a little bit too excited. But using bhyve allows you to get your wireless card, for which your host OS f.e. has no driver at the moment,  working where you borrow the wireless driver from the guest OS. I find this most remarkable. May be it is trivial and I am too amazed by this .


----------



## allanjude@ (Jan 21, 2015)

This has already been done.

Shawn Webb uses a linux vm to run his Intel wireless nic that doesn't yet have a freebsd driver: http://0xfeedface.org/2014/12/11/FreeBSD-Intel-wifi-via-bhyve.html


----------



## yggdrasil (Jan 21, 2015)

Yes, the idea is not new, and its logical continuation can be found in NetBSDs rumpkernel idea. It essentially cuts the kernel down to just the drivers and runs it as a userland process, without the need for virtualisation overhead. But for the concrete problem at hand (missing wifi drivers) this is of course purely academic and not a real-world-solution unfortunately.


----------



## usdmatt (Jan 22, 2015)

It seems like Shawn Webb is doing exactly what I described (using the Linux VM as a router). He even has the same conclusion - down to the wording - about it:


> This seems like a complete hack–and it definitely is.



I personally think there isn't really a replacement for having drivers in the base OS for the hardware you intend to use. Anything else is creating far too much complication and scope for things to go wrong. I suspect Shawn is eagerly awaiting the day FreeBSD gets native support for that wireless so he doesn't have to jump through hoops.


----------

