diff --git a/playbook.yml b/playbook.yml
index 7878fc3..25f2450 100644
--- a/playbook.yml
+++ b/playbook.yml
@@ -9,6 +9,8 @@
- '054c:05c4' # Sony Corp. DualShock 4 [CUH-ZCT1x]
- '046d:c539' # Logitech, Inc. USB Receiver
- '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:
- win10
diff --git a/roles/win10/defaults/main.yml b/roles/win10/defaults/main.yml
index 9e5462c..a255b50 100644
--- a/roles/win10/defaults/main.yml
+++ b/roles/win10/defaults/main.yml
@@ -1,3 +1,4 @@
pcie_device_ids: []
usb_device_ids: []
-kbd_device_path: ''
\ No newline at end of file
+keyboards: []
+mice: []
\ No newline at end of file
diff --git a/roles/win10/files/archlinux_iommu.conf b/roles/win10/files/archlinux_iommu.conf
index 9971acf..f3861d3 100644
--- a/roles/win10/files/archlinux_iommu.conf
+++ b/roles/win10/files/archlinux_iommu.conf
@@ -2,5 +2,5 @@ title Archlinux w/ VFIO
linux /vmlinuz-linux
initrd /intel-ucode.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
diff --git a/roles/win10/files/hooks/qemu b/roles/win10/files/hooks/qemu
index e5cabfe..ceed7da 100755
--- a/roles/win10/files/hooks/qemu
+++ b/roles/win10/files/hooks/qemu
@@ -2,14 +2,27 @@
prepare() {
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 \
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
+
+ # 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
sleep 3
@@ -21,6 +34,12 @@ prepare() {
release() {
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
systemctl stop win10-usb
sysctl -w vm.nr_hugepages=0
diff --git a/roles/win10/handlers/main.yml b/roles/win10/handlers/main.yml
index f905d74..126adb1 100644
--- a/roles/win10/handlers/main.yml
+++ b/roles/win10/handlers/main.yml
@@ -16,3 +16,9 @@
name: virtlogd.socket
enabled: yes
state: restarted
+
+- name: restart persistent-evdev
+ systemd:
+ name: persistent-evdev.service
+ enabled: yes
+ state: restarted
\ No newline at end of file
diff --git a/roles/win10/tasks/main.yml b/roles/win10/tasks/main.yml
index ae12bbe..bd31c69 100644
--- a/roles/win10/tasks/main.yml
+++ b/roles/win10/tasks/main.yml
@@ -5,15 +5,17 @@
- libvirt
- ovmf
- virt-manager
+ - python-evdev
+ - python-pyudev
notify:
- - restart libvirtd.socket
+ - restart libvirtd.service
- restart virtlogd.socket
-# TODO
-# - name: install required packages from aur
-# aur:
-# name:
-# - vfio-isolate
+- name: install required aur packages
+ aur:
+ name:
+ - vfio-isolate
+ - persistent-evdev-git
- name: create hooks directory
file:
@@ -92,12 +94,17 @@
marker: '# {mark} DEVICE ACL CONFIGURATION'
block: |
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/null", "/dev/full", "/dev/zero",
"/dev/random", "/dev/urandom",
"/dev/ptmx", "/dev/kvm", "/dev/kqemu",
- "/dev/rtc","/dev/hpet", "/dev/sev",
- "{{ kbd_device_path }}"
+ "/dev/rtc","/dev/hpet", "/dev/sev"
]
- name: install domain configuration
@@ -113,8 +120,14 @@
# regexp: '^#?CPUAffinity'
# 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
systemd:
name: libvirtd.socket
enabled: yes
-
+ state: started
diff --git a/roles/win10/templates/persistent-evdev/config.json.j2 b/roles/win10/templates/persistent-evdev/config.json.j2
new file mode 100644
index 0000000..60e02b6
--- /dev/null
+++ b/roles/win10/templates/persistent-evdev/config.json.j2
@@ -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"
+ }
+}
\ No newline at end of file
diff --git a/roles/win10/templates/win10-usb.service.j2 b/roles/win10/templates/win10-usb.service.j2
index 484b08e..dbba8ca 100644
--- a/roles/win10/templates/win10-usb.service.j2
+++ b/roles/win10/templates/win10-usb.service.j2
@@ -2,7 +2,7 @@
Description=Attach usb devices to vm
[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
diff --git a/roles/win10/templates/win10.xml b/roles/win10/templates/win10.xml
index 127e5e5..26507c4 100644
--- a/roles/win10/templates/win10.xml
+++ b/roles/win10/templates/win10.xml
@@ -83,7 +83,7 @@
/usr/bin/qemu-system-x86_64
-
+
@@ -180,7 +180,9 @@
+
+
+ {% for item in keyboards %}
-
-
-
-
-
+
+ {% endfor %}
+
+ {% for item in mice %}
+
+
+ {% endfor %}