From patchwork Mon Oct 10 00:34:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9368845 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 8FF6F6048F for ; Mon, 10 Oct 2016 00:45:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DB6228B4D for ; Mon, 10 Oct 2016 00:45:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FB2928B51; Mon, 10 Oct 2016 00:45:04 +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 D2B6528B4D for ; Mon, 10 Oct 2016 00:45:03 +0000 (UTC) Received: from localhost ([::1]:46640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btOiF-000572-2a for patchwork-qemu-devel@patchwork.kernel.org; Sun, 09 Oct 2016 20:45:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btOYo-0006EM-7E for qemu-devel@nongnu.org; Sun, 09 Oct 2016 20:35:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btOYl-0003KT-Q3 for qemu-devel@nongnu.org; Sun, 09 Oct 2016 20:35:17 -0400 Received: from mga02.intel.com ([134.134.136.20]:20615) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btOYl-0003K0-GB for qemu-devel@nongnu.org; Sun, 09 Oct 2016 20:35:15 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP; 09 Oct 2016 17:35:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,469,1473145200"; d="scan'208";a="770697106" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.148]) by FMSMGA003.fm.intel.com with ESMTP; 09 Oct 2016 17:35:12 -0700 From: Haozhong Zhang To: qemu-devel@nongnu.org, xen-devel@lists.xensource.com Date: Mon, 10 Oct 2016 08:34:22 +0800 Message-Id: <20161010003423.4333-8-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161010003423.4333-1-haozhong.zhang@intel.com> References: <20161010003423.4333-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.20 Subject: [Qemu-devel] [RFC QEMU PATCH 7/8] xen-hvm: create hotplug memory region for HVM guest 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 , Stefano Stabellini , Xiao Guangrong , "Michael S. Tsirkin" , Konrad Rzeszutek Wilk , Anthony Perard , Igor Mammedov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Reserve the address space after guest physical memory for the hotplug memory region which is used by the existing implementation to place NVDIMM devices. Signed-off-by: Haozhong Zhang --- Cc: "Michael S. Tsirkin" Cc: Igor Mammedov Cc: Stefano Stabellini Cc: Anthony Perard Cc: xen-devel@lists.xensource.com --- hw/mem/pc-dimm.c | 5 ++++- xen-hvm.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 9e8dab0..69c5784 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -28,6 +28,7 @@ #include "sysemu/kvm.h" #include "trace.h" #include "hw/virtio/vhost.h" +#include "hw/xen/xen.h" typedef struct pc_dimms_capacity { uint64_t size; @@ -107,7 +108,9 @@ void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms, } memory_region_add_subregion(&hpms->mr, addr - hpms->base, mr); - vmstate_register_ram(vmstate_mr, dev); + if (!xen_enabled()) { + vmstate_register_ram(vmstate_mr, dev); + } numa_set_mem_node_id(addr, memory_region_size(mr), dimm->node); out: diff --git a/xen-hvm.c b/xen-hvm.c index 768c4c2..68833db 100644 --- a/xen-hvm.c +++ b/xen-hvm.c @@ -25,6 +25,7 @@ #include "sysemu/xen-mapcache.h" #include "trace.h" #include "exec/address-spaces.h" +#include "exec/ram_addr.h" #include #include @@ -201,6 +202,8 @@ static void xen_ram_init(PCMachineState *pcms, uint64_t user_lowmem = object_property_get_int(qdev_get_machine(), PC_MACHINE_MAX_RAM_BELOW_4G, &error_abort); + MachineState *machine = MACHINE(pcms); + PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms); /* Handle the machine opt max-ram-below-4g. It is basically doing * min(xen limit, user limit). @@ -252,6 +255,39 @@ static void xen_ram_init(PCMachineState *pcms, pcms->above_4g_mem_size); memory_region_add_subregion(sysmem, 0x100000000ULL, &ram_hi); } + + /* reserve hotplug memory region for vNVDIMM */ + if (pcmc->has_reserved_memory && + (machine->ram_size < machine->maxram_size)) { + ram_addr_t hotplug_mem_size = machine->maxram_size - machine->ram_size; + + if (QEMU_ALIGN_UP(machine->maxram_size, + TARGET_PAGE_SIZE) != machine->maxram_size) { + error_report("maximum memory size must by aligned to multiple of " + "%d bytes", TARGET_PAGE_SIZE); + exit(EXIT_FAILURE); + } + + pcms->hotplug_memory.base = + ROUND_UP(0x100000000ULL + pcms->above_4g_mem_size, 1ULL << 30); + + if (pcmc->enforce_aligned_dimm) { + /* size hotplug region assuming 1G page max alignment per slot */ + hotplug_mem_size += (1ULL << 30) * machine->ram_slots; + } + + if ((pcms->hotplug_memory.base + hotplug_mem_size) < + hotplug_mem_size) { + error_report("unsupported amount of maximum memory: " RAM_ADDR_FMT, + machine->maxram_size); + exit(EXIT_FAILURE); + } + + memory_region_init(&pcms->hotplug_memory.mr, OBJECT(pcms), + "hotplug-memory", hotplug_mem_size); + memory_region_add_subregion(sysmem, pcms->hotplug_memory.base, + &pcms->hotplug_memory.mr); + } } void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr,