qemu_domain.c: align all pSeries mem modules when PARSE_ABI_UPDATE

qemuDomainAlignMemorySizes() has an operation order problem. We are
calculating 'initialmem' without aligning the memory modules first.
Since we're aligning the dimms afterwards this can create inconsistencies
in the end result. x86 has alignment of 1-2MiB and it's not severely
impacted by it, but pSeries works with 256MiB alignment and the difference
is noticeable.

This is the case of the existing 'memory-hotplug-ppc64-nonuma' test.
The test consists of a 2GiB (aligned value) guest with 2 ~520MiB dimms,
both unaligned. 'initialmem' is calculated by taking total_mem and
subtracting the dimms size (via virDomainDefGetMemoryInitial()), which
wil give us 2GiB - 520MiB - 520MiB, ending up with a little more than
an 1GiB of 'initialmem'. Note that this value is now unaligned, and
will be aligned up via VIR_ROUND_UP(), and we'll end up with 'initialmem'
of 1GiB + 256MiB. Given that the dimms are aligned later on, the end
result for QEMU is that the guest will have a 'mem' size of 1310720k,
plus the two 512 MiB dimms, exceeding in 256MiB the desired 2GiB
memory and currentMemory specified in the XML.

Existing guests can't be fixed without breaking ABI, but we have
code already in place to align pSeries NVDIMM modules for new guests.
Let's extend it to align all pSeries mem modules.

A new test, 'memory-hotplug-ppc64-nonuma-abi-update', a copy of the
existing 'memory-hotplug-ppc64-nonuma', was added to demonstrate the
result for new pSeries guests. For the same unaligned XML mentioned
above, after applying this patch:

- starting QEMU mem size without PARSE_ABI_UPDATE:
    -m size=1310720k,slots=16,maxmem=4194304k \ (no changes)

- starting QEMU mem size with PARSE_ABI_UPDATE:
    -m size=1048576k,slots=16,maxmem=4194304k \ (size fixed)

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Daniel Henrique Barboza 2020-11-18 16:58:34 -03:00
parent 167b5fd6a8
commit 198c1eb6b4
6 changed files with 92 additions and 4 deletions

View File

@ -5358,10 +5358,16 @@ qemuDomainMemoryDefPostParse(virDomainMemoryDefPtr mem, virArch arch,
* later on by qemuDomainAlignMemorySizes() to contemplate existing
* guests as well. */
if (parseFlags & VIR_DOMAIN_DEF_PARSE_ABI_UPDATE) {
if (ARCH_IS_PPC64(arch) &&
mem->model == VIR_DOMAIN_MEMORY_MODEL_NVDIMM &&
virDomainNVDimmAlignSizePseries(mem) < 0)
return -1;
if (ARCH_IS_PPC64(arch)) {
unsigned long long ppc64MemModuleAlign = 256 * 1024;
if (mem->model == VIR_DOMAIN_MEMORY_MODEL_NVDIMM) {
if (virDomainNVDimmAlignSizePseries(mem) < 0)
return -1;
} else {
mem->size = VIR_ROUND_UP(mem->size, ppc64MemModuleAlign);
}
}
}
return 0;

View File

@ -0,0 +1,29 @@
LC_ALL=C \
PATH=/bin \
HOME=/tmp/lib/domain--1-QEMUGuest1 \
USER=test \
LOGNAME=test \
XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \
XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \
XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
QEMU_AUDIO_DRV=none \
/usr/bin/qemu-system-ppc64 \
-name QEMUGuest1 \
-S \
-machine pseries,accel=kvm,usb=off,dump-guest-core=off \
-m size=1048576k,slots=16,maxmem=4194304k \
-realtime mlock=off \
-smp 1,sockets=1,cores=1,threads=1 \
-object memory-backend-ram,id=memdimm0,size=536870912 \
-device pc-dimm,memdev=memdimm0,id=dimm0,slot=0 \
-object memory-backend-ram,id=memdimm1,size=536870912 \
-device pc-dimm,memdev=memdimm1,id=dimm1,slot=1 \
-uuid 49545eb3-75e1-2d0a-acdd-f0294406c99e \
-display none \
-no-user-config \
-nodefaults \
-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,\
server,nowait \
-mon chardev=charmonitor,id=monitor,mode=control \
-rtc base=utc \
-no-shutdown

View File

@ -0,0 +1 @@
memory-hotplug-ppc64-nonuma.xml

View File

@ -3005,6 +3005,13 @@ mymain(void)
DO_TEST("memory-hotplug-ppc64-nonuma", QEMU_CAPS_KVM, QEMU_CAPS_DEVICE_PC_DIMM, QEMU_CAPS_NUMA,
QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE,
QEMU_CAPS_OBJECT_MEMORY_RAM, QEMU_CAPS_OBJECT_MEMORY_FILE);
DO_TEST_FULL("memory-hotplug-ppc64-nonuma-abi-update",
ARG_PARSEFLAGS, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE,
ARG_QEMU_CAPS,
QEMU_CAPS_KVM, QEMU_CAPS_DEVICE_PC_DIMM,
QEMU_CAPS_NUMA, QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE,
QEMU_CAPS_OBJECT_MEMORY_RAM,
QEMU_CAPS_OBJECT_MEMORY_FILE);
DO_TEST_CAPS_LATEST("memory-hotplug-nvdimm");
DO_TEST_CAPS_LATEST("memory-hotplug-nvdimm-access");
DO_TEST_CAPS_LATEST("memory-hotplug-nvdimm-label");

View File

@ -0,0 +1,38 @@
<domain type='kvm'>
<name>QEMUGuest1</name>
<uuid>49545eb3-75e1-2d0a-acdd-f0294406c99e</uuid>
<maxMemory slots='16' unit='KiB'>4194304</maxMemory>
<memory unit='KiB'>2097152</memory>
<currentMemory unit='KiB'>2097152</currentMemory>
<vcpu placement='static'>1</vcpu>
<os>
<type arch='ppc64' machine='pseries'>hvm</type>
<boot dev='hd'/>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-ppc64</emulator>
<controller type='usb' index='0' model='none'/>
<controller type='pci' index='0' model='pci-root'>
<model name='spapr-pci-host-bridge'/>
<target index='0'/>
</controller>
<memballoon model='none'/>
<panic model='pseries'/>
<memory model='dimm'>
<target>
<size unit='KiB'>524288</size>
</target>
<address type='dimm' slot='0'/>
</memory>
<memory model='dimm'>
<target>
<size unit='KiB'>524288</size>
</target>
<address type='dimm' slot='1'/>
</memory>
</devices>
</domain>

View File

@ -1232,6 +1232,13 @@ mymain(void)
DO_TEST("memory-hotplug-ppc64-nonuma", QEMU_CAPS_KVM, QEMU_CAPS_DEVICE_PC_DIMM, QEMU_CAPS_NUMA,
QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE,
QEMU_CAPS_OBJECT_MEMORY_RAM, QEMU_CAPS_OBJECT_MEMORY_FILE);
DO_TEST_FULL("memory-hotplug-ppc64-nonuma-abi-update", WHEN_BOTH,
ARG_PARSEFLAGS, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE,
ARG_QEMU_CAPS,
QEMU_CAPS_KVM, QEMU_CAPS_DEVICE_PC_DIMM,
QEMU_CAPS_NUMA, QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE,
QEMU_CAPS_OBJECT_MEMORY_RAM,
QEMU_CAPS_OBJECT_MEMORY_FILE, QEMU_CAPS_LAST);
DO_TEST("memory-hotplug", NONE);
DO_TEST("memory-hotplug-dimm", QEMU_CAPS_DEVICE_PC_DIMM);
DO_TEST("memory-hotplug-nvdimm", QEMU_CAPS_DEVICE_NVDIMM);