render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
397dc2
From 0ae283a1cb5224f3eb4fa32706e9b9c212577e51 Mon Sep 17 00:00:00 2001
397dc2
Message-Id: <0ae283a1cb5224f3eb4fa32706e9b9c212577e51@dist-git>
397dc2
From: Michal Privoznik <mprivozn@redhat.com>
397dc2
Date: Wed, 7 Oct 2020 18:45:40 +0200
397dc2
Subject: [PATCH] conf: Validate NUMA HMAT configuration
397dc2
MIME-Version: 1.0
397dc2
Content-Type: text/plain; charset=UTF-8
397dc2
Content-Transfer-Encoding: 8bit
397dc2
397dc2
There are several restrictions, for instance @initiator and
397dc2
@target have to refer to existing NUMA nodes (daa), @cache has to
397dc2
refer to a defined cache level and so on.
397dc2
397dc2
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
397dc2
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
397dc2
(cherry picked from commit f0611fe8830543d03d1871422f8c542453f0c8db)
397dc2
397dc2
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1749518
397dc2
397dc2
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
397dc2
Message-Id: <e8488a2e49fa251dd0e2ab51f5ab627e3b265440.1602087923.git.mprivozn@redhat.com>
397dc2
Reviewed-by: Ján Tomko <jtomko@redhat.com>
397dc2
---
397dc2
 src/conf/domain_conf.c |  3 ++
397dc2
 src/conf/numa_conf.c   | 99 ++++++++++++++++++++++++++++++++++++++++++
397dc2
 src/conf/numa_conf.h   |  1 +
397dc2
 3 files changed, 103 insertions(+)
397dc2
397dc2
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
397dc2
index 3229d5ec95..f41559f33e 100644
397dc2
--- a/src/conf/domain_conf.c
397dc2
+++ b/src/conf/domain_conf.c
397dc2
@@ -7144,6 +7144,9 @@ virDomainDefValidateInternal(const virDomainDef *def,
397dc2
     if (virDomainDefCputuneValidate(def) < 0)
397dc2
         return -1;
397dc2
 
397dc2
+    if (virDomainNumaDefValidate(def->numa) < 0)
397dc2
+        return -1;
397dc2
+
397dc2
     return 0;
397dc2
 }
397dc2
 
397dc2
diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c
397dc2
index 5c764190c3..c90fb01bb6 100644
397dc2
--- a/src/conf/numa_conf.c
397dc2
+++ b/src/conf/numa_conf.c
397dc2
@@ -1365,6 +1365,105 @@ virDomainNumaDefFormatXML(virBufferPtr buf,
397dc2
 }
397dc2
 
397dc2
 
397dc2
+int
397dc2
+virDomainNumaDefValidate(const virDomainNuma *def)
397dc2
+{
397dc2
+    size_t i;
397dc2
+    size_t j;
397dc2
+
397dc2
+    if (!def)
397dc2
+        return 0;
397dc2
+
397dc2
+    for (i = 0; i < def->nmem_nodes; i++) {
397dc2
+        const virDomainNumaNode *node = &def->mem_nodes[i];
397dc2
+        g_autoptr(virBitmap) levelsSeen = virBitmapNewEmpty();
397dc2
+
397dc2
+        for (j = 0; j < node->ncaches; j++) {
397dc2
+            const virDomainNumaCache *cache = &node->caches[j];
397dc2
+
397dc2
+            /* Relax this if there's ever fourth layer of cache */
397dc2
+            if (cache->level > 3) {
397dc2
+                virReportError(VIR_ERR_XML_ERROR, "%s",
397dc2
+                               _("Ain't nobody heard of that much cache level"));
397dc2
+                return -1;
397dc2
+            }
397dc2
+
397dc2
+            if (virBitmapIsBitSet(levelsSeen, cache->level)) {
397dc2
+                virReportError(VIR_ERR_XML_ERROR,
397dc2
+                               _("Cache level '%u' already defined"),
397dc2
+                               cache->level);
397dc2
+                return -1;
397dc2
+            }
397dc2
+
397dc2
+            if (virBitmapSetBitExpand(levelsSeen, cache->level))
397dc2
+                return -1;
397dc2
+        }
397dc2
+    }
397dc2
+
397dc2
+    for (i = 0; i < def->ninterconnects; i++) {
397dc2
+        const virDomainNumaInterconnect *l = &def->interconnects[i];
397dc2
+
397dc2
+        if (l->initiator >= def->nmem_nodes) {
397dc2
+            virReportError(VIR_ERR_XML_ERROR, "%s",
397dc2
+                           _("'initiator' refers to a non-existent NUMA node"));
397dc2
+            return -1;
397dc2
+        }
397dc2
+
397dc2
+        if (l->target >= def->nmem_nodes) {
397dc2
+            virReportError(VIR_ERR_XML_ERROR, "%s",
397dc2
+                           _("'target' refers to a non-existent NUMA node"));
397dc2
+            return -1;
397dc2
+        }
397dc2
+
397dc2
+        if (!def->mem_nodes[l->initiator].cpumask) {
397dc2
+            virReportError(VIR_ERR_XML_ERROR, "%s",
397dc2
+                           _("NUMA nodes without CPUs can't be initiator"));
397dc2
+            return -1;
397dc2
+        }
397dc2
+
397dc2
+        if (l->cache > 0) {
397dc2
+            for (j = 0; j < def->mem_nodes[l->target].ncaches; j++) {
397dc2
+                const virDomainNumaCache *cache = def->mem_nodes[l->target].caches;
397dc2
+
397dc2
+                if (l->cache == cache->level)
397dc2
+                    break;
397dc2
+            }
397dc2
+
397dc2
+            if (j == def->mem_nodes[l->target].ncaches) {
397dc2
+                virReportError(VIR_ERR_XML_ERROR, "%s",
397dc2
+                               _("'cache' refers to a non-existent NUMA node cache"));
397dc2
+                return -1;
397dc2
+            }
397dc2
+        }
397dc2
+
397dc2
+        for (j = 0; j < i; j++) {
397dc2
+            const virDomainNumaInterconnect *ll = &def->interconnects[j];
397dc2
+
397dc2
+            if (l->type == ll->type &&
397dc2
+                l->initiator == ll->initiator &&
397dc2
+                l->target == ll->target &&
397dc2
+                l->cache == ll->cache &&
397dc2
+                l->accessType == ll->accessType) {
397dc2
+                virReportError(VIR_ERR_XML_ERROR, "%s",
397dc2
+                               _("Duplicate info for NUMA latencies"));
397dc2
+                return -1;
397dc2
+            }
397dc2
+
397dc2
+
397dc2
+            if (l->initiator != l->target &&
397dc2
+                l->initiator == ll->target &&
397dc2
+                l->target == ll->initiator) {
397dc2
+                virReportError(VIR_ERR_XML_ERROR, "%s",
397dc2
+                               _("Link already defined"));
397dc2
+                return -1;
397dc2
+            }
397dc2
+        }
397dc2
+    }
397dc2
+
397dc2
+    return 0;
397dc2
+}
397dc2
+
397dc2
+
397dc2
 unsigned int
397dc2
 virDomainNumaGetCPUCountTotal(virDomainNumaPtr numa)
397dc2
 {
397dc2
diff --git a/src/conf/numa_conf.h b/src/conf/numa_conf.h
397dc2
index 5043c5a6d4..2963004c94 100644
397dc2
--- a/src/conf/numa_conf.h
397dc2
+++ b/src/conf/numa_conf.h
397dc2
@@ -217,5 +217,6 @@ bool virDomainNumatuneNodeSpecified(virDomainNumaPtr numatune,
397dc2
 
397dc2
 int virDomainNumaDefParseXML(virDomainNumaPtr def, xmlXPathContextPtr ctxt);
397dc2
 int virDomainNumaDefFormatXML(virBufferPtr buf, virDomainNumaPtr def);
397dc2
+int virDomainNumaDefValidate(const virDomainNuma *def);
397dc2
 
397dc2
 unsigned int virDomainNumaGetCPUCountTotal(virDomainNumaPtr numa);
397dc2
-- 
397dc2
2.29.2
397dc2