From patchwork Mon Nov 2 09:13:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 7535091 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 54ECB9F327 for ; Mon, 2 Nov 2015 09:21:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 62E9B205E7 for ; Mon, 2 Nov 2015 09:21:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 477C22052C for ; Mon, 2 Nov 2015 09:21:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752299AbbKBJVd (ORCPT ); Mon, 2 Nov 2015 04:21:33 -0500 Received: from mga02.intel.com ([134.134.136.20]:55106 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752107AbbKBJVN (ORCPT ); Mon, 2 Nov 2015 04:21:13 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP; 02 Nov 2015 01:20:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,234,1444719600"; d="scan'208";a="840963551" Received: from xiaoreal1.sh.intel.com (HELO xiaoreal1.sh.intel.com.sh.intel.com) ([10.239.48.79]) by fmsmga002.fm.intel.com with ESMTP; 02 Nov 2015 01:20:24 -0800 From: Xiao Guangrong To: pbonzini@redhat.com, imammedo@redhat.com Cc: gleb@kernel.org, mtosatti@redhat.com, stefanha@redhat.com, mst@redhat.com, rth@twiddle.net, ehabkost@redhat.com, dan.j.williams@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, vsementsov@virtuozzo.com, eblake@redhat.com, Xiao Guangrong Subject: [PATCH v7 33/35] nvdimm: allow using whole backend memory as pmem Date: Mon, 2 Nov 2015 17:13:35 +0800 Message-Id: <1446455617-129562-34-git-send-email-guangrong.xiao@linux.intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1446455617-129562-1-git-send-email-guangrong.xiao@linux.intel.com> References: <1446455617-129562-1-git-send-email-guangrong.xiao@linux.intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 | 12 ++++++++++++ hw/mem/nvdimm.c | 43 ++++++++++++++++++++++++++++++++++++------- include/hw/mem/nvdimm.h | 6 ++++++ 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c index 2553be9..eab5d9c 100644 --- a/hw/acpi/nvdimm.c +++ b/hw/acpi/nvdimm.c @@ -531,6 +531,12 @@ static void nvdimm_dsm_func_label_size(NVDIMMDevice *nvdimm, GArray *out) static uint32_t nvdimm_rw_label_data_check(NVDIMMDevice *nvdimm, uint32_t offset, uint32_t length) { + if (!nvdimm->reserve_label_data) { + nvdimm_debug("read/write label request on the device without " + "label data reserved.\n"); + return NVDIMM_DSM_STATUS_NOT_SUPPORTED; + } + if (offset + length < offset) { nvdimm_debug("offset %#x + length %#x is overflow.\n", offset, length); @@ -637,6 +643,12 @@ static void nvdimm_dsm_device(NvdimmDsmIn *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 c310887..fde1c7f 100644 --- a/hw/mem/nvdimm.c +++ b/hw/mem/nvdimm.c @@ -39,14 +39,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, @@ -55,15 +56,19 @@ 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, uint64_t size, uint64_t offset) { - assert((nvdimm->label_size >= size + offset) && (offset + size > offset)); + assert(nvdimm->reserve_label_data && + (nvdimm->label_size >= size + offset) && (offset + size > offset)); memcpy(buf, nvdimm->label_data + offset, size); } @@ -75,7 +80,8 @@ static void nvdimm_write_label_data(NVDIMMDevice *nvdimm, const void *buf, DIMMDevice *dimm = DIMM(nvdimm); uint64_t backend_offset; - assert((nvdimm->label_size >= size + offset) && (offset + size > offset)); + assert(nvdimm->reserve_label_data && + (nvdimm->label_size >= size + offset) && (offset + size > offset)); memcpy(nvdimm->label_data + offset, buf, size); @@ -100,10 +106,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. */