render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 0ae283a1cb5224f3eb4fa32706e9b9c212577e51 Mon Sep 17 00:00:00 2001
Message-Id: <0ae283a1cb5224f3eb4fa32706e9b9c212577e51@dist-git>
From: Michal Privoznik <mprivozn@redhat.com>
Date: Wed, 7 Oct 2020 18:45:40 +0200
Subject: [PATCH] conf: Validate NUMA HMAT configuration
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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 <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
(cherry picked from commit f0611fe8830543d03d1871422f8c542453f0c8db)

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1749518

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Message-Id: <e8488a2e49fa251dd0e2ab51f5ab627e3b265440.1602087923.git.mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 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 3229d5ec95..f41559f33e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7144,6 +7144,9 @@ virDomainDefValidateInternal(const virDomainDef *def,
     if (virDomainDefCputuneValidate(def) < 0)
         return -1;
 
+    if (virDomainNumaDefValidate(def->numa) < 0)
+        return -1;
+
     return 0;
 }
 
diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c
index 5c764190c3..c90fb01bb6 100644
--- a/src/conf/numa_conf.c
+++ b/src/conf/numa_conf.c
@@ -1365,6 +1365,105 @@ virDomainNumaDefFormatXML(virBufferPtr buf,
 }
 
 
+int
+virDomainNumaDefValidate(const virDomainNuma *def)
+{
+    size_t i;
+    size_t j;
+
+    if (!def)
+        return 0;
+
+    for (i = 0; i < def->nmem_nodes; i++) {
+        const virDomainNumaNode *node = &def->mem_nodes[i];
+        g_autoptr(virBitmap) levelsSeen = virBitmapNewEmpty();
+
+        for (j = 0; j < node->ncaches; j++) {
+            const virDomainNumaCache *cache = &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 level"));
+                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 = 0; i < def->ninterconnects; i++) {
+        const virDomainNumaInterconnect *l = &def->interconnects[i];
+
+        if (l->initiator >= def->nmem_nodes) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("'initiator' refers to a non-existent NUMA node"));
+            return -1;
+        }
+
+        if (l->target >= 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 = 0; j < def->mem_nodes[l->target].ncaches; j++) {
+                const virDomainNumaCache *cache = def->mem_nodes[l->target].caches;
+
+                if (l->cache == cache->level)
+                    break;
+            }
+
+            if (j == def->mem_nodes[l->target].ncaches) {
+                virReportError(VIR_ERR_XML_ERROR, "%s",
+                               _("'cache' refers to a non-existent NUMA node cache"));
+                return -1;
+            }
+        }
+
+        for (j = 0; j < i; j++) {
+            const virDomainNumaInterconnect *ll = &def->interconnects[j];
+
+            if (l->type == ll->type &&
+                l->initiator == ll->initiator &&
+                l->target == ll->target &&
+                l->cache == ll->cache &&
+                l->accessType == ll->accessType) {
+                virReportError(VIR_ERR_XML_ERROR, "%s",
+                               _("Duplicate info for NUMA latencies"));
+                return -1;
+            }
+
+
+            if (l->initiator != l->target &&
+                l->initiator == ll->target &&
+                l->target == 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 5043c5a6d4..2963004c94 100644
--- a/src/conf/numa_conf.h
+++ b/src/conf/numa_conf.h
@@ -217,5 +217,6 @@ bool virDomainNumatuneNodeSpecified(virDomainNumaPtr numatune,
 
 int virDomainNumaDefParseXML(virDomainNumaPtr def, xmlXPathContextPtr ctxt);
 int virDomainNumaDefFormatXML(virBufferPtr buf, virDomainNumaPtr def);
+int virDomainNumaDefValidate(const virDomainNuma *def);
 
 unsigned int virDomainNumaGetCPUCountTotal(virDomainNumaPtr numa);
-- 
2.29.2