Qubes OS and CPU affinity

You can use a hack and pin the CPUs in template /usr/share/qubes/templates/libvirt/xen.xml:
For example to restrict guests to only run on CPUs 2-15 change:
<vcpu placement="static">{{ vm.vcpus }}</vcpu>
to
<vcpu placement="static" cpuset="2-15">{{ vm.vcpus }}</vcpu>
But this doesn’t apply to HVMs device model stubdom (vmname-dm domains) and they will still run on all CPUs.
There’s an emulatorpin option in libvirt but it seems that stubdom emulator don’t support it.

UPD:
It’s better to override the xen config by making changes in /etc/qubes/templates/libvirt/xen-user.xml as stated here:
Custom libvirt config — core-admin mm_bcdf5771-0-gbcdf5771-dirty documentation

$ cat /etc/qubes/templates/libvirt/xen-user.xml
{% extends 'libvirt/xen.xml' %}
{% block basic %}
        <vcpu placement="static" cpuset="2-15">{{ vm.vcpus }}</vcpu>
        {{ super() }}
{% endblock %}
4 Likes