What is the current status of audio emulation in bhyve ?

but sound quality is significantly worse compared to xfreerdp()'s way for a Windows guest:

Well that's a shame. As mentioned I don't have anything to do with audio on FreeBSD, but I would of hoped that the "hda" device would of effectively provided high definition channels direct between the host and guest. (There is mention that a sysctl needs to change with a Windows guest, as Windows tries to reduce latency by accessing the device far more often that stock FreeBSD is set up for)

I'm not sure who is working on bhyve these days (Peter & Neel still seem to be around but don't think they are anywhere near as involved as they used to be). It's worrying that numerous parts (e.g sound, efi nv-vars, improved disk format support) seem to be fairly stagnant. The only real changes I see in the logs are usually just minor fixes or simply keeping the code inline with improvements elsewhere in the kernel.
 
What I do is pass thru a GT710/GT730 NVidia card to each desktop bhyve VM. On this card is HDMI jack and Audio is passed thru on that interface.
Code:
ppt6@pci0:134:0:0:    class=0x030000 card=0x8c931462 chip=0x128b10de rev=0xa1 hdr=0x00
    vendor     = 'NVIDIA Corporation'
    device     = 'GK208B [GeForce GT 710]'
    class      = display
    subclass   = VGA
ppt7@pci0:134:0:1:    class=0x040300 card=0x8c931462 chip=0x0e0f10de rev=0xa1 hdr=0x00
    vendor     = 'NVIDIA Corporation'
    device     = 'GK208 HDMI/DP Audio Controller'
    class      = multimedia
    subclass   = HDA
 
This pci passthrough is a very interesting concept.
If i'm correct it allows to use hardware recognised by the guest even when there is no driver for the host.
 
This pci passthrough is a very interesting concept.
If i'm correct it allows to use hardware recognised by the guest even when there is no driver for the host.
Did you mean the reverse - use hardware recognised by the host even when there is no driver for the guest?
 
No he had it right. Suppose you wanted to use an Atheros Module that is 802.11ac.
We have no support for that module. So you could pass it through and use it with Linux VM where it is supported. Even run it on a OpenWRT VM perhaps.
 
HD sound works perfectly fine in bhyve and sound quality is as good as the host in my case.

You need commit 349335 and 350255 from FreeBSD head, you can get them at the following links: patch1 and patch2.

Alternatively, you can get them by using svn

Code:
$ cd $HOME
$ svn co https://svn.FreeBSD.org/base/head freebsd-head
$ cd  freebsd-head
$ svn diff -c 349335 > patch1.diff
$ svn diff -c 350255 > patch2.diff

Then apply those patches to /usr/src/usr.sbin/bhyve.

Code:
# cd /usr/src/usr.sbin/bhyve
# patch -Np2 -i $HOME/freebsd-head/patch1.diff
# patch -Np2 -i $HOME/freebsd-head/patch2.diff
# make
# make install

Then choose which dsp you want to use for play and rec
Code:
-s 6,hda,play=/dev/dsp0,rec=/dev/dsp0

I'm even using it at dsp2 (HDMI output) and it works perfectly fine. I use it mostly for my Linux guest for running google chrome in order to be able to use
a proprietary web conferecing used by my company.
 
I was able to play sound from the linux guest to my usb dac scarlett 8i6 focusrite which does not work with freesd.
However after stopping bhyve no usb devices our found so i guess the software is a bit buggy and does not release all resources, a reboot is needed.
 
Another minor issue is that you cannot boot the host through grub/kfreebsd as pptdevs="2/0/0" is nor a kernel tunable parameter nor a loadable module.
 
Last edited:
Could you expand on your issue here?
grub does not need any settings. It is only a bootloader. The settings go in your bhyve arguments.
My bhyve host machine has pptdevs="132/0/1" setting in its /boot/loader.conf
I am running grub-bhyve for a Devuan VM with the networking passed-thru.
Here is my example for setup of new VM:
grub-bhyve -S -r cd0 -m /vm/device.map -M 2048 devuan1
Then hit "Install" from the grub menu. It will drop you back to a command prompt. Then start bhyve:
bhyve -S -c 4 -m 8G -A -H -P -u -s 0:0,hostbridge -s 3:0,ahci-hd,/vm/devuan1.img -s 4:0,ahci-cd,/vm/devuan_ascii_2.1_amd64_netinst.iso -s 5:0,passthru,132/0/1 -s 30:0,xhci,tablet -s 31:0,lpc -l com1,/dev/nmdm4A devuan1

My device map:
(hd0) /vm/devuan1.img
(cd0) /vm/devuan_ascii_2.1_amd64_netinst.iso

For running the devuan1 VM:
grub-bhyve -m /vm/device.map -r hd0,msdos1 -M 2048M -S devuan1 -d /boot/grub/
sleep 6 ### I need this for my bhyve startup script as the grub menu has to complete before I can load bhyve ###
bhyve -S -c 4 -m 2G -A -H -P -u -s 0:0,hostbridge -s 3:0,ahci-hd,/vm/devuan1.img -s 5:0,passthru,132/0/1 -s 30:0,xhci,tablet -s 31:0,lpc -l com1,/dev/nmdm4A devuan1 & ### the ampersand(&) is needed for my startup script.###

So as you can see I am passing thru 132/0/1 for my networking. A quad port Intel NIC. One port is 132/0/1.
Please notice that you need the "-S" switch for both grub-bhyve and bhyve to use pass-thru.
I access this vm locally with cu:
cu -l /dev/nmdm4B
lspci | egrep -i 'network|ethernet'
00:00.0 Host bridge: Network Appliance Corporation Device 1275
00:05.0 Ethernet controller: Intel Corporation 82571EB Gigabit Ethernet Controller (Copper) (rev 06)
 
Hello, guys. Thanks for sharing the information.
Sorry to feed the thread two months later, but I would like to share some comments to help other people. It took me hours to notice that one line of the patch was rejected. 💩 I also spent time with many tests and configurations.

I'm running 12.1-RELEASE .

Patching
I downloaded a raw diff from https://reviews.freebsd.org/D12419 (attached here).

Bash:
cd /usr/src/usr.sbin/bhyve && svn info
URL: svn://svn.freebsd.org/base/release/12.1.0/usr.sbin/bhyve
Relative URL: ^/release/12.1.0/usr.sbin/bhyve
Revision: 360835
patch < /path/to/raw/diff/downloaded/from/reviews.freebsd.org

If you have the same revision as mine, and probably will if you compiled 12.1-RELEASE, make sure Makefile has these entries ( hda_codec.c was rejected, so I manually added):

Bash:
 svn diff
Index: Makefile
===================================================================
--- Makefile    (revision 360835)
+++ Makefile    (working copy)
@@ -16,6 +16,7 @@
 SRCS=  \
        atkbdc.c                \
        acpi.c                  \
+       audio.c                 \
        bhyvegc.c               \
        bhyverun.c              \
        block_if.c              \
@@ -27,6 +28,7 @@
        dbgport.c               \
        fwctl.c                 \
        gdb.c                   \
+       hda_codec.c             \
        inout.c                 \
        ioapic.c                \
        mem.c                   \
@@ -37,6 +39,7 @@
        pci_ahci.c              \
        pci_e82545.c            \
        pci_emul.c              \
+       pci_hda.c               \
        pci_fbuf.c              \
        pci_hostbridge.c        \
        pci_irq.c               \

I cleaned and compiled bhyve again:

Bash:
cd /usr/src/usr.sbin/bhyve
make clean install

Running the VM
My guest is Windows 7 SP1.

TIP: If you need networking, remember to add tap0 and a physical NIC to the same bridge device. It took me some time... I'm lazy, I usally use vm-bhyve script, so I zeroed my mind on this subject.
I mean this (for more info, look for help on the forums or read the Handbook):

Bash:
ifconfig tap0 create
ifconfig bridge0 addm tap0 addm re0

Another problem I had was setting the dsp device (see below). I don't know if this HDA patch has incomplete validation or what, but if added a numbered device, bhyve exited with assert error on function hda_init . So, the tip is: use /dev/dsp . If you have many audio devices, select one with sysctl:
Example:

Bash:
sysctl hw.snd.default_unit=3

Then run bhyve:

Bash:
bhyve -c 2 -m 4G -Hwl bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd \
-U a7fd1b43-51d2-11e9-9fe5-54bf64f6fd48 \
-u \
-s 0,hostbridge \
-s 31,lpc \
-s 4:0,ahci-hd,/arquivo/virtual-machines/win7/vm-win7.img \
-s 10:0,virtio-net,tap0,mac=00:A0:98:22:92:FA \
-s 6:0,fbuf,tcp=0.0.0.0:5900,w=640,h=480 \
-s 7:0,xhci, \
-s 15:0,hda,play=/dev/dsp,rec=/dev/dsp \
-s 3:0,ahci-cd,/arquivo/virtual-machines/.config/null.iso \
win7

Audio Devices

Bash:
 cat /dev/sndstat
Installed devices:
pcm0: <Realtek ALC256 (Internal Analog)> (play/rec)
pcm1: <Realtek ALC256 (Front Analog Headphones)> (play)
pcm2: <Intel Kaby Lake (HDMI/DP 8ch)> (play)
pcm3: <USB audio> (play/rec) default
No devices installed from userspace.

Results

Device 3, M-AUDIO Fast Track Pro, USB audio :

  • play: OK
  • rec: FAILED. Windows did not found a device

Then I changed to builtin audio:

Bash:
sysctl hw.snd.default_unit=0

Ran bhyve again:

Device 0 (laptop builtin speakers):
  • play: OK
  • rec: OK

I rather connect using net/tsclient (Remote Desktop).
 

Attachments

  • D12419.diff.txt
    141.4 KB · Views: 120
Back
Top