I ran across your question today looking for a solution myself. I found something that seems to work. Not exactly elegant, but it was the best I have found. Here is what I have:
System: Manjaro with qemu 5.1 on the host
The key for me was to modify /etc/pulse/default.pa
and add (at the bottom):
load-module module-native-protocol-unix auth-anonymous=1 socket=/tmp/pulse-socket
Then run: pulseaudio --kill
(should restart on its own, pulseaudio --start
if it doesn't)
At this point, /tmp/pulse-socket
should exist.
I did not see this step in the Arch/Manjaro documents I was initially reading. So this was my sticking point.
Other than that, it it comes down to the steps in the Arch wiki:
https://wiki.archlinux.org/index.php/PCI_passthrough_via_OVMF#Passing_VM_audio_to_host_via_PulseAudio
Specifically, my virsh edit <vm-name>
looks like this at the bottom (don't forget changes to the domain
line at the top too):
<qemu:commandline>
<qemu:arg value='-object'/>
<qemu:arg value='input-linux,id=mouse1,evdev=/dev/input/by-id/usb-1bcf_USB_Optical_Mouse-event-mouse'/>
<qemu:arg value='-object'/>
<qemu:arg value='input-linux,id=kbd1,evdev=/dev/input/by-id/usb-0c45_USB_Keyboard-event-kbd,grab_all=on,repeat=on'/>
<qemu:arg value='-device'/>
<qemu:arg value='ich9-intel-hda,bus=pcie.0,addr=0x1b'/>
<qemu:arg value='-device'/>
<qemu:arg value='hda-micro,audiodev=hda'/>
<qemu:arg value='-audiodev'/>
<qemu:arg value='pa,id=hda,server=unix:/tmp/pulse-socket,out.buffer-length=512,timer-period=1000'/>
</qemu:commandline>
The evdev lines are unrelated to sound, but I put them in for context (assuming you are using evdev to share keyboard and mouse).
Note I did NOT have to make any changes to /etc/libvirt/qemu.conf
to get sound to work (though I did for evdev with the keyboard/mouse). I also did NOT have to setup the /root/.config/pulse
directory since I am using an anonymous socket.