From nobody Mon Feb 9 01:31:18 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560937302; cv=none; d=zoho.com; s=zohoarc; b=OWRj66LN4VkEKXsjKkJceR5ONmFKqBYM4YI6guQsUA17roafoJ54TQJK0+cOwQEqBxxtUjDoLIysqBeJtFqu2xfr/Iq7mNDrsqGXnJ3V5Z8R0xayv82eLfmA4z857tm7QFq2J4+4UnWc5Dv1h/OGInzOSFCtOI8bEJrCQID9YAE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560937302; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=MNLso1chqSPGX0BR8FRtqF3MeB/1uJhgb7Is/fm26Mw=; b=e6Swf2MzgWrUTipkD/BrpClTrvxzq/flZysBu37nWh3+VlIDNRwmBH/i/qPp+rZQf82IPceWEexMwLem7EKutm4iNp4bvBQ12Dfnqm09qEjuOWJ0RSp7lSnXebLDrjM1blyuX4hL1/THC1pkRqlApyBIa6ya0ZPxaLVXd3kSQac= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1560937302985743.382205568424; Wed, 19 Jun 2019 02:41:42 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 74734C05B1CA; Wed, 19 Jun 2019 09:41:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4C37A5C207; Wed, 19 Jun 2019 09:41:36 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0D028206D4; Wed, 19 Jun 2019 09:41:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5J9cTxs024322 for ; Wed, 19 Jun 2019 05:38:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id A3D1B608C2; Wed, 19 Jun 2019 09:38:29 +0000 (UTC) Received: from orkuz.int.mamuti.net (ovpn-204-21.brq.redhat.com [10.40.204.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 759C918854 for ; Wed, 19 Jun 2019 09:38:29 +0000 (UTC) Received: by orkuz.int.mamuti.net (Postfix, from userid 500) id 9EB342A2D1E; Wed, 19 Jun 2019 11:38:23 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 19 Jun 2019 11:38:08 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 11/24] qemu: Add APIs for translating CPU features X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 19 Jun 2019 09:41:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" So far we always used libvirt's name of each CPU feature relying on backward compatible aliases in QEMU. The new translation table can be used whenever QEMU mandates or prefers canonical feature names. Signed-off-by: Jiri Denemark --- src/qemu/qemu_capabilities.c | 64 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_capabilities.h | 8 +++++ 2 files changed, 72 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 5f989a2613..712933c13a 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2848,6 +2848,70 @@ virQEMUCapsCPUFilterFeatures(const char *name, } =20 =20 +typedef struct _virQEMUCapsCPUFeatureTranslationTable virQEMUCapsCPUFeatur= eTranslationTable; +typedef virQEMUCapsCPUFeatureTranslationTable *virQEMUCapsCPUFeatureTransl= ationTablePtr; +struct _virQEMUCapsCPUFeatureTranslationTable { + const char *libvirt; + const char *qemu; +}; + +virQEMUCapsCPUFeatureTranslationTable virQEMUCapsCPUFeaturesX86[] =3D { + {"cmp_legacy", "cmp-legacy"}, + {"ds_cpl", "ds-cpl"}, + {"fxsr_opt", "fxsr-opt"}, + {"kvm_pv_eoi", "kvm-pv-eoi"}, + {"kvm_pv_unhalt", "kvm-pv-unhalt"}, + {"lahf_lm", "lahf-lm"}, + {"nodeid_msr", "nodeid-msr"}, + {"pclmuldq", "pclmulqdq"}, + {"perfctr_core", "perfctr-core"}, + {"perfctr_nb", "perfctr-nb"}, + {"tsc_adjust", "tsc-adjust"}, + {NULL, NULL} +}; + + +static const char * +virQEMUCapsCPUFeatureTranslate(virQEMUCapsPtr qemuCaps, + const char *feature, + bool reversed) +{ + virQEMUCapsCPUFeatureTranslationTablePtr table =3D NULL; + virQEMUCapsCPUFeatureTranslationTablePtr entry; + + if (ARCH_IS_X86(qemuCaps->arch)) + table =3D virQEMUCapsCPUFeaturesX86; + + if (!table || !feature) + return feature; + + for (entry =3D table; entry->libvirt; entry++) { + const char *key =3D reversed ? entry->qemu : entry->libvirt; + + if (STREQ(feature, key)) + return reversed ? entry->libvirt : entry->qemu; + } + + return feature; +} + + +const char * +virQEMUCapsCPUFeatureToQEMU(virQEMUCapsPtr qemuCaps, + const char *feature) +{ + return virQEMUCapsCPUFeatureTranslate(qemuCaps, feature, false); +} + + +const char * +virQEMUCapsCPUFeatureFromQEMU(virQEMUCapsPtr qemuCaps, + const char *feature) +{ + return virQEMUCapsCPUFeatureTranslate(qemuCaps, feature, true); +} + + /** * Returns 0 when host CPU model provided by QEMU was filled in qemuCaps, * 1 when the caller should fall back to using virCapsPtr->host.c= pu, diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 3032d4edcd..685a77a8b0 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -646,6 +646,14 @@ bool virQEMUCapsGuestIsNative(virArch host, bool virQEMUCapsCPUFilterFeatures(const char *name, void *opaque); =20 +const char * +virQEMUCapsCPUFeatureToQEMU(virQEMUCapsPtr qemuCaps, + const char *feature); + +const char * +virQEMUCapsCPUFeatureFromQEMU(virQEMUCapsPtr qemuCaps, + const char *feature); + virSEVCapabilityPtr virQEMUCapsGetSEVCapabilities(virQEMUCapsPtr qemuCaps); =20 --=20 2.22.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list