From nobody Sat May 11 17:33:55 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1709573893551172.2396357549402; Mon, 4 Mar 2024 09:38:13 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4932619EB; Mon, 4 Mar 2024 12:38:12 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 49B4019AD; Mon, 4 Mar 2024 12:35:47 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 3CE3519C1; Mon, 4 Mar 2024 12:35:30 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 9515319F0 for ; Mon, 4 Mar 2024 12:34:48 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-288-Agfpm-VAP5O7rhKxkeinrg-1; Mon, 04 Mar 2024 12:34:44 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 78A963CBD4E0 for ; Mon, 4 Mar 2024 17:34:44 +0000 (UTC) Received: from orkuz (unknown [10.45.225.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C26739D6D for ; Mon, 4 Mar 2024 17:34:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: Agfpm-VAP5O7rhKxkeinrg-1 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [PATCH] qemu: Optimize CPU check='partial' for usable CPUs Date: Mon, 4 Mar 2024 18:34:29 +0100 Message-ID: <3def6c56f82d586e1f9e5056f3fde91c2e994c5d.1709573669.git.jdenemar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: 555TJYGDU2SHIRRY2HLOZNAARLNWEH6E X-Message-ID-Hash: 555TJYGDU2SHIRRY2HLOZNAARLNWEH6E X-MailFrom: jdenemar@redhat.com 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; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header 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: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1709573895143100001 Ideally check=3D'partial' would check exactly the features QEMU would want to enable when asked for a specific CPU model (and features). But there is no way we could ask QEMU how a specific CPU would look like. So we use our definition from CPU map, which may slightly differ as QEMU adds or removes features from CPU models, and thus we may end up checking features which QEMU would not enable while missing some required ones. We can do better in specific cases, though. If a CPU definition uses only a model and disabled features (or none at all), we already know whether QEMU can enable all features required by the CPU model as that's what we use to set usable=3D'yes' attribute in the list of available CPU models in domain capbilities XML. So when a usable CPU model is requested without asking for additional features (disabling features is fine) we can avoid our possible inaccurate check using our CPU map. For backward compatibility we only consider usable models. If a specified model is not usable, we still check it the old way and even let QEMU start it (and disable some features) in case our definition lacks some features compared to QEMU. Signed-off-by: Jiri Denemark Reviewed-by: Peter Krempa --- src/qemu/qemu_capabilities.c | 44 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_capabilities.h | 3 +++ src/qemu/qemu_process.c | 1 + 3 files changed, 48 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index e383d85920..cb9846dfcf 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2433,6 +2433,50 @@ virQEMUCapsIsCPUDeprecated(virQEMUCaps *qemuCaps, } =20 =20 +/** + * virQEMUCapsIsCPUUsable: + * @qemuCaps: QEMU capabilities + * @type: virtualization type (kvm vs tcg) + * @cpu: CPU definition to check, including explicitly configured features + * + * Checks whether @cpu is considered usable by QEMU, i.e., all features + * required by the CPU model are supported and can be enabled. If so, we c= an + * avoid checking the CPU according to its definition in the CPU map when + * starting a domain with check=3D'partial'. Our checks could be inaccurate + * anyway because QEMU might have changed the definition of the CPU model + * since we added it into the CPU map. + * + * Returns true iff @cpu is usable. + */ +bool +virQEMUCapsIsCPUUsable(virQEMUCaps *qemuCaps, + virDomainVirtType type, + virCPUDef *cpu) +{ + qemuMonitorCPUDefs *defs; + size_t i; + + if (!cpu->model || + !(defs =3D virQEMUCapsGetAccel(qemuCaps, type)->cpuModels)) + return false; + + /* CPU model usability is valid only when CPU def does not contain any + * features or all features are disabled. + */ + for (i =3D 0; i < cpu->nfeatures; i++) { + if (cpu->features[i].policy !=3D VIR_CPU_FEATURE_DISABLE) + return false; + } + + for (i =3D 0; i < defs->ncpus; i++) { + if (STREQ(defs->cpus[i].name, cpu->model)) + return defs->cpus[i].usable =3D=3D VIR_DOMCAPS_CPU_USABLE_YES; + } + + return false; +} + + bool virQEMUCapsIsMachineDeprecated(virQEMUCaps *qemuCaps, virDomainVirtType type, diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 486a4a6f63..ef1ad2c01c 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -770,6 +770,9 @@ const char *virQEMUCapsGetMachineDefaultCPU(virQEMUCaps= *qemuCaps, bool virQEMUCapsIsCPUDeprecated(virQEMUCaps *qemuCaps, virDomainVirtType type, const char *model); +bool virQEMUCapsIsCPUUsable(virQEMUCaps *qemuCaps, + virDomainVirtType type, + virCPUDef *cpu); bool virQEMUCapsIsMachineDeprecated(virQEMUCaps *qemuCaps, virDomainVirtType type, const char *machine); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 6e51d6586b..8e35d0a73f 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6288,6 +6288,7 @@ qemuProcessUpdateGuestCPU(virDomainDef *def, g_autoptr(virDomainCapsCPUModels) cpuModels =3D NULL; =20 if (def->cpu->check =3D=3D VIR_CPU_CHECK_PARTIAL && + !virQEMUCapsIsCPUUsable(qemuCaps, def->virtType, def->cpu) && virCPUCompare(hostarch, virQEMUCapsGetHostModel(qemuCaps, def->virtType, VIR_QEMU_CAPS_HOST_CPU_F= ULL), --=20 2.44.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org