From nobody Tue Dec 16 16:56:33 2025 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=fail; 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=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 1740065368307679.379725532216; Thu, 20 Feb 2025 07:29:28 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id AE3242189; Thu, 20 Feb 2025 10:29:27 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id AD4462231; Thu, 20 Feb 2025 10:26:56 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id C2A2121AC; Thu, 20 Feb 2025 10:26:48 -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 CA7B421AC for ; Thu, 20 Feb 2025 10:26:34 -0500 (EST) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-20-iptBn0w8Mr-cK1EHCTYAdw-1; Thu, 20 Feb 2025 10:26:33 -0500 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 68DE71800878 for ; Thu, 20 Feb 2025 15:26:32 +0000 (UTC) Received: from orkuz (unknown [10.43.3.115]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E89D619560A3 for ; Thu, 20 Feb 2025 15:26:31 +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=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740065194; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=szSjZsXHlqKzody158+w4L/WUjhodfSOeSvqKLxDGTQ=; b=ApHqDJzID+WoM/BaMrVoGATrCVAv4kT19n3YThm/Hieiizu/dTWK7KGIxCHeQco3BMX/br Sz7CUqdRukyB/HKw7ncCZE7CMdzVPfXyZL4LQinyxelWsvyoY6J5xEV9hRoC2GJ4e2oogG 747/IBWI6XFNpGVplDwLdWkUluKhwGA= X-MC-Unique: iptBn0w8Mr-cK1EHCTYAdw-1 X-Mimecast-MFC-AGG-ID: iptBn0w8Mr-cK1EHCTYAdw_1740065192 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [PATCH 07/13] virsh: Warn when hypervisor-cpu-* is used with host CPU Date: Thu, 20 Feb 2025 16:26:09 +0100 Message-ID: <2d0e6fb092e0f91a1e2f53cf415a0102cea59bcf.1740064957.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 03wAOVR83Goqs6C4aL2230cMRPLboJMAPUe2dqsAZck_1740065192 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 4224EP7ZEHP2IVLNRGWDPD5F7SDQDT5T X-Message-ID-Hash: 4224EP7ZEHP2IVLNRGWDPD5F7SDQDT5T 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: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1740065370388019000 Content-Type: text/plain; charset="utf-8" While using host CPU definition from capabilities XML is allowed for historical reasons, it will likely provide incorrect results and should be avoided. Signed-off-by: Jiri Denemark --- tools/virsh-host.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tools/virsh-host.c b/tools/virsh-host.c index f4e7324f42..418bd995da 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -1093,7 +1093,8 @@ cmdURI(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUS= ED) */ static char ** vshExtractCPUDefXMLs(vshControl *ctl, - const char *xmlFile) + const char *xmlFile, + bool hostCPUWarning) { g_auto(GStrv) cpus =3D NULL; g_autofree char *buffer =3D NULL; @@ -1137,6 +1138,8 @@ vshExtractCPUDefXMLs(vshControl *ctl, cpus =3D g_new0(char *, n + 1); =20 for (i =3D 0; i < n; i++) { + ctxt->node =3D nodes[i]; + /* If the user provided domain capabilities XML, we need to replace * element with . */ if (xmlStrEqual(nodes[i]->name, BAD_CAST "mode")) { @@ -1150,6 +1153,11 @@ vshExtractCPUDefXMLs(vshControl *ctl, } } =20 + if (hostCPUWarning && + virXPathBoolean("boolean(./feature[not(@policy)])", ctxt) =3D= =3D 1) { + vshWarn(ctl, "%s", _("using host CPU definition as input may p= rovide incorrect results")); + } + if (!(cpus[i] =3D virXMLNodeToString(xml, nodes[i]))) { vshSaveLibvirtError(); return NULL; @@ -1199,7 +1207,7 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(ctl, cmd, "file", &from) < 0) return false; =20 - if (!(cpus =3D vshExtractCPUDefXMLs(ctl, from))) + if (!(cpus =3D vshExtractCPUDefXMLs(ctl, from, false))) return false; =20 result =3D virConnectCompareCPU(priv->conn, cpus[0], flags); @@ -1268,7 +1276,7 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(ctl, cmd, "file", &from) < 0) return false; =20 - if (!(list =3D vshExtractCPUDefXMLs(ctl, from))) + if (!(list =3D vshExtractCPUDefXMLs(ctl, from, false))) return false; =20 if (!(result =3D virConnectBaselineCPU(priv->conn, (const char **)list, @@ -1612,7 +1620,7 @@ cmdHypervisorCPUCompare(vshControl *ctl, vshCommandOptString(ctl, cmd, "machine", &machine) < 0) return false; =20 - if (!(cpus =3D vshExtractCPUDefXMLs(ctl, from))) + if (!(cpus =3D vshExtractCPUDefXMLs(ctl, from, true))) return false; =20 result =3D virConnectCompareHypervisorCPU(priv->conn, emulator, arch, @@ -1736,7 +1744,7 @@ cmdHypervisorCPUBaseline(vshControl *ctl, VSH_ALTERNATIVE_OPTIONS_EXPR("file", from, "model", model); =20 if (from) { - if (!(list =3D vshExtractCPUDefXMLs(ctl, from))) + if (!(list =3D vshExtractCPUDefXMLs(ctl, from, true))) return false; } else { list =3D g_new0(char *, 2); --=20 2.48.1