From f92f3f5fa082362c2c7a5ea1eec8f6dc042e9459 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 13 Mar 2024 15:34:36 +0100 Subject: [PATCH] Use KVM when running an x86 image on x86_64 --- mkosi/config.py | 6 ++++++ mkosi/qemu.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mkosi/config.py b/mkosi/config.py index ee8fda78a..fe4d23332 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -396,6 +396,12 @@ def supports_fw_cfg(self) -> bool: def supports_smm(self) -> bool: return self.is_x86_variant() + def can_kvm(self) -> bool: + return ( + self == Architecture.native() or + (Architecture.native() == Architecture.x86_64 and self == Architecture.x86) + ) + def default_qemu_machine(self) -> str: m = { Architecture.x86 : "q35", diff --git a/mkosi/qemu.py b/mkosi/qemu.py index 7e40946eb..8ab354950 100644 --- a/mkosi/qemu.py +++ b/mkosi/qemu.py @@ -620,7 +620,7 @@ def run_qemu(args: Args, config: Config) -> None: elif config.runtime_network == Network.none: cmdline += ["-nic", "none"] - if config.qemu_kvm != ConfigFeature.disabled and have_kvm and config.architecture.is_native(): + if config.qemu_kvm != ConfigFeature.disabled and have_kvm and config.architecture.can_kvm(): accel = "kvm" if qemu_version(config) >= QEMU_KVM_DEVICE_VERSION: cmdline += ["--add-fd", f"fd={qemu_device_fds[QemuDeviceNode.kvm]},set=1,opaque=/dev/kvm"]