From patchwork Mon Oct 19 00:54:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 531980 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42EC91402D1 for ; Mon, 19 Oct 2015 04:12:56 +1100 (AEDT) Received: from localhost ([::1]:34793 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnrVt-0003Sd-Uv for incoming@patchwork.ozlabs.org; Sun, 18 Oct 2015 13:12:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43018) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnrK9-0008V8-2m for qemu-devel@nongnu.org; Sun, 18 Oct 2015 13:00:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZnrK7-0000Ri-VB for qemu-devel@nongnu.org; Sun, 18 Oct 2015 13:00:45 -0400 Received: from mga09.intel.com ([134.134.136.24]:55490) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnrK7-0000RF-FN for qemu-devel@nongnu.org; Sun, 18 Oct 2015 13:00:43 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP; 18 Oct 2015 10:00:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,698,1437462000"; d="scan'208";a="583276057" Received: from xiaoreal1.sh.intel.com (HELO xiaoreal1.sh.intel.com.sh.intel.com) ([10.239.48.79]) by FMSMGA003.fm.intel.com with ESMTP; 18 Oct 2015 10:00:41 -0700 From: Xiao Guangrong To: pbonzini@redhat.com, imammedo@redhat.com Date: Mon, 19 Oct 2015 08:54:18 +0800 Message-Id: <1445216059-88521-33-git-send-email-guangrong.xiao@linux.intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1445216059-88521-1-git-send-email-guangrong.xiao@linux.intel.com> References: <1445216059-88521-1-git-send-email-guangrong.xiao@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.24 Cc: Xiao Guangrong , ehabkost@redhat.com, kvm@vger.kernel.org, mst@redhat.com, gleb@kernel.org, mtosatti@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, dan.j.williams@intel.com, rth@twiddle.net Subject: [Qemu-devel] [PATCH v4 32/33] nvdimm: allow using whole backend memory as pmem X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- hw/acpi/nvdimm.c | 21 +++++++++++++++++++++ hw/mem/nvdimm.c | 37 ++++++++++++++++++++++++++++++++----- include/hw/mem/nvdimm.h | 6 ++++++ 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c index 838a57e..f69bb39 100644 --- a/hw/acpi/nvdimm.c +++ b/hw/acpi/nvdimm.c @@ -647,6 +647,13 @@ nvdimm_dsm_cmd_get_label_data(NVDIMMDevice *nvdimm, dsm_in *in, GArray *out) nvdimm_debug("Read Label Data: offset %#x length %#x.\n", cmd_in->offset, cmd_in->length); + if (!nvdimm->reserve_label_data) { + nvdimm_debug("read label request on the device without " + "label data reserved.\n"); + status = DSM_STATUS_NOT_SUPPORTED; + goto exit; + } + if (nvdimm->label_size < cmd_in->offset + cmd_in->length) { nvdimm_debug("position %#x is beyond label data (len = %#lx).\n", cmd_in->offset + cmd_in->length, nvdimm->label_size); @@ -687,6 +694,14 @@ nvdimm_dsm_cmd_set_label_data(NVDIMMDevice *nvdimm, dsm_in *in, GArray *out) nvdimm_debug("Write Label Data: offset %#x length %#x.\n", cmd_in->offset, cmd_in->length); + + if (!nvdimm->reserve_label_data) { + nvdimm_debug("write label request on the device without " + "label data reserved.\n"); + status = DSM_STATUS_NOT_SUPPORTED; + goto exit; + } + if (nvdimm->label_size < cmd_in->offset + cmd_in->length) { nvdimm_debug("position %#x is beyond label data (len = %#lx).\n", cmd_in->offset + cmd_in->length, nvdimm->label_size); @@ -724,6 +739,12 @@ static void nvdimm_dsm_write_nvdimm(dsm_in *in, GArray *out) /* please refer to ACPI 6.0: 9.14.1 _DSM (Device Specific Method) */ case DSM_FUN_IMPLEMENTED: cmd_list = cpu_to_le64(DIMM_SUPPORT_FUN); + + /* no function support if the device does not have label data. */ + if (!nvdimm->reserve_label_data) { + cmd_list = cpu_to_le64(0UL); + } + g_array_append_vals(out, &cmd_list, sizeof(cmd_list)); goto free; case DSM_DEV_FUN_NAMESPACE_LABEL_SIZE: diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c index 2d121f6..cc69a3e 100644 --- a/hw/mem/nvdimm.c +++ b/hw/mem/nvdimm.c @@ -60,14 +60,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, @@ -76,9 +77,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_class_init(ObjectClass *oc, void *data) @@ -93,10 +97,33 @@ static void nvdimm_class_init(ObjectClass *oc, void *data) ddc->get_memory_region = nvdimm_get_memory_region; } +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, }; diff --git a/include/hw/mem/nvdimm.h b/include/hw/mem/nvdimm.h index c2dc635..10f85ec 100644 --- a/include/hw/mem/nvdimm.h +++ b/include/hw/mem/nvdimm.h @@ -55,6 +55,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. */