From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33972) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WxIWj-0007ss-CF for qemu-devel@nongnu.org; Wed, 18 Jun 2014 12:16:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WxIWd-0005nA-8d for qemu-devel@nongnu.org; Wed, 18 Jun 2014 12:15:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12151) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WxIWc-0005mh-48 for qemu-devel@nongnu.org; Wed, 18 Jun 2014 12:15:50 -0400 Date: Wed, 18 Jun 2014 19:16:11 +0300 From: "Michael S. Tsirkin" Message-ID: <1403108034-32054-12-git-send-email-mst@redhat.com> References: <1403108034-32054-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1403108034-32054-1-git-send-email-mst@redhat.com> Subject: [Qemu-devel] [PULL v2 011/106] pc-dimm: do not allow setting an in-use memdev List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Vasilis Liaskovitis , Anthony Liguori , Peter Crosthwaite , Igor Mammedov From: Igor Mammedov using the same memdev backend more than once will cause assertion at MemoryRegion mapping time because it's already mapped. Prevent it by checking that the associated MemoryRegion is not mapped. Signed-off-by: Igor Mammedov Acked-by: Peter Crosthwaite Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin MST: tweak commit log --- hw/mem/pc-dimm.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index b4937fe..3cced63 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -43,6 +43,21 @@ static void pc_dimm_get_size(Object *obj, Visitor *v, void *opaque, visit_type_int(v, &value, name, errp); } +static void pc_dimm_check_memdev_is_busy(Object *obj, const char *name, + Object *val, Error **errp) +{ + MemoryRegion *mr; + + mr = host_memory_backend_get_memory(MEMORY_BACKEND(val), errp); + if (memory_region_is_mapped(mr)) { + char *path = object_get_canonical_path_component(val); + error_setg(errp, "can't use already busy memdev: %s", path); + g_free(path); + } else { + qdev_prop_allow_set_link_before_realize(obj, name, val, errp); + } +} + static void pc_dimm_init(Object *obj) { PCDIMMDevice *dimm = PC_DIMM(obj); @@ -51,7 +66,7 @@ static void pc_dimm_init(Object *obj) NULL, NULL, NULL, &error_abort); object_property_add_link(obj, PC_DIMM_MEMDEV_PROP, TYPE_MEMORY_BACKEND, (Object **)&dimm->hostmem, - qdev_prop_allow_set_link_before_realize, + pc_dimm_check_memdev_is_busy, OBJ_PROP_LINK_UNREF_ON_RELEASE, &error_abort); } -- MST