From patchwork Mon Sep 11 04:41:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9946633 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4BE6B6035D for ; Mon, 11 Sep 2017 04:43:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41EE928AD7 for ; Mon, 11 Sep 2017 04:43:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3561228ADA; Mon, 11 Sep 2017 04:43:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C7ECA28AD7 for ; Mon, 11 Sep 2017 04:43:49 +0000 (UTC) Received: from localhost ([::1]:55351 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGZX-0000sS-8H for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Sep 2017 00:43:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56196) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGY5-0000ry-1o for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drGY1-0004VC-3k for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:17 -0400 Received: from mga04.intel.com ([192.55.52.120]:52456) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1drGY0-0004Si-QQ for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:13 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2017 21:42:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.42,376,1500966000"; d="scan'208"; a="1217079070" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga002.fm.intel.com with ESMTP; 10 Sep 2017 21:42:06 -0700 From: Haozhong Zhang To: qemu-devel@nongnu.org, xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:41:48 +0800 Message-Id: <20170911044157.15403-2-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170911044157.15403-1-haozhong.zhang@intel.com> References: <20170911044157.15403-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.120 Subject: [Qemu-devel] [RFC QEMU PATCH v3 01/10] nvdimm: do not intiailize nvdimm->label_data if label size is zero X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Haozhong Zhang , Xiao Guangrong , "Michael S. Tsirkin" , Konrad Rzeszutek Wilk , Igor Mammedov , Chao Peng , Dan Williams Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The memory region of vNVDIMM on Xen is a RAM memory region, so memory_region_get_ram_ptr() cannot be used in nvdimm_realize() to get a pointer to the label data area in that region. To be worse, it may abort QEMU. As Xen currently does not support labels (i.e. label size is 0) and every access in QEMU to labels is led by a label size check, let's not intiailize nvdimm->label_data if the label size is 0. Signed-off-by: Haozhong Zhang --- Cc: Xiao Guangrong Cc: "Michael S. Tsirkin" Cc: Igor Mammedov --- hw/mem/nvdimm.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c index 952fce5ec8..3e58538b99 100644 --- a/hw/mem/nvdimm.c +++ b/hw/mem/nvdimm.c @@ -87,7 +87,15 @@ static void nvdimm_realize(PCDIMMDevice *dimm, Error **errp) align = memory_region_get_alignment(mr); pmem_size = size - nvdimm->label_size; - nvdimm->label_data = memory_region_get_ram_ptr(mr) + pmem_size; + /* + * The memory region of vNVDIMM on Xen is not a RAM memory region, + * so memory_region_get_ram_ptr() below will abort QEMU. In + * addition that Xen currently does not support vNVDIMM labels + * (i.e. label_size is zero here), let's not initialize of the + * pointer to label data if the label size is zero. + */ + if (nvdimm->label_size) + nvdimm->label_data = memory_region_get_ram_ptr(mr) + pmem_size; pmem_size = QEMU_ALIGN_DOWN(pmem_size, align); if (size <= nvdimm->label_size || !pmem_size) {