From nobody Mon Feb 9 16:51:27 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=1564063621; cv=none; d=zoho.com; s=zohoarc; b=ETb4Dmym7q9ELTX/8UtwLLin0+Yyww2hzwhsAsYGpL8u8VkJtV13XqNafnZBHh2iBpH9s3F8/o498Yl5A6zSLoJf70fchYToqZg1aSkd+7BWX06zmOoRexaoj47jFNOg5Pz2jvcVeuMnEmmDrb/r/kDvHAff1pDyWiNwxt/E8nA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564063621; 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=3/ZJPS9tfMUo2rWBpPhSNK5jR9GtqgXMYNR3lXDhRIE=; b=amLqFp1i1PKNLfJitnTPf3S6v6fv+1GpdooF9QLXK684xdLujE2qizS9tH8pDz5t88+M9L0lIyOnGFliHaQSQQ/qbXGDB82pz5bK2US5yUqJcKPVNiCWUiOeG5nLBaeRd7/kWQC+ERIJbMC1S8MTXs9dK7DNqJjRUcbeQo2ifKo= 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 1564063621655773.8391173511882; Thu, 25 Jul 2019 07:07:01 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1818913A82; Thu, 25 Jul 2019 14:07:00 +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 E2FE51001B0F; Thu, 25 Jul 2019 14:06:59 +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 9F9E9E166; Thu, 25 Jul 2019 14:06:59 +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 x6PE6uQE007609 for ; Thu, 25 Jul 2019 10:06:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5C20C6061B; Thu, 25 Jul 2019 14:06:56 +0000 (UTC) Received: from kinshicho.brq.redhat.com (unknown [10.43.2.73]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D430460606 for ; Thu, 25 Jul 2019 14:06:55 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Thu, 25 Jul 2019 16:06:23 +0200 Message-Id: <20190725140625.2397-10-abologna@redhat.com> In-Reply-To: <20190725140625.2397-1-abologna@redhat.com> References: <20190725140625.2397-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH RFC 09/11] cpu: Validate ARM 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 25 Jul 2019 14:07:00 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Andrea Bolognani --- src/cpu/cpu_arm.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c index 65d69c00af..fd504c8aef 100644 --- a/src/cpu/cpu_arm.c +++ b/src/cpu/cpu_arm.c @@ -23,7 +23,9 @@ =20 #include "viralloc.h" #include "cpu.h" +#include "cpu_map.h" #include "virstring.h" +#include "virxml.h" =20 #define VIR_FROM_THIS VIR_FROM_CPU =20 @@ -34,6 +36,153 @@ static const virArch archs[] =3D { VIR_ARCH_AARCH64, }; =20 +typedef struct _virCPUarmFeature virCPUarmFeature; +typedef virCPUarmFeature *virCPUarmFeaturePtr; +struct _virCPUarmFeature { + char *name; +}; + +static virCPUarmFeaturePtr +virCPUarmFeatureNew(void) +{ + virCPUarmFeaturePtr feature; + + if (VIR_ALLOC(feature) < 0) + return NULL; + + return feature; +} + +static void +virCPUarmFeatureFree(virCPUarmFeaturePtr feature) +{ + if (!feature) + return; + + VIR_FREE(feature->name); + VIR_FREE(feature); +} + +typedef struct _virCPUarmMap virCPUarmMap; +typedef virCPUarmMap *virCPUarmMapPtr; +struct _virCPUarmMap { + size_t nfeatures; + virCPUarmFeaturePtr *features; +}; + +static virCPUarmMapPtr +virCPUarmMapNew(void) +{ + virCPUarmMapPtr map; + + if (VIR_ALLOC(map) < 0) + return NULL; + + return map; +} + +static void +virCPUarmMapFree(virCPUarmMapPtr map) +{ + size_t i; + + if (!map) + return; + + for (i =3D 0; i < map->nfeatures; i++) + virCPUarmFeatureFree(map->features[i]); + VIR_FREE(map->features); + + VIR_FREE(map); +} + +static virCPUarmFeaturePtr +virCPUarmMapFeatureFind(virCPUarmMapPtr map, + const char *name) +{ + size_t i; + + for (i =3D 0; i < map->nfeatures; i++) { + if (STREQ(map->features[i]->name, name)) + return map->features[i]; + } + + return NULL; +} + +static int +virCPUarmMapFeatureParse(xmlXPathContextPtr ctxt ATTRIBUTE_UNUSED, + const char *name, + void *data) +{ + virCPUarmMapPtr map =3D data; + virCPUarmFeaturePtr feature; + int ret =3D -1; + + if (!(feature =3D virCPUarmFeatureNew())) + goto cleanup; + + if (VIR_STRDUP(feature->name, name) < 0) + goto cleanup; + + if (virCPUarmMapFeatureFind(map, feature->name)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("CPU feature %s already defined"), feature->name); + goto cleanup; + } + + if (VIR_APPEND_ELEMENT(map->features, map->nfeatures, feature) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + virCPUarmFeatureFree(feature); + + return ret; +} + +static virCPUarmMapPtr +virCPUarmLoadMap(void) +{ + virCPUarmMapPtr map; + + if (!(map =3D virCPUarmMapNew())) + goto error; + + if (cpuMapLoad("arm", NULL, virCPUarmMapFeatureParse, NULL, map) < 0) + goto error; + + return map; + + error: + virCPUarmMapFree(map); + + return NULL; +} + +static virCPUarmMapPtr cpuMap; + +int virCPUarmDriverOnceInit(void); +VIR_ONCE_GLOBAL_INIT(virCPUarmDriver); + +int +virCPUarmDriverOnceInit(void) +{ + if (!(cpuMap =3D virCPUarmLoadMap())) + return -1; + + return 0; +} + +static virCPUarmMapPtr +virCPUarmGetMap(void) +{ + if (virCPUarmDriverInitialize() < 0) + return NULL; + + return cpuMap; +} =20 static int virCPUarmUpdate(virCPUDefPtr guest, @@ -98,6 +247,27 @@ virCPUarmCompare(virCPUDefPtr host ATTRIBUTE_UNUSED, return VIR_CPU_COMPARE_IDENTICAL; } =20 +static int +virCPUarmValidateFeatures(virCPUDefPtr cpu) +{ + virCPUarmMapPtr map; + size_t i; + + if (!(map =3D virCPUarmGetMap())) + return -1; + + for (i =3D 0; i < cpu->nfeatures; i++) { + if (!virCPUarmMapFeatureFind(map, cpu->features[i].name)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown CPU feature: %s"), + cpu->features[i].name); + return -1; + } + } + + return 0; +} + struct cpuArchDriver cpuDriverArm =3D { .name =3D "arm", .arch =3D archs, @@ -107,4 +277,5 @@ struct cpuArchDriver cpuDriverArm =3D { .encode =3D NULL, .baseline =3D virCPUarmBaseline, .update =3D virCPUarmUpdate, + .validateFeatures =3D virCPUarmValidateFeatures, }; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list