1
0
Fork 0

cgroupsv2 partial compat + update audio config format

This commit is contained in:
Massaki Archambault 2021-07-22 09:40:24 -04:00
parent 2e0f4c91b4
commit 513ab94563
9 changed files with 83 additions and 24 deletions

View File

@ -9,6 +9,8 @@
- '054c:05c4' # Sony Corp. DualShock 4 [CUH-ZCT1x] - '054c:05c4' # Sony Corp. DualShock 4 [CUH-ZCT1x]
- '046d:c539' # Logitech, Inc. USB Receiver - '046d:c539' # Logitech, Inc. USB Receiver
- '046d:c08d' # Logitech, Inc. G502 LIGHTSPEED Wireless Gaming Mouse - '046d:c08d' # Logitech, Inc. G502 LIGHTSPEED Wireless Gaming Mouse
kbd_device_path: '/dev/input/by-id/usb-0d3d_USBPS2-event-kbd' keyboards:
- '/dev/input/by-id/usb-0d3d_USBPS2-event-kbd'
mice: []
roles: roles:
- win10 - win10

View File

@ -1,3 +1,4 @@
pcie_device_ids: [] pcie_device_ids: []
usb_device_ids: [] usb_device_ids: []
kbd_device_path: '' keyboards: []
mice: []

View File

@ -2,5 +2,5 @@ title Archlinux w/ VFIO
linux /vmlinuz-linux linux /vmlinuz-linux
initrd /intel-ucode.img initrd /intel-ucode.img
initrd /initramfs-linux.img initrd /initramfs-linux.img
options mitigations=off intel_iommu=on iommu=pt intel_iommu=igfx_off experimental_zcopytx=1 kvm.ignore_msrs=1 acpi_backlight=none root=LABEL=ARCHROOT rw options mitigations=off intel_iommu=on iommu=pt intel_iommu=igfx_off experimental_zcopytx=1 kvm.ignore_msrs=1 acpi_backlight=none root=LABEL=ARCHLINUX rw

View File

@ -2,15 +2,28 @@
prepare() { prepare() {
systemctl start win10-usb systemctl start win10-usb
# setup cgroupv2
systemctl set-property --runtime -- user.slice AllowedCPUs=0,4
systemctl set-property --runtime -- system.slice AllowedCPUs=0,4
systemctl set-property --runtime -- init.scope AllowedCPUs=0,4
vfio-isolate -u /tmp/win10.undo \ vfio-isolate -u /tmp/win10.undo \
drop-caches \ drop-caches \
compact-memory \ compact-memory \
irq-affinity mask C1-3,5-7 \ irq-affinity mask C1-3,5-7 \
cpuset-create --cpus C0,4 /host.slice \
cpuset-create --cpus C1-3,5-7 -nlb /win10.slice \
move-tasks / /host.slice \
cpu-governor performance C0-7 cpu-governor performance C0-7
# vfio-isolate -u /tmp/win10.undo \
# drop-caches \
# compact-memory \
# irq-affinity mask C1-3,5-7 \
# cpuset-create --cpus C0,4 /host.slice \
# cpuset-create --cpus C1-3,5-7 -nlb /win10.slice \
# move-tasks / /host.slice \
# cpu-governor performance C0-7
for _ in $(seq 5); do for _ in $(seq 5); do
sleep 3 sleep 3
# assign hugepages # assign hugepages
@ -21,6 +34,12 @@ prepare() {
release() { release() {
echo "Restore system" echo "Restore system"
# restore cgroupv2
systemctl set-property --runtime -- user.slice AllowedCPUs=0,1,2,3,4,5,6,7
systemctl set-property --runtime -- system.slice AllowedCPUs=0,1,2,3,4,5,6,7
systemctl set-property --runtime -- init.scope AllowedCPUs=0,1,2,3,4,5,6,7
vfio-isolate restore /tmp/win10.undo vfio-isolate restore /tmp/win10.undo
systemctl stop win10-usb systemctl stop win10-usb
sysctl -w vm.nr_hugepages=0 sysctl -w vm.nr_hugepages=0

View File

@ -16,3 +16,9 @@
name: virtlogd.socket name: virtlogd.socket
enabled: yes enabled: yes
state: restarted state: restarted
- name: restart persistent-evdev
systemd:
name: persistent-evdev.service
enabled: yes
state: restarted

View File

@ -5,15 +5,17 @@
- libvirt - libvirt
- ovmf - ovmf
- virt-manager - virt-manager
- python-evdev
- python-pyudev
notify: notify:
- restart libvirtd.socket - restart libvirtd.service
- restart virtlogd.socket - restart virtlogd.socket
# TODO - name: install required aur packages
# - name: install required packages from aur aur:
# aur: name:
# name: - vfio-isolate
# - vfio-isolate - persistent-evdev-git
- name: create hooks directory - name: create hooks directory
file: file:
@ -92,12 +94,17 @@
marker: '# {mark} DEVICE ACL CONFIGURATION' marker: '# {mark} DEVICE ACL CONFIGURATION'
block: | block: |
cgroup_device_acl = [ cgroup_device_acl = [
{% for item in keyboards %}
"/dev/input/by-id/uinput-persist-keyboard{{ loop.index0 }}",
{% endfor %}
{% for item in mice %}
"/dev/input/by-id/uinput-persist-mouse{{ loop.index0 }}",
{% endfor %}
"/dev/kvm", "/dev/kvm",
"/dev/null", "/dev/full", "/dev/zero", "/dev/null", "/dev/full", "/dev/zero",
"/dev/random", "/dev/urandom", "/dev/random", "/dev/urandom",
"/dev/ptmx", "/dev/kvm", "/dev/kqemu", "/dev/ptmx", "/dev/kvm", "/dev/kqemu",
"/dev/rtc","/dev/hpet", "/dev/sev", "/dev/rtc","/dev/hpet", "/dev/sev"
"{{ kbd_device_path }}"
] ]
- name: install domain configuration - name: install domain configuration
@ -113,8 +120,14 @@
# regexp: '^#?CPUAffinity' # regexp: '^#?CPUAffinity'
# line: 'CPUAffinity=0 4' # line: 'CPUAffinity=0 4'
- name: configure persistent-evedev
template:
src: persistent-evdev/config.json.j2
dest: /opt/persistent-evdev/etc/config.json
notify: restart persistent-evdev
- name: enable libvirtd.socket - name: enable libvirtd.socket
systemd: systemd:
name: libvirtd.socket name: libvirtd.socket
enabled: yes enabled: yes
state: started

View File

@ -0,0 +1,12 @@
{
"cache": "/opt/persistent-evdev/cache",
"devices": {
{% for item in keyboards %}
"persist-keyboard{{loop.index0}}": "{{ item }}",
{% endfor %}
{% for item in mice %}
"persist-mouse{{loop.index0}}": "{{ item }}",
{% endfor %}
"dummy" : "/dev/null"
}
}

View File

@ -2,7 +2,7 @@
Description=Attach usb devices to vm Description=Attach usb devices to vm
[Service] [Service]
ExecStart=/usr/bin/vfio-usb win10 --evdev-kbd "{{ kbd_device_path }}" {{ ' '.join(usb_device_ids) }} ExecStart=/usr/bin/vfio-usb win10 --evdev-kbd "/dev/input/by-id/uinput-persist-keyboard0" {{ ' '.join(usb_device_ids) }}
Restart=always Restart=always

View File

@ -83,7 +83,7 @@
<devices> <devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator> <emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type='file' device='disk'> <disk type='file' device='disk'>
<driver name='qemu' type='raw' io='threads'/> <driver name='qemu' type='raw'/>
<source file='/home/marchambault/Documents/virtualmachines/img/win10.img'/> <source file='/home/marchambault/Documents/virtualmachines/img/win10.img'/>
<target dev='sda' bus='scsi'/> <target dev='sda' bus='scsi'/>
<boot order='1'/> <boot order='1'/>
@ -180,7 +180,9 @@
</graphics> </graphics>
<sound model='ich9'> <sound model='ich9'>
<address type='pci' domain='0x0000' bus='0x02' slot='0x02' function='0x0'/> <address type='pci' domain='0x0000' bus='0x02' slot='0x02' function='0x0'/>
<audio id='1'/>
</sound> </sound>
<audio id='1' type='pulseaudio' serverName='/run/user/1000/pulse/native'/>
<hostdev mode='subsystem' type='pci' managed='yes'> <hostdev mode='subsystem' type='pci' managed='yes'>
<source> <source>
<address domain='0x0000' bus='0x00' slot='0x1f' function='0x6'/> <address domain='0x0000' bus='0x00' slot='0x1f' function='0x6'/>
@ -205,9 +207,10 @@
<redirdev bus='usb' type='spicevmc'> <redirdev bus='usb' type='spicevmc'>
<address type='usb' bus='0' port='3'/> <address type='usb' bus='0' port='3'/>
</redirdev> </redirdev>
<memballoon model='virtio'> <memballoon model='none'/>
<!-- <memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x07' slot='0x00' function='0x0'/> <address type='pci' domain='0x0000' bus='0x07' slot='0x00' function='0x0'/>
</memballoon> </memballoon> -->
<shmem name='looking-glass'> <shmem name='looking-glass'>
<model type='ivshmem-plain'/> <model type='ivshmem-plain'/>
<size unit='M'>32</size> <size unit='M'>32</size>
@ -216,11 +219,14 @@
</devices> </devices>
<qemu:commandline> <qemu:commandline>
<!-- keyboard evdev passthrough --> <!-- keyboard evdev passthrough -->
{% for item in keyboards %}
<qemu:arg value='-object'/> <qemu:arg value='-object'/>
<qemu:arg value='input-linux,id=kbd1,evdev={{ kbd_device_path }},grab_all=off,repeat=on'/> <qemu:arg value='input-linux,id=kbd1,evdev=/dev/input/by-id/uinput-persist-keyboard{{ loop.index0 }},grab_all=off,repeat=on'/>
<!-- audio passthrough --> {% endfor %}
<qemu:arg value='-audiodev'/> <!-- mouse evdev passthrough -->
<qemu:arg value="driver=pa,id=hda,server=/run/user/1000/pulse/native,out.buffer-length=2000,timer-period=1000"/> {% for item in mice %}
<!-- <qemu:arg value="driver=pa,id=hda,server=127.0.0.1,out.buffer-length=2000,timer-period=1000"/> --> <qemu:arg value='-object'/>
<qemu:arg value='input-linux,id=input5,evdev=/dev/input/by-id/uinput-persist-mouse{{ loop.index0 }}'/>
{% endfor %}
</qemu:commandline> </qemu:commandline>
</domain> </domain>