From: Daan De Meyer Date: Thu, 11 May 2023 13:26:52 +0000 (+0200) Subject: Add a feature for enabling/disabling qemu vsock usage X-Git-Tag: v15~164^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1557%2Fhead;p=thirdparty%2Fmkosi.git Add a feature for enabling/disabling qemu vsock usage --- diff --git a/mkosi.md b/mkosi.md index fdb2aa103..9c67a3315 100644 --- a/mkosi.md +++ b/mkosi.md @@ -978,6 +978,11 @@ a boolean argument: either "1", "yes", or "true" to enable, or "0", : When used with the `qemu` verb, this option specifies whether QEMU should use KVM acceleration. Takes a boolean value or `auto`. Defaults to `auto`. +`QemuVsock=`, `--qemu-vsock=` + +: When used with the `qemu` verb, this option specifies whether QEMU should be configured with a vsock. Takes + a boolean value or `auto`. Defaults to `auto`. + `QemuArgs=` : Space-delimited list of additional arguments to pass when invoking diff --git a/mkosi/config.py b/mkosi/config.py index c79b0b8a8..0c8a426f7 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -37,6 +37,7 @@ from mkosi.util import ( is_dnf_distribution, prepend_to_environ_path, qemu_check_kvm_support, + qemu_check_vsock_support, ) __version__ = "14" @@ -643,6 +644,7 @@ class MkosiConfig: qemu_smp: str qemu_mem: str qemu_kvm: ConfigFeature + qemu_vsock: ConfigFeature qemu_args: Sequence[str] passphrase: Optional[Path] @@ -1163,6 +1165,11 @@ class MkosiConfigParser: section="Host", parse=config_parse_feature, ), + MkosiConfigSetting( + dest="qemu_vsock", + section="Host", + parse=config_parse_feature, + ), MkosiConfigSetting( dest="qemu_args", section="Host", @@ -1879,6 +1886,13 @@ class MkosiConfigParser: nargs="?", action=action, ) + group.add_argument( + "--qemu-vsock", + metavar="FEATURE", + help="Configure whether to use qemu with a vsock or not", + nargs="?", + action=action, + ) group.add_argument( "--qemu-args", metavar="ARGS", @@ -2211,6 +2225,9 @@ def load_config(args: argparse.Namespace) -> MkosiConfig: if args.qemu_kvm == ConfigFeature.enabled and not qemu_check_kvm_support(): die("Sorry, the host machine does not support KVM acceleration.") + if args.qemu_vsock == ConfigFeature.enabled and not qemu_check_vsock_support(log=False): + die("Sorry, the host machine does not support vsock") + if args.repositories and not (is_dnf_distribution(args.distribution) or is_apt_distribution(args.distribution)): die("Sorry, the --repositories option is only supported on DNF/Debian based distributions") diff --git a/mkosi/qemu.py b/mkosi/qemu.py index c7e5afa8f..bc6c1738b 100644 --- a/mkosi/qemu.py +++ b/mkosi/qemu.py @@ -214,7 +214,9 @@ def run_qemu(args: MkosiArgs, config: MkosiConfig) -> None: "-nic", "user,model=virtio-net-pci", ] - if qemu_check_vsock_support(log=True): + use_vsock = (config.qemu_vsock == ConfigFeature.enabled or + (config.qemu_vsock == ConfigFeature.auto and qemu_check_vsock_support(log=True))) + if use_vsock: cmdline += ["-device", f"vhost-vsock-pci,guest-cid={machine_cid(config)}"] cmdline += ["-cpu", "max"] @@ -292,8 +294,9 @@ def run_qemu(args: MkosiArgs, config: MkosiConfig) -> None: elif config.architecture == "aarch64": cmdline += ["-device", "tpm-tis-device,tpmdev=tpm0"] - addr, notifications = stack.enter_context(vsock_notify_handler()) - cmdline += ["-smbios", f"type=11,value=io.systemd.credential:vmm.notify_socket={addr}"] + if use_vsock: + addr, notifications = stack.enter_context(vsock_notify_handler()) + cmdline += ["-smbios", f"type=11,value=io.systemd.credential:vmm.notify_socket={addr}"] cmdline += config.qemu_args cmdline += args.cmdline