feat: arch packages with dkms kvm modules and patched qemu
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
pkgbase = vfio-native
|
||||
pkgdesc = Present a libvirt guest as a self-consistent physical machine, and tune it
|
||||
pkgver = 1.1.0
|
||||
pkgrel = 1
|
||||
url = https://git.archworks.co/sandwich/vfio-native
|
||||
install = vfio-native.install
|
||||
arch = any
|
||||
license = GPL-2.0-only
|
||||
makedepends = git
|
||||
depends = libvirt
|
||||
depends = qemu-base
|
||||
depends = python
|
||||
depends = openssh
|
||||
depends = bash
|
||||
depends = ethtool
|
||||
optdepends = mingw-w64-gcc: build the in-guest benchmark and the TIMER probe
|
||||
optdepends = cpupower: set the host CPU governor
|
||||
optdepends = vfio-native-kvm-dkms: patched KVM modules for the full level
|
||||
optdepends = vfio-native-qemu: patched QEMU for the full level
|
||||
source = git+https://git.archworks.co/sandwich/vfio-native.git#tag=v1.1.0
|
||||
sha256sums = SKIP
|
||||
|
||||
pkgname = vfio-native
|
||||
@@ -0,0 +1,51 @@
|
||||
# Maintainer: Sandwich <sandwich@archworks.co>
|
||||
#
|
||||
# Platform-fidelity corrections and VFIO tuning for libvirt guests.
|
||||
#
|
||||
# Three packages:
|
||||
# vfio-native scripts, patches, ACPI tables and the benchmark
|
||||
# vfio-native-kvm-dkms the patched KVM modules, rebuilt by DKMS per kernel
|
||||
# vfio-native-qemu QEMU 11.1.1 with the platform-identity patches, in /opt
|
||||
|
||||
pkgname=vfio-native
|
||||
pkgver=1.1.0
|
||||
pkgrel=1
|
||||
pkgdesc="Present a libvirt guest as a self-consistent physical machine, and tune it"
|
||||
arch=('any')
|
||||
url="https://git.archworks.co/sandwich/vfio-native"
|
||||
license=('GPL-2.0-only')
|
||||
depends=('libvirt' 'qemu-base' 'python' 'openssh' 'bash' 'ethtool')
|
||||
makedepends=('git')
|
||||
optdepends=('mingw-w64-gcc: build the in-guest benchmark and the TIMER probe'
|
||||
'cpupower: set the host CPU governor'
|
||||
'vfio-native-kvm-dkms: patched KVM modules for the full level'
|
||||
'vfio-native-qemu: patched QEMU for the full level')
|
||||
install=vfio-native.install
|
||||
source=("git+${url}.git#tag=v${pkgver}")
|
||||
sha256sums=('SKIP')
|
||||
|
||||
package() {
|
||||
cd "${srcdir}/${pkgname}"
|
||||
install -Dm755 scripts/setup-vm.sh "${pkgdir}/usr/bin/vm-native-setup"
|
||||
install -Dm755 scripts/verify-perf.sh "${pkgdir}/usr/bin/vm-native-verify"
|
||||
install -Dm755 scripts/gpu-passthrough.sh "${pkgdir}/usr/bin/vm-native-gpu"
|
||||
|
||||
local share="${pkgdir}/usr/share/vfio-native"
|
||||
install -Dm644 bench/vmbench.c "${share}/bench/vmbench.c"
|
||||
install -Dm644 bench/timerprobe.c "${share}/bench/timerprobe.c"
|
||||
install -Dm755 scripts/install-modules.sh "${share}/scripts/install-modules.sh"
|
||||
install -Dm755 scripts/restore-stock-kvm.sh "${share}/scripts/restore-stock-kvm.sh"
|
||||
install -Dm755 scripts/generate-tables.py "${share}/scripts/generate-tables.py"
|
||||
install -Dm644 -t "${share}/acpi" acpi/*.aml acpi/*.dsl
|
||||
install -dm755 "${share}/patches"
|
||||
cp -r patches/. "${share}/patches/"
|
||||
install -Dm644 -t "${share}/doc" README.md docs/*.md
|
||||
|
||||
# libvirt runs every executable in qemu.d/ after the main qemu hook, so
|
||||
# this coexists with whatever hook the host already has.
|
||||
install -Dm755 scripts/libvirt-hook-cpu-isolation.sh \
|
||||
"${pkgdir}/etc/libvirt/hooks/qemu.d/10-cpu-isolation.sh"
|
||||
# e1000e offloads corrupt integrity-checked traffic on libvirt taps; host-wide by nature
|
||||
install -Dm644 scripts/99-vfio-native-vnet-offload.rules \
|
||||
"${pkgdir}/usr/lib/udev/rules.d/99-vfio-native-vnet-offload.rules"
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
post_install() {
|
||||
cat <<'MSG'
|
||||
|
||||
vfio-native installed.
|
||||
|
||||
Three commands. You do not need to read anything else.
|
||||
|
||||
vm-native-setup configure a libvirt domain
|
||||
vm-native-verify check it is actually working
|
||||
vm-native-gpu set up GPU passthrough
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
Getting a corrected, tuned guest:
|
||||
|
||||
1. In the Windows guest, once - turn off its own hypervisor. This is the
|
||||
single most valuable change and it makes the VM FASTER:
|
||||
|
||||
bcdedit /set hypervisorlaunchtype off
|
||||
Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All -NoRestart
|
||||
|
||||
Reboot twice. Uninstall the QEMU and SPICE guest agents.
|
||||
|
||||
2. Move the guest disk to emulated NVMe (bus='nvme'), and give it a <serial>.
|
||||
|
||||
3. On the host, once:
|
||||
|
||||
sudo cpupower frequency-set -g performance
|
||||
|
||||
4. Shut the domain down and run:
|
||||
|
||||
vm-native-setup
|
||||
|
||||
It detects your CPU layout - AMD CCDs or Intel P/E cores - and asks four
|
||||
questions, all with sensible defaults. It pins vCPUs onto real SMT pairs,
|
||||
keeps the emulator off the vCPU cores, and writes the corrected CPU and
|
||||
firmware settings. It backs the domain up first and prints how to revert.
|
||||
|
||||
5. Start the guest, let it idle a minute, then:
|
||||
|
||||
vm-native-verify
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
Fidelity levels, asked in step 4:
|
||||
|
||||
tuned performance tuning only, no platform corrections
|
||||
native tuning + domain-level corrections. No patched binaries, no upkeep.
|
||||
full lowest score. Needs vfio-native-kvm and a patched QEMU, and a
|
||||
module rebuild after each kernel update.
|
||||
|
||||
'native' is a good default if you would rather not maintain anything.
|
||||
|
||||
A udev rule (99-vfio-native-vnet-offload.rules) turns TX offloads off on every
|
||||
libvirt tap as it appears. The emulated e1000e NIC corrupts integrity-checked
|
||||
traffic with them on; SSH to the guest fails with "Corrupted MAC on input".
|
||||
It applies to every VM on the host; the throughput cost on a host<->guest
|
||||
link is not measurable.
|
||||
|
||||
A libvirt hook is installed at /etc/libvirt/hooks/qemu.d/10-cpu-isolation.sh.
|
||||
It keeps host processes off the cores the guest is pinned to, automatically,
|
||||
whenever the guest runs. Measured: stalls over 10us in a 10 second window fell
|
||||
from ~100 to ~36. If your libvirt does not read qemu.d/, chain it from your
|
||||
existing /etc/libvirt/hooks/qemu.
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
Leave the host at least 4 physical cores. Windows calibrates the TSC once at
|
||||
boot, and if the host cannot schedule the guest's vCPU threads cleanly while
|
||||
that runs, Windows abandons the TSC and every QueryPerformanceCounter call
|
||||
costs ~1300ns instead of ~15 for the rest of that boot. Software that polls
|
||||
the clock in a tight loop makes that call thousands of times a second, so it
|
||||
shows up as constant hitching in an interactive session. 24 of 32 threads is
|
||||
reliable, 32 of 32 is not, and vm-native-setup warns you when you go under
|
||||
the margin.
|
||||
|
||||
It is a race, so one slow reading proves nothing. If vm-native-verify shows
|
||||
QPC over 1000ns, reboot and measure again before changing any setting.
|
||||
|
||||
Patches, grouped by the detection each one clears:
|
||||
/usr/share/vfio-native/patches/README.md
|
||||
|
||||
MSG
|
||||
}
|
||||
|
||||
post_upgrade() { post_install; }
|
||||
Reference in New Issue
Block a user