From nobody Sat Nov 23 18:35:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=none dis=none) header.from=szczek.dev ARC-Seal: i=1; a=rsa-sha256; t=1723453836; cv=none; d=zohomail.com; s=zohoarc; b=LbMWvG/qhoxUZGHz7Nf7GIfP65+MUm7pg/r5n7g2G6o5AT4TExIyYbe2BPM7+suby/OpM0W032ufBm4BFdf9I9fA4ZlIxWHr8kf+SJBZy08sWN0Jc5jEbl96n9Q3PN2E4/jiEPGYB32YCFd/fiCzUHyzQiTq5zcz6mqzJODZXNM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723453836; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=mLwrqQWXoVWH/6gHqQXwbYQC6P2NHek6lhYFUlJ/YTo=; b=h4Pj02uVLxVSo9oqVKG+7kgvDPvDhNMBUA0rHNM3JXpTeNj9WBAG+MP/kT/s2CqiFfnSivRDfjKf0c/CS1DJveMtABL8R/Q3LpjlHHQBwvtqYqZR6lOZYWL17ez1PO7mdppavbbscaZHQjvxtUgpQvNOco3nc5zbGWSVoxO2wYA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1723453836227770.3067775481318; Mon, 12 Aug 2024 02:10:36 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 0FCB41610; Mon, 12 Aug 2024 05:10:35 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 0D1E415C4; Mon, 12 Aug 2024 05:08:55 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 76FE713C8; Sun, 11 Aug 2024 12:54:39 -0400 (EDT) Received: from mail-41103.protonmail.ch (mail-41103.protonmail.ch [185.70.41.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id BB20C130F for ; Sun, 11 Aug 2024 12:54:38 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szczek.dev; s=protonmail3; t=1723395271; x=1723654471; bh=mLwrqQWXoVWH/6gHqQXwbYQC6P2NHek6lhYFUlJ/YTo=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=rTZPurt5oWQ5cGteZMx9wuZy1js994NeCBM5XwkReNZ3KzgrbHUsgurgwwnZH2kTP UX49+6AGRwJ51Ta4uvDHvRK9Qa9ad/JhgnXOg0AnLvxjLBfdWh4br8A8O2onR1N++u XzSnETQxW3/DfnVzg9Qph6oRqyoC/VtEXOPtem6zTVytusF2hZHuoHSt1aVygRSLAb OpDHL55D6uIXDM4L3NdVED9gfYb4eDILmL/zNhxjoDi26Aq0aVNM+ARal74HctCLH9 2AC2efNWy0DyGNRre0jluLHprYPBNDl84EwBFmEP6K9hiaMhcvBBGJobxodu15FvLt cWPo9tbQICSsQ== Date: Sun, 11 Aug 2024 16:54:26 +0000 To: "devel@lists.libvirt.org" From: =?utf-8?Q?Kamil_Szcz=C4=99k?= Subject: [PATCH v2 1/6] qemu: Improve PS/2 controller detection Message-ID: In-Reply-To: References: Feedback-ID: 37679334:user:proton X-Pm-Message-ID: 48282a382993ed7ded0c915b77b0575e89f5c5ea MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MailFrom: kamil@szczek.dev X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 Message-ID-Hash: Y773APF32OMRJROZZDIWNPTOG3YJSEHE X-Message-ID-Hash: Y773APF32OMRJROZZDIWNPTOG3YJSEHE X-Mailman-Approved-At: Mon, 12 Aug 2024 09:08:49 -0400 X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: pass (identity @szczek.dev) X-ZM-MESSAGEID: 1723453837613116600 Content-Type: text/plain; charset="utf-8" Up until now, we've assumed that all x86 machines have a PS/2 controller built-in. This assumption was correct until QEMU v4.2 introduced a new x86-based machine type - microvm. Due to this assumption, a pair of unnecessary PS/2 inputs are implicitly added to all microvm domains. This patch fixes that by whitelisting machine types which are known to include the i8042 PS/2 controller. Signed-off-by: Kamil Szcz=C4=99k --- src/qemu/qemu_capabilities.c | 20 ++++++++++++++++++++ src/qemu/qemu_capabilities.h | 5 ++++- src/qemu/qemu_domain.c | 28 +++++++++++++++++++++++++--- src/qemu/qemu_domain.h | 1 + src/qemu/qemu_validate.c | 4 ++-- 5 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 2f66a49711..2765fba7c8 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -1360,6 +1360,13 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes= [] =3D { { "vhost-user-vga", QEMU_CAPS_DEVICE_VHOST_USER_VGA }, { "ramfb", QEMU_CAPS_DEVICE_RAMFB }, { "max-arm-cpu", QEMU_CAPS_ARM_MAX_CPU }, + /* + * The i8042 controller is a built-in device and is not user-creatable. + * However, since not all machine types include this controller, you s= hould + * avoid checking for this capability directly. + * + * Prefer using virQEMUCapsSupportsI8042() instead. + */ { "i8042", QEMU_CAPS_DEVICE_I8042 }, { "rng-builtin", QEMU_CAPS_OBJECT_RNG_BUILTIN }, { "tpm-spapr", QEMU_CAPS_DEVICE_TPM_SPAPR }, @@ -6008,6 +6015,19 @@ virQEMUCapsSupportsVmport(virQEMUCaps *qemuCaps, STREQ(def->os.machine, "isapc"); } =20 +bool +virQEMUCapsSupportsI8042(virQEMUCaps *qemuCaps, + const virDomainDef *def) +{ + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_I8042)) + return false; + + return qemuDomainIsI440FX(def) || + qemuDomainIsQ35(def) || + qemuDomainIsXenFV(def) || + STREQ(def->os.machine, "isapc"); +} + =20 /* * The preferred machine to use if none is listed explicitly diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index edeb870e01..659efd9182 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -535,7 +535,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for = syntax-check */ QEMU_CAPS_SMP_DIES, /* -smp dies=3D */ =20 /* 350 */ - QEMU_CAPS_DEVICE_I8042, /* PS/2 controller */ + QEMU_CAPS_DEVICE_I8042, /* PS/2 controller, use virQEMUCapsSupportsI80= 42() to query this capability */ QEMU_CAPS_OBJECT_RNG_BUILTIN, /* -object rng-builtin */ X_QEMU_CAPS_VIRTIO_NET_FAILOVER, /* virtio-net-*.failover */ QEMU_CAPS_DEVICE_TPM_SPAPR, /* -device tpm-spapr */ @@ -718,6 +718,9 @@ void virQEMUCapsInitProcessCapsInterlock(virQEMUCaps *q= emuCaps); bool virQEMUCapsSupportsVmport(virQEMUCaps *qemuCaps, const virDomainDef *def); =20 +bool virQEMUCapsSupportsI8042(virQEMUCaps *qemuCaps, + const virDomainDef *def); + const char *virQEMUCapsGetBinary(virQEMUCaps *qemuCaps); virArch virQEMUCapsGetArch(virQEMUCaps *qemuCaps); unsigned int virQEMUCapsGetVersion(virQEMUCaps *qemuCaps); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index f87ba6ba51..2b4bb54efc 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -3925,9 +3925,10 @@ virXMLNamespace virQEMUDriverDomainXMLNamespace =3D { =20 =20 static int -qemuDomainDefAddImplicitInputDevice(virDomainDef *def) +qemuDomainDefAddImplicitInputDevice(virDomainDef *def, + virQEMUCaps *qemuCaps) { - if (ARCH_IS_X86(def->os.arch)) { + if (virQEMUCapsSupportsI8042(qemuCaps, def)) { if (virDomainDefMaybeAddInput(def, VIR_DOMAIN_INPUT_TYPE_MOUSE, VIR_DOMAIN_INPUT_BUS_PS2) < 0) @@ -4166,7 +4167,7 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *driver, bool addITCOWatchdog =3D false; =20 /* add implicit input devices */ - if (qemuDomainDefAddImplicitInputDevice(def) < 0) + if (qemuDomainDefAddImplicitInputDevice(def, qemuCaps) < 0) return -1; =20 /* Add implicit PCI root controller if the machine has one */ @@ -9177,6 +9178,21 @@ qemuDomainMachineIsMipsMalta(const char *machine, return false; } =20 +static bool +qemuDomainMachineIsXenFV(const char *machine, + const virArch arch) +{ + if (!ARCH_IS_X86(arch)) + return false; + + if (STREQ(machine, "xenfv") || + STRPREFIX(machine, "xenfv-")) { + return true; + } + + return false; +} + =20 /* You should normally avoid this function and use * qemuDomainHasBuiltinIDE() instead. */ @@ -9263,6 +9279,12 @@ qemuDomainIsLoongArchVirt(const virDomainDef *def) return qemuDomainMachineIsLoongArchVirt(def->os.machine, def->os.arch); } =20 +bool +qemuDomainIsXenFV(const virDomainDef *def) +{ + return qemuDomainMachineIsXenFV(def->os.machine, def->os.arch); +} + =20 bool qemuDomainHasPCIRoot(const virDomainDef *def) diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index af0bb04c45..1179b0d6dc 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -838,6 +838,7 @@ bool qemuDomainIsLoongArchVirt(const virDomainDef *def); bool qemuDomainIsRISCVVirt(const virDomainDef *def); bool qemuDomainIsPSeries(const virDomainDef *def); bool qemuDomainIsMipsMalta(const virDomainDef *def); +bool qemuDomainIsXenFV(const virDomainDef *def); bool qemuDomainHasPCIRoot(const virDomainDef *def); bool qemuDomainHasPCIeRoot(const virDomainDef *def); bool qemuDomainHasBuiltinIDE(const virDomainDef *def); diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index b885fe7c77..6f7aeababe 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -4868,8 +4868,8 @@ qemuValidateDomainDeviceDefInput(const virDomainInput= Def *input, int cap; int ccwCap; =20 - if (input->bus =3D=3D VIR_DOMAIN_INPUT_BUS_PS2 && !ARCH_IS_X86(def->os= .arch) && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_I8042)) { + if (input->bus =3D=3D VIR_DOMAIN_INPUT_BUS_PS2 && + !virQEMUCapsSupportsI8042(qemuCaps, def)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("%1$s is not supported by this QEMU binary"), virDomainInputBusTypeToString(input->bus)); --=20 2.45.0