From nobody Wed Dec 4 19:07:15 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=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 173204267192939.05899244125203; Tue, 19 Nov 2024 10:57:51 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id DB16213F8; Tue, 19 Nov 2024 13:57:50 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 7601F14A7; Tue, 19 Nov 2024 13:51:27 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 11EE81456; Tue, 19 Nov 2024 13:51:23 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 3F28214A7 for ; Tue, 19 Nov 2024 13:50:40 -0500 (EST) Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-615-3KmWNe3NNW2KlHbghVvUmQ-1; Tue, 19 Nov 2024 13:50:38 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 698C81955F69 for ; Tue, 19 Nov 2024 18:50:37 +0000 (UTC) Received: from orkuz (unknown [10.45.226.13]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E190B30000DF for ; Tue, 19 Nov 2024 18:50:36 +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.5 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=1732042239; 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=ImzIME9O/wLOM3Wa1jJw5El2boTGVKPJU3BPaR/vExE=; b=DDzkciNe0SmB4uCEJV20WReEfe7fLPgXs6zWCEZJRLxWPOe1NOXd+c//hUxGqnUdnqVEax wVj1gPr/Ced+b+x4lElDvJLiyGWdQu6gZjIYOHWY2kHqfFdVbeUlZX+luAdDCI8O1T1gF8 iY3Xko2aLH9Zij3sUSuYRySlSZgIyuA= X-MC-Unique: 3KmWNe3NNW2KlHbghVvUmQ-1 X-Mimecast-MFC-AGG-ID: 3KmWNe3NNW2KlHbghVvUmQ From: Jiri Denemark To: devel@lists.libvirt.org Subject: [PATCH 12/32] cpu: Introduce virCPUCheckModel Date: Tue, 19 Nov 2024 19:49:48 +0100 Message-ID: <0fa4a72e164ee8a2abcb78b9ad2c1517d350df9f.1732039836.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: mTRXw3IvZ4L5mhIcbvk8s-VyMmtJCLJAiZzGX1eK7hY_1732042237 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: L36XT4NVDVPPH3Y7INTGFHCHCZ5OQKCN X-Message-ID-Hash: L36XT4NVDVPPH3Y7INTGFHCHCZ5OQKCN 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: 1732042672846116600 Content-Type: text/plain; charset="utf-8" A helper for checking whether a given CPU model is defined in the CPU map. Signed-off-by: Jiri Denemark Reviewed-by: Daniel P. Berrang=C3=A9 --- src/cpu/cpu.c | 25 +++++++++++++++++++++++++ src/cpu/cpu.h | 8 ++++++++ src/cpu/cpu_x86.c | 23 +++++++++++++++++++++++ src/libvirt_private.syms | 1 + 4 files changed, 57 insertions(+) diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 2b0d641e78..a83904f08e 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -1367,3 +1367,28 @@ virCPUArchIsSupported(virArch arch) =20 return false; } + + +/** + * virCPUCheckModel: + * @arch: CPU architecture + * @name: CPU model name + * + * Checks whether the CPU model exists in the CPU map. + * + * Returns true if @name is found in the CPU map, false otherwise. + */ +bool +virCPUCheckModel(virArch arch, + const char *name) +{ + struct cpuArchDriver *driver; + + if (!(driver =3D cpuGetSubDriver(arch))) + return false; + + if (!driver->checkModel) + return false; + + return driver->checkModel(name); +} diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index ff68c5da2d..19edae6880 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -140,6 +140,9 @@ typedef int (*virCPUArchGetCheckMode)(const char *modelName, bool *compat); =20 +typedef bool +(*virCPUArchCheckModel)(const char *name); + struct cpuArchDriver { const char *name; const virArch *arch; @@ -168,6 +171,7 @@ struct cpuArchDriver { virCPUArchDataIsIdentical dataIsIdentical; virCPUArchDataGetHost dataGetHost; virCPUArchGetCheckMode getCheckMode; + virCPUArchCheckModel checkModel; }; =20 =20 @@ -327,6 +331,10 @@ virCPUGetCheckMode(virArch arch, bool virCPUArchIsSupported(virArch arch); =20 +bool +virCPUCheckModel(virArch arch, + const char *name); + /* virCPUDataFormat and virCPUDataParse are implemented for unit tests onl= y and * have no real-life usage */ diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 7cfab8278d..a86e29064a 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -3653,6 +3653,28 @@ virCPUx86GetCheckMode(const char *modelName, } =20 =20 +/** + * virCPUx86CheckModel: + * @name: CPU model name + * + * Checks whether the CPU model exists in the CPU map. + * + * Returns true if @name is found in the CPU map, false otherwise. + */ +static bool +virCPUx86CheckModel(const char *name) +{ + virCPUx86Map *map; + virCPUx86Model *model; + + if (!(map =3D virCPUx86GetMap())) + return false; + + model =3D x86ModelFind(map, name); + return !!model; +} + + struct cpuArchDriver cpuDriverX86 =3D { .name =3D "x86", .arch =3D archs, @@ -3686,4 +3708,5 @@ struct cpuArchDriver cpuDriverX86 =3D { .dataGetHost =3D virCPUx86DataGetHost, #endif .getCheckMode =3D virCPUx86GetCheckMode, + .checkModel =3D virCPUx86CheckModel, }; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 5b9b44ef96..9b863b613e 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1527,6 +1527,7 @@ virCPUArchIsSupported; virCPUBaseline; virCPUCheckFeature; virCPUCheckForbiddenFeatures; +virCPUCheckModel; virCPUCompare; virCPUCompareUnusable; virCPUCompareXML; --=20 2.47.0