Introduce a parameter, named "reserve-label-data", if it is false which indicates that QEMU does not reserve any region on the backend memory to support label data. It is a 'label-less' NVDIMM device mode that linux will use whole memory on the device as a single namesapce This is useful for the users who want to pass whole nvdimm device and make its data completely be visible to guest The parameter is false on default Signed-off-by: Xiao Guangrong <guangrong.xiao@xxxxxxxxxxxxxxx> --- hw/acpi/nvdimm.c | 20 ++++++++++++++++++++ hw/mem/nvdimm.c | 37 ++++++++++++++++++++++++++++++++----- include/hw/mem/nvdimm.h | 6 ++++++ 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c index 5e72ca8..c5a50ea 100644 --- a/hw/acpi/nvdimm.c +++ b/hw/acpi/nvdimm.c @@ -545,6 +545,13 @@ static void nvdimm_dsm_func_get_label_data(NVDIMMDevice *nvdimm, nvdimm_debug("Read Label Data: offset %#x length %#x.\n", get_label_data->offset, get_label_data->length); + if (!nvdimm->reserve_label_data) { + nvdimm_debug("read label request on the device without " + "label data reserved.\n"); + status = NVDIMM_DSM_STATUS_NOT_SUPPORTED; + goto exit; + } + if (nvdimm->label_size < get_label_data->offset + get_label_data->length) { nvdimm_debug("position %#x is beyond label data (len = %#lx).\n", get_label_data->offset + get_label_data->length, @@ -588,6 +595,13 @@ static void nvdimm_dsm_func_set_label_data(NVDIMMDevice *nvdimm, nvdimm_debug("Write Label Data: offset %#x length %#x.\n", set_label_data->offset, set_label_data->length); + if (!nvdimm->reserve_label_data) { + nvdimm_debug("write label request on the device without " + "label data reserved.\n"); + status = NVDIMM_DSM_STATUS_NOT_SUPPORTED; + goto exit; + } + if (nvdimm->label_size < set_label_data->offset + set_label_data->length) { nvdimm_debug("position %#x is beyond label data (len = %#lx).\n", set_label_data->offset + set_label_data->length, @@ -632,6 +646,12 @@ static void nvdimm_dsm_device(nvdimm_dsm_in *in, GArray *out) 1 << 4 /* Get Namespace Label Size */ | 1 << 5 /* Get Namespace Label Data */ | 1 << 6 /* Set Namespace Label Data */); + + /* no function support if the device does not have label data. */ + if (!nvdimm->reserve_label_data) { + cmd_list = cpu_to_le64(0); + } + build_append_int_noprefix(out, cmd_list, sizeof(cmd_list)); goto free; case 0x4 /* Get Namespace Label Size */: diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c index 825d664..27dbfbd 100644 --- a/hw/mem/nvdimm.c +++ b/hw/mem/nvdimm.c @@ -36,14 +36,15 @@ static void nvdimm_realize(DIMMDevice *dimm, Error **errp) { MemoryRegion *mr; NVDIMMDevice *nvdimm = NVDIMM(dimm); - uint64_t size; + uint64_t reserved_label_size, size; nvdimm->label_size = MIN_NAMESPACE_LABEL_SIZE; + reserved_label_size = nvdimm->reserve_label_data ? nvdimm->label_size : 0; mr = host_memory_backend_get_memory(dimm->hostmem, errp); size = memory_region_size(mr); - if (size <= nvdimm->label_size) { + if (size <= reserved_label_size) { char *path = object_get_canonical_path_component(OBJECT(dimm->hostmem)); error_setg(errp, "the size of memdev %s (0x%" PRIx64 ") is too small" " to contain nvdimm namespace label (0x%" PRIx64 ")", path, @@ -52,9 +53,12 @@ static void nvdimm_realize(DIMMDevice *dimm, Error **errp) } memory_region_init_alias(&nvdimm->nvdimm_mr, OBJECT(dimm), "nvdimm-memory", - mr, 0, size - nvdimm->label_size); - nvdimm->label_data = memory_region_get_ram_ptr(mr) + - memory_region_size(&nvdimm->nvdimm_mr); + mr, 0, size - reserved_label_size); + + if (reserved_label_size) { + nvdimm->label_data = memory_region_get_ram_ptr(mr) + + memory_region_size(&nvdimm->nvdimm_mr); + } } static void nvdimm_read_label_data(NVDIMMDevice *nvdimm, void *buf, @@ -97,10 +101,33 @@ static void nvdimm_class_init(ObjectClass *oc, void *data) nvc->write_label_data = nvdimm_write_label_data; } +static bool nvdimm_get_reserve_label_data(Object *obj, Error **errp) +{ + NVDIMMDevice *nvdimm = NVDIMM(obj); + + return nvdimm->reserve_label_data; +} + +static void +nvdimm_set_reserve_label_data(Object *obj, bool value, Error **errp) +{ + NVDIMMDevice *nvdimm = NVDIMM(obj); + + nvdimm->reserve_label_data = value; +} + +static void nvdimm_init(Object *obj) +{ + object_property_add_bool(obj, "reserve-label-data", + nvdimm_get_reserve_label_data, + nvdimm_set_reserve_label_data, NULL); +} + static TypeInfo nvdimm_info = { .name = TYPE_NVDIMM, .parent = TYPE_DIMM, .instance_size = sizeof(NVDIMMDevice), + .instance_init = nvdimm_init, .class_init = nvdimm_class_init, .class_size = sizeof(NVDIMMClass), }; diff --git a/include/hw/mem/nvdimm.h b/include/hw/mem/nvdimm.h index 7fdf591..b6ac266 100644 --- a/include/hw/mem/nvdimm.h +++ b/include/hw/mem/nvdimm.h @@ -63,6 +63,12 @@ struct NVDIMMDevice { /* public */ /* + * if we need to reserve memory region for NVDIMM label data at + * the end of backend memory? + */ + bool reserve_label_data; + + /* * the size of label data in NVDIMM device which is presented to * guest via __DSM "Get Namespace Label Size" command. */ -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html