[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 08/15] pc: explicitly check maxmem limit when adding
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 08/15] pc: explicitly check maxmem limit when adding DIMM |
Date: |
Sun, 23 Nov 2014 13:18:06 +0200 |
From: Igor Mammedov <address@hidden>
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>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
hw/i386/pc.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 021ec44..d448d0d 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1545,6 +1545,37 @@ void qemu_register_pc_machine(QEMUMachine *m)
g_free(name);
}
+static int pc_dimm_count(Object *obj, void *opaque)
+{
+ int *count = opaque;
+
+ if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
+ (*count)++;
+ }
+
+ object_child_foreach(obj, pc_dimm_count, opaque);
+ return 0;
+}
+
+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)
{
@@ -1556,6 +1587,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;
@@ -1576,6 +1608,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;
--
MST
- [Qemu-devel] [PULL 00/15] pc, pci, misc bugfixes, Michael S. Tsirkin, 2014/11/23
- [Qemu-devel] [PULL 01/15] qemu-char: fix tcp_get_fds, Michael S. Tsirkin, 2014/11/23
- [Qemu-devel] [PULL 02/15] pc: kvm: check if KVM has free memory slots to avoid abort(), Michael S. Tsirkin, 2014/11/23
- [Qemu-devel] [PULL 03/15] pc: make pc_dimm_plug() more readble, Michael S. Tsirkin, 2014/11/23
- [Qemu-devel] [PULL 04/15] pc: limit DIMM address and size to page aligned values, Michael S. Tsirkin, 2014/11/23
- [Qemu-devel] [PULL 06/15] pc: align DIMM's address/size by backend's alignment value, Michael S. Tsirkin, 2014/11/23
- [Qemu-devel] [PULL 05/15] memory: expose alignment used for allocating RAM as MemoryRegion API, Michael S. Tsirkin, 2014/11/23
- [Qemu-devel] [PULL 07/15] pc: pc-dimm: use backend alignment during address auto allocation, Michael S. Tsirkin, 2014/11/23
- [Qemu-devel] [PULL 08/15] pc: explicitly check maxmem limit when adding DIMM,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 09/15] pc: count in 1Gb hugepage alignment when sizing hotplug-memory container, Michael S. Tsirkin, 2014/11/23
- [Qemu-devel] [PULL 10/15] hw/pci: fix crash on shpc error flow, Michael S. Tsirkin, 2014/11/23
- [Qemu-devel] [PULL 11/15] acpi-build: mark RAM dirty on table update, Michael S. Tsirkin, 2014/11/23
- [Qemu-devel] [PULL 12/15] target-i386: move generic memory hotplug methods to DSDTs, Michael S. Tsirkin, 2014/11/23
- [Qemu-devel] [PULL 13/15] pcie: fix typo in pcie_cap_deverr_init(), Michael S. Tsirkin, 2014/11/23
- [Qemu-devel] [PULL 14/15] pcie: fix improper use of negative value, Michael S. Tsirkin, 2014/11/23
- [Qemu-devel] [PULL 15/15] pc: acpi: mark all possible CPUs as enabled in SRAT, Michael S. Tsirkin, 2014/11/23
- Re: [Qemu-devel] [PULL 00/15] pc, pci, misc bugfixes, Peter Maydell, 2014/11/24