pc-dimm: do not allow setting an in-use memdev
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 <imammedo@redhat.com> Acked-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> MST: tweak commit log
This commit is contained in:
parent
eed2bacfd2
commit
7bb5d6ade6
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user