[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 10/11] pc: explicitly check maxmem limit when adding
From: |
Igor Mammedov |
Subject: |
[Qemu-devel] [PATCH 10/11] pc: explicitly check maxmem limit when adding DIMM |
Date: |
Fri, 31 Oct 2014 16:38:41 +0000 |
Currently maxmem limit is not checked and depends on
hotplug region container not being able to fit more RAM
than maxmem. Do check explicitly so that it would
be possible to change hotplug container size later
to deal with fragmentation.
Signed-off-by: Igor Mammedov <address@hidden>
---
hw/i386/pc.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index ed50344..0d9681e 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1586,6 +1586,25 @@ void qemu_register_pc_machine(QEMUMachine *m)
g_free(name);
}
+static int pc_existing_dimms_capacity(Object *obj, void *opaque)
+{
+ Error *local_err = NULL;
+ uint64_t *size = opaque;
+
+ if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
+ (*size) += object_property_get_int(obj, PC_DIMM_SIZE_PROP, &local_err);
+
+ if (local_err) {
+ qerror_report_err(local_err);
+ error_free(local_err);
+ return 1;
+ }
+ }
+
+ object_child_foreach(obj, pc_dimm_count, opaque);
+ return 0;
+}
+
static void pc_dimm_plug(HotplugHandler *hotplug_dev,
DeviceState *dev, Error **errp)
{
@@ -1597,6 +1616,7 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
PCDIMMDevice *dimm = PC_DIMM(dev);
PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
MemoryRegion *mr = ddc->get_memory_region(dimm);
+ uint64_t existing_dimms_capacity = 0;
uint64_t align = TARGET_PAGE_SIZE;
uint64_t addr;
@@ -1617,6 +1637,19 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
goto out;
}
+ if (pc_existing_dimms_capacity(OBJECT(machine), &existing_dimms_capacity))
{
+ error_setg(&local_err, "failed to get total size of existing DIMMs");
+ goto out;
+ }
+
+ if (existing_dimms_capacity + memory_region_size(mr) >
+ machine->maxram_size - machine->ram_size) {
+ error_setg(&local_err, "not enough space, currently 0x%" PRIx64
+ " in use of total 0x%" PRIx64,
+ existing_dimms_capacity, machine->maxram_size);
+ goto out;
+ }
+
object_property_set_int(OBJECT(dev), addr, PC_DIMM_ADDR_PROP, &local_err);
if (local_err) {
goto out;
--
1.8.3.1
- [Qemu-devel] [PATCH 00/11] pc: kvm: memory hotplug fixes, Igor Mammedov, 2014/10/31
- [Qemu-devel] [PATCH 01/11] pc: kvm: check if KVM has free memory slots to avoid abort(), Igor Mammedov, 2014/10/31
- [Qemu-devel] [PATCH 02/11] kvm: provide API to query amount of memory slots supported by KVM, Igor Mammedov, 2014/10/31
- [Qemu-devel] [PATCH 03/11] pc: check if KVM has enough memory slots for DIMM devices, Igor Mammedov, 2014/10/31
- [Qemu-devel] [PATCH 04/11] pc: make pc_dimm_plug() more readble, Igor Mammedov, 2014/10/31
- [Qemu-devel] [PATCH 05/11] pc: limit DIMM address and size to page aligned values, Igor Mammedov, 2014/10/31
- [Qemu-devel] [PATCH 06/11] memory: expose alignment used for allocating RAM as MemoryRegion API, Igor Mammedov, 2014/10/31
- [Qemu-devel] [PATCH 08/11] pc: align DIMM's address/size by backend's alignment value, Igor Mammedov, 2014/10/31
- [Qemu-devel] [PATCH 07/11] pc: add pc_init_pci_2_1() and pc_compat_2_1(), Igor Mammedov, 2014/10/31
- [Qemu-devel] [PATCH 09/11] pc: pc-dimm: use backend alignment during address auto allocation, Igor Mammedov, 2014/10/31
- [Qemu-devel] [PATCH 10/11] pc: explicitly check maxmem limit when adding DIMM,
Igor Mammedov <=
- [Qemu-devel] [PATCH 11/11] pc: count in 1Gb hugepage alignment when sizing hotplug-memory container, Igor Mammedov, 2014/10/31