From patchwork Mon Nov 2 09:13:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 7534951 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 582199F327 for ; Mon, 2 Nov 2015 09:20:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 73FAF205EB for ; Mon, 2 Nov 2015 09:20:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 78C09205E7 for ; Mon, 2 Nov 2015 09:20:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753131AbbKBJUX (ORCPT ); Mon, 2 Nov 2015 04:20:23 -0500 Received: from mga02.intel.com ([134.134.136.20]:42286 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753474AbbKBJUQ (ORCPT ); Mon, 2 Nov 2015 04:20:16 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP; 02 Nov 2015 01:19:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,234,1444719600"; d="scan'208";a="840963213" 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:19:53 -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 20/35] dimm: get mapped memory region from DIMMDeviceClass->get_memory_region Date: Mon, 2 Nov 2015 17:13:22 +0800 Message-Id: <1446455617-129562-21-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 Curretly, the memory region of backed memory is directly mapped to guest's address space, however, it is not true for nvdimm device This patch let dimm device realize this fact and use DIMMDeviceClass->get_memory_region method to get the mapped memory region Current code did not check the return value of get_memory_region as it assumed the backend memory of pc-dimm is always properly initialized, we make get_memory_region internally catch the case if something is wrong Signed-off-by: Xiao Guangrong --- hw/mem/dimm.c | 3 ++- hw/mem/pc-dimm.c | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/hw/mem/dimm.c b/hw/mem/dimm.c index 4a63409..498d380 100644 --- a/hw/mem/dimm.c +++ b/hw/mem/dimm.c @@ -377,8 +377,9 @@ static void dimm_get_size(Object *obj, Visitor *v, void *opaque, int64_t value; MemoryRegion *mr; DIMMDevice *dimm = DIMM(obj); + DIMMDeviceClass *ddc = DIMM_GET_CLASS(obj); - mr = host_memory_backend_get_memory(dimm->hostmem, errp); + mr = ddc->get_memory_region(dimm); value = memory_region_size(mr); visit_type_int(v, &value, name, errp); diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 38323e9..e6b6a9f 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -22,7 +22,17 @@ static MemoryRegion *pc_dimm_get_memory_region(DIMMDevice *dimm) { - return host_memory_backend_get_memory(dimm->hostmem, &error_abort); + Error *local_err = NULL; + MemoryRegion *mr; + + mr = host_memory_backend_get_memory(dimm->hostmem, &local_err); + + /* + * plug a pc-dimm device whose backend memory was not properly + * initialized? + */ + assert(!local_err && mr); + return mr; } static void pc_dimm_class_init(ObjectClass *oc, void *data)