]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Align memory module sizes to 2MiB
authorPeter Krempa <pkrempa@redhat.com>
Wed, 23 Sep 2015 11:07:03 +0000 (13:07 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 23 Sep 2015 11:54:54 +0000 (13:54 +0200)
My original implementation was based on a qemu version that still did
not have all the checks in place. Using sizes that would align to odd
megabyte increments will produce the following error:

qemu-kvm: -device pc-dimm,node=0,memdev=memdimm0,id=dimm0: backend memory size must be multiple of 0x200000
qemu-kvm: -device pc-dimm,node=0,memdev=memdimm0,id=dimm0: Device 'pc-dimm' could not be initialized

Introduce an alignment retrieval function for memory devices and use it
to align the devices separately and modify a test case to verify it.

src/qemu/qemu_domain.c
tests/qemuxml2argvdata/qemuxml2argv-memory-hotplug-dimm.xml

index 7d92f3a54478bbfa93899a14c11bd6f305a92c30..7680c87b84e0a5b5f614682102444d9a14f6c4fb 100644 (file)
@@ -3376,6 +3376,21 @@ qemuDomainGetMemorySizeAlignment(virDomainDefPtr def)
 }
 
 
+static unsigned long long
+qemuDomainGetMemoryModuleSizeAlignment(const virDomainDef *def,
+                                       const virDomainMemoryDef *mem ATTRIBUTE_UNUSED)
+{
+    /* PPC requires the memory sizes to be rounded to 256MiB increments, so
+     * round them to the size always. */
+    if (ARCH_IS_PPC64(def->os.arch))
+        return 256 * 1024;
+
+    /* dimm memory modules require 2MiB alignment rather than the 1MiB we are
+     * using elsewhere. */
+    return 2048;
+}
+
+
 int
 qemuDomainAlignMemorySizes(virDomainDefPtr def)
 {
@@ -3402,8 +3417,10 @@ qemuDomainAlignMemorySizes(virDomainDefPtr def)
     def->mem.max_memory = VIR_ROUND_UP(def->mem.max_memory, align);
 
     /* Align memory module sizes */
-    for (i = 0; i < def->nmems; i++)
+    for (i = 0; i < def->nmems; i++) {
+        align = qemuDomainGetMemoryModuleSizeAlignment(def, def->mems[i]);
         def->mems[i]->size = VIR_ROUND_UP(def->mems[i]->size, align);
+    }
 
     return 0;
 }
index 3f468ecb7cef2b7dbed662726094fc1d9f3ed701..fbcac841c1bfd323ae6aa036ebfe65c22508f60c 100644 (file)
@@ -36,7 +36,7 @@
     <memballoon model='virtio'/>
     <memory model='dimm'>
       <target>
-        <size unit='KiB'>524287</size>
+        <size unit='KiB'>523264</size>
         <node>0</node>
       </target>
     </memory>