Sys-audio and (Windows) HVMs

Deprecated in favor for: Proper guide on how to use sys-audio (AudioVM) must be created - #16 by neowutran

The following patches and script automatically applies the needed steps:
stubdom_libvirtargs.patch

--- init	2023-04-12 17:17:09.718014699 +0100
+++ init	2023-04-12 17:16:44.420014339 +0100
@@ -27,6 +27,14 @@
     mdev -d
 fi
 
+# Get audio params and remove from dm_args
+audio_args=$(echo "$dm_args" | sed -n '/^-qubes-audio:/p')
+dm_args=$(echo "$dm_args" | sed '/^-qubes-audio:/d')
+
+get_audio_arg() {
+    echo "$audio_args" | sed -n 's/^.*[:,]'$1'=\([^,]\+\).*$/\1/p'
+}
+
 # add audiodev conf to cmdline and run pulseaudio 
 audio_model=$(echo "$dm_args" | sed -n '/^-soundhw/ {n;p}')
 if [ -n "$audio_model" ] ; then
@@ -38,7 +46,7 @@
     pa_args=$'-audiodev\npa,id=qemupa,server=unix:/tmp/pa.sock'$model_args;
     pulseaudio --use-pid-file=no --daemonize=no --exit-idle-time=-1 --disable-shm=yes -n \
 	-L "module-native-protocol-unix auth-anonymous=1 socket=/tmp/pa.sock" \
-	-L "module-vchan-sink domid=0" &
+	-L "module-vchan-sink domid=$(get_audio_arg 'audiovm_xid')" &
 fi
 
 # Extract network parameters and remove them from dm_args

xenxml.patch

--- xen.xml	2023-04-12 17:24:15.359020758 +0100
+++ xen.xml	2023-04-12 17:24:44.456021172 +0100
@@ -160,6 +160,11 @@
             {% endfor %}
 
 
+            {% if vm.audiovm %}
+              {% set audiovm_xid = vm.audiovm.xid %}
+            {% else %}
+              {% set audiovm_xid = 0 %}
+            {% endif %}
             {% if vm.virt_mode == 'hvm' %}
                 <!-- server_ip is the address of stubdomain. It hosts it's own DNS server. -->
                 <emulator
@@ -174,13 +179,15 @@
                             ,dns_0={{ vm.dns[0] -}}
                             ,dns_1={{ vm.dns[1] -}}
                             ,gw={{ vm.netvm.gateway -}}
-                            ,netmask={{ vm.netmask }}"
+                            ,netmask={{ vm.netmask }}
+                            -qubes-audio:audiovm_xid={{ audiovm_xid }}"
                       {% else %}
                         cmdline="-net lwip,client_ip={{ vm.ip -}}
                             ,server_ip={{ vm.dns[1] -}}
                             ,dns={{ vm.dns[0] -}}
                             ,gw={{ vm.netvm.gateway -}}
-                            ,netmask={{ vm.netmask }}"
+                            ,netmask={{ vm.netmask }}
+                            -qubes-audio:audiovm_xid={{ audiovm_xid }}"
                       {% endif %}
                     {% endif %}
                     {% if vm.stubdom_mem %}

script.sh

#!/bin/bash
qubes-dom0-update patch

ORIGLOC=`pwd`
# Apply patch to xen.xml
cd /usr/share/qubes/templates/libvirt
patch -N < $ORIGLOC/xemxml.patch
rm xen.xml.rej || true

# Patch stubdom
mkdir /tmp/stubroot
cp /usr/libexec/xen/boot/qemu-stubdom-linux-full-rootfs /tmp/stubroot/stubdom.gz
cd /tmp/stubroot
gzip -d stubdom.gz
cpio -i -d -H newc --no-absolute-filenames < stubdom ; rm stubdom
patch -N < $ORIGLOC/stubdom_libvirtargs.patch
rm init.rej || true
cp /usr/libexec/xen/boot/qemu-stubdom-linux-full-rootfs /usr/libexec/xen/boot/stubdom-full-rootfs.BAK
find . -print0 | cpio --null -ov --format=newc | gzip -9 > /usr/libexec/xen/boot/qemu-stubdom-linux-full-rootfs
rm -fR /tmp/stubroot
# Return to starting location
cd $ORIGLOC

Could easily be adapted into a salt script.

2 Likes