From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56902) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wzj6q-0001Hj-Az for qemu-devel@nongnu.org; Wed, 25 Jun 2014 05:03:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wzj6l-0004Sf-A5 for qemu-devel@nongnu.org; Wed, 25 Jun 2014 05:03:16 -0400 Received: from [59.151.112.132] (port=30570 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wzj6k-0004O2-T4 for qemu-devel@nongnu.org; Wed, 25 Jun 2014 05:03:11 -0400 From: Hu Tao Date: Wed, 25 Jun 2014 17:01:04 +0800 Message-ID: <1403686864-13567-1-git-send-email-hutao@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH] check if we have space left for hotplugged memory List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Yasunori Goto , Igor Mammedov , "Michael S. Tsirkin" If pc-dimm is specified on qemu command line, but only with -m size (aka not -m size,maxmem,slots) then qemu will core dump. This patch fixes the problem. Signed-off-by: Hu Tao --- hw/i386/pc.c | 5 +++++ hw/mem/pc-dimm.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 2cf22b1..1a0d96e 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1566,6 +1566,11 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev, goto out; } + if (memory_region_size(&pcms->hotplug_memory) == 0) { + error_setg(&local_err, "no space left for hotplugged memory."); + goto out; + } + addr = pc_dimm_get_free_addr(pcms->hotplug_memory_base, memory_region_size(&pcms->hotplug_memory), !addr ? NULL : &addr, diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index ad176b7..59ed9c0 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -146,6 +146,11 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, uint64_t new_addr, ret = 0; uint64_t address_space_end = address_space_start + address_space_size; + if (address_space_size == 0) { + error_setg(errp, "no space left for hotplugged memory."); + goto out; + } + assert(address_space_end > address_space_size); object_child_foreach(qdev_get_machine(), pc_dimm_built_list, &list); -- 1.9.3