7a3408
From 64eebe80b8722e3abb3c51a9b7282ae7445fef58 Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <64eebe80b8722e3abb3c51a9b7282ae7445fef58@dist-git>
7a3408
From: Peter Krempa <pkrempa@redhat.com>
7a3408
Date: Wed, 23 Sep 2015 14:06:01 +0200
7a3408
Subject: [PATCH] qemu: Align memory module sizes to 2MiB
7a3408
7a3408
https://bugzilla.redhat.com/show_bug.cgi?id=1252685
7a3408
7a3408
My original implementation was based on a qemu version that still did
7a3408
not have all the checks in place. Using sizes that would align to odd
7a3408
megabyte increments will produce the following error:
7a3408
7a3408
qemu-kvm: -device pc-dimm,node=0,memdev=memdimm0,id=dimm0: backend memory size must be multiple of 0x200000
7a3408
qemu-kvm: -device pc-dimm,node=0,memdev=memdimm0,id=dimm0: Device 'pc-dimm' could not be initialized
7a3408
7a3408
Introduce an alignment retrieval function for memory devices and use it
7a3408
to align the devices separately and modify a test case to verify it.
7a3408
7a3408
(cherry picked from commit 624ec1c2f9157082db415711cd3b347d1af7f5c4)
7a3408
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/qemu/qemu_domain.c                                | 19 ++++++++++++++++++-
7a3408
 .../qemuxml2argv-memory-hotplug-dimm.xml              |  2 +-
7a3408
 2 files changed, 19 insertions(+), 2 deletions(-)
7a3408
7a3408
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
7a3408
index a47535e..1528cfd 100644
7a3408
--- a/src/qemu/qemu_domain.c
7a3408
+++ b/src/qemu/qemu_domain.c
7a3408
@@ -3173,6 +3173,21 @@ qemuDomainGetMemorySizeAlignment(virDomainDefPtr def)
7a3408
 }
7a3408
 
7a3408
 
7a3408
+static unsigned long long
7a3408
+qemuDomainGetMemoryModuleSizeAlignment(const virDomainDef *def,
7a3408
+                                       const virDomainMemoryDef *mem ATTRIBUTE_UNUSED)
7a3408
+{
7a3408
+    /* PPC requires the memory sizes to be rounded to 256MiB increments, so
7a3408
+     * round them to the size always. */
7a3408
+    if (ARCH_IS_PPC64(def->os.arch))
7a3408
+        return 256 * 1024;
7a3408
+
7a3408
+    /* dimm memory modules require 2MiB alignment rather than the 1MiB we are
7a3408
+     * using elsewhere. */
7a3408
+    return 2048;
7a3408
+}
7a3408
+
7a3408
+
7a3408
 int
7a3408
 qemuDomainAlignMemorySizes(virDomainDefPtr def)
7a3408
 {
7a3408
@@ -3199,8 +3214,10 @@ qemuDomainAlignMemorySizes(virDomainDefPtr def)
7a3408
     def->mem.max_memory = VIR_ROUND_UP(def->mem.max_memory, align);
7a3408
 
7a3408
     /* Align memory module sizes */
7a3408
-    for (i = 0; i < def->nmems; i++)
7a3408
+    for (i = 0; i < def->nmems; i++) {
7a3408
+        align = qemuDomainGetMemoryModuleSizeAlignment(def, def->mems[i]);
7a3408
         def->mems[i]->size = VIR_ROUND_UP(def->mems[i]->size, align);
7a3408
+    }
7a3408
 
7a3408
     return 0;
7a3408
 }
7a3408
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-memory-hotplug-dimm.xml b/tests/qemuxml2argvdata/qemuxml2argv-memory-hotplug-dimm.xml
7a3408
index 3f468ec..fbcac84 100644
7a3408
--- a/tests/qemuxml2argvdata/qemuxml2argv-memory-hotplug-dimm.xml
7a3408
+++ b/tests/qemuxml2argvdata/qemuxml2argv-memory-hotplug-dimm.xml
7a3408
@@ -36,7 +36,7 @@
7a3408
     <memballoon model='virtio'/>
7a3408
     <memory model='dimm'>
7a3408
       <target>
7a3408
-        <size unit='KiB'>524287</size>
7a3408
+        <size unit='KiB'>523264</size>
7a3408
         <node>0</node>
7a3408
       </target>
7a3408
     </memory>
7a3408
-- 
7a3408
2.5.3
7a3408