From patchwork Mon Sep 11 04:41:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9946639 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 D6B716035D for ; Mon, 11 Sep 2017 04:43:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC71D28ABB for ; Mon, 11 Sep 2017 04:43:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C159328ABE; Mon, 11 Sep 2017 04:43:51 +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 0897728AD8 for ; Mon, 11 Sep 2017 04:43:50 +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 1drGY3-00063C-BX; Mon, 11 Sep 2017 04:42:15 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drGY1-00060D-KD for xen-devel@lists.xen.org; Mon, 11 Sep 2017 04:42:13 +0000 Received: from [85.158.137.68] by server-13.bemta-3.messagelabs.com id 89/B6-01916-42416B95; Mon, 11 Sep 2017 04:42:12 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrPLMWRWlGSWpSXmKPExsXS1tYhr6sisi3 S4N90IYslHxezODB6HN39mymAMYo1My8pvyKBNWPJ036WguV6Fd2P1RoY5yt3MXJyCAlUSmzt 72ICsSUEeCWOLJvBCmEHSHya2M3SxcgFVNPLKPHh6mZ2kASbgL7EiscHgYo4OEQEjCXabjqD1 DALrGSWmPH9PwtIjbBAmETT9Algg1gEVCUeHusE6+UVsJWYsOw0O8QCeYldbRfBajgF7CT6Wt 4zQxxkK7F25QOWCYy8CxgZVjFqFKcWlaUW6RqZ6SUVZaZnlOQmZuboGhoY6+WmFhcnpqfmJCY V6yXn525iBAZDPQMD4w7Ghr1+hxglOZiURHnfHd8SKcSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mC 967QtkghwaLU9NSKtMwcYFjCpCU4eJREeKNA0rzFBYm5xZnpEKlTjMYcxzZd/sPE0XHz7h8mI Za8/LxUKXHe6SClAiClGaV5cINg8XKJUVZKmJeRgYFBiKcgtSg3swRV/hWjOAejkjDvRZApPJ l5JXD7XgGdwgR0Cs+lLSCnlCQipKQaGB1sLvH99WD4PeP05zzGC0IfnTgkJ+iUaotttdW6aqv JvEdfYTPXuYv3MoudXsY0dEWc4Fv1z/kkg8OXtiUdjI4pzZcr5k9/E/X/UHKw2YvU5bM4Kt7d P7rOIHC5SvThEw+fP3Vc0mPKGBJ5Inj34l93re7qyL32T57w4UmkZnCBWDPvU48jdUosxRmJh lrMRcWJAMw4dS6SAgAA X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-8.tower-31.messagelabs.com!1505104925!114186094!3 X-Originating-IP: [134.134.136.31] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 33303 invoked from network); 11 Sep 2017 04:42:11 -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:11 -0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP; 10 Sep 2017 21:42:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.42,376,1500966000"; d="scan'208"; a="1217079098" 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:08 -0700 From: Haozhong Zhang To: qemu-devel@nongnu.org, xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:41:49 +0800 Message-Id: <20170911044157.15403-3-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 , Stefano Stabellini , Eduardo Habkost , "Michael S. Tsirkin" , Paolo Bonzini , Anthony Perard , Chao Peng , Dan Williams , Richard Henderson Subject: [Xen-devel] [RFC QEMU PATCH v3 02/10] hw/xen-hvm: create the hotplug memory region on Xen 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 guest physical address of vNVDIMM is allocated from the hotplug memory region, which is not created when QEMU is used as Xen device model. In order to use vNVDIMM for Xen HVM domains, this commit reuses the code for pc machine type to create the hotplug memory region for Xen HVM domains. Signed-off-by: Haozhong Zhang --- Cc: Paolo Bonzini Cc: Richard Henderson CC: Eduardo Habkost Cc: "Michael S. Tsirkin" Cc: Stefano Stabellini Cc: Anthony Perard --- hw/i386/pc.c | 86 ++++++++++++++++++++++++++++----------------------- hw/i386/xen/xen-hvm.c | 2 ++ include/hw/i386/pc.h | 1 + 3 files changed, 51 insertions(+), 38 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 21081041d5..5cbdce61a7 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1347,6 +1347,53 @@ void xen_load_linux(PCMachineState *pcms) pcms->fw_cfg = fw_cfg; } +void pc_memory_hotplug_init(PCMachineState *pcms, MemoryRegion *system_memory) +{ + MachineState *machine = MACHINE(pcms); + PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms); + ram_addr_t hotplug_mem_size = machine->maxram_size - machine->ram_size; + + if (!pcmc->has_reserved_memory || machine->ram_size >= machine->maxram_size) + return; + + if (memory_region_size(&pcms->hotplug_memory.mr)) { + error_report("hotplug memory region has been initialized"); + exit(EXIT_FAILURE); + } + + if (machine->ram_slots > ACPI_MAX_RAM_SLOTS) { + error_report("unsupported amount of memory slots: %"PRIu64, + machine->ram_slots); + exit(EXIT_FAILURE); + } + + 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(system_memory, pcms->hotplug_memory.base, + &pcms->hotplug_memory.mr); +} + void pc_memory_init(PCMachineState *pcms, MemoryRegion *system_memory, MemoryRegion *rom_memory, @@ -1398,44 +1445,7 @@ void pc_memory_init(PCMachineState *pcms, } /* initialize hotplug memory address space */ - if (pcmc->has_reserved_memory && - (machine->ram_size < machine->maxram_size)) { - ram_addr_t hotplug_mem_size = - machine->maxram_size - machine->ram_size; - - if (machine->ram_slots > ACPI_MAX_RAM_SLOTS) { - error_report("unsupported amount of memory slots: %"PRIu64, - machine->ram_slots); - exit(EXIT_FAILURE); - } - - 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(system_memory, pcms->hotplug_memory.base, - &pcms->hotplug_memory.mr); - } + pc_memory_hotplug_init(pcms, system_memory); /* Initialize PC system firmware */ pc_system_firmware_init(rom_memory, !pcmc->pci_enabled); diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index d9ccd5d0d6..90163e1a1b 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -235,6 +235,8 @@ static void xen_ram_init(PCMachineState *pcms, pcms->above_4g_mem_size); memory_region_add_subregion(sysmem, 0x100000000ULL, &ram_hi); } + + pc_memory_hotplug_init(pcms, sysmem); } void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr, diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 8226904524..b65c5dd5ec 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -249,6 +249,7 @@ void pc_memory_init(PCMachineState *pcms, MemoryRegion *system_memory, MemoryRegion *rom_memory, MemoryRegion **ram_memory); +void pc_memory_hotplug_init(PCMachineState *pcms, MemoryRegion *system_memory); qemu_irq pc_allocate_cpu_irq(void); DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus); void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,