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: 9946641 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 62E8E6035D for ; Mon, 11 Sep 2017 04:43:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59B1F28ABB for ; Mon, 11 Sep 2017 04:43:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4DD4128AD7; Mon, 11 Sep 2017 04:43:52 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0870128ABB for ; Mon, 11 Sep 2017 04:43:52 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drGXy-0005wt-WA; Mon, 11 Sep 2017 04:42:10 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drGXy-0005vL-1t for xen-devel@lists.xen.org; Mon, 11 Sep 2017 04:42:10 +0000 Received: from [85.158.137.68] by server-14.bemta-3.messagelabs.com id 59/30-01910-12416B95; Mon, 11 Sep 2017 04:42:09 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpgkeJIrShJLcpLzFFi42Jpa+uQ11UQ2RZ p8HKnjsWSj4tZHBg9ju7+zRTAGMWamZeUX5HAmjF1Vg9jwXWeihf7bzM3MG7k6mLk5BASqJRo +jCFHcSWEOCVOLJsBiuEHSBxtHMWUxcjF1BNL6PEwY+fWUASbAL6EiseHwQq4uAQETCWaLvpD FLDLLCBSWLD2wtsIDXCAqkSiw69BBvEIqAqMWvfaSYQm1fAVuLQ18VQy+QldrVdBKvhFLCT6G t5zwxxkK3E2pUPWCYw8i5gZFjFqFGcWlSWWqRrZKaXVJSZnlGSm5iZo2toYKyXm1pcnJiempO YVKyXnJ+7iREYDvUMDIw7GBv2+h1ilORgUhLlfXd8S6QQX1J+SmVGYnFGfFFpTmrxIUYZDg4l Cd67QtsihQSLUtNTK9Iyc4CBCZOW4OBREuGNAknzFhck5hZnpkOkTjEacxzbdPkPE0fHzbt/m IRY8vLzUqXEeaeDlAqAlGaU5sENgkXMJUZZKWFeRgYGBiGegtSi3MwSVPlXjOIcjErCvBdBpv Bk5pXA7XsFdAoT0Ck8l7aAnFKSiJCSamCszv8jbRZf17bw9hOX1IgTzznUZF9a/vmTsSWPT8Z 6oe//V+xCjBcFriv5RWzLyzyXwO5fX3O25J2e6+29tc2nw92TZ9oeCHCUChQOjd21g9+3bmt9 sel9XYsvL3hmPRJZ85J5oaKx+Hft3bzMtVWOagyfY/S/Z4U4TZqp1P6Kc/2ixoADgkosxRmJh lrMRcWJANzJHruTAgAA X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-8.tower-31.messagelabs.com!1505104925!114186094!2 X-Originating-IP: [134.134.136.31] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 33047 invoked from network); 11 Sep 2017 04:42:08 -0000 Received: from mga06.intel.com (HELO mga06.intel.com) (134.134.136.31) by server-8.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 11 Sep 2017 04:42:08 -0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP; 10 Sep 2017 21:42:08 -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> Cc: Haozhong Zhang , Xiao Guangrong , "Michael S. Tsirkin" , Igor Mammedov , Chao Peng , Dan Williams Subject: [Xen-devel] [RFC QEMU PATCH v3 01/10] nvdimm: do not intiailize nvdimm->label_data if label size is zero X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-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) {