[libvirt] [PATCH 0/3] qemu: Add baybysitting for memory hotplug users

Add sanity checks for some unsupported/invalid configs of memory devices. Peter Krempa (3): qemu: conf: Reject memory device if it would exceed configured max size qemu: command: Validate that memory devices slot ID is in range qemu: Validate available slot count for memory devices src/conf/domain_conf.c | 11 +++++++++++ src/qemu/qemu_command.c | 19 ++++++++++++++++++- src/qemu/qemu_command.h | 1 + src/qemu/qemu_driver.c | 6 ++++++ src/qemu/qemu_hotplug.c | 8 +++++++- 5 files changed, 43 insertions(+), 2 deletions(-) -- 2.3.5

If the added memory device would exceed the maximum memory size, reject it. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1216046 --- src/conf/domain_conf.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index fc48ed5..7e4f0af 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -21661,6 +21661,17 @@ virDomainDefCompatibleDevice(virDomainDefPtr def, return -1; } + if (dev->type == VIR_DOMAIN_DEVICE_MEMORY) { + unsigned long long sz = dev->data.memory->size; + + if ((virDomainDefGetMemoryActual(def) + sz) > def->mem.max_memory) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Attaching memory device with size '%llu' would " + "exceed domain's maxMemory config"), sz); + return -1; + } + } + return 0; } -- 2.3.5

slot id, if specified, has to be less than the slots count. --- src/qemu/qemu_command.c | 11 ++++++++++- src/qemu/qemu_command.h | 1 + src/qemu/qemu_hotplug.c | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index ba15dc9..21daf18 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4946,6 +4946,7 @@ qemuBuildMemoryDimmBackendStr(virDomainMemoryDefPtr mem, char * qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem, + virDomainDefPtr def, virQEMUCapsPtr qemuCaps) { virBuffer buf = VIR_BUFFER_INITIALIZER; @@ -4972,6 +4973,14 @@ qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem, return NULL; } + if (mem->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM && + mem->info.addr.dimm.slot >= def->mem.memory_slots) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("memory device slot '%u' exceeds slots count '%u'"), + mem->info.addr.dimm.slot, def->mem.memory_slots); + return NULL; + } + virBufferAsprintf(&buf, "pc-dimm,node=%d,memdev=mem%s,id=%s", mem->targetNode, mem->info.alias, mem->info.alias); @@ -8821,7 +8830,7 @@ qemuBuildCommandLine(virConnectPtr conn, qemuCaps, cfg))) goto error; - if (!(dimmStr = qemuBuildMemoryDeviceStr(def->mems[i], qemuCaps))) { + if (!(dimmStr = qemuBuildMemoryDeviceStr(def->mems[i], def, qemuCaps))) { VIR_FREE(backStr); goto error; } diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index a29db41..675eb62 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -175,6 +175,7 @@ int qemuBuildMemoryBackendStr(unsigned long long size, bool force); char *qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem, + virDomainDefPtr def, virQEMUCapsPtr qemuCaps); /* Legacy, pre device support */ diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 58224bf..ba92320 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1736,7 +1736,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, if (virAsprintf(&objalias, "mem%s", mem->info.alias) < 0) goto cleanup; - if (!(devstr = qemuBuildMemoryDeviceStr(mem, priv->qemuCaps))) + if (!(devstr = qemuBuildMemoryDeviceStr(mem, vm->def, priv->qemuCaps))) goto cleanup; qemuDomainMemoryDeviceAlignSize(mem); -- 2.3.5

While qemu would reject the configuration we can check whether it makes sense to plug the device upfront. --- src/qemu/qemu_command.c | 8 ++++++++ src/qemu/qemu_driver.c | 6 ++++++ src/qemu/qemu_hotplug.c | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 21daf18..e62833f 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8822,6 +8822,14 @@ qemuBuildCommandLine(virConnectPtr conn, /* memory hotplug requires NUMA to be enabled - we already checked * that memory devices are present only when NUMA is */ + + if (def->nmems > def->mem.memory_slots) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("memory device count '%zu' exceeds slots count '%u'"), + def->nmems, def->mem.memory_slots); + goto error; + } + for (i = 0; i < def->nmems; i++) { char *backStr; char *dimmStr; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 80463f2..d181439 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -8489,6 +8489,12 @@ qemuDomainAttachDeviceConfig(virQEMUCapsPtr qemuCaps, break; case VIR_DOMAIN_DEVICE_MEMORY: + if (vmdef->nmems == vmdef->mem.memory_slots) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("no free memory device slot available")); + return -1; + } + if (virDomainMemoryInsert(vmdef, dev->data.memory) < 0) return -1; dev->data.memory = NULL; diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index ba92320..613b728 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1730,6 +1730,12 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, int id; int ret = -1; + if (vm->def->nmems == vm->def->mem.memory_slots) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("no free memory device slot available")); + goto cleanup; + } + if (virAsprintf(&mem->info.alias, "dimm%zu", vm->def->nmems) < 0) goto cleanup; -- 2.3.5

On Tue, Apr 28, 2015 at 17:37:42 +0200, Peter Krempa wrote:
Add sanity checks for some unsupported/invalid configs of memory devices.
Peter Krempa (3): qemu: conf: Reject memory device if it would exceed configured max size qemu: command: Validate that memory devices slot ID is in range qemu: Validate available slot count for memory devices
src/conf/domain_conf.c | 11 +++++++++++ src/qemu/qemu_command.c | 19 ++++++++++++++++++- src/qemu/qemu_command.h | 1 + src/qemu/qemu_driver.c | 6 ++++++ src/qemu/qemu_hotplug.c | 8 +++++++- 5 files changed, 43 insertions(+), 2 deletions(-)
ACK series

On Tue, Apr 28, 2015 at 20:21:27 +0200, Jiri Denemark wrote:
On Tue, Apr 28, 2015 at 17:37:42 +0200, Peter Krempa wrote:
Add sanity checks for some unsupported/invalid configs of memory devices.
Peter Krempa (3): qemu: conf: Reject memory device if it would exceed configured max size qemu: command: Validate that memory devices slot ID is in range qemu: Validate available slot count for memory devices
src/conf/domain_conf.c | 11 +++++++++++ src/qemu/qemu_command.c | 19 ++++++++++++++++++- src/qemu/qemu_command.h | 1 + src/qemu/qemu_driver.c | 6 ++++++ src/qemu/qemu_hotplug.c | 8 +++++++- 5 files changed, 43 insertions(+), 2 deletions(-)
ACK series
Pushed; Thanks. Peter
participants (2)
-
Jiri Denemark
-
Peter Krempa