[PATCH v1 06/10] qemu_domain.c: move size check for mem modules after alignment

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The loop in which 'hotplugmem' is calculated in qemuDomainAlignMemorySizes()
is throwing a max size overflow error. This is a reminiscent of
the time where this loop was doing the memory module alignment.

It doesn't hurt to leave the check here, but it makes more sense to
move it to the places where the alignments are being done.

Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
 src/conf/domain_conf.c |  9 +++++++++
 src/qemu/qemu_domain.c | 20 ++++++++++----------
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e4aecc9a4d..943084ef71 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -16852,11 +16852,20 @@ virDomainSEVDefParseXML(xmlNodePtr sevNode,
 int
 virDomainMemoryDeviceAlignSizePseries(virDomainMemoryDefPtr mem)
 {
+    unsigned long long maxmemkb = virMemoryMaxValue(false) >> 10;
     unsigned long long ppc64AlignSize =  256 * 1024;
     unsigned long long guestArea;
 
     if (mem->model != VIR_DOMAIN_MEMORY_MODEL_NVDIMM) {
         mem->size = VIR_ROUND_UP(mem->size, ppc64AlignSize);
+
+        if (mem->size > maxmemkb) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("size of memory module overflowed after "
+                             "alignment"));
+            return -1;
+        }
+
         return 0;
     }
 
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index c06c33f8d0..7067d49d7a 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5350,11 +5350,19 @@ qemuDomainMemoryDefPostParse(virDomainMemoryDefPtr mem,
     /* For x86, dimm memory modules require 2MiB alignment rather than
      * the 1MiB we are using elsewhere. */
     unsigned int x86MemoryModuleSizeAlignment = 2048;
+    unsigned long long maxmemkb = virMemoryMaxValue(false) >> 10;
 
     /* ppc64 memory module alignment is done in
      * virDomainMemoryDefPostParse(). */
-    if (!ARCH_IS_PPC64(arch))
+    if (!ARCH_IS_PPC64(arch)) {
         mem->size = VIR_ROUND_UP(mem->size, x86MemoryModuleSizeAlignment);
+        if (mem->size > maxmemkb) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("size of memory module overflowed after "
+                             "alignment"));
+            return -1;
+        }
+    }
 
     return 0;
 }
@@ -8093,17 +8101,9 @@ qemuDomainAlignMemorySizes(virDomainDefPtr def)
      *
      * - ppc64 mem modules are being aligned by virDomainMemoryDefPostParse();
      * - x86 mem modules are being aligned by qemuDomainMemoryDefPostParse(). */
-    for (i = 0; i < def->nmems; i++) {
+    for (i = 0; i < def->nmems; i++)
         hotplugmem += def->mems[i]->size;
 
-        if (def->mems[i]->size > maxmemkb) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("size of memory module '%zu' overflowed after "
-                             "alignment"), i);
-            return -1;
-        }
-    }
-
     /* Align initial memory size, if NUMA is present calculate it as total of
      * individual aligned NUMA node sizes. */
     if (initialmem == 0) {
-- 
2.26.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux