From nobody Sun Feb 8 17:22:40 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1593006585; cv=none; d=zohomail.com; s=zohoarc; b=VYEqyrhaElff4S9pcHXBGG1WYB1eRyOIdFWoVqBFbwVpFmOVkSlkcQU+N4luxJmXCqBQ3LPPagr7tn5vfa/L4RVc9JjAMGhyhTOgge0qZMNHWkJfuH0aG/fod4jVolbfawulMlO3fILGOkXRrxLH7a7EAIOZptte1UXVUoXVzJQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593006585; 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; bh=w8YW0+8B6mctUVxKFSge+1aCQxnA5CE3PAHJqFcnq/Q=; b=idm38BWVUW3Y6l138tA39nnTF4SzE2MJpTDs+I54BpneGPAsJt62F50eaLpom21GZi2cXxKS4TZzsJd9WWzJye7gxiBhe6cJjiGY8mnKWMuM/R4n1HBoA2KLwYoYBw5Zu34PLTK6nMVprHJ+QVTNrlJaZ3095hxDnxRhsiAlgLY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 159300658518979.45128363128549; Wed, 24 Jun 2020 06:49:45 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-425-Np-eI3iKNFe7gd8uSapsww-1; Wed, 24 Jun 2020 09:49:41 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2E361EC1A9; Wed, 24 Jun 2020 13:49: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 0E09517D04; Wed, 24 Jun 2020 13:49: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 D54F0104918; Wed, 24 Jun 2020 13:49:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 05ODnOuc015703 for ; Wed, 24 Jun 2020 09:49:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id A11905DAA0; Wed, 24 Jun 2020 13:49:24 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 228BE5D9DC for ; Wed, 24 Jun 2020 13:49:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593006583; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=w8YW0+8B6mctUVxKFSge+1aCQxnA5CE3PAHJqFcnq/Q=; b=HRSPj2nP61CGP+lhcK2RPFcuQFKWp1G413dsh98H9m86I+0QLg8wsJqNUUJEvmmztsvbye 8jhv6LjTBnonH74OrJqazB7GZMo0yoN7MYfV42OMz7shbD8Kf65M3hNszvS6PWdpjtsFS7 X7sErZzXn79WAPWH4OpzSgvMvl2AIEs= X-MC-Unique: Np-eI3iKNFe7gd8uSapsww-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 09/13] conf: Validate NUMA HMAT configuration Date: Wed, 24 Jun 2020 15:49:07 +0200 Message-Id: <57be78b6c05e118caa87a3b3d64596ce448fb71f.1593006346.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" There are several restrictions, for instance @initiator and @target have to refer to existing NUMA nodes (daa), @cache has to refer to a defined cache level and so on. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza --- src/conf/domain_conf.c | 3 ++ src/conf/numa_conf.c | 99 ++++++++++++++++++++++++++++++++++++++++++ src/conf/numa_conf.h | 1 + 3 files changed, 103 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ce75831037..0d73968221 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7321,6 +7321,9 @@ virDomainDefValidateInternal(const virDomainDef *def, if (virDomainDefCputuneValidate(def) < 0) return -1; =20 + if (virDomainNumaDefValidate(def->numa) < 0) + return -1; + return 0; } =20 diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c index f510dfebce..bf8442eada 100644 --- a/src/conf/numa_conf.c +++ b/src/conf/numa_conf.c @@ -1363,6 +1363,105 @@ virDomainNumaDefFormatXML(virBufferPtr buf, } =20 =20 +int +virDomainNumaDefValidate(const virDomainNuma *def) +{ + size_t i; + size_t j; + + if (!def) + return 0; + + for (i =3D 0; i < def->nmem_nodes; i++) { + const virDomainNumaNode *node =3D &def->mem_nodes[i]; + g_autoptr(virBitmap) levelsSeen =3D virBitmapNewEmpty(); + + for (j =3D 0; j < node->ncaches; j++) { + const virDomainNumaCache *cache =3D &node->caches[j]; + + /* Relax this if there's ever fourth layer of cache */ + if (cache->level > 3) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Ain't nobody heard of that much cache le= vel")); + return -1; + } + + if (virBitmapIsBitSet(levelsSeen, cache->level)) { + virReportError(VIR_ERR_XML_ERROR, + _("Cache level '%u' already defined"), + cache->level); + return -1; + } + + if (virBitmapSetBitExpand(levelsSeen, cache->level)) + return -1; + } + } + + for (i =3D 0; i < def->nlatencies; i++) { + const virDomainNumaLatency *l =3D &def->latencies[i]; + + if (l->initiator >=3D def->nmem_nodes) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("'initiator' refers to a non-existent NUMA no= de")); + return -1; + } + + if (l->target >=3D def->nmem_nodes) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("'target' refers to a non-existent NUMA node"= )); + return -1; + } + + if (!def->mem_nodes[l->initiator].cpumask) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("NUMA nodes without CPUs can't be initiator")= ); + return -1; + } + + if (l->cache > 0) { + for (j =3D 0; j < def->mem_nodes[l->target].ncaches; j++) { + const virDomainNumaCache *cache =3D def->mem_nodes[l->targ= et].caches; + + if (l->cache =3D=3D cache->level) + break; + } + + if (j =3D=3D def->mem_nodes[l->target].ncaches) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("'cache' refers to a non-existent NUMA no= de cache")); + return -1; + } + } + + for (j =3D 0; j < i; j++) { + virDomainNumaLatencyPtr ll =3D &def->latencies[j]; + + if (l->type =3D=3D ll->type && + l->initiator =3D=3D ll->initiator && + l->target =3D=3D ll->target && + l->cache =3D=3D ll->cache && + l->accessType =3D=3D ll->accessType) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Duplicate info for NUMA latencies")); + return -1; + } + + + if (l->initiator !=3D l->target && + l->initiator =3D=3D ll->target && + l->target =3D=3D ll->initiator) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Link already defined")); + return -1; + } + } + } + + return 0; +} + + unsigned int virDomainNumaGetCPUCountTotal(virDomainNumaPtr numa) { diff --git a/src/conf/numa_conf.h b/src/conf/numa_conf.h index a7dc3190d3..6d6e9de551 100644 --- a/src/conf/numa_conf.h +++ b/src/conf/numa_conf.h @@ -216,6 +216,7 @@ bool virDomainNumatuneNodeSpecified(virDomainNumaPtr nu= matune, =20 int virDomainNumaDefParseXML(virDomainNumaPtr def, xmlXPathContextPtr ctxt= ); int virDomainNumaDefFormatXML(virBufferPtr buf, virDomainNumaPtr def); +int virDomainNumaDefValidate(const virDomainNuma *def); =20 unsigned int virDomainNumaGetCPUCountTotal(virDomainNumaPtr numa); =20 --=20 2.26.2