← Back to team overview

touch-packages team mailing list archive

[Bug 1246929] Re: no audio in KVM virtual machines : cannot select alsa or pa

 

the emulated HDA works fine in Windows 7 VM using the above, with proviso that I run VM as root, ie. 
/etc/libvirt/qemu.conf      includes (in my case, which works)
user = "root"
group = "root"
cgroup_device_acl = [
    "/dev/null", "/dev/full", "/dev/zero",
    "/dev/random", "/dev/urandom",
    "/dev/ptmx", "/dev/kvm", "/dev/kqemu",
    "/dev/rtc","/dev/hpet", "/dev/vfio/vfio",
    "/dev/vfio/1", "/dev/vfio/14", "/dev/vfio/15", "/dev/vfio/16", "/dev/vfio/17",
    "/dev/shm", "/root/.config/pulse", "/dev/snd",
]
nographics_allow_host_audio = 1
security_require_confined = 0
hugetlbfs_mount = "/dev/hugepages"
clear_emulator_capabilities = 0
relaxed_acs_check = 1

If using VNC rather than Spice, you may also need
vnc_allow_host_audio = 1


and /etc/apparmor.d/abstractions/libvirt/qemu contains the following additional lines (in my case)
  /{dev,run}/shm/pulse-shm* rw,
  @{HOME}/.config/puls** rwk,
  @{HOME}/** r,
  /root/.config/puls** rwk,
  /root/.asoundrc r,
  /dev/vfio/* rw,

This works nicely with a Windows 7 guest using the following xml (where a graphics card is apssed through at 01:00.0 and a USB card is passed at 02:00.0, note that the inbuilt audio device on the graphics card is NOT passed through i'ts still attached to pci-stub)
!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
  virsh edit ssd-win7
or other application using the libvirt API.
-->

<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
  <name>ssd-win7</name>
  <uuid>92faa169-292a-4086-a398-31df57266eb1</uuid>
  <memory unit='KiB'>6291456</memory>
  <currentMemory unit='KiB'>6291456</currentMemory>
  <vcpu placement='static'>2</vcpu>
  <os>
    <type arch='x86_64' machine='pc-q35-2.0'>hvm</type>
    <loader>/mnt/programming_data/virtualisation/bios/bios.bin</loader>
    <boot dev='hd'/>
    <bootmenu enable='yes'/>
  </os>
  <features>
    <acpi/>
    <hyperv>
      <relaxed state='on'/>
      <vapic state='on'/>
      <spinlocks state='on' retries='4096'/>
    </hyperv>
  </features>
  <cpu mode='custom' match='exact'>
    <model fallback='allow'>Haswell</model>
    <topology sockets='1' cores='2' threads='1'/>
  </cpu>
  <clock offset='localtime'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/bin/qemu-system-x86_64</emulator>
    <disk type='block' device='disk'>
      <driver name='qemu' type='raw'/>
      <source dev='/dev/ssd-virt/lvwin7_kvm'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x04' function='0x0'/>
    </disk>
    <controller type='usb' index='0'>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x03' function='0x0'/>
    </controller>
    <controller type='sata' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pcie-root'/>
    <controller type='pci' index='1' model='dmi-to-pci-bridge'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x1e' function='0x0'/>
    </controller>
    <controller type='pci' index='2' model='pci-bridge'>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x01' function='0x0'/>
    </controller>
    <interface type='user'>
      <mac address='00:00:00:0a:5b:2c'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x01' function='0x0'/>
    </interface>
    <input type='tablet' bus='usb'/>
    <sound model='ac97'>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x02' function='0x0'/>
    </sound>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x05' function='0x0'/>
    </memballoon>
  </devices>
  <qemu:commandline>
    <qemu:arg value='-rtc'/>
    <qemu:arg value='base=localtime'/>
    <qemu:arg value='-nodefconfig'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='nec-usb-xhci,id=xhci'/>
    <qemu:arg value='-spice'/>
    <qemu:arg value='port=5902,disable-ticketing'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='ioh3420,bus=pcie.0,addr=1c.1,multifunction=on,port=2,chassis=2,id=root.2'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='ich9-intel-hda,bus=root.2'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='hda-duplex,bus=hda.0'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='usb-ehci,id=ehci'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='vfio-pci,host=01:00.0,bus=root.1,addr=00.0,multifunction=on,x-vga=on'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='vfio-pci,host=02:00.0,bus=pcie.0'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='ahci,bus=pcie.0,id=ahci'/>
    <qemu:env name='DISPLAY' value=':0'/>
    <qemu:env name='QEMU_ALSA_DAC_BUFFER_SIZE' value='512'/>
    <qemu:env name='QEMU_ALSA_DAC_PERIOD_SIZE' value='100'/>
    <qemu:env name='QEMU_AUDIO_DRV' value='alsa'/>
  </qemu:commandline>
</domain>


If you'd rather grant access at the VM level you can update the apparmor entries in /etc/apparmor.d/libvirt/libivrt-<uuid>
What worked best for me was to create a new permissions file based on the "libvirt-<uuid>.files" entry which was autmatically generated. The new file contains the following 
# Added by R E to support use of VFIO.
  "/dev/vfio/*" rw,
# Needed for ALSA sound (based on error messages about not having access).
  "/dev/shm/pulse-shm*" rwk,
  "/run/shm/pulse-shm*" rwk,
  "/root/.config/puls**" rwk,
  "/root/.asoundrc" r,
# Rather than specifying individual files, allow the whole directory
  "/mnt/programming_data/isos/**" r,
# don't audit writes to readonly files
  deny "/mnt/programming_data/isos/**" w,

Then add a pointer to that file in the master at "libvirt-<uuid>" ie. to
look like this (see the last entry, the file which i created)

#
# This profile is for the domain whose UUID matches this file.
#

#include <tunables/global>

profile libvirt-c1a86cb2-82b4-4db9-89c2-ced5be57b39e {
  #include <abstractions/libvirt-qemu>
  #include <libvirt/libvirt-c1a86cb2-82b4-4db9-89c2-ced5be57b39e.files>
  #include <libvirt/libvirt-c1a86cb2-82b4-4db9-89c2-ced5be57b39e.files_re>

}

For some reason, when I do the same for a Ubuntu Trusty VM it initially worked but now shows a "device busy" error for some reason, which i'm unable to overcome - even though a Windows VM operating in exactly the same manner works fine. Arcane magic involved - sacrifice may be required
Both the AC97 and the HDA devices work on Windows ie. go into Control Panel / Sound and select one, run a test and it works fine. Neither of them is a PCI pasthrough card. As it happens I have a separate USB soundcard I can use in Windows because it's attached to the USB controller with is passed through via PCI passthrough, but that's a spearate story.

In my situation, the host is Ubuntu Trusty running kvm, qemu, libvirt
and virt-manager from the standard repos. The kernel is patched to
support VGA passthrough (mostly to deal with Intel graphics poor
handling of VGA arbitration)

Have you tried this arrangement ?

-- 
You received this bug notification because you are a member of Ubuntu
Touch seeded packages, which is subscribed to pulseaudio in Ubuntu.
https://bugs.launchpad.net/bugs/1246929

Title:
  no audio in KVM virtual machines : cannot select alsa or pa

Status in “libvirt” package in Ubuntu:
  Confirmed
Status in “pulseaudio” package in Ubuntu:
  Confirmed
Status in “virt-manager” package in Ubuntu:
  Confirmed

Bug description:
  I am on Ubuntu 13.10 desktop
  16GB ram
  asus sabertooth 990fx r2.0 motherboard
  amd 8346 cpu
  nvidia gtx650 video card

  Since upgrading to Ubuntu 13.10 audio no longer works in KVM.
  Checking SYSLOG I found this error being logged:

  Oct 31 15:32:31 bmullan-virtual-machine pulseaudio[1814]: [alsa-source-ID 21 Analog] alsa-source.c: ALSA woke us up to read new data from the device, but there was actually nothing to read!
  Oct 31 15:32:31 bmullan-virtual-machine pulseaudio[1814]: [alsa-source-ID 21 Analog] alsa-source.c: Most likely this is a bug in the ALSA driver 'snd_hda_intel'. Please report this issue to the ALSA developers.
  Oct 31 15:32:31 bmullan-virtual-machine pulseaudio[1814]: [alsa-source-ID 21 Analog] alsa-source.c: We were woken up with POLLIN set -- however a subsequent snd_pcm_avail() returned 0 or another value < min_avail.

  brian

  ProblemType: Bug
  DistroRelease: Ubuntu 13.10
  Package: alsa-base 1.0.25+dfsg-0ubuntu4
  ProcVersionSignature: Ubuntu 3.11.0-11.17-generic 3.11.3
  Uname: Linux 3.11.0-11-generic x86_64
  ApportVersion: 2.12.5-0ubuntu2.1
  Architecture: amd64
  Date: Thu Oct 31 19:45:53 2013
  InstallationDate: Installed on 2013-10-31 (0 days ago)
  InstallationMedia: Ubuntu 13.10 "Saucy Salamander" - Beta amd64 (20131003)
  MarkForUpload: True
  PackageArchitecture: all
  SourcePackage: alsa-driver
  Symptom: audio
  Title: PCI/internal sound card not detected
  UpgradeStatus: No upgrade log present (probably fresh install)
  dmi.bios.date: 04/09/2013
  dmi.bios.vendor: American Megatrends Inc.
  dmi.bios.version: 1708
  dmi.board.asset.tag: To be filled by O.E.M.
  dmi.board.name: SABERTOOTH 990FX R2.0
  dmi.board.vendor: ASUSTeK COMPUTER INC.
  dmi.board.version: Rev 1.xx
  dmi.chassis.asset.tag: To Be Filled By O.E.M.
  dmi.chassis.type: 3
  dmi.chassis.vendor: To Be Filled By O.E.M.
  dmi.chassis.version: To Be Filled By O.E.M.
  dmi.modalias: dmi:bvnAmericanMegatrendsInc.:bvr1708:bd04/09/2013:svnTobefilledbyO.E.M.:pnTobefilledbyO.E.M.:pvrTobefilledbyO.E.M.:rvnASUSTeKCOMPUTERINC.:rnSABERTOOTH990FXR2.0:rvrRev1.xx:cvnToBeFilledByO.E.M.:ct3:cvrToBeFilledByO.E.M.:
  dmi.product.name: To be filled by O.E.M.
  dmi.product.version: To be filled by O.E.M.
  dmi.sys.vendor: To be filled by O.E.M.

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1246929/+subscriptions